diff options
author | Stephen Hines <srhines@google.com> | 2014-04-23 16:57:46 -0700 |
---|---|---|
committer | Stephen Hines <srhines@google.com> | 2014-04-24 15:53:16 -0700 |
commit | 36b56886974eae4f9c5ebc96befd3e7bfe5de338 (patch) | |
tree | e6cfb69fbbd937f450eeb83bfb83b9da3b01275a /tools/yaml2obj | |
parent | 69a8640022b04415ae9fac62f8ab090601d8f889 (diff) | |
download | external_llvm-36b56886974eae4f9c5ebc96befd3e7bfe5de338.zip external_llvm-36b56886974eae4f9c5ebc96befd3e7bfe5de338.tar.gz external_llvm-36b56886974eae4f9c5ebc96befd3e7bfe5de338.tar.bz2 |
Update to LLVM 3.5a.
Change-Id: Ifadecab779f128e62e430c2b4f6ddd84953ed617
Diffstat (limited to 'tools/yaml2obj')
-rw-r--r-- | tools/yaml2obj/CMakeLists.txt | 7 | ||||
-rw-r--r-- | tools/yaml2obj/yaml2coff.cpp | 82 | ||||
-rw-r--r-- | tools/yaml2obj/yaml2elf.cpp | 336 | ||||
-rw-r--r-- | tools/yaml2obj/yaml2obj.cpp | 3 |
4 files changed, 250 insertions, 178 deletions
diff --git a/tools/yaml2obj/CMakeLists.txt b/tools/yaml2obj/CMakeLists.txt index 8d9d652..5e63dfb 100644 --- a/tools/yaml2obj/CMakeLists.txt +++ b/tools/yaml2obj/CMakeLists.txt @@ -1,9 +1,10 @@ -set(LLVM_LINK_COMPONENTS object) +set(LLVM_LINK_COMPONENTS + Object + Support + ) add_llvm_utility(yaml2obj yaml2obj.cpp yaml2coff.cpp yaml2elf.cpp ) - -target_link_libraries(yaml2obj LLVMSupport) diff --git a/tools/yaml2obj/yaml2coff.cpp b/tools/yaml2obj/yaml2coff.cpp index c757eb6..a0ede24 100644 --- a/tools/yaml2obj/yaml2coff.cpp +++ b/tools/yaml2obj/yaml2coff.cpp @@ -14,6 +14,7 @@ #include "yaml2obj.h" #include "llvm/ADT/SmallString.h" +#include "llvm/ADT/STLExtras.h" #include "llvm/ADT/StringExtras.h" #include "llvm/ADT/StringMap.h" #include "llvm/ADT/StringSwitch.h" @@ -153,13 +154,22 @@ static bool layoutCOFF(COFFParser &CP) { for (std::vector<COFFYAML::Symbol>::iterator i = CP.Obj.Symbols.begin(), e = CP.Obj.Symbols.end(); i != e; ++i) { - unsigned AuxBytes = i->AuxiliaryData.binary_size(); - if (AuxBytes % COFF::SymbolSize != 0) { - errs() << "AuxiliaryData size not a multiple of symbol size!\n"; - return false; - } - i->Header.NumberOfAuxSymbols = AuxBytes / COFF::SymbolSize; - NumberOfSymbols += 1 + i->Header.NumberOfAuxSymbols; + uint32_t NumberOfAuxSymbols = 0; + if (i->FunctionDefinition) + NumberOfAuxSymbols += 1; + if (i->bfAndefSymbol) + NumberOfAuxSymbols += 1; + if (i->WeakExternal) + NumberOfAuxSymbols += 1; + if (!i->File.empty()) + NumberOfAuxSymbols += + (i->File.size() + COFF::SymbolSize - 1) / COFF::SymbolSize; + if (i->SectionDefinition) + NumberOfAuxSymbols += 1; + if (i->CLRToken) + NumberOfAuxSymbols += 1; + i->Header.NumberOfAuxSymbols = NumberOfAuxSymbols; + NumberOfSymbols += 1 + NumberOfAuxSymbols; } // Store all the allocated start addresses in the header. @@ -194,6 +204,24 @@ binary_le_impl<value_type> binary_le(value_type V) { return binary_le_impl<value_type>(V); } +template <size_t NumBytes> +struct zeros_impl { + zeros_impl() {} +}; + +template <size_t NumBytes> +raw_ostream &operator<<(raw_ostream &OS, const zeros_impl<NumBytes> &) { + char Buffer[NumBytes]; + memset(Buffer, 0, sizeof(Buffer)); + OS.write(Buffer, sizeof(Buffer)); + return OS; +} + +template <typename T> +zeros_impl<sizeof(T)> zeros(const T &) { + return zeros_impl<sizeof(T)>(); +} + bool writeCOFF(COFFParser &CP, raw_ostream &OS) { OS << binary_le(CP.Obj.Header.Machine) << binary_le(CP.Obj.Header.NumberOfSections) @@ -253,7 +281,45 @@ bool writeCOFF(COFFParser &CP, raw_ostream &OS) { << binary_le(i->Header.Type) << binary_le(i->Header.StorageClass) << binary_le(i->Header.NumberOfAuxSymbols); - i->AuxiliaryData.writeAsBinary(OS); + + if (i->FunctionDefinition) + OS << binary_le(i->FunctionDefinition->TagIndex) + << binary_le(i->FunctionDefinition->TotalSize) + << binary_le(i->FunctionDefinition->PointerToLinenumber) + << binary_le(i->FunctionDefinition->PointerToNextFunction) + << zeros(i->FunctionDefinition->unused); + if (i->bfAndefSymbol) + OS << zeros(i->bfAndefSymbol->unused1) + << binary_le(i->bfAndefSymbol->Linenumber) + << zeros(i->bfAndefSymbol->unused2) + << binary_le(i->bfAndefSymbol->PointerToNextFunction) + << zeros(i->bfAndefSymbol->unused3); + if (i->WeakExternal) + OS << binary_le(i->WeakExternal->TagIndex) + << binary_le(i->WeakExternal->Characteristics) + << zeros(i->WeakExternal->unused); + if (!i->File.empty()) { + uint32_t NumberOfAuxRecords = + (i->File.size() + COFF::SymbolSize - 1) / COFF::SymbolSize; + uint32_t NumberOfAuxBytes = NumberOfAuxRecords * COFF::SymbolSize; + uint32_t NumZeros = NumberOfAuxBytes - i->File.size(); + OS.write(i->File.data(), i->File.size()); + for (uint32_t Padding = 0; Padding < NumZeros; ++Padding) + OS.write(0); + } + if (i->SectionDefinition) + OS << binary_le(i->SectionDefinition->Length) + << binary_le(i->SectionDefinition->NumberOfRelocations) + << binary_le(i->SectionDefinition->NumberOfLinenumbers) + << binary_le(i->SectionDefinition->CheckSum) + << binary_le(i->SectionDefinition->Number) + << binary_le(i->SectionDefinition->Selection) + << zeros(i->SectionDefinition->unused); + if (i->CLRToken) + OS << binary_le(i->CLRToken->AuxType) + << zeros(i->CLRToken->unused1) + << binary_le(i->CLRToken->SymbolTableIndex) + << zeros(i->CLRToken->unused2); } // Output string table. diff --git a/tools/yaml2obj/yaml2elf.cpp b/tools/yaml2obj/yaml2elf.cpp index d46e154..21506d9 100644 --- a/tools/yaml2obj/yaml2elf.cpp +++ b/tools/yaml2obj/yaml2elf.cpp @@ -134,94 +134,125 @@ static void zero(T &Obj) { memset(&Obj, 0, sizeof(Obj)); } -/// \brief Create a string table in `SHeader`, which we assume is already -/// zero'd. -template <class Elf_Shdr> -static void createStringTableSectionHeader(Elf_Shdr &SHeader, - StringTableBuilder &STB, - ContiguousBlobAccumulator &CBA) { - SHeader.sh_type = ELF::SHT_STRTAB; - STB.writeToStream(CBA.getOSAndAlignedOffset(SHeader.sh_offset)); - SHeader.sh_size = STB.size(); - SHeader.sh_addralign = 1; -} - namespace { /// \brief "Single point of truth" for the ELF file construction. /// TODO: This class still has a ways to go before it is truly a "single /// point of truth". template <class ELFT> class ELFState { + typedef typename object::ELFFile<ELFT>::Elf_Ehdr Elf_Ehdr; + typedef typename object::ELFFile<ELFT>::Elf_Shdr Elf_Shdr; + typedef typename object::ELFFile<ELFT>::Elf_Sym Elf_Sym; + /// \brief The future ".strtab" section. StringTableBuilder DotStrtab; - /// \brief The section number of the ".strtab" section. - unsigned DotStrtabSecNo; - /// \brief The accumulated contents of all sections so far. - ContiguousBlobAccumulator &SectionContentAccum; - typedef typename object::ELFFile<ELFT>::Elf_Ehdr Elf_Ehdr; - /// \brief The ELF file header. - Elf_Ehdr &Header; - SectionNameToIdxMap &SN2I; + /// \brief The future ".shstrtab" section. + StringTableBuilder DotShStrtab; -public: + SectionNameToIdxMap SN2I; + const ELFYAML::Object &Doc; + + bool buildSectionIndex(); + void initELFHeader(Elf_Ehdr &Header); + bool initSectionHeaders(std::vector<Elf_Shdr> &SHeaders, + ContiguousBlobAccumulator &CBA); + void initSymtabSectionHeader(Elf_Shdr &SHeader, + ContiguousBlobAccumulator &CBA); + void initStrtabSectionHeader(Elf_Shdr &SHeader, StringRef Name, + StringTableBuilder &STB, + ContiguousBlobAccumulator &CBA); + void addSymbols(const std::vector<ELFYAML::Symbol> &Symbols, + std::vector<Elf_Sym> &Syms, unsigned SymbolBinding); + + // - 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 (.shstrtab) (placed last) + unsigned getDotSymTabSecNo() const { return Doc.Sections.size() + 1; } + unsigned getDotStrTabSecNo() const { return Doc.Sections.size() + 2; } + unsigned getDotShStrTabSecNo() const { return Doc.Sections.size() + 3; } + unsigned getSectionCount() const { return Doc.Sections.size() + 4; } - ELFState(Elf_Ehdr &Header_, ContiguousBlobAccumulator &Accum, - unsigned DotStrtabSecNo_, SectionNameToIdxMap &SN2I_) - : DotStrtab(), DotStrtabSecNo(DotStrtabSecNo_), - SectionContentAccum(Accum), Header(Header_), SN2I(SN2I_) {} + ELFState(const ELFYAML::Object &D) : Doc(D) {} - unsigned getDotStrTabSecNo() const { return DotStrtabSecNo; } - StringTableBuilder &getStringTable() { return DotStrtab; } - ContiguousBlobAccumulator &getSectionContentAccum() { - return SectionContentAccum; - } - SectionNameToIdxMap &getSN2I() { return SN2I; } +public: + static int writeELF(raw_ostream &OS, const ELFYAML::Object &Doc); }; } // end anonymous namespace -// FIXME: At this point it is fairly clear that we need to refactor these -// static functions into methods of a class sharing some typedefs. These -// ELF type names are insane. template <class ELFT> -static void -addSymbols(const std::vector<ELFYAML::Symbol> &Symbols, ELFState<ELFT> &State, - std::vector<typename object::ELFFile<ELFT>::Elf_Sym> &Syms, - unsigned SymbolBinding) { - typedef typename object::ELFFile<ELFT>::Elf_Sym Elf_Sym; - for (unsigned i = 0, e = Symbols.size(); i != e; ++i) { - const ELFYAML::Symbol &Sym = Symbols[i]; - Elf_Sym Symbol; - zero(Symbol); - if (!Sym.Name.empty()) - Symbol.st_name = State.getStringTable().addString(Sym.Name); - Symbol.setBindingAndType(SymbolBinding, Sym.Type); - if (!Sym.Section.empty()) { +void ELFState<ELFT>::initELFHeader(Elf_Ehdr &Header) { + using namespace llvm::ELF; + zero(Header); + Header.e_ident[EI_MAG0] = 0x7f; + Header.e_ident[EI_MAG1] = 'E'; + Header.e_ident[EI_MAG2] = 'L'; + Header.e_ident[EI_MAG3] = 'F'; + Header.e_ident[EI_CLASS] = ELFT::Is64Bits ? ELFCLASS64 : ELFCLASS32; + bool IsLittleEndian = ELFT::TargetEndianness == support::little; + Header.e_ident[EI_DATA] = IsLittleEndian ? ELFDATA2LSB : ELFDATA2MSB; + Header.e_ident[EI_VERSION] = EV_CURRENT; + Header.e_ident[EI_OSABI] = Doc.Header.OSABI; + Header.e_ident[EI_ABIVERSION] = 0; + Header.e_type = Doc.Header.Type; + Header.e_machine = Doc.Header.Machine; + Header.e_version = EV_CURRENT; + Header.e_entry = Doc.Header.Entry; + Header.e_flags = Doc.Header.Flags; + Header.e_ehsize = sizeof(Elf_Ehdr); + Header.e_shentsize = sizeof(Elf_Shdr); + // Immediately following the ELF header. + Header.e_shoff = sizeof(Header); + Header.e_shnum = getSectionCount(); + Header.e_shstrndx = getDotShStrTabSecNo(); +} + +template <class ELFT> +bool ELFState<ELFT>::initSectionHeaders(std::vector<Elf_Shdr> &SHeaders, + ContiguousBlobAccumulator &CBA) { + // Ensure SHN_UNDEF entry is present. An all-zero section header is a + // valid SHN_UNDEF entry since SHT_NULL == 0. + Elf_Shdr SHeader; + zero(SHeader); + SHeaders.push_back(SHeader); + + for (const auto &Sec : Doc.Sections) { + zero(SHeader); + SHeader.sh_name = DotShStrtab.addString(Sec.Name); + SHeader.sh_type = Sec.Type; + SHeader.sh_flags = Sec.Flags; + SHeader.sh_addr = Sec.Address; + + Sec.Content.writeAsBinary(CBA.getOSAndAlignedOffset(SHeader.sh_offset)); + SHeader.sh_size = Sec.Content.binary_size(); + + if (!Sec.Link.empty()) { unsigned Index; - if (State.getSN2I().lookupSection(Sym.Section, Index)) { - errs() << "error: Unknown section referenced: '" << Sym.Section - << "' by YAML symbol " << Sym.Name << ".\n"; - exit(1); + if (SN2I.lookupSection(Sec.Link, Index)) { + errs() << "error: Unknown section referenced: '" << Sec.Link + << "' at YAML section '" << Sec.Name << "'.\n"; + return false;; } - Symbol.st_shndx = Index; - } // else Symbol.st_shndex == SHN_UNDEF (== 0), since it was zero'd earlier. - Symbol.st_value = Sym.Value; - Symbol.st_size = Sym.Size; - Syms.push_back(Symbol); + SHeader.sh_link = Index; + } + SHeader.sh_info = 0; + SHeader.sh_addralign = Sec.AddressAlign; + SHeader.sh_entsize = 0; + SHeaders.push_back(SHeader); } + return true; } template <class ELFT> -static void -handleSymtabSectionHeader(const ELFYAML::LocalGlobalWeakSymbols &Symbols, - ELFState<ELFT> &State, - typename object::ELFFile<ELFT>::Elf_Shdr &SHeader) { - - typedef typename object::ELFFile<ELFT>::Elf_Sym Elf_Sym; +void ELFState<ELFT>::initSymtabSectionHeader(Elf_Shdr &SHeader, + ContiguousBlobAccumulator &CBA) { + zero(SHeader); + SHeader.sh_name = DotShStrtab.addString(StringRef(".symtab")); SHeader.sh_type = ELF::SHT_SYMTAB; - SHeader.sh_link = State.getDotStrTabSecNo(); + SHeader.sh_link = getDotStrTabSecNo(); // One greater than symbol table index of the last local symbol. - SHeader.sh_info = Symbols.Local.size() + 1; + SHeader.sh_info = Doc.Symbols.Local.size() + 1; SHeader.sh_entsize = sizeof(Elf_Sym); std::vector<Elf_Sym> Syms; @@ -231,134 +262,109 @@ handleSymtabSectionHeader(const ELFYAML::LocalGlobalWeakSymbols &Symbols, zero(Sym); Syms.push_back(Sym); } - addSymbols(Symbols.Local, State, Syms, ELF::STB_LOCAL); - addSymbols(Symbols.Global, State, Syms, ELF::STB_GLOBAL); - addSymbols(Symbols.Weak, State, Syms, ELF::STB_WEAK); + addSymbols(Doc.Symbols.Local, Syms, ELF::STB_LOCAL); + addSymbols(Doc.Symbols.Global, Syms, ELF::STB_GLOBAL); + addSymbols(Doc.Symbols.Weak, Syms, ELF::STB_WEAK); - ContiguousBlobAccumulator &CBA = State.getSectionContentAccum(); writeArrayData(CBA.getOSAndAlignedOffset(SHeader.sh_offset), makeArrayRef(Syms)); SHeader.sh_size = arrayDataSize(makeArrayRef(Syms)); } template <class ELFT> -static int writeELF(raw_ostream &OS, const ELFYAML::Object &Doc) { - using namespace llvm::ELF; - typedef typename object::ELFFile<ELFT>::Elf_Ehdr Elf_Ehdr; - typedef typename object::ELFFile<ELFT>::Elf_Shdr Elf_Shdr; - - const ELFYAML::FileHeader &Hdr = Doc.Header; - - Elf_Ehdr Header; - zero(Header); - Header.e_ident[EI_MAG0] = 0x7f; - Header.e_ident[EI_MAG1] = 'E'; - Header.e_ident[EI_MAG2] = 'L'; - Header.e_ident[EI_MAG3] = 'F'; - Header.e_ident[EI_CLASS] = ELFT::Is64Bits ? ELFCLASS64 : ELFCLASS32; - bool IsLittleEndian = ELFT::TargetEndianness == support::little; - Header.e_ident[EI_DATA] = IsLittleEndian ? ELFDATA2LSB : ELFDATA2MSB; - Header.e_ident[EI_VERSION] = EV_CURRENT; - Header.e_ident[EI_OSABI] = Hdr.OSABI; - Header.e_ident[EI_ABIVERSION] = 0; - Header.e_type = Hdr.Type; - Header.e_machine = Hdr.Machine; - Header.e_version = EV_CURRENT; - Header.e_entry = Hdr.Entry; - Header.e_ehsize = sizeof(Elf_Ehdr); +void ELFState<ELFT>::initStrtabSectionHeader(Elf_Shdr &SHeader, StringRef Name, + StringTableBuilder &STB, + ContiguousBlobAccumulator &CBA) { + zero(SHeader); + SHeader.sh_name = DotShStrtab.addString(Name); + SHeader.sh_type = ELF::SHT_STRTAB; + STB.writeToStream(CBA.getOSAndAlignedOffset(SHeader.sh_offset)); + SHeader.sh_size = STB.size(); + SHeader.sh_addralign = 1; +} - // TODO: Flesh out section header support. - // TODO: Program headers. +template <class ELFT> +void ELFState<ELFT>::addSymbols(const std::vector<ELFYAML::Symbol> &Symbols, + std::vector<Elf_Sym> &Syms, + unsigned SymbolBinding) { + for (const auto &Sym : Symbols) { + Elf_Sym Symbol; + zero(Symbol); + if (!Sym.Name.empty()) + Symbol.st_name = DotStrtab.addString(Sym.Name); + Symbol.setBindingAndType(SymbolBinding, Sym.Type); + if (!Sym.Section.empty()) { + unsigned Index; + if (SN2I.lookupSection(Sym.Section, Index)) { + errs() << "error: Unknown section referenced: '" << Sym.Section + << "' by YAML symbol " << Sym.Name << ".\n"; + exit(1); + } + Symbol.st_shndx = Index; + } // else Symbol.st_shndex == SHN_UNDEF (== 0), since it was zero'd earlier. + Symbol.st_value = Sym.Value; + Symbol.st_size = Sym.Size; + Syms.push_back(Symbol); + } +} - Header.e_shentsize = sizeof(Elf_Shdr); - // Immediately following the ELF header. - Header.e_shoff = sizeof(Header); - const std::vector<ELFYAML::Section> &Sections = Doc.Sections; - // "+ 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() + 4; - // Place section header string table last. - Header.e_shstrndx = Header.e_shnum - 1; - const unsigned DotStrtabSecNo = Header.e_shnum - 2; +template <class ELFT> bool ELFState<ELFT>::buildSectionIndex() { + SN2I.addName(".symtab", getDotSymTabSecNo()); + SN2I.addName(".strtab", getDotStrTabSecNo()); + SN2I.addName(".shstrtab", getDotShStrTabSecNo()); - // XXX: This offset is tightly coupled with the order that we write - // things to `OS`. - const size_t SectionContentBeginOffset = - Header.e_ehsize + Header.e_shentsize * Header.e_shnum; - ContiguousBlobAccumulator CBA(SectionContentBeginOffset); - SectionNameToIdxMap SN2I; - for (unsigned i = 0, e = Sections.size(); i != e; ++i) { - StringRef Name = Sections[i].Name; + for (unsigned i = 0, e = Doc.Sections.size(); i != e; ++i) { + StringRef Name = Doc.Sections[i].Name; if (Name.empty()) continue; // "+ 1" to take into account the SHT_NULL entry. if (SN2I.addName(Name, i + 1)) { errs() << "error: Repeated section name: '" << Name << "' at YAML section number " << i << ".\n"; - return 1; + return false; } } + return true; +} - ELFState<ELFT> State(Header, CBA, DotStrtabSecNo, SN2I); +template <class ELFT> +int ELFState<ELFT>::writeELF(raw_ostream &OS, const ELFYAML::Object &Doc) { + ELFState<ELFT> State(Doc); + if (!State.buildSectionIndex()) + return 1; - StringTableBuilder SHStrTab; - std::vector<Elf_Shdr> SHeaders; - { - // Ensure SHN_UNDEF entry is present. An all-zero section header is a - // valid SHN_UNDEF entry since SHT_NULL == 0. - Elf_Shdr SHdr; - zero(SHdr); - SHeaders.push_back(SHdr); - } - for (unsigned i = 0, e = Sections.size(); i != e; ++i) { - const ELFYAML::Section &Sec = Sections[i]; - Elf_Shdr SHeader; - zero(SHeader); - SHeader.sh_name = SHStrTab.addString(Sec.Name); - SHeader.sh_type = Sec.Type; - SHeader.sh_flags = Sec.Flags; - SHeader.sh_addr = Sec.Address; + Elf_Ehdr Header; + State.initELFHeader(Header); - Sec.Content.writeAsBinary(CBA.getOSAndAlignedOffset(SHeader.sh_offset)); - SHeader.sh_size = Sec.Content.binary_size(); + // TODO: Flesh out section header support. + // TODO: Program headers. - if (!Sec.Link.empty()) { - unsigned Index; - if (SN2I.lookupSection(Sec.Link, Index)) { - errs() << "error: Unknown section referenced: '" << Sec.Link - << "' at YAML section number " << i << ".\n"; - return 1; - } - SHeader.sh_link = Index; - } - SHeader.sh_info = 0; - SHeader.sh_addralign = Sec.AddressAlign; - SHeader.sh_entsize = 0; - SHeaders.push_back(SHeader); - } + // XXX: This offset is tightly coupled with the order that we write + // things to `OS`. + const size_t SectionContentBeginOffset = + Header.e_ehsize + Header.e_shentsize * Header.e_shnum; + ContiguousBlobAccumulator CBA(SectionContentBeginOffset); + + std::vector<Elf_Shdr> SHeaders; + if(!State.initSectionHeaders(SHeaders, CBA)) + return 1; // .symtab section. Elf_Shdr SymtabSHeader; - zero(SymtabSHeader); - SymtabSHeader.sh_name = SHStrTab.addString(StringRef(".symtab")); - handleSymtabSectionHeader<ELFT>(Doc.Symbols, State, SymtabSHeader); + State.initSymtabSectionHeader(SymtabSHeader, CBA); SHeaders.push_back(SymtabSHeader); // .strtab string table header. Elf_Shdr DotStrTabSHeader; - zero(DotStrTabSHeader); - DotStrTabSHeader.sh_name = SHStrTab.addString(StringRef(".strtab")); - createStringTableSectionHeader(DotStrTabSHeader, State.getStringTable(), CBA); + State.initStrtabSectionHeader(DotStrTabSHeader, ".strtab", State.DotStrtab, + CBA); SHeaders.push_back(DotStrTabSHeader); - // Section header string table header. - Elf_Shdr SHStrTabSHeader; - zero(SHStrTabSHeader); - createStringTableSectionHeader(SHStrTabSHeader, SHStrTab, CBA); - SHeaders.push_back(SHStrTabSHeader); + // .shstrtab string table header. + Elf_Shdr ShStrTabSHeader; + State.initStrtabSectionHeader(ShStrTabSHeader, ".shstrtab", State.DotShStrtab, + CBA); + SHeaders.push_back(ShStrTabSHeader); OS.write((const char *)&Header, sizeof(Header)); writeArrayData(OS, makeArrayRef(SHeaders)); @@ -389,13 +395,13 @@ int yaml2elf(llvm::raw_ostream &Out, llvm::MemoryBuffer *Buf) { typedef ELFType<support::big, 4, false> BE32; if (is64Bit(Doc)) { if (isLittleEndian(Doc)) - return writeELF<LE64>(outs(), Doc); + return ELFState<LE64>::writeELF(outs(), Doc); else - return writeELF<BE64>(outs(), Doc); + return ELFState<BE64>::writeELF(outs(), Doc); } else { if (isLittleEndian(Doc)) - return writeELF<LE32>(outs(), Doc); + return ELFState<LE32>::writeELF(outs(), Doc); else - return writeELF<BE32>(outs(), Doc); + return ELFState<BE32>::writeELF(outs(), Doc); } } diff --git a/tools/yaml2obj/yaml2obj.cpp b/tools/yaml2obj/yaml2obj.cpp index 6d1107c..cc0fecc 100644 --- a/tools/yaml2obj/yaml2obj.cpp +++ b/tools/yaml2obj/yaml2obj.cpp @@ -15,7 +15,6 @@ //===----------------------------------------------------------------------===// #include "yaml2obj.h" -#include "llvm/ADT/OwningPtr.h" #include "llvm/Support/CommandLine.h" #include "llvm/Support/ManagedStatic.h" #include "llvm/Support/MemoryBuffer.h" @@ -57,7 +56,7 @@ int main(int argc, char **argv) { PrettyStackTraceProgram X(argc, argv); llvm_shutdown_obj Y; // Call llvm_shutdown() on exit. - OwningPtr<MemoryBuffer> Buf; + std::unique_ptr<MemoryBuffer> Buf; if (MemoryBuffer::getFileOrSTDIN(Input, Buf)) return 1; if (Format == YOF_COFF) { |