[llvm] [llvm-objcopy][ELF] Add an option to remove notes (PR #118739)

James Henderson via llvm-commits llvm-commits at lists.llvm.org
Thu Dec 12 01:32:15 PST 2024


https://github.com/jh7370 commented:

Please update the Command Guide documentation under llvm/docs with the new option.

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.

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.

https://github.com/llvm/llvm-project/pull/118739


More information about the llvm-commits mailing list