This is the mail archive of the binutils@sourceware.org mailing list for the binutils project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

strip sometimes corrupts pe-i386 or pe-x86_64 executables


Hello,

Recently I've found that strip can trash PE executables in some situations. I'm
using strip 2.24.51.20140703 from TDM-GCC distribution, but I've checked also on
strip 2.25 from Cygwin and strip 2.23.2 from MinGW32, and it suffers from the
same issue.

The source code doesn't really matter, but I was testing it on this program:

    $ cat test.cpp
    #include <iostream>

    int main() {
        std::cout << "works\n";
        return 0;
    }

Compilation of the program is standard. The `-gdwarf-4` option isn't the cause
of the problem, because removing it doesn't fix the issue:

    $ g++ -gdwarf-4 -O3 test.cpp -o test

Then I would like to copy debug symbols to external file:

    $ objcopy --only-keep-debug test.exe test.debug

Next step is adding a `gnu_debuglink` information to the executable:

    $ objcopy --add-gnu-debuglink=test.debug test.exe

Up to now, the executable works:

    $ ./test.exe
    works

But, when trying to remove now unnecessary debug symbols from the executable,
strip corrupts the executable:

    $ strip test.exe
    $ ./test.exe
    -bash: ./test.exe: nie moÅna uruchomiÄ pliku binarnego: Exec format error

When running the executable from Windows' explorer, the error box says that
"test.exe is not a valid Win32 application."

However, it appears that strip is working correctly before adding the
`gnu_debuglink` section. So, simply switching two last steps so that strip will
be executed first, resolves the issue:

    $ strip test.exe
    $ objcopy --add-gnu-debuglink=test.debug test.exe
    $ ./test.exe
    works

Should strip behave this way? If the core of the problem is on my side,
shouldn't strip produce an error message instead of corrupting the executable
file?


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]