Bug 21861 - mingw-w64 binutils built on x86_64-musl segfaults when compiling zlib.
Summary: mingw-w64 binutils built on x86_64-musl segfaults when compiling zlib.
Status: RESOLVED FIXED
Alias: None
Product: binutils
Classification: Unclassified
Component: binutils (show other bugs)
Version: 2.28
: P2 normal
Target Milestone: ---
Assignee: Not yet assigned to anyone
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2017-07-28 22:54 UTC by ntzrmtthihu777
Modified: 2017-09-05 14:33 UTC (History)
1 user (show)

See Also:
Host: x86_64-gentoo-linux-musl
Target: x86_64-w64-mingw32
Build:
Last reconfirmed:


Attachments
fix taken from midipix (244 bytes, patch)
2017-07-29 00:29 UTC, ntzrmtthihu777
Details | Diff

Note You need to log in before you can comment on or make changes to this bug.
Description ntzrmtthihu777 2017-07-28 22:54:06 UTC
An odd corner case. After setting up a x86_64-w64-mingw32 toolchain
(binutils-2.28, gcc-7.1.0, mingw-w64 5.0.2) on gentoo musl, attempting
to `x86_64-w64-mingw32-emerge sys-libs/zlib` results in a segfault
upon invoking the resource compiler as such:
`x86_64-w64-mingw32-windres --define GCC_WINDRES -o zlibrc.o win32/zlib1.rc`

Testing with the bare compilers ouside of emerge is reproducable.
After asking about it in irc.freenode.net/#musl we narrowed it down
to iconv issues, whereupon user midipix pointed me at the following patch:
http://git.midipix.org/cgit.cgi/ports/chainport/tree/binutils-2.24.51.midipix.patch
Reducing this down to https://bpaste.net/show/089908e214c3 was enough to
fix the issue. Applying this patch on a glibc system's mingw-w64 toolchain
does not affect the compilation, and as this is a windows only tool
it would not affect any non-windows system/compiler toolchain.
Comment 1 ntzrmtthihu777 2017-07-29 00:24:41 UTC
Original backtrace:
https://bpaste.net/show/84d29f3b5921
Comment 2 ntzrmtthihu777 2017-07-29 00:29:09 UTC
Created attachment 10291 [details]
fix taken from midipix

Suggested in irc.freenode.net/#musl by user midipix, works on musl and doesn't break glibc.
Comment 3 cvs-commit@gcc.gnu.org 2017-07-31 09:32:46 UTC
The master branch has been updated by Nick Clifton <nickc@sourceware.org>:

https://sourceware.org/git/gitweb.cgi?p=binutils-gdb.git;h=54387c7fe27848e41a51c1eccc6a24b3d6d3441f

commit 54387c7fe27848e41a51c1eccc6a24b3d6d3441f
Author: Marty Plummer <ntzrmtthihu777@gmail.com>
Date:   Mon Jul 31 10:31:18 2017 +0100

    Fix compiling zlib using x86_64-musl.
    
    	PR 21861
    	* winduni.c (codepages): Use cp1252 for codepage 0.
Comment 4 Nick Clifton 2017-07-31 09:35:02 UTC
Hi Marty,

  Thanks very much for reporting this problem, and for providing such a nice
  simple fix.  I have checked your patch in, along with the changelog entry 
  below.

Cheers
  Nick

binutils/ChangeLog
2017-07-31  Marty Plummer  <ntzrmtthihu777@gmail.com>

	PR 21861
	* winduni.c (codepages): Use cp1252 for codepage 0.
Comment 5 ntzrmtthihu777 2017-07-31 10:14:49 UTC
(In reply to Nick Clifton from comment #4)
> Hi Marty,
> 
>   Thanks very much for reporting this problem, and for providing such a nice
>   simple fix.  I have checked your patch in, along with the changelog entry 
>   below.
> 
> Cheers
>   Nick
> 
> binutils/ChangeLog
> 2017-07-31  Marty Plummer  <ntzrmtthihu777@gmail.com>
> 
> 	PR 21861
> 	* winduni.c (codepages): Use cp1252 for codepage 0.

Thank you for applying the fix. Damn, I should have sent this patch
with my netz.kernel@gmail.org, I typically use that one for 'major'
project contributions but I had not set up access to that email on
my new musl install.
Comment 6 ntzrmtthihu777 2017-07-31 10:29:46 UTC
erm, netz.kernel@gmail.com wtf were my fingers doing :/
Comment 7 cvs-commit@gcc.gnu.org 2017-09-05 14:33:25 UTC
The binutils-2_29-branch branch has been updated by Nick Clifton <nickc@sourceware.org>:

https://sourceware.org/git/gitweb.cgi?p=binutils-gdb.git;h=64aa1246572306b72dc479b46d13ff749b0c3236

commit 64aa1246572306b72dc479b46d13ff749b0c3236
Author: Nick Clifton <nickc@redhat.com>
Date:   Tue Sep 5 15:32:04 2017 +0100

    Import patches from mainline to fix minor binutils bugs:
    
    	PR 21861
    	* winduni.c (codepages): Use cp1252 for codepage 0.
    
    	PR 21813
    	* rddbg.c (read_symbol_stabs_debugging_info): Check for an empty
    	string whilst concatenating symbol names.
    
    	PR 21909
    	* prdbg.c (pr_int_type): Increase size of local string buffer.
    	(pr_float_type): Likewise.
    	(pr_bool_type): Likewise.
    
    	PR 21820
    	* readelf.c (dump_section_as_strings): Do not fail if the section
    	was empty.
    	(dump_section_as_bytes): Likewise.
    
    	PR 21990
    	* readelf.c (process_version_sections <SHT_GNU_verneed>): Check
    	for invalid vn_next field before adding to idx.  Use unsigned
    	long for index vars.  Move index checks.
    	<SHT_GNU_verdef>: Likewise for vd_next.
    
    	PR 21994
    	* readelf.c (process_version_sections <SHT_GNU_verdef>): Check
    	vd_aux and vda_next for sanity.  Delete "end".  Correct overflow
    	checks.
    	(process_version_sections <SHT_GNU_verneed>): Correct overflow
    	check.  Don't report invalid vna_next on overflow.  Do report
    	invalid vna_next on size less than aux info.