When a SHT_GROUP section is removed, but other sections of the group are kept, the SHF_GROUP flag of these sections should be dropped, otherwise the resulting ELF file will be malformed.
Details
Diff Detail
Event Timeline
The code looks good. We have another issue: https://bugs.llvm.org/show_bug.cgi?id=46064 (if a member is deleted, SHT_GROUP content needs a change)
GNU objcopy was fixed by https://sourceware.org/git/?p=binutils-gdb.git;a=commit;h=30288845d67c64d07905c1e4ca9de4768d3b2dd8
llvm/test/tools/llvm-objcopy/ELF/remove-group-section.test | ||
---|---|---|
1 ↗ | (On Diff #265983) | I'd prefer remove-section-group.test because the operation is remove-section. (SHT_GROUP is referred to as "section group") |
29 ↗ | (On Diff #265983) | Sections [ this line can be deleted |
31 ↗ | (On Diff #265983) | Indent keys. See other files for examples |
Sounds reasonable to me. I don't think this behaviour (removing .group sections) has been considered before. Some testing related to that behaviour that we should probably have, but which is outside the scope of this change is to show that you can remove a signature symbol, if the .group section has been removed (assuming that it works of course). Something else that I'm wondering perhaps DOES belong with this change - should we test that if you remove a group section in the same run as removing a member of that group no problems occur? I could imagine an issue with dangling pointers if we didn't do things properly.
llvm/test/tools/llvm-objcopy/ELF/remove-section-group.test | ||
---|---|---|
7–8 | Nit: use '##' for comments for easy distinction from test commands. | |
30 | Up to you, but you can probably also delete this line too, as you are only dumping sections. |
As far as I can see, the symbol is removed.
Something else that I'm wondering perhaps DOES belong with this change - should we test that if you remove a group section in the same run as removing a member of that group no problems occur? I could imagine an issue with dangling pointers if we didn't do things properly.
The objects which represent the sections are not actually deleted, just moved to Object::RemovedSections to be used later in ELFWriter<ELFT>::writeSegmentData(). Thus, there are no dangling pointers.
Indeed, that's the current state of the code, so it should work, but it won't necessarily apply in the event of a future refactor. Anyway, LGTM, since this is not really part of this change.
llvm/test/tools/llvm-objcopy/ELF/remove-section-group.test | ||
---|---|---|
30 | Move CHECK: before the YAML text as people seem to think the following order RUN: CHECK: source is easier to read. |
Nit: use '##' for comments for easy distinction from test commands.