From 068463b714bd53fffd41322a5654b4f359c2166c Mon Sep 17 00:00:00 2001 From: Sean Silva Date: Sat, 22 Jun 2013 01:38:00 +0000 Subject: [yaml2obj][ELF] Make symbol table top-level key. Although in reality the symbol table in ELF resides in a section, the standard requires that there be no more than one SHT_SYMTAB. To enforce this constraint, it is cleaner to group all the symbols under a top-level `Symbols` key on the object file. git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@184627 91177308-0d34-0410-b5e6-96231b3b80d8 --- tools/yaml2obj/yaml2elf.cpp | 20 +++++++++++--------- 1 file changed, 11 insertions(+), 9 deletions(-) (limited to 'tools/yaml2obj') diff --git a/tools/yaml2obj/yaml2elf.cpp b/tools/yaml2obj/yaml2elf.cpp index 82ff78756e..61252a4a28 100644 --- a/tools/yaml2obj/yaml2elf.cpp +++ b/tools/yaml2obj/yaml2elf.cpp @@ -216,8 +216,7 @@ static void handleSymtabSectionHeader( typename object::ELFObjectFile::Elf_Shdr &SHeader) { typedef typename object::ELFObjectFile::Elf_Sym Elf_Sym; - // TODO: Ensure that a manually specified `Link` field is diagnosed as an - // error for SHT_SYMTAB. + SHeader.sh_type = ELF::SHT_SYMTAB; SHeader.sh_link = State.getDotStrTabSecNo(); // One greater than symbol table index of the last local symbol. SHeader.sh_info = Symbols.Local.size() + 1; @@ -272,11 +271,12 @@ static int writeELF(raw_ostream &OS, const ELFYAML::Object &Doc) { // Immediately following the ELF header. Header.e_shoff = sizeof(Header); const std::vector &Sections = Doc.Sections; - // "+ 3" for + // "+ 4" for // - SHT_NULL entry (placed first, i.e. 0'th entry) + // - symbol table (.symtab) (placed third to last) // - string table (.strtab) (placed second to last) // - section header string table. (placed last) - Header.e_shnum = Sections.size() + 3; + Header.e_shnum = Sections.size() + 4; // Place section header string table last. Header.e_shstrndx = Header.e_shnum - 1; const unsigned DotStrtabSecNo = Header.e_shnum - 2; @@ -334,14 +334,16 @@ static int writeELF(raw_ostream &OS, const ELFYAML::Object &Doc) { SHeader.sh_info = 0; SHeader.sh_addralign = Sec.AddressAlign; SHeader.sh_entsize = 0; - // XXX: Really ugly right now. Should not be writing to `CBA` above - // (and setting sh_offset and sh_size) when going through this branch - // here. - if (Sec.Type == ELFYAML::ELF_SHT(SHT_SYMTAB)) - handleSymtabSectionHeader(Sec.Symbols, State, SHeader); SHeaders.push_back(SHeader); } + // .symtab section. + Elf_Shdr SymtabSHeader; + zero(SymtabSHeader); + SymtabSHeader.sh_name = SHStrTab.addString(StringRef(".symtab")); + handleSymtabSectionHeader(Doc.Symbols, State, SymtabSHeader); + SHeaders.push_back(SymtabSHeader); + // .strtab string table header. Elf_Shdr DotStrTabSHeader; zero(DotStrTabSHeader); -- cgit v1.2.3