- Improve comments.
- Reorder the assignment to Obj.SectionNames before the symbol table creation code. Add a test.
Details
Diff Detail
- Repository
- rG LLVM Github Monorepo
Event Timeline
LGTM with a nit, put please wait for others too.
llvm/test/tools/llvm-objcopy/ELF/add-symbol-no-symtab.test | ||
---|---|---|
101 | I'd suggest to use "Symbols: []" to emphasise we just want to create a ".symtab". Up to you. | |
llvm/tools/llvm-objcopy/ELF/Object.cpp | ||
1555 | I see you just moved this part, so comment below is FTR. |
I think this part of one of my comments may have been missed, as I don't see a response to it anywhere:
Is there anything stopping the section header string table having the SHF_ALLOC bit set however? If not, we need a separate test for this case, I believe.
I had another thought about this, and I wonder if we might mess things up if we try to change the section names when the section header string table has SHF_ALLOC set. But this seems unlikely, so is probably a non-issue.
llvm/test/tools/llvm-objcopy/ELF/add-symbol-no-symtab.test | ||
---|---|---|
35 | Do you think this check should also have an --implicit-check-not=.strtab? | |
96–100 | This may be me being forgetful, but I don't follow how this YAML will generate anything different from the previous YAML doc. Also, the comment for this test case says that it is checking that we prefer the string table that is not the section header table, but the test itself checks that we add it to the section header string table when the string table is not there. We need both test cases, but I'm under the impression that the latter is already covered by the previous test. |
llvm/test/tools/llvm-objcopy/ELF/add-symbol-no-symtab.test | ||
---|---|---|
96–100 |
Previous YAML does not specify sections. .strtab will be created implicitly before .shstrtab: std::vector<StringRef> ImplicitSections; if (Doc.Symbols) ImplicitSections.push_back(".symtab"); ImplicitSections.insert(ImplicitSections.end(), {".strtab", ".shstrtab"}); if (!Doc.DynamicSymbols.empty()) ImplicitSections.insert(ImplicitSections.end(), {".dynsym", ".dynstr"}); // Insert placeholders for implicit sections that are not // defined explicitly in YAML. for (StringRef SecName : ImplicitSections) { if (DocSections.count(SecName)) continue; std::unique_ptr<ELFYAML::Section> Sec = std::make_unique<ELFYAML::Section>( ELFYAML::Section::SectionKind::RawContent, true /*IsImplicit*/); Sec->Name = SecName; Doc.Sections.push_back(std::move(Sec)); } This YAML specifies .shstrtab and strtab. These are not created implicitly and yaml2obj hence will follow the order requested. |
Address review comments
llvm/test/tools/llvm-objcopy/ELF/add-symbol-no-symtab.test | ||
---|---|---|
96–100 | Yes, the first test checks the order .strtab followed by .shstrtab while the second test checks the order .shstrtab followed by .strtab . You may see another example in yaml2obj/section-ordering.yaml . | |
llvm/tools/llvm-objcopy/ELF/Object.cpp | ||
1555 | The substring is not a string table occurs twice aside from here in this file. I haven't looked into it closely but one or both may be difficult to test. Improved the error message just in this place. |
I agree that changing section names may be delicate. Let's stick with:
if (Sec.Type == ELF::SHT_STRTAB && !(Sec.Flags & SHF_ALLOC)) { StrTab = static_cast<StringTableSection *>(&Sec); // Prefer a string table that is not the section header string table, if // such a table exists. if (Obj.SectionNames != &Sec) break; }
llvm/test/tools/llvm-objcopy/ELF/add-symbol-no-symtab.test | ||
---|---|---|
96–100 | Okay, that makes sense. It might be a good idea to add a comment to that effect. Or just force the first case to be in the other order rather than relying on the implicit yaml2obj ordering. |
Do you think this check should also have an --implicit-check-not=.strtab?