forked from OSchip/llvm-project
Revert "Allow yaml2obj to order implicit sections for ELF"
Also, revert "Fix build bots after r317622" This reverts commit r317622, r317626. llvm-svn: 317630
This commit is contained in:
parent
9737f54f1d
commit
dcce03300d
|
@ -388,7 +388,7 @@ void ScalarEnumerationTraits<ELFYAML::ELF_SHT>::enumeration(
|
||||||
#define ECase(X) IO.enumCase(Value, #X, ELF::X)
|
#define ECase(X) IO.enumCase(Value, #X, ELF::X)
|
||||||
ECase(SHT_NULL);
|
ECase(SHT_NULL);
|
||||||
ECase(SHT_PROGBITS);
|
ECase(SHT_PROGBITS);
|
||||||
ECase(SHT_SYMTAB);
|
// No SHT_SYMTAB. Use the top-level `Symbols` key instead.
|
||||||
// FIXME: Issue a diagnostic with this information.
|
// FIXME: Issue a diagnostic with this information.
|
||||||
ECase(SHT_STRTAB);
|
ECase(SHT_STRTAB);
|
||||||
ECase(SHT_RELA);
|
ECase(SHT_RELA);
|
||||||
|
|
|
@ -1,29 +0,0 @@
|
||||||
# Ensures that implicitly added sections can be ordered within Sections.
|
|
||||||
# RUN: yaml2obj %s -o %t
|
|
||||||
# RUN: llvm-readobj -sections %t | FileCheck %s
|
|
||||||
|
|
||||||
!ELF
|
|
||||||
FileHeader:
|
|
||||||
Class: ELFCLASS64
|
|
||||||
Data: ELFDATA2LSB
|
|
||||||
Type: ET_EXEC
|
|
||||||
Machine: EM_X86_64
|
|
||||||
Sections:
|
|
||||||
- Name: .text
|
|
||||||
Type: SHT_PROGBITS
|
|
||||||
Flags: [ SHF_ALLOC, SHF_EXECINSTR ]
|
|
||||||
- Name: .symtab
|
|
||||||
Type: SHT_SYMTAB
|
|
||||||
- Name: .data
|
|
||||||
Type: SHT_PROGBITS
|
|
||||||
Flags: [ SHF_ALLOC, SHF_WRITE ]
|
|
||||||
- Name: .shstrtab
|
|
||||||
Type: SHT_STRTAB
|
|
||||||
- Name: .strtab
|
|
||||||
Type: SHT_STRTAB
|
|
||||||
|
|
||||||
# CHECK: Name: .text
|
|
||||||
# CHECK: Name: .symtab
|
|
||||||
# CHECK: Name: .data
|
|
||||||
# CHECK: Name: .shstrtab
|
|
||||||
# CHECK: Name: .strtab
|
|
|
@ -74,13 +74,6 @@ public:
|
||||||
Idx = I->getValue();
|
Idx = I->getValue();
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
/// asserts if name is not present in the map
|
|
||||||
unsigned get(StringRef Name) const {
|
|
||||||
unsigned Idx = 0;
|
|
||||||
assert(!lookup(Name, Idx) && "Expected section not found in index");
|
|
||||||
return Idx;
|
|
||||||
}
|
|
||||||
unsigned size() const { return Map.size(); }
|
|
||||||
};
|
};
|
||||||
} // end anonymous namespace
|
} // end anonymous namespace
|
||||||
|
|
||||||
|
@ -151,21 +144,19 @@ class ELFState {
|
||||||
ContiguousBlobAccumulator &CBA);
|
ContiguousBlobAccumulator &CBA);
|
||||||
|
|
||||||
// - SHT_NULL entry (placed first, i.e. 0'th entry)
|
// - SHT_NULL entry (placed first, i.e. 0'th entry)
|
||||||
// - symbol table (.symtab) (defaults to third to last)
|
// - symbol table (.symtab) (placed third to last)
|
||||||
// - string table (.strtab) (defaults to second to last)
|
// - string table (.strtab) (placed second to last)
|
||||||
// - section header string table (.shstrtab) (defaults to last)
|
// - section header string table (.shstrtab) (placed last)
|
||||||
unsigned getDotSymTabSecNo() const { return SN2I.get(".symtab"); }
|
unsigned getDotSymTabSecNo() const { return Doc.Sections.size() + 1; }
|
||||||
unsigned getDotStrTabSecNo() const { return SN2I.get(".strtab"); }
|
unsigned getDotStrTabSecNo() const { return Doc.Sections.size() + 2; }
|
||||||
unsigned getDotShStrTabSecNo() const { return SN2I.get(".shstrtab"); }
|
unsigned getDotShStrTabSecNo() const { return Doc.Sections.size() + 3; }
|
||||||
unsigned getSectionCount() const { return SN2I.size() + 1; }
|
unsigned getSectionCount() const { return Doc.Sections.size() + 4; }
|
||||||
|
|
||||||
ELFState(const ELFYAML::Object &D) : Doc(D) {}
|
ELFState(const ELFYAML::Object &D) : Doc(D) {}
|
||||||
|
|
||||||
public:
|
public:
|
||||||
static int writeELF(raw_ostream &OS, const ELFYAML::Object &Doc);
|
static int writeELF(raw_ostream &OS, const ELFYAML::Object &Doc);
|
||||||
};
|
};
|
||||||
|
|
||||||
static const char * const ImplicitSecNames[] = {".symtab", ".strtab", ".shstrtab"};
|
|
||||||
} // end anonymous namespace
|
} // end anonymous namespace
|
||||||
|
|
||||||
template <class ELFT>
|
template <class ELFT>
|
||||||
|
@ -220,6 +211,10 @@ bool ELFState<ELFT>::initSectionHeaders(std::vector<Elf_Shdr> &SHeaders,
|
||||||
zero(SHeader);
|
zero(SHeader);
|
||||||
SHeaders.push_back(SHeader);
|
SHeaders.push_back(SHeader);
|
||||||
|
|
||||||
|
for (const auto &Sec : Doc.Sections)
|
||||||
|
DotShStrtab.add(Sec->Name);
|
||||||
|
DotShStrtab.finalize();
|
||||||
|
|
||||||
for (const auto &Sec : Doc.Sections) {
|
for (const auto &Sec : Doc.Sections) {
|
||||||
zero(SHeader);
|
zero(SHeader);
|
||||||
SHeader.sh_name = DotShStrtab.getOffset(Sec->Name);
|
SHeader.sh_name = DotShStrtab.getOffset(Sec->Name);
|
||||||
|
@ -552,6 +547,10 @@ bool ELFState<ELFT>::writeSectionContent(Elf_Shdr &SHeader,
|
||||||
}
|
}
|
||||||
|
|
||||||
template <class ELFT> bool ELFState<ELFT>::buildSectionIndex() {
|
template <class ELFT> bool ELFState<ELFT>::buildSectionIndex() {
|
||||||
|
SN2I.addName(".symtab", getDotSymTabSecNo());
|
||||||
|
SN2I.addName(".strtab", getDotStrTabSecNo());
|
||||||
|
SN2I.addName(".shstrtab", getDotShStrTabSecNo());
|
||||||
|
|
||||||
for (unsigned i = 0, e = Doc.Sections.size(); i != e; ++i) {
|
for (unsigned i = 0, e = Doc.Sections.size(); i != e; ++i) {
|
||||||
StringRef Name = Doc.Sections[i]->Name;
|
StringRef Name = Doc.Sections[i]->Name;
|
||||||
if (Name.empty())
|
if (Name.empty())
|
||||||
|
@ -562,19 +561,7 @@ template <class ELFT> bool ELFState<ELFT>::buildSectionIndex() {
|
||||||
<< "' at YAML section number " << i << ".\n";
|
<< "' at YAML section number " << i << ".\n";
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
DotShStrtab.add(Name);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
auto SecNo = 1 + Doc.Sections.size();
|
|
||||||
// Add special sections after input sections, if necessary.
|
|
||||||
for (const auto &Name : ImplicitSecNames)
|
|
||||||
if (!SN2I.addName(Name, SecNo)) {
|
|
||||||
// Account for this section, since it wasn't in the Doc
|
|
||||||
++SecNo;
|
|
||||||
DotShStrtab.add(Name);
|
|
||||||
}
|
|
||||||
|
|
||||||
DotShStrtab.finalize();
|
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -621,23 +608,32 @@ int ELFState<ELFT>::writeELF(raw_ostream &OS, const ELFYAML::Object &Doc) {
|
||||||
Header.e_shentsize * Header.e_shnum;
|
Header.e_shentsize * Header.e_shnum;
|
||||||
ContiguousBlobAccumulator CBA(SectionContentBeginOffset);
|
ContiguousBlobAccumulator CBA(SectionContentBeginOffset);
|
||||||
|
|
||||||
|
// Doc might not contain .symtab, .strtab and .shstrtab sections,
|
||||||
|
// but we will emit them, so make sure to add them to ShStrTabSHeader.
|
||||||
|
State.DotShStrtab.add(".symtab");
|
||||||
|
State.DotShStrtab.add(".strtab");
|
||||||
|
State.DotShStrtab.add(".shstrtab");
|
||||||
|
|
||||||
std::vector<Elf_Shdr> SHeaders;
|
std::vector<Elf_Shdr> SHeaders;
|
||||||
SHeaders.reserve(State.SN2I.size());
|
|
||||||
if(!State.initSectionHeaders(SHeaders, CBA))
|
if(!State.initSectionHeaders(SHeaders, CBA))
|
||||||
return 1;
|
return 1;
|
||||||
|
|
||||||
// Populate SHeaders with implicit sections not present in the Doc
|
// .symtab section.
|
||||||
for (const auto &Name : ImplicitSecNames)
|
Elf_Shdr SymtabSHeader;
|
||||||
if (State.SN2I.get(Name) >= SHeaders.size())
|
State.initSymtabSectionHeader(SymtabSHeader, CBA);
|
||||||
SHeaders.push_back({});
|
SHeaders.push_back(SymtabSHeader);
|
||||||
|
|
||||||
// Initialize the implicit sections
|
// .strtab string table header.
|
||||||
auto Index = State.SN2I.get(".symtab");
|
Elf_Shdr DotStrTabSHeader;
|
||||||
State.initSymtabSectionHeader(SHeaders[Index], CBA);
|
State.initStrtabSectionHeader(DotStrTabSHeader, ".strtab", State.DotStrtab,
|
||||||
Index = State.SN2I.get(".strtab");
|
CBA);
|
||||||
State.initStrtabSectionHeader(SHeaders[Index], ".strtab", State.DotStrtab, CBA);
|
SHeaders.push_back(DotStrTabSHeader);
|
||||||
Index = State.SN2I.get(".shstrtab");
|
|
||||||
State.initStrtabSectionHeader(SHeaders[Index], ".shstrtab", State.DotShStrtab, CBA);
|
// .shstrtab string table header.
|
||||||
|
Elf_Shdr ShStrTabSHeader;
|
||||||
|
State.initStrtabSectionHeader(ShStrTabSHeader, ".shstrtab", State.DotShStrtab,
|
||||||
|
CBA);
|
||||||
|
SHeaders.push_back(ShStrTabSHeader);
|
||||||
|
|
||||||
// Now we can decide segment offsets
|
// Now we can decide segment offsets
|
||||||
State.setProgramHeaderLayout(PHeaders, SHeaders);
|
State.setProgramHeaderLayout(PHeaders, SHeaders);
|
||||||
|
|
Loading…
Reference in New Issue