Repository navigation
Fix shared library corruption when rerunning patchelf - #202
Conversation
When running patchelf on some existing patchelf'd binaries to change to longer RPATHS, ldd would report the binaries as invalid. The output of objdump -x on those libraryies should show the top of the .dynamic section is getting trashed, something like: 0x600000001 0x0000000000429000 0x335000 0x0000000000335000 0xc740 0x000000000000c740 0x1000 0x0000000000009098 SONAME libglib-2.0.so.0 (which should be RPATH and DT_NEEDED entries) This was tracked down to the code which injects the PT_LOAD section. The issue is that if the program headers were previously relocated to the end of the file which was how patchelf operated previously, the relocation code wouldn't work properly on a second run as it now assumes they're located after the elf header. This change forces them back to immediately follow the elf header which is where the code has made space for them. Should fix NixOS#170 and NixOS#192 Signed-off-by: Richard Purdie <[email protected]>
|
@rpurdie Thank you! Any chance to add a test case in tests directory? |
|
The easiest test case would be to check in the shared lib from the testcase in #170, run patchelf against it as described and check ldd finds the binary is still valid. Not sure if you can add that lib though and creating such a lib from sources would be a much more involved exercise. |
|
I'm going to merge this and bump patchelfUnstable in nixpkgs. Then we can build all packages and check for possible regressions. |
|
🎉 ❤️ Thank you very much for this fix, Richard! |
|
@domenkozar Is there a stable release of |
|
Yes, you can follow NixOS/nixpkgs#69213 as we rebuild all nix packages to verify there are no regressions this time. Once that's done we'll make a release. |
When running patchelf on some existing patchelf'd binaries to change to longer
RPATHS, ldd would report the binaries as invalid. The output of objdump -x on
those libraryies should show the top of the .dynamic section is getting trashed,
something like:
0x600000001 0x0000000000429000
0x335000 0x0000000000335000
0xc740 0x000000000000c740
0x1000 0x0000000000009098
SONAME libglib-2.0.so.0
(which should be RPATH and DT_NEEDED entries)
This was tracked down to the code which injects the PT_LOAD section.
The issue is that if the program headers were previously relocated to the end
of the file which was how patchelf operated previously, the relocation code
wouldn't work properly on a second run as it now assumes they're located after
the elf header. This change forces them back to immediately follow the elf
header which is where the code has made space for them.
Should fix #170
and #192
Signed-off-by: Richard Purdie [email protected]