diff options
author | Sean Silva <silvas@purdue.edu> | 2013-06-22 01:38:00 +0000 |
---|---|---|
committer | Sean Silva <silvas@purdue.edu> | 2013-06-22 01:38:00 +0000 |
commit | 068463b714bd53fffd41322a5654b4f359c2166c (patch) | |
tree | 78bbe3b036bd29783bed1505bfaab0162b42611d /tools | |
parent | 681dafbb6c605b96b141accf428923076606ec9e (diff) | |
download | llvm-068463b714bd53fffd41322a5654b4f359c2166c.tar.gz llvm-068463b714bd53fffd41322a5654b4f359c2166c.tar.bz2 llvm-068463b714bd53fffd41322a5654b4f359c2166c.tar.xz |
[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
Diffstat (limited to 'tools')
-rw-r--r-- | tools/yaml2obj/yaml2elf.cpp | 20 |
1 files changed, 11 insertions, 9 deletions
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<ELFT>::Elf_Shdr &SHeader) { typedef typename object::ELFObjectFile<ELFT>::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<ELFYAML::Section> &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<ELFT>(Sec.Symbols, State, SHeader); SHeaders.push_back(SHeader); } + // .symtab section. + Elf_Shdr SymtabSHeader; + zero(SymtabSHeader); + SymtabSHeader.sh_name = SHStrTab.addString(StringRef(".symtab")); + handleSymtabSectionHeader<ELFT>(Doc.Symbols, State, SymtabSHeader); + SHeaders.push_back(SymtabSHeader); + // .strtab string table header. Elf_Shdr DotStrTabSHeader; zero(DotStrTabSHeader); |