patchelf icon indicating copy to clipboard operation
patchelf copied to clipboard

stripping debug symbols after running patchelf --no-default-lib corrupts executable

Open clopez opened this issue 3 years ago • 0 comments

This is related to #145 but I think is a different issue, since in this case the problem happens when patchelf runs with the option --no-default-lib (but if that option is not passed then the issue can't be reproduced) and #145 was an issue when passing --set-rpath $myrpath to patchelf, which is fixed.

This was tested with patchelf built from master as of today (8f5ac59adec499a4cbb871ffe935f944037b8468)

  1. Download the attached mb.zip file that contains an ELF binary inside and uncompress it (FYI: this binary was built with clang)
  2. Check that you can run ldd over the binary and it tries to find several libraries on the system
$ ldd MiniBrowser
  • output: http://sprunge.us/FJ6XSH
  1. Run over it this patchelf command
patchelf --no-default-lib MiniBrowser
  1. Run again ldd and check how now it doesn't find any library because NODEFLIB is set
$ ldd MiniBrowser
  • output: http://sprunge.us/ZBbBBc
  1. Strip the binary, you can see how strip prints a warning
$ strip -g MiniBrowser 
strip: stv8EN8Y: warning: allocated section `.dynstr' not in segment
  1. Run ldd again, the binary is corrupted
$ ldd MiniBrowser
./MiniBrowser: ./MiniBrowser: no version information available (required by ./MiniBrowser)
./MiniBrowser: ./MiniBrowser: no version information available (required by ./MiniBrowser)
./MiniBrowser: ./MiniBrowser: no version information available (required by ./MiniBrowser)
	linux-vdso.so.1 (0x00007ffe8e9fe000)

If the order of the commands is inverted (first strip and then patchelf) the issue doesn't happen.

clopez avatar Mar 28 '22 23:03 clopez