From: Rui Ueyama Date: Fri, 21 Oct 2016 03:23:23 +0000 (+0000) Subject: Do not create .shstrtab and use .strtab instead. X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=a9a2adcf25d336c2258330ab36f3c46e77cc714e;p=platform%2Fupstream%2Fllvm.git Do not create .shstrtab and use .strtab instead. In-memory ELF object files created here are consumed immediately, so as long as the generated files are syntactically correct, we don't care about the details. llvm-svn: 284803 --- diff --git a/lld/ELF/ELFCreator.cpp b/lld/ELF/ELFCreator.cpp index d95f5ab..2b49643 100644 --- a/lld/ELF/ELFCreator.cpp +++ b/lld/ELF/ELFCreator.cpp @@ -48,11 +48,9 @@ private: Elf_Ehdr Header = {}; std::vector Sections; std::vector Symbols; - StringTableBuilder ShStrTabBuilder{StringTableBuilder::ELF}; StringTableBuilder StrTabBuilder{StringTableBuilder::ELF}; BumpPtrAllocator Alloc; StringSaver Saver{Alloc}; - Elf_Shdr *ShStrTab; Elf_Shdr *StrTab; Elf_Shdr *SymTab; }; @@ -72,17 +70,13 @@ ELFCreator::ELFCreator(std::uint16_t Type, std::uint16_t Machine) { Header.e_shentsize = sizeof(Elf_Shdr); Header.e_shstrndx = 1; - ShStrTab = addSection(".shstrtab").Header; - ShStrTab->sh_type = SHT_STRTAB; - ShStrTab->sh_addralign = 1; - StrTab = addSection(".strtab").Header; StrTab->sh_type = SHT_STRTAB; StrTab->sh_addralign = 1; SymTab = addSection(".symtab").Header; SymTab->sh_type = SHT_SYMTAB; - SymTab->sh_link = 2; + SymTab->sh_link = 1; SymTab->sh_info = 1; SymTab->sh_addralign = sizeof(uintX_t); SymTab->sh_entsize = sizeof(Elf_Sym); @@ -92,7 +86,7 @@ template typename ELFCreator::Section ELFCreator::addSection(StringRef Name) { auto *Shdr = new (Alloc) Elf_Shdr{}; - Shdr->sh_name = ShStrTabBuilder.add(Saver.save(Name)); + Shdr->sh_name = StrTabBuilder.add(Saver.save(Name)); Sections.push_back(Shdr); return {Shdr, Sections.size()}; } @@ -106,12 +100,8 @@ typename ELFT::Sym *ELFCreator::addSymbol(StringRef Name) { } template size_t ELFCreator::layout() { - ShStrTabBuilder.finalizeInOrder(); - ShStrTab->sh_size = ShStrTabBuilder.getSize(); - StrTabBuilder.finalizeInOrder(); StrTab->sh_size = StrTabBuilder.getSize(); - SymTab->sh_size = (Symbols.size() + 1) * sizeof(Elf_Sym); uintX_t Offset = sizeof(Elf_Ehdr); @@ -125,13 +115,11 @@ template size_t ELFCreator::layout() { Header.e_shoff = Offset; Offset += (Sections.size() + 1) * sizeof(Elf_Shdr); Header.e_shnum = Sections.size() + 1; - return Offset; } template void ELFCreator::writeTo(uint8_t *Out) { std::memcpy(Out, &Header, sizeof(Elf_Ehdr)); - ShStrTabBuilder.write(Out + ShStrTab->sh_offset); StrTabBuilder.write(Out + StrTab->sh_offset); Elf_Sym *Sym = reinterpret_cast(Out + SymTab->sh_offset); @@ -166,8 +154,8 @@ std::vector elf::wrapBinaryWithElfHeader(ArrayRef Blob, [](char C) { return isalnum(C) ? C : '_'; }); // Add _start, _end and _size symbols. - auto AddSym = [&](std::string Name, uintX_t SecIdx, uintX_t Value) { - Elf_Sym *Sym = File.addSymbol("_binary_" + Filename + Name); + auto AddSym = [&](std::string Suffix, uintX_t SecIdx, uintX_t Value) { + Elf_Sym *Sym = File.addSymbol("_binary_" + Filename + Suffix); Sym->setBindingAndType(STB_GLOBAL, STT_OBJECT); Sym->st_shndx = SecIdx; Sym->st_value = Value;