summaryrefslogtreecommitdiffstats
path: root/lld/ELF/InputFiles.cpp
diff options
context:
space:
mode:
authorRui Ueyama <ruiu@google.com>2016-10-20 06:44:58 +0000
committerRui Ueyama <ruiu@google.com>2016-10-20 06:44:58 +0000
commit673c9d901882211602c5167877f750cf74465763 (patch)
treeb6e99af26868d5d782975d84bc65cff63f0d121e /lld/ELF/InputFiles.cpp
parentf2e78818e80ab48c949bbfd8c4867d2ec5832727 (diff)
downloadbcm5719-llvm-673c9d901882211602c5167877f750cf74465763.tar.gz
bcm5719-llvm-673c9d901882211602c5167877f750cf74465763.zip
Add a helper function to define symbols.
Also replace std::copy with memcpy because in other places we are using memcpy. llvm-svn: 284700
Diffstat (limited to 'lld/ELF/InputFiles.cpp')
-rw-r--r--lld/ELF/InputFiles.cpp32
1 files changed, 14 insertions, 18 deletions
diff --git a/lld/ELF/InputFiles.cpp b/lld/ELF/InputFiles.cpp
index a2c1f71e6ec..54f3a2faf76 100644
--- a/lld/ELF/InputFiles.cpp
+++ b/lld/ELF/InputFiles.cpp
@@ -781,6 +781,9 @@ 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;
+
// Fill the ELF file header.
ELFCreator<ELFT> File(ET_REL, Config->EMachine);
auto DataSec = File.addSection(".data");
@@ -795,22 +798,15 @@ template <class ELFT> InputFile *BinaryFile::createELF() {
[](char C) { return isalnum(C) ? C : '_'; });
// Add _start, _end and _size symbols.
- std::string StartSym = "_binary_" + Filepath + "_start";
- 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 = 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 = File.addSymbol(SizeSym);
- SZSym.Sym->setBindingAndType(STB_GLOBAL, STT_OBJECT);
- SZSym.Sym->st_shndx = SHN_ABS;
- SZSym.Sym->st_value = MB.getBufferSize();
+ 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();
@@ -818,8 +814,8 @@ template <class ELFT> InputFile *BinaryFile::createELF() {
File.writeTo(ELFData.data());
// Fill .data section with actual data.
- std::copy(MB.getBufferStart(), MB.getBufferEnd(),
- ELFData.data() + DataSec.Header->sh_offset);
+ memcpy(ELFData.data() + DataSec.Header->sh_offset, MB.getBufferStart(),
+ MB.getBufferSize());
return createELFFile<ObjectFile>(MemoryBufferRef(
StringRef((char *)ELFData.data(), Size), MB.getBufferIdentifier()));
OpenPOWER on IntegriCloud