-
-
Notifications
You must be signed in to change notification settings - Fork 473
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Allow multiple modifications in same call #361
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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@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! |
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.
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