[llvm] r366785 - [yaml2elf] - Treat the SHN_UNDEF section as kind of regular section.
George Rimar via llvm-commits
llvm-commits at lists.llvm.org
Tue Jul 23 00:38:44 PDT 2019
Author: grimar
Date: Tue Jul 23 00:38:44 2019
New Revision: 366785
URL: http://llvm.org/viewvc/llvm-project?rev=366785&view=rev
Log:
[yaml2elf] - Treat the SHN_UNDEF section as kind of regular section.
We have a logic that adds a few sections implicitly.
Though the SHT_NULL section with section number 0
is an exception.
In D64913 I want to teach yaml2obj to redefine the null section.
And in this patch I add it to the sections list,
to make it kind of a regular section.
Differential revision: https://reviews.llvm.org/D65087
Modified:
llvm/trunk/test/tools/yaml2obj/duplicate-section-names.test
llvm/trunk/tools/yaml2obj/yaml2elf.cpp
Modified: llvm/trunk/test/tools/yaml2obj/duplicate-section-names.test
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/test/tools/yaml2obj/duplicate-section-names.test?rev=366785&r1=366784&r2=366785&view=diff
==============================================================================
--- llvm/trunk/test/tools/yaml2obj/duplicate-section-names.test (original)
+++ llvm/trunk/test/tools/yaml2obj/duplicate-section-names.test Tue Jul 23 00:38:44 2019
@@ -29,7 +29,7 @@ Sections:
## sections with equal names and suffixes.
# RUN: not yaml2obj --docnum=2 %s 2>&1 | FileCheck %s --check-prefix=CASE2
-# CASE2: error: Repeated section name: '.foo [1]' at YAML section number 1.
+# CASE2: error: Repeated section name: '.foo [1]' at YAML section number 2.
--- !ELF
FileHeader:
@@ -48,7 +48,7 @@ Sections:
## names are equal.
# RUN: not yaml2obj --docnum=3 %s 2>&1 | FileCheck %s --check-prefix=CASE3
-# CASE3: error: Repeated section name: '.foo' at YAML section number 1.
+# CASE3: error: Repeated section name: '.foo' at YAML section number 2.
--- !ELF
FileHeader:
Modified: llvm/trunk/tools/yaml2obj/yaml2elf.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/tools/yaml2obj/yaml2elf.cpp?rev=366785&r1=366784&r2=366785&view=diff
==============================================================================
--- llvm/trunk/tools/yaml2obj/yaml2elf.cpp (original)
+++ llvm/trunk/tools/yaml2obj/yaml2elf.cpp Tue Jul 23 00:38:44 2019
@@ -192,6 +192,12 @@ ELFState<ELFT>::ELFState(ELFYAML::Object
if (!D->Name.empty())
DocSections.insert(D->Name);
+ // Insert SHT_NULL section implicitly.
+ Doc.Sections.insert(
+ Doc.Sections.begin(),
+ llvm::make_unique<ELFYAML::Section>(
+ ELFYAML::Section::SectionKind::RawContent, /*IsImplicit=*/true));
+
std::vector<StringRef> ImplicitSections = {".symtab", ".strtab", ".shstrtab"};
if (!Doc.DynamicSymbols.empty())
ImplicitSections.insert(ImplicitSections.end(), {".dynsym", ".dynstr"});
@@ -317,13 +323,11 @@ bool ELFState<ELFT>::initSectionHeaders(
ContiguousBlobAccumulator &CBA) {
// Ensure SHN_UNDEF entry is present. An all-zero section header is a
// valid SHN_UNDEF entry since SHT_NULL == 0.
- SHeaders.resize(Doc.Sections.size() + 1);
- zero(SHeaders[0]);
+ SHeaders.resize(Doc.Sections.size());
- for (size_t I = 1; I < Doc.Sections.size() + 1; ++I) {
+ for (size_t I = 1; I < Doc.Sections.size(); ++I) {
Elf_Shdr &SHeader = SHeaders[I];
- zero(SHeader);
- ELFYAML::Section *Sec = Doc.Sections[I - 1].get();
+ ELFYAML::Section *Sec = Doc.Sections[I].get();
// We have a few sections like string or symbol tables that are usually
// added implicitly to the end. However, if they are explicitly specified
@@ -944,13 +948,12 @@ bool ELFState<ELFT>::writeSectionContent
}
template <class ELFT> bool ELFState<ELFT>::buildSectionIndex() {
- for (unsigned i = 0, e = Doc.Sections.size(); i != e; ++i) {
- StringRef Name = Doc.Sections[i]->Name;
+ for (unsigned I = 1, E = Doc.Sections.size(); I != E; ++I) {
+ StringRef Name = Doc.Sections[I]->Name;
DotShStrtab.add(dropUniqueSuffix(Name));
- // "+ 1" to take into account the SHT_NULL entry.
- if (!SN2I.addName(Name, i + 1)) {
+ if (!SN2I.addName(Name, I)) {
WithColor::error() << "Repeated section name: '" << Name
- << "' at YAML section number " << i << ".\n";
+ << "' at YAML section number " << I << ".\n";
return false;
}
}
More information about the llvm-commits
mailing list