Repository navigation
Allow multiple modifications in same call - #361
Conversation
`patchelf` previously would incorrectly patch the ELF header if it was called with multiple changes at once such as _add_ & _replace_. In order to support that, rewrite the sections in between each section modification. Fix NixOS#359
| # We have to set the soname on these libraries | ||
| ${PATCHELF} --set-soname libbar.so ./libbar.so |
There was a problem hiding this comment.
Interestingly discussed with @trws that if the shared object doesn't have a DT_SONAME, it won't make use of the previously discovered loaded shared object.
This was discovered while writing this test. You can see below that libbar.so was not found, even though its set with an absolute path.
ldd ~/code/github.com/NixOS/patchelf/tests/scratch/replace-add-needed/simple
linux-vdso.so.1 (0x00007ffc90565000)
/home/fmzakari/code/github.com/NixOS/patchelf/tests/scratch/replace-add-needed/libbar.so (0x00007f532a4c4000)
/home/fmzakari/code/github.com/NixOS/patchelf/tests/scratch/replace-add-needed/libfoo.so (0x00007f532a4bf000)
libc.so.6 => /lib/x86_64-linux-gnu/libc.so.6 (0x00007f532a2da000)
/nix/store/jsp3h3wpzc842j0rz61m5ly71ak6qgdn-glibc-2.32-54/lib/ld-linux-x86-64.so.2 => /lib64/ld-linux-x86-64.so.2 (0x00007f532a4cb000)
libbar.so => not found
d66caff to
e268662
Compare
|
The test error for musl looks legit |
|
@Mic92 ah -- my test tries to grep for glibc ! I didn't know we build musl libraries lol. |
2284a70 to
3e60d5e
Compare
Made changes according to feedback from @Mic92 such as moving the `rewriteSections` inline into every method. Improved `replace-add-needed.sh` to work with musl libc
3e60d5e to
d02a3ec
Compare
|
Okay I started alpine locally and see that the issue is that the musl linker is working differently than glibc. It's failing to skip the This is quite interesting; tagging @trws |
| # Make the NEEDED in libfoo the same as simple | ||
| # This is a current "bug" in musl | ||
| # https://www.openwall.com/lists/musl/2021/12/21/1 | ||
| ${PATCHELF} --replace-needed libbar.so $(readlink -f ./libbar.so) ./libfoo.so |
There was a problem hiding this comment.
@Mic92 please read the linked mailing issue I opened for why we have to do this for musl
https://www.openwall.com/lists/musl/2021/12/21/1
This should now succeed on musl and glibc proving the fix of the bug.
|
Thanks! |
patchelfpreviously would incorrectly patch the ELF header if it was called with multiple changes at once such as add & replace.In order to support that, rewrite the sections in between each section modification.
Please see the issue for the bug and here is now the fix:
Fix #359
Thank you @trws for the idea of the fix.
CC @Mic92