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
Better support relocating NOTE sections/segments #218
Conversation
Hmm, looks like this won't be enough. The situation with multiple SHT_NOTE covered by a single PT_NOTE is common enough that apparently we hit it even in the test suite :-/
And indeed there is a single Not completely sure what the best way forward is -- maybe some kind of normalization step where we break up the |
SHT_NOTE sections can be mapped in memory by PT_NOTE segments. When rewriting an SHT_NOTE, attempt to also rewrite a matching segment if it exists. Note that an ELF can contain multiple SHT_NOTE sections, and a given PT_NOTE segment can theoretically map multiple contiguous sections. There are multiple ways this could be handled, the one picked here is to pre-normalize PT_NOTE segments so that a multi-section segment gets broken up into multiple separate segments instead. Also fix (or more like hack around) alignment issues with note sections. Keeping the original alignment value when possible is important because it determines how the data within the section needs to be parsed.
I implemented the normalization. Tests now pass, and as far as I can tell in my limited testing everything seems to be working fine. |
@domenkozar, can you take a look at this? This should fix NixOS/nixpkgs#91145. |
I'm not familiar with the codebase, maybe @edolstra can take a look. |
Does any of the tests exercise this segment? |
I also added a regression test in #225 |
Feel free to cherry pick. |
Thanks, I've merged #225 which includes this one! |
Fixes #217
SHT_NOTE sections can be mapped in memory by PT_NOTE segments. When
rewriting an SHT_NOTE, attempt to also rewrite a matching segment if it
exists.
Note that an ELF can contain multiple SHT_NOTE sections, and a given
PT_NOTE segment can theoretically map multiple contiguous sections. This
is not currently supported, but we fail loudly when encountering it.
Also fix (or more like hack around) alignment issues with note sections.
Keeping the original alignment value when possible is important because
it determines how the data within the section needs to be parsed.