From f2e78818e80ab48c949bbfd8c4867d2ec5832727 Mon Sep 17 00:00:00 2001 From: Rui Ueyama Date: Thu, 20 Oct 2016 06:34:03 +0000 Subject: [PATCH] Rename variables so that they are more in line with rest of the code. llvm-svn: 284699 --- lld/ELF/ELFCreator.cpp | 23 +++++++++-------------- lld/ELF/ELFCreator.h | 8 ++++---- lld/ELF/InputFiles.cpp | 14 +++++++------- 3 files changed, 20 insertions(+), 25 deletions(-) diff --git a/lld/ELF/ELFCreator.cpp b/lld/ELF/ELFCreator.cpp index 3130d0d..27a1bf6 100644 --- a/lld/ELF/ELFCreator.cpp +++ b/lld/ELF/ELFCreator.cpp @@ -29,15 +29,10 @@ ELFCreator::ELFCreator(std::uint16_t Type, std::uint16_t Machine) { ? ELFDATA2LSB : ELFDATA2MSB; Header.e_ident[EI_VERSION] = EV_CURRENT; - Header.e_ident[EI_OSABI] = 0; Header.e_type = Type; Header.e_machine = Machine; Header.e_version = EV_CURRENT; - Header.e_entry = 0; - Header.e_phoff = 0; - Header.e_flags = 0; Header.e_ehsize = sizeof(Elf_Ehdr); - Header.e_phnum = 0; Header.e_shentsize = sizeof(Elf_Shdr); Header.e_shstrndx = 1; @@ -61,7 +56,7 @@ template typename ELFCreator::Section ELFCreator::addSection(StringRef Name) { auto Shdr = new (Alloc) Elf_Shdr{}; - Shdr->sh_name = SecHdrStrTabBuilder.add(Name); + Shdr->sh_name = ShStrTabBuilder.add(Name); Sections.push_back(Shdr); return {Shdr, Sections.size()}; } @@ -70,18 +65,18 @@ template typename ELFCreator::Symbol ELFCreator::addSymbol(StringRef Name) { auto Sym = new (Alloc) Elf_Sym{}; Sym->st_name = StrTabBuilder.add(Name); - StaticSymbols.push_back(Sym); - return {Sym, StaticSymbols.size()}; + Symbols.push_back(Sym); + return {Sym, Symbols.size()}; } template size_t ELFCreator::layout() { - SecHdrStrTabBuilder.finalizeInOrder(); - ShStrTab->sh_size = SecHdrStrTabBuilder.getSize(); + ShStrTabBuilder.finalizeInOrder(); + ShStrTab->sh_size = ShStrTabBuilder.getSize(); StrTabBuilder.finalizeInOrder(); StrTab->sh_size = StrTabBuilder.getSize(); - SymTab->sh_size = (StaticSymbols.size() + 1) * sizeof(Elf_Sym); + SymTab->sh_size = (Symbols.size() + 1) * sizeof(Elf_Sym); uintX_t Offset = sizeof(Elf_Ehdr); for (Elf_Shdr *Sec : Sections) { @@ -98,15 +93,15 @@ template size_t ELFCreator::layout() { return Offset; } -template void ELFCreator::write(uint8_t *Out) { +template void ELFCreator::writeTo(uint8_t *Out) { std::memcpy(Out, &Header, sizeof(Elf_Ehdr)); - SecHdrStrTabBuilder.write(Out + ShStrTab->sh_offset); + ShStrTabBuilder.write(Out + ShStrTab->sh_offset); StrTabBuilder.write(Out + StrTab->sh_offset); Elf_Sym *Sym = reinterpret_cast(Out + SymTab->sh_offset); // Skip null. ++Sym; - for (Elf_Sym *S : StaticSymbols) + for (Elf_Sym *S : Symbols) *Sym++ = *S; Elf_Shdr *Shdr = reinterpret_cast(Out + Header.e_shoff); diff --git a/lld/ELF/ELFCreator.h b/lld/ELF/ELFCreator.h index 9efe76e..c720aa9 100644 --- a/lld/ELF/ELFCreator.h +++ b/lld/ELF/ELFCreator.h @@ -39,13 +39,13 @@ public: Section addSection(StringRef Name); Symbol addSymbol(StringRef Name); size_t layout(); - void write(uint8_t *Out); + void writeTo(uint8_t *Out); private: - Elf_Ehdr Header; + Elf_Ehdr Header = {}; std::vector Sections; - std::vector StaticSymbols; - llvm::StringTableBuilder SecHdrStrTabBuilder{llvm::StringTableBuilder::ELF}; + std::vector Symbols; + llvm::StringTableBuilder ShStrTabBuilder{llvm::StringTableBuilder::ELF}; llvm::StringTableBuilder StrTabBuilder{llvm::StringTableBuilder::ELF}; llvm::BumpPtrAllocator Alloc; Elf_Shdr *ShStrTab; diff --git a/lld/ELF/InputFiles.cpp b/lld/ELF/InputFiles.cpp index c70a850..a2c1f71 100644 --- a/lld/ELF/InputFiles.cpp +++ b/lld/ELF/InputFiles.cpp @@ -782,8 +782,8 @@ static InputFile *createELFFile(MemoryBufferRef MB) { // so that we can link it as a regular ELF file. template InputFile *BinaryFile::createELF() { // Fill the ELF file header. - ELFCreator ELF(ET_REL, Config->EMachine); - auto DataSec = ELF.addSection(".data"); + ELFCreator File(ET_REL, Config->EMachine); + auto DataSec = File.addSection(".data"); DataSec.Header->sh_flags = SHF_ALLOC; DataSec.Header->sh_size = MB.getBufferSize(); DataSec.Header->sh_type = SHT_PROGBITS; @@ -796,26 +796,26 @@ template InputFile *BinaryFile::createELF() { // Add _start, _end and _size symbols. std::string StartSym = "_binary_" + Filepath + "_start"; - auto SSym = ELF.addSymbol(StartSym); + auto SSym = File.addSymbol(StartSym); SSym.Sym->setBindingAndType(STB_GLOBAL, STT_OBJECT); SSym.Sym->st_shndx = DataSec.Index; std::string EndSym = "_binary_" + Filepath + "_end"; - auto ESym = ELF.addSymbol(EndSym); + auto ESym = File.addSymbol(EndSym); ESym.Sym->setBindingAndType(STB_GLOBAL, STT_OBJECT); ESym.Sym->st_shndx = DataSec.Index; ESym.Sym->st_value = MB.getBufferSize(); std::string SizeSym = "_binary_" + Filepath + "_size"; - auto SZSym = ELF.addSymbol(SizeSym); + auto SZSym = File.addSymbol(SizeSym); SZSym.Sym->setBindingAndType(STB_GLOBAL, STT_OBJECT); SZSym.Sym->st_shndx = SHN_ABS; SZSym.Sym->st_value = MB.getBufferSize(); // Fix the ELF file layout and write it down to ELFData uint8_t vector. - size_t Size = ELF.layout(); + size_t Size = File.layout(); ELFData.resize(Size); - ELF.write(ELFData.data()); + File.writeTo(ELFData.data()); // Fill .data section with actual data. std::copy(MB.getBufferStart(), MB.getBufferEnd(), -- 2.7.4