Skip to content
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

Fix bug in walking .gnu.version_r linked list #86

Merged
merged 1 commit into from
Apr 28, 2016

Conversation

njsmith
Copy link
Contributor

@njsmith njsmith commented Apr 2, 2016

When writing the code to teach --replace-needed to modify the
.gnu.version_r section (gh-85), I misunderstood how the ->vn_next
pointers in the Elf_Verneed structs are supposed to be interpreted: I
thought they gave an offset from the beginning of the section, but in
fact they give an offset relative to the current struct. The resulting
bug was very odd: generally, patchelf would complete without signalling
an error, but it would only successfully replace filenames that occurred
as either the first or second entries in the .gnu.version_r section,
while the third or later entries would be left untouched.

This commit fixes the interpretation of the ->vn_next pointers, so that
now --replace-needed should work correctly even on ELF files with more
than two version needed structs.

Thanks to @matthew-brett for finding the bug / providing a test case,
and to @rmcgibbo for helping me diagnose it.

When writing the code to teach --replace-needed to modify the
.gnu.version_r section (NixOSgh-85), I misunderstood how the ->vn_next
pointers in the Elf_Verneed structs are supposed to be interpreted: I
thought they gave an offset from the beginning of the section, but in
fact they give an offset relative to the current struct. The resulting
bug was very odd: generally, patchelf would complete without signalling
an error, but it would only successfully replace filenames that occurred
as either the first or second entries in the .gnu.version_r section,
while the third or later entries would be left untouched.

This commit fixes the interpretation of the ->vn_next pointers, so that
now --replace-needed should work correctly even on ELF files with more
than two version needed structs.

Thanks to @matthew-brett for finding the bug / providing a test case,
and to @rmcgibbo for helping me diagnose it.
@cstrahan
Copy link

cstrahan commented Apr 2, 2016

@njsmith Awesome work! You're work on improving the correctness of patchelf is greatly appreciated. Bugs aside, I hope it's proven useful in wheels.

@njsmith
Copy link
Contributor Author

njsmith commented Apr 2, 2016

@cstrahan: thanks! And yes, it's proven very useful; it's an integral part of the auditwheel tool that we use to make wheels self contained, and we probably couldn't practically make Linux wheels work without it. In fact I like it so much that I wrote my own version for PE files :-) (https://github.com/njsmith/redll)

@njsmith
Copy link
Contributor Author

njsmith commented Apr 15, 2016

Ping. We've been shipping this in the manylinux docker image for a few weeks now and it seems to be working well.

@cstrahan
Copy link

@edolstra Can we merge this?

@edolstra edolstra merged commit 927b332 into NixOS:master Apr 28, 2016
@edolstra
Copy link
Member

Thanks, merged!

@domenkozar
Copy link
Member

Really glad Python community is slowly moving to Nix :-)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants