llvm.org GIT mirror llvm / aeaece7
Revert "Reapply: Allow yaml2obj to order implicit sections for ELF" This reverts commit r317646. git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@317654 91177308-0d34-0410-b5e6-96231b3b80d8 Dave Lee 1 year, 11 months ago
4 changed file(s) with 38 addition(s) and 86 deletion(s). Raw diff Collapse all Expand all
387387 #define ECase(X) IO.enumCase(Value, #X, ELF::X)
388388 ECase(SHT_NULL);
389389 ECase(SHT_PROGBITS);
390 ECase(SHT_SYMTAB);
390 // No SHT_SYMTAB. Use the top-level `Symbols` key instead.
391391 // FIXME: Issue a diagnostic with this information.
392392 ECase(SHT_STRTAB);
393393 ECase(SHT_RELA);
+0
-29
test/tools/yaml2obj/section-ordering.yaml less more
None # Ensures that implicitly added sections can be ordered within Sections.
1 # RUN: yaml2obj %s -o %t
2 # RUN: llvm-readobj -sections %t | FileCheck %s
3
4 !ELF
5 FileHeader:
6 Class: ELFCLASS64
7 Data: ELFDATA2LSB
8 Type: ET_EXEC
9 Machine: EM_X86_64
10 Sections:
11 - Name: .text
12 Type: SHT_PROGBITS
13 Flags: [ SHF_ALLOC, SHF_EXECINSTR ]
14 - Name: .symtab
15 Type: SHT_SYMTAB
16 - Name: .data
17 Type: SHT_PROGBITS
18 Flags: [ SHF_ALLOC, SHF_WRITE ]
19 - Name: .shstrtab
20 Type: SHT_STRTAB
21 - Name: .strtab
22 Type: SHT_STRTAB
23
24 # CHECK: Name: .text
25 # CHECK: Name: .symtab
26 # CHECK: Name: .data
27 # CHECK: Name: .shstrtab
28 # CHECK: Name: .strtab
+0
-14
test/tools/yaml2obj/unnamed-section.yaml less more
None # Ensure yaml2obj doesn't crash on unnamed sections
1 # RUN: yaml2obj %s
2
3 !ELF
4 FileHeader:
5 Class: ELFCLASS64
6 Data: ELFDATA2LSB
7 Type: ET_EXEC
8 Machine: EM_X86_64
9 Sections:
10 - Type: SHT_PROGBITS
11 - Name: .text
12 Type: SHT_PROGBITS
13 Flags: [ SHF_ALLOC, SHF_EXECINSTR ]
7373 Idx = I->getValue();
7474 return false;
7575 }
76 /// asserts if name is not present in the map
77 unsigned get(StringRef Name) const {
78 unsigned Idx = 0;
79 auto missing = lookup(Name, Idx);
80 assert(!missing && "Expected section not found in index");
81 return Idx;
82 }
83 unsigned size() const { return Map.size(); }
8476 };
8577 } // end anonymous namespace
8678
151143 ContiguousBlobAccumulator &CBA);
152144
153145 // - SHT_NULL entry (placed first, i.e. 0'th entry)
154 // - symbol table (.symtab) (defaults to third to last)
155 // - string table (.strtab) (defaults to second to last)
156 // - section header string table (.shstrtab) (defaults to last)
157 unsigned getDotSymTabSecNo() const { return SN2I.get(".symtab"); }
158 unsigned getDotStrTabSecNo() const { return SN2I.get(".strtab"); }
159 unsigned getDotShStrTabSecNo() const { return SN2I.get(".shstrtab"); }
160 unsigned getSectionCount() const { return SN2I.size() + 1; }
146 // - symbol table (.symtab) (placed third to last)
147 // - string table (.strtab) (placed second to last)
148 // - section header string table (.shstrtab) (placed last)
149 unsigned getDotSymTabSecNo() const { return Doc.Sections.size() + 1; }
150 unsigned getDotStrTabSecNo() const { return Doc.Sections.size() + 2; }
151 unsigned getDotShStrTabSecNo() const { return Doc.Sections.size() + 3; }
152 unsigned getSectionCount() const { return Doc.Sections.size() + 4; }
161153
162154 ELFState(const ELFYAML::Object &D) : Doc(D) {}
163155
164156 public:
165157 static int writeELF(raw_ostream &OS, const ELFYAML::Object &Doc);
166158 };
167
168 static const char * const ImplicitSecNames[] = {".symtab", ".strtab", ".shstrtab"};
169159 } // end anonymous namespace
170160
171161 template
220210 zero(SHeader);
221211 SHeaders.push_back(SHeader);
222212
213 for (const auto &Sec : Doc.Sections)
214 DotShStrtab.add(Sec->Name);
215 DotShStrtab.finalize();
216
223217 for (const auto &Sec : Doc.Sections) {
224218 zero(SHeader);
225219 SHeader.sh_name = DotShStrtab.getOffset(Sec->Name);
552546 }
553547
554548 template bool ELFState::buildSectionIndex() {
549 SN2I.addName(".symtab", getDotSymTabSecNo());
550 SN2I.addName(".strtab", getDotStrTabSecNo());
551 SN2I.addName(".shstrtab", getDotShStrTabSecNo());
552
555553 for (unsigned i = 0, e = Doc.Sections.size(); i != e; ++i) {
556554 StringRef Name = Doc.Sections[i]->Name;
557 DotShStrtab.add(Name);
558555 if (Name.empty())
559556 continue;
560557 // "+ 1" to take into account the SHT_NULL entry.
564561 return false;
565562 }
566563 }
567
568 auto SecNo = 1 + Doc.Sections.size();
569 // Add special sections after input sections, if necessary.
570 for (const auto &Name : ImplicitSecNames)
571 if (!SN2I.addName(Name, SecNo)) {
572 // Account for this section, since it wasn't in the Doc
573 ++SecNo;
574 DotShStrtab.add(Name);
575 }
576
577 DotShStrtab.finalize();
578564 return true;
579565 }
580566
621607 Header.e_shentsize * Header.e_shnum;
622608 ContiguousBlobAccumulator CBA(SectionContentBeginOffset);
623609
610 // Doc might not contain .symtab, .strtab and .shstrtab sections,
611 // but we will emit them, so make sure to add them to ShStrTabSHeader.
612 State.DotShStrtab.add(".symtab");
613 State.DotShStrtab.add(".strtab");
614 State.DotShStrtab.add(".shstrtab");
615
624616 std::vector SHeaders;
625 SHeaders.reserve(State.SN2I.size());
626617 if(!State.initSectionHeaders(SHeaders, CBA))
627618 return 1;
628619
629 // Populate SHeaders with implicit sections not present in the Doc
630 for (const auto &Name : ImplicitSecNames)
631 if (State.SN2I.get(Name) >= SHeaders.size())
632 SHeaders.push_back({});
633
634 // Initialize the implicit sections
635 auto Index = State.SN2I.get(".symtab");
636 State.initSymtabSectionHeader(SHeaders[Index], CBA);
637 Index = State.SN2I.get(".strtab");
638 State.initStrtabSectionHeader(SHeaders[Index], ".strtab", State.DotStrtab, CBA);
639 Index = State.SN2I.get(".shstrtab");
640 State.initStrtabSectionHeader(SHeaders[Index], ".shstrtab", State.DotShStrtab, CBA);
620 // .symtab section.
621 Elf_Shdr SymtabSHeader;
622 State.initSymtabSectionHeader(SymtabSHeader, CBA);
623 SHeaders.push_back(SymtabSHeader);
624
625 // .strtab string table header.
626 Elf_Shdr DotStrTabSHeader;
627 State.initStrtabSectionHeader(DotStrTabSHeader, ".strtab", State.DotStrtab,
628 CBA);
629 SHeaders.push_back(DotStrTabSHeader);
630
631 // .shstrtab string table header.
632 Elf_Shdr ShStrTabSHeader;
633 State.initStrtabSectionHeader(ShStrTabSHeader, ".shstrtab", State.DotShStrtab,
634 CBA);
635 SHeaders.push_back(ShStrTabSHeader);
641636
642637 // Now we can decide segment offsets
643638 State.setProgramHeaderLayout(PHeaders, SHeaders);