This is an archive of the discontinued LLVM Phabricator instance.

[llvm-objcopy] Address post-commit reviews of D69093
ClosedPublic

Authored by MaskRay on Oct 28 2019, 12:58 PM.

Details

Summary
  • Improve comments.
  • Reorder the assignment to Obj.SectionNames before the symbol table creation code. Add a test.

Diff Detail

Event Timeline

MaskRay created this revision.Oct 28 2019, 12:58 PM
MaskRay updated this revision to Diff 226735.Oct 28 2019, 12:59 PM

Improve tests

grimar accepted this revision.Oct 29 2019, 12:34 AM

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.
A field value can never be a string table.
"does not reference a string table" would probably be better.

This revision is now accepted and ready to land.Oct 29 2019, 12:34 AM

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.

grimar added inline comments.Oct 29 2019, 2:42 AM
llvm/test/tools/llvm-objcopy/ELF/add-symbol-no-symtab.test
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.

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.

MaskRay updated this revision to Diff 226910.Oct 29 2019, 8:50 AM
MaskRay marked 5 inline comments as done.

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 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.

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;
}
jhenderson added inline comments.Oct 30 2019, 2:44 AM
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.

MaskRay updated this revision to Diff 227125.Oct 30 2019, 9:28 AM

test: make .shstrtab and .strtab explicit

MaskRay marked an inline comment as done.Oct 30 2019, 9:28 AM
This revision was automatically updated to reflect the committed changes.