summaryrefslogtreecommitdiffstats
path: root/lld/ELF/InputFiles.cpp
diff options
context:
space:
mode:
authorRafael Espindola <rafael.espindola@gmail.com>2016-10-27 17:45:40 +0000
committerRafael Espindola <rafael.espindola@gmail.com>2016-10-27 17:45:40 +0000
commit093abab817e61da02ddc30774b22a16641deac38 (patch)
tree231e6cd2c0452af501838bd0bd5a8c3f46588c29 /lld/ELF/InputFiles.cpp
parent9a134fc917ad83e00bf5f591f296643749776859 (diff)
downloadbcm5719-llvm-093abab817e61da02ddc30774b22a16641deac38.tar.gz
bcm5719-llvm-093abab817e61da02ddc30774b22a16641deac38.zip
Don't create a dummy ELF to process a binary file.
Now that it is easy to create input section and symbols, this is simple. llvm-svn: 285322
Diffstat (limited to 'lld/ELF/InputFiles.cpp')
-rw-r--r--lld/ELF/InputFiles.cpp39
1 files changed, 26 insertions, 13 deletions
diff --git a/lld/ELF/InputFiles.cpp b/lld/ELF/InputFiles.cpp
index 34e55efd6fa..355d406a838 100644
--- a/lld/ELF/InputFiles.cpp
+++ b/lld/ELF/InputFiles.cpp
@@ -9,7 +9,6 @@
#include "InputFiles.h"
#include "Driver.h"
-#include "ELFCreator.h"
#include "Error.h"
#include "InputSection.h"
#include "LinkerScript.h"
@@ -822,15 +821,29 @@ static InputFile *createELFFile(BumpPtrAllocator &Alloc, MemoryBufferRef MB) {
return Obj;
}
-// 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() {
- ArrayRef<uint8_t> Blob((uint8_t *)MB.getBufferStart(), MB.getBufferSize());
- StringRef Filename = MB.getBufferIdentifier();
- Buffer = wrapBinaryWithElfHeader<ELFT>(Blob, Filename);
+template <class ELFT> void BinaryFile::parse() {
+ StringRef Buf = MB.getBuffer();
+ ArrayRef<uint8_t> Data =
+ makeArrayRef<uint8_t>((const uint8_t *)Buf.data(), Buf.size());
- return createELFFile<ObjectFile>(
- Alloc, MemoryBufferRef(toStringRef(Buffer), Filename));
+ std::string Filename = MB.getBufferIdentifier();
+ std::transform(Filename.begin(), Filename.end(), Filename.begin(),
+ [](char C) { return isalnum(C) ? C : '_'; });
+ Filename = "_binary_" + Filename;
+ StringRef StartName = Saver.save(Twine(Filename) + "_start");
+ StringRef EndName = Saver.save(Twine(Filename) + "_end");
+ StringRef SizeName = Saver.save(Twine(Filename) + "_size");
+
+ auto *Section =
+ new InputSection<ELFT>(SHF_ALLOC, SHT_PROGBITS, 8, Data, ".data");
+ Sections.push_back(Section);
+
+ elf::Symtab<ELFT>::X->addRegular(StartName, STV_DEFAULT, Section, STB_GLOBAL,
+ STT_OBJECT, 0);
+ elf::Symtab<ELFT>::X->addRegular(EndName, STV_DEFAULT, Section, STB_GLOBAL,
+ STT_OBJECT, Data.size());
+ elf::Symtab<ELFT>::X->addRegular(SizeName, STV_DEFAULT, nullptr, STB_GLOBAL,
+ STT_OBJECT, Data.size());
}
static bool isBitcode(MemoryBufferRef MB) {
@@ -942,10 +955,10 @@ template class elf::SharedFile<ELF32BE>;
template class elf::SharedFile<ELF64LE>;
template class elf::SharedFile<ELF64BE>;
-template InputFile *BinaryFile::createELF<ELF32LE>();
-template InputFile *BinaryFile::createELF<ELF32BE>();
-template InputFile *BinaryFile::createELF<ELF64LE>();
-template InputFile *BinaryFile::createELF<ELF64BE>();
+template void BinaryFile::parse<ELF32LE>();
+template void BinaryFile::parse<ELF32BE>();
+template void BinaryFile::parse<ELF64LE>();
+template void BinaryFile::parse<ELF64BE>();
template class elf::DIHelper<ELF32LE>;
template class elf::DIHelper<ELF32BE>;
OpenPOWER on IntegriCloud