diff options
| author | Rui Ueyama <ruiu@google.com> | 2016-10-20 21:57:06 +0000 |
|---|---|---|
| committer | Rui Ueyama <ruiu@google.com> | 2016-10-20 21:57:06 +0000 |
| commit | 617d587432739ed20ca4244debfdbfb3d6dad912 (patch) | |
| tree | bd2ae0c6f299ccc70bb209d7b49dd0949338daaa /lld/ELF/InputFiles.cpp | |
| parent | eb7ef2e1cae45a04ed92bf2ef7b02417e6022041 (diff) | |
| download | bcm5719-llvm-617d587432739ed20ca4244debfdbfb3d6dad912.tar.gz bcm5719-llvm-617d587432739ed20ca4244debfdbfb3d6dad912.zip | |
Move code from InputFile to ELFCreator to decouple the two files.
Now that only one non-member function is exported from ELFCreator.h.
All the details are handled internally in ELFCreator.cpp file.
llvm-svn: 284786
Diffstat (limited to 'lld/ELF/InputFiles.cpp')
| -rw-r--r-- | lld/ELF/InputFiles.cpp | 42 |
1 files changed, 5 insertions, 37 deletions
diff --git a/lld/ELF/InputFiles.cpp b/lld/ELF/InputFiles.cpp index 154f792e564..27cfcee6e7e 100644 --- a/lld/ELF/InputFiles.cpp +++ b/lld/ELF/InputFiles.cpp @@ -781,44 +781,12 @@ static InputFile *createELFFile(MemoryBufferRef MB) { // Wraps a binary blob with an ELF header and footer // so that we can link it as a regular ELF file. template <class ELFT> InputFile *BinaryFile::createELF() { - typedef typename ELFT::uint uintX_t; - typedef typename ELFT::Sym Elf_Sym; + ArrayRef<uint8_t> Blob((uint8_t *)MB.getBufferStart(), MB.getBufferSize()); + StringRef Filename = MB.getBufferIdentifier(); + Buffer = wrapBinaryWithElfHeader<ELFT>(Blob, Filename); - // Fill the ELF file header. - ELFCreator<ELFT> 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; - DataSec.Header->sh_addralign = 8; - - // Replace non-alphanumeric characters with '_'. - std::string Filepath = MB.getBufferIdentifier(); - std::transform(Filepath.begin(), Filepath.end(), Filepath.begin(), - [](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_" + Filepath + Name); - Sym->setBindingAndType(STB_GLOBAL, STT_OBJECT); - Sym->st_shndx = SecIdx; - Sym->st_value = Value; - }; - AddSym("_start", DataSec.Index, 0); - AddSym("_end", DataSec.Index, MB.getBufferSize()); - AddSym("_size", SHN_ABS, MB.getBufferSize()); - - // Fix the ELF file layout and write it down to ELFData uint8_t vector. - size_t Size = File.layout(); - ELFData.resize(Size); - File.writeTo(ELFData.data()); - - // Fill .data section with actual data. - memcpy(ELFData.data() + DataSec.Header->sh_offset, MB.getBufferStart(), - MB.getBufferSize()); - - return createELFFile<ObjectFile>(MemoryBufferRef( - StringRef((char *)ELFData.data(), Size), MB.getBufferIdentifier())); + return createELFFile<ObjectFile>( + MemoryBufferRef(toStringRef(Buffer), Filename)); } static bool isBitcode(MemoryBufferRef MB) { |

