[llvm] [llvm-objcopy][ELF] Add an option to remove notes (PR #118739)
Igor Kudrin via llvm-commits
llvm-commits at lists.llvm.org
Fri Dec 13 23:19:27 PST 2024
igorkudrin wrote:
> Please update the Command Guide documentation under llvm/docs with the new option.
Done
> Just some initial thoughts as I don't have time to go through this in much depth yet.
>
> I'm concerned that this approach seems to only work with notes in segments, when the option seems to apply reasonably to ET_REL objects too, where the notes are in sections only. Indeed, more generally llvm-objcopy is designed to work primarily with sections, with direct interactions with segments being very limited. I think it would more naturally fit with llvm-objcopy's design to work with note sections first. You could swap the section contents is the same way as other replace section operations work, so that much of the existing writing behaviour works unchanged.
>
> Clearly, something special would need to be done for PT_NOTE segments, especially those without sections. One option might be to create an artificial section that covers the whole segment (or any parts of the segment not covered by an existing section at least) so that the section-based approach outlined above would still work, then have special handling to adjust the file/memsz fields after the sections have been updated.
Thanks! I'll try to rework the patch using the sections-first approach.
> Somewhat related to the previous point, I'm concerned with how `updateSegmentData` might interact with `--remove-section` for sections in segments. The current approach of the latter is that removed section data is overwritten with null bytes, preserving the segment size. I understand that for a PT_NOTE this may not be quite so desirable, but I think we need to do something to prevent mixing the two behaviours, because what the end result should be is non-obvious. One way would be to emit an error if a note section/segment is touched by both --remove-section and --remove-note.
For the initial implementation, I plan to simply refuse to remove notes that reside in PT_LOAD segments. It seems that it is possible to actually remove data in non-load segments and update their contents and size accordingly. The sections in such segments and sections without segments (i.e. in ET_REL files) can also be updated in this way. Later, we can update the `--remove-section` command for non-load segments to work similarly.
https://github.com/llvm/llvm-project/pull/118739
More information about the llvm-commits
mailing list