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
elf: fix parsing of notes after patchelf mangling #3111
Conversation
We cannot rely on iterating on the notes via the note segment. Patchelf may move note sections into other segments, and worse yet, possibly leave the note segment standing with invalid data. Here we instead iterate over each section and (more) reliably gather the note information. There is some improvement that should be done on the patchelf side, as `readelf` complains on these binaries, and other issues have surfaced in the past (e.g. mesa in classic snaps). However, this will hopefully address snapcraft build-time issues with not only our patched files for classic snaps, but externally patched binaries that are being packaged. Add a couple of developer logs to indicate when we are parsing an ELF, so future investigations are easier when something explodes. Signed-off-by: Chris Patterson <chris.patterson@canonical.com>
Fixes SNAPCRAFT-1K4, SNAPCRAFT-1ET |
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.
Looks good. I think we can get away with scanning a single section though, rather than all sections though (assuming tests pass with that change).
snapcraft/internal/elf.py
Outdated
# Here we instead iterate over each section and (more) reliably | ||
# gather the note information. | ||
for section in elf.iter_sections(): | ||
if isinstance(section, elftools.elf.sections.NoteSection): |
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.
I was curious about what the best canonical way of determining the build ID is. I think this is the relevant part of the GDB source code:
It seems to use the following process:
- Find the section named
.note.gnu.build-id
- Read the contents of the section (this presumably makes sure its not a
SHT_NOBITS
section). - Look for a note with name "GNU" and type "NT_GNU_BUILD_ID". The description field of that note is the build ID.
So you are right to switch over to checking sections, but I think we can switch this to section = elf.get_section_by_name('.note.gnu-build-id')
, and work from there.
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.
Good idea, will do! Thanks!
Signed-off-by: Chris Patterson <chris.patterson@canonical.com>
We cannot rely on iterating on the notes via the note segment.
Patchelf may move note sections into other segments, and worse
yet, possibly leave the note segment standing with invalid data.
Here we instead iterate over each section and (more) reliably
gather the note information.
There is some improvement that should be done on the patchelf
side, as
readelf
complains on these binaries, and other issueshave surfaced in the past (e.g. mesa in classic snaps). However,
this will hopefully address snapcraft build-time issues with not
only our patched files for classic snaps, but externally patched
binaries that are being packaged.
Add a couple of developer logs to indicate when we are parsing
an ELF, so future investigations are easier when something explodes.
Signed-off-by: Chris Patterson chris.patterson@canonical.com
./runtests.sh static
?./runtests.sh tests/unit
?