Bug 23348 - binutils strip corrupts binaries produced by clang+lld+mingw-w64 toolchain
Summary: binutils strip corrupts binaries produced by clang+lld+mingw-w64 toolchain
Status: RESOLVED INVALID
Alias: None
Product: binutils
Classification: Unclassified
Component: binutils (show other bugs)
Version: 2.32
: P2 normal
Target Milestone: ---
Assignee: Not yet assigned to anyone
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2018-06-27 19:19 UTC by Jacek Caban
Modified: 2018-08-08 23:04 UTC (History)
1 user (show)

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


Attachments
test.exe (36.00 KB, application/x-ms-dos-executable)
2018-06-27 19:19 UTC, Jacek Caban
Details
test-stripped-by-binutils.exe (7.24 KB, application/x-ms-dos-executable)
2018-06-27 19:19 UTC, Jacek Caban
Details

Note You need to log in before you can comment on or make changes to this bug.
Description Jacek Caban 2018-06-27 19:19:18 UTC
Created attachment 11103 [details]
test.exe

The problem can be reproduced by toolchains using mingw-w64 with clang and lld such as:
https://github.com/mstorsjo/llvm-mingw
or attempts to build Mozilla with similar config:
https://bugzilla.mozilla.org/show_bug.cgi?id=1465798

Stripped binaries can't be ran on Windows and instead I get "is not a valid win32 application" error. Experimenting a bit, I found if we use -Wl,-s to let linker strip the binaries and then strip again with binutils, the resulting file is fine.

To reproduce:

$ cat test.c
#include <stdio.h>

int main() {
    printf("hello world\n");
    return 0;
}
$ x86_64-w64-mingw32-clang test.c -o test.exe
# test.exe works fine
$ x86_64-w64-mingw32-strip test.exe  -o test-stripped-by-binutils.exe
# test-stripped-by-binutils.exe is corrupted

I will attach test.exe and test-stripped-by-binutils.exe.
Comment 1 Jacek Caban 2018-06-27 19:19:59 UTC
Created attachment 11104 [details]
test-stripped-by-binutils.exe
Comment 2 Martin Storsjö 2018-07-15 20:44:30 UTC
This doesn't seem to be an issue with binutils, but with LLD; initial fix suggestions for LLD are at https://reviews.llvm.org/D49350 and https://reviews.llvm.org/D49351.
Comment 3 Martin Storsjö 2018-07-20 18:57:06 UTC
This should have been fixed now in LLD SVN r337598.
Comment 4 Jacek Caban 2018-08-08 23:04:47 UTC
Thanks! Resolving as invalid as it wasn't binutils bug after all.