From 2795627509076c4d3e2b96234f92ec5c00c722fa Mon Sep 17 00:00:00 2001 From: Rui Ueyama Date: Fri, 21 Oct 2016 04:32:46 +0000 Subject: [PATCH] Simplify by merging a lambda with addSymbol. NFC. llvm-svn: 284804 --- lld/ELF/ELFCreator.cpp | 26 ++++++++++---------------- 1 file changed, 10 insertions(+), 16 deletions(-) diff --git a/lld/ELF/ELFCreator.cpp b/lld/ELF/ELFCreator.cpp index 2b49643..9d1904e 100644 --- a/lld/ELF/ELFCreator.cpp +++ b/lld/ELF/ELFCreator.cpp @@ -40,7 +40,7 @@ public: ELFCreator(std::uint16_t Type, std::uint16_t Machine); Section addSection(StringRef Name); - Elf_Sym *addSymbol(StringRef Name); + void addSymbol(StringRef Name, uintX_t SecIdx, uintX_t Value); size_t layout(); void writeTo(uint8_t *Out); @@ -92,11 +92,14 @@ ELFCreator::addSection(StringRef Name) { } template -typename ELFT::Sym *ELFCreator::addSymbol(StringRef Name) { +void ELFCreator::addSymbol(StringRef Name, uintX_t SecIdx, + uintX_t Value) { auto *Sym = new (Alloc) Elf_Sym{}; Sym->st_name = StrTabBuilder.add(Saver.save(Name)); + Sym->setBindingAndType(STB_GLOBAL, STT_OBJECT); + Sym->st_shndx = SecIdx; + Sym->st_value = Value; Symbols.push_back(Sym); - return Sym; } template size_t ELFCreator::layout() { @@ -138,12 +141,9 @@ template void ELFCreator::writeTo(uint8_t *Out) { template std::vector elf::wrapBinaryWithElfHeader(ArrayRef Blob, std::string Filename) { - typedef typename ELFT::uint uintX_t; - typedef typename ELFT::Sym Elf_Sym; - // Fill the ELF file header. ELFCreator File(ET_REL, Config->EMachine); - auto Sec = File.addSection(".data"); + typename ELFCreator::Section Sec = File.addSection(".data"); Sec.Header->sh_flags = SHF_ALLOC; Sec.Header->sh_size = Blob.size(); Sec.Header->sh_type = SHT_PROGBITS; @@ -154,15 +154,9 @@ std::vector elf::wrapBinaryWithElfHeader(ArrayRef Blob, [](char C) { return isalnum(C) ? C : '_'; }); // Add _start, _end and _size symbols. - 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; - }; - AddSym("_start", Sec.Index, 0); - AddSym("_end", Sec.Index, Blob.size()); - AddSym("_size", SHN_ABS, Blob.size()); + File.addSymbol("_binary_" + Filename + "_start", Sec.Index, 0); + File.addSymbol("_binary_" + Filename + "_end", Sec.Index, Blob.size()); + File.addSymbol("_binary_" + Filename + "_size", SHN_ABS, Blob.size()); // Fix the ELF file layout and write it down to a uint8_t vector. size_t Size = File.layout(); -- 2.7.4