2015-07-25 05:03:07 +08:00
|
|
|
//===- InputFiles.cpp -----------------------------------------------------===//
|
|
|
|
//
|
|
|
|
// The LLVM Linker
|
|
|
|
//
|
|
|
|
// This file is distributed under the University of Illinois Open Source
|
|
|
|
// License. See LICENSE.TXT for details.
|
|
|
|
//
|
|
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
|
|
|
|
#include "InputFiles.h"
|
2015-09-22 08:01:39 +08:00
|
|
|
#include "InputSection.h"
|
2015-08-06 23:08:23 +08:00
|
|
|
#include "Error.h"
|
2015-07-25 05:03:07 +08:00
|
|
|
#include "Symbols.h"
|
|
|
|
#include "llvm/ADT/STLExtras.h"
|
|
|
|
|
2015-09-05 06:28:10 +08:00
|
|
|
using namespace llvm;
|
2015-07-25 05:03:07 +08:00
|
|
|
using namespace llvm::ELF;
|
2015-09-04 04:03:54 +08:00
|
|
|
using namespace llvm::object;
|
2015-10-01 01:06:09 +08:00
|
|
|
using namespace llvm::sys::fs;
|
2015-07-25 05:03:07 +08:00
|
|
|
|
|
|
|
using namespace lld;
|
|
|
|
using namespace lld::elf2;
|
|
|
|
|
2015-09-24 23:11:50 +08:00
|
|
|
namespace {
|
|
|
|
class ECRAII {
|
2015-07-25 05:03:07 +08:00
|
|
|
std::error_code EC;
|
2015-09-24 23:11:50 +08:00
|
|
|
|
|
|
|
public:
|
|
|
|
std::error_code &getEC() { return EC; }
|
|
|
|
~ECRAII() { error(EC); }
|
|
|
|
};
|
2015-09-04 04:03:54 +08:00
|
|
|
}
|
|
|
|
|
2015-09-24 23:11:50 +08:00
|
|
|
template <class ELFT>
|
2015-10-13 09:17:02 +08:00
|
|
|
ELFFileBase<ELFT>::ELFFileBase(Kind K, MemoryBufferRef M)
|
|
|
|
: InputFile(K, M), ELFObj(MB.getBuffer(), ECRAII().getEC()) {}
|
2015-09-24 23:11:50 +08:00
|
|
|
|
2015-09-08 23:50:05 +08:00
|
|
|
template <class ELFT>
|
2015-10-12 09:55:32 +08:00
|
|
|
typename ELFFileBase<ELFT>::Elf_Sym_Range
|
|
|
|
ELFFileBase<ELFT>::getSymbolsHelper(bool Local) {
|
2015-09-08 23:50:05 +08:00
|
|
|
if (!Symtab)
|
|
|
|
return Elf_Sym_Range(nullptr, nullptr);
|
2015-09-24 23:11:50 +08:00
|
|
|
Elf_Sym_Range Syms = ELFObj.symbols(Symtab);
|
2015-09-17 04:45:57 +08:00
|
|
|
uint32_t NumSymbols = std::distance(Syms.begin(), Syms.end());
|
|
|
|
uint32_t FirstNonLocal = Symtab->sh_info;
|
|
|
|
if (FirstNonLocal > NumSymbols)
|
|
|
|
error("Invalid sh_info in symbol table");
|
|
|
|
if (!Local)
|
2015-09-30 10:37:51 +08:00
|
|
|
return make_range(Syms.begin() + FirstNonLocal, Syms.end());
|
|
|
|
// +1 to skip over dummy symbol.
|
|
|
|
return make_range(Syms.begin() + 1, Syms.begin() + FirstNonLocal);
|
2015-09-17 04:45:57 +08:00
|
|
|
}
|
2015-09-08 23:50:05 +08:00
|
|
|
|
2015-10-12 09:55:32 +08:00
|
|
|
template <class ELFT> void ELFFileBase<ELFT>::initStringTable() {
|
2015-10-02 04:26:37 +08:00
|
|
|
if (!Symtab)
|
|
|
|
return;
|
2015-09-24 23:11:50 +08:00
|
|
|
ErrorOr<StringRef> StringTableOrErr = ELFObj.getStringTableForSymtab(*Symtab);
|
2015-09-08 23:50:05 +08:00
|
|
|
error(StringTableOrErr.getError());
|
|
|
|
StringTable = *StringTableOrErr;
|
2015-10-02 03:52:48 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
template <class ELFT>
|
2015-10-12 09:55:32 +08:00
|
|
|
typename ELFFileBase<ELFT>::Elf_Sym_Range
|
|
|
|
ELFFileBase<ELFT>::getNonLocalSymbols() {
|
2015-09-17 04:45:57 +08:00
|
|
|
return getSymbolsHelper(false);
|
|
|
|
}
|
2015-09-08 23:50:05 +08:00
|
|
|
|
2015-09-24 23:11:50 +08:00
|
|
|
template <class ELFT>
|
|
|
|
ObjectFile<ELFT>::ObjectFile(MemoryBufferRef M)
|
2015-10-13 09:17:02 +08:00
|
|
|
: ELFFileBase<ELFT>(Base::ObjectKind, M) {}
|
2015-09-24 23:11:50 +08:00
|
|
|
|
2015-09-17 04:45:57 +08:00
|
|
|
template <class ELFT>
|
|
|
|
typename ObjectFile<ELFT>::Elf_Sym_Range ObjectFile<ELFT>::getLocalSymbols() {
|
|
|
|
return this->getSymbolsHelper(true);
|
2015-09-08 23:50:05 +08:00
|
|
|
}
|
|
|
|
|
2015-10-10 03:25:07 +08:00
|
|
|
template <class ELFT>
|
|
|
|
void elf2::ObjectFile<ELFT>::parse(DenseSet<StringRef> &Comdats) {
|
2015-07-25 05:03:07 +08:00
|
|
|
// Read section and symbol tables.
|
2015-10-10 03:25:07 +08:00
|
|
|
initializeSections(Comdats);
|
2015-07-25 05:03:07 +08:00
|
|
|
initializeSymbols();
|
|
|
|
}
|
|
|
|
|
2015-10-10 03:25:07 +08:00
|
|
|
template <class ELFT>
|
|
|
|
StringRef ObjectFile<ELFT>::getShtGroupSignature(const Elf_Shdr &Sec) {
|
|
|
|
const ELFFile<ELFT> &Obj = this->ELFObj;
|
|
|
|
uint32_t SymtabdSectionIndex = Sec.sh_link;
|
|
|
|
ErrorOr<const Elf_Shdr *> SecOrErr = Obj.getSection(SymtabdSectionIndex);
|
|
|
|
error(SecOrErr);
|
|
|
|
const Elf_Shdr *SymtabSec = *SecOrErr;
|
|
|
|
uint32_t SymIndex = Sec.sh_info;
|
|
|
|
const Elf_Sym *Sym = Obj.getSymbol(SymtabSec, SymIndex);
|
|
|
|
ErrorOr<StringRef> StringTableOrErr = Obj.getStringTableForSymtab(*SymtabSec);
|
|
|
|
error(StringTableOrErr);
|
|
|
|
ErrorOr<StringRef> SignatureOrErr = Sym->getName(*StringTableOrErr);
|
|
|
|
error(SignatureOrErr);
|
|
|
|
return *SignatureOrErr;
|
|
|
|
}
|
|
|
|
|
|
|
|
template <class ELFT>
|
|
|
|
ArrayRef<typename ObjectFile<ELFT>::GroupEntryType>
|
|
|
|
ObjectFile<ELFT>::getShtGroupEntries(const Elf_Shdr &Sec) {
|
|
|
|
const ELFFile<ELFT> &Obj = this->ELFObj;
|
|
|
|
ErrorOr<ArrayRef<GroupEntryType>> EntriesOrErr =
|
|
|
|
Obj.template getSectionContentsAsArray<GroupEntryType>(&Sec);
|
|
|
|
error(EntriesOrErr.getError());
|
|
|
|
ArrayRef<GroupEntryType> Entries = *EntriesOrErr;
|
|
|
|
if (Entries.empty() || Entries[0] != GRP_COMDAT)
|
|
|
|
error("Unsupported SHT_GROUP format");
|
|
|
|
return Entries.slice(1);
|
|
|
|
}
|
|
|
|
|
|
|
|
template <class ELFT>
|
|
|
|
void elf2::ObjectFile<ELFT>::initializeSections(DenseSet<StringRef> &Comdats) {
|
2015-09-24 23:11:50 +08:00
|
|
|
uint64_t Size = this->ELFObj.getNumSections();
|
2015-09-22 08:16:19 +08:00
|
|
|
Sections.resize(Size);
|
2015-10-10 03:25:07 +08:00
|
|
|
unsigned I = -1;
|
2015-10-08 20:02:38 +08:00
|
|
|
const ELFFile<ELFT> &Obj = this->ELFObj;
|
|
|
|
for (const Elf_Shdr &Sec : Obj.sections()) {
|
2015-10-10 03:25:07 +08:00
|
|
|
++I;
|
|
|
|
if (Sections[I] == &InputSection<ELFT>::Discarded)
|
|
|
|
continue;
|
|
|
|
|
2015-08-13 22:45:44 +08:00
|
|
|
switch (Sec.sh_type) {
|
2015-10-10 03:25:07 +08:00
|
|
|
case SHT_GROUP:
|
|
|
|
Sections[I] = &InputSection<ELFT>::Discarded;
|
|
|
|
if (Comdats.insert(getShtGroupSignature(Sec)).second)
|
|
|
|
continue;
|
|
|
|
for (GroupEntryType E : getShtGroupEntries(Sec)) {
|
|
|
|
uint32_t SecIndex = E;
|
|
|
|
if (SecIndex >= Size)
|
|
|
|
error("Invalid section index in group");
|
|
|
|
Sections[SecIndex] = &InputSection<ELFT>::Discarded;
|
|
|
|
}
|
|
|
|
break;
|
2015-08-13 22:45:44 +08:00
|
|
|
case SHT_SYMTAB:
|
2015-09-08 23:50:05 +08:00
|
|
|
this->Symtab = &Sec;
|
2015-08-13 22:45:44 +08:00
|
|
|
break;
|
2015-08-25 05:43:25 +08:00
|
|
|
case SHT_SYMTAB_SHNDX: {
|
2015-10-08 20:02:38 +08:00
|
|
|
ErrorOr<ArrayRef<Elf_Word>> ErrorOrTable = Obj.getSHNDXTable(Sec);
|
2015-08-25 05:43:25 +08:00
|
|
|
error(ErrorOrTable);
|
|
|
|
SymtabSHNDX = *ErrorOrTable;
|
|
|
|
break;
|
|
|
|
}
|
2015-08-13 22:45:44 +08:00
|
|
|
case SHT_STRTAB:
|
|
|
|
case SHT_NULL:
|
2015-08-28 07:15:56 +08:00
|
|
|
break;
|
2015-08-13 22:45:44 +08:00
|
|
|
case SHT_RELA:
|
2015-08-28 07:15:56 +08:00
|
|
|
case SHT_REL: {
|
|
|
|
uint32_t RelocatedSectionIndex = Sec.sh_info;
|
|
|
|
if (RelocatedSectionIndex >= Size)
|
|
|
|
error("Invalid relocated section index");
|
2015-09-22 08:16:19 +08:00
|
|
|
InputSection<ELFT> *RelocatedSection = Sections[RelocatedSectionIndex];
|
2015-08-28 07:15:56 +08:00
|
|
|
if (!RelocatedSection)
|
|
|
|
error("Unsupported relocation reference");
|
|
|
|
RelocatedSection->RelocSections.push_back(&Sec);
|
2015-08-13 22:45:44 +08:00
|
|
|
break;
|
2015-08-28 07:15:56 +08:00
|
|
|
}
|
2015-08-13 22:45:44 +08:00
|
|
|
default:
|
2015-10-12 09:55:32 +08:00
|
|
|
Sections[I] = new (this->Alloc) InputSection<ELFT>(this, &Sec);
|
2015-08-13 22:45:44 +08:00
|
|
|
break;
|
2015-07-25 05:03:07 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
template <class ELFT> void elf2::ObjectFile<ELFT>::initializeSymbols() {
|
2015-10-02 03:52:48 +08:00
|
|
|
this->initStringTable();
|
2015-09-08 23:50:05 +08:00
|
|
|
Elf_Sym_Range Syms = this->getNonLocalSymbols();
|
2015-08-12 04:06:51 +08:00
|
|
|
uint32_t NumSymbols = std::distance(Syms.begin(), Syms.end());
|
2015-10-12 09:55:32 +08:00
|
|
|
this->SymbolBodies.reserve(NumSymbols);
|
2015-08-04 22:00:56 +08:00
|
|
|
for (const Elf_Sym &Sym : Syms)
|
2015-10-12 09:55:32 +08:00
|
|
|
this->SymbolBodies.push_back(createSymbolBody(this->StringTable, &Sym));
|
2015-07-25 05:03:07 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
template <class ELFT>
|
|
|
|
SymbolBody *elf2::ObjectFile<ELFT>::createSymbolBody(StringRef StringTable,
|
|
|
|
const Elf_Sym *Sym) {
|
|
|
|
ErrorOr<StringRef> NameOrErr = Sym->getName(StringTable);
|
|
|
|
error(NameOrErr.getError());
|
|
|
|
StringRef Name = *NameOrErr;
|
2015-08-25 05:43:25 +08:00
|
|
|
|
|
|
|
uint32_t SecIndex = Sym->st_shndx;
|
2015-08-29 05:26:51 +08:00
|
|
|
switch (SecIndex) {
|
|
|
|
case SHN_ABS:
|
2015-10-12 09:55:32 +08:00
|
|
|
return new (this->Alloc) DefinedAbsolute<ELFT>(Name, *Sym);
|
2015-08-29 05:26:51 +08:00
|
|
|
case SHN_UNDEF:
|
2015-10-12 09:55:32 +08:00
|
|
|
return new (this->Alloc) Undefined<ELFT>(Name, *Sym);
|
2015-08-29 05:26:51 +08:00
|
|
|
case SHN_COMMON:
|
2015-10-12 09:55:32 +08:00
|
|
|
return new (this->Alloc) DefinedCommon<ELFT>(Name, *Sym);
|
2015-08-29 05:26:51 +08:00
|
|
|
case SHN_XINDEX:
|
2015-09-24 23:11:50 +08:00
|
|
|
SecIndex = this->ELFObj.getExtendedSymbolTableIndex(Sym, this->Symtab,
|
|
|
|
SymtabSHNDX);
|
2015-08-29 05:26:51 +08:00
|
|
|
break;
|
|
|
|
}
|
2015-08-25 05:43:25 +08:00
|
|
|
|
2015-10-09 04:29:22 +08:00
|
|
|
if (SecIndex >= Sections.size() || !SecIndex || !Sections[SecIndex])
|
2015-08-25 06:00:25 +08:00
|
|
|
error("Invalid section index");
|
|
|
|
|
2015-08-12 01:33:02 +08:00
|
|
|
switch (Sym->getBinding()) {
|
|
|
|
default:
|
|
|
|
error("unexpected binding");
|
|
|
|
case STB_GLOBAL:
|
2015-08-29 04:19:34 +08:00
|
|
|
case STB_WEAK:
|
2015-10-10 03:25:07 +08:00
|
|
|
case STB_GNU_UNIQUE: {
|
|
|
|
InputSection<ELFT> *Sec = Sections[SecIndex];
|
|
|
|
if (Sec == &InputSection<ELFT>::Discarded)
|
2015-10-12 09:55:32 +08:00
|
|
|
return new (this->Alloc) Undefined<ELFT>(Name, *Sym);
|
|
|
|
return new (this->Alloc) DefinedRegular<ELFT>(Name, *Sym, *Sec);
|
2015-10-10 03:25:07 +08:00
|
|
|
}
|
2015-08-12 01:33:02 +08:00
|
|
|
}
|
2015-07-25 05:03:07 +08:00
|
|
|
}
|
|
|
|
|
2015-10-02 02:02:21 +08:00
|
|
|
static std::unique_ptr<Archive> openArchive(MemoryBufferRef MB) {
|
2015-09-30 10:42:27 +08:00
|
|
|
ErrorOr<std::unique_ptr<Archive>> ArchiveOrErr = Archive::create(MB);
|
2015-09-05 06:28:10 +08:00
|
|
|
error(ArchiveOrErr, "Failed to parse archive");
|
2015-10-02 02:02:21 +08:00
|
|
|
return std::move(*ArchiveOrErr);
|
|
|
|
}
|
|
|
|
|
|
|
|
void ArchiveFile::parse() {
|
|
|
|
File = openArchive(MB);
|
2015-09-05 06:28:10 +08:00
|
|
|
|
|
|
|
// Allocate a buffer for Lazy objects.
|
|
|
|
size_t NumSyms = File->getNumberOfSymbols();
|
|
|
|
LazySymbols.reserve(NumSyms);
|
|
|
|
|
|
|
|
// Read the symbol table to construct Lazy objects.
|
|
|
|
for (const Archive::Symbol &Sym : File->symbols())
|
|
|
|
LazySymbols.emplace_back(this, Sym);
|
|
|
|
}
|
|
|
|
|
|
|
|
// Returns a buffer pointing to a member file containing a given symbol.
|
|
|
|
MemoryBufferRef ArchiveFile::getMember(const Archive::Symbol *Sym) {
|
|
|
|
ErrorOr<Archive::child_iterator> ItOrErr = Sym->getMember();
|
2015-10-12 23:49:06 +08:00
|
|
|
error(ItOrErr, "Could not get the member for symbol " + Sym->getName());
|
2015-09-05 06:28:10 +08:00
|
|
|
Archive::child_iterator It = *ItOrErr;
|
|
|
|
|
2015-09-09 04:36:20 +08:00
|
|
|
if (!Seen.insert(It->getChildOffset()).second)
|
2015-09-05 06:28:10 +08:00
|
|
|
return MemoryBufferRef();
|
2015-09-09 04:36:20 +08:00
|
|
|
|
2015-09-05 06:28:10 +08:00
|
|
|
ErrorOr<MemoryBufferRef> Ret = It->getMemoryBufferRef();
|
2015-10-12 23:49:06 +08:00
|
|
|
error(Ret, "Could not get the buffer for the member defining symbol " +
|
2015-09-05 06:28:10 +08:00
|
|
|
Sym->getName());
|
|
|
|
return *Ret;
|
|
|
|
}
|
|
|
|
|
2015-10-02 02:02:21 +08:00
|
|
|
std::vector<MemoryBufferRef> ArchiveFile::getMembers() {
|
|
|
|
File = openArchive(MB);
|
|
|
|
|
|
|
|
std::vector<MemoryBufferRef> Result;
|
|
|
|
for (const Archive::Child &Child : File->children()) {
|
|
|
|
ErrorOr<MemoryBufferRef> MbOrErr = Child.getMemoryBufferRef();
|
2015-10-12 23:49:06 +08:00
|
|
|
error(MbOrErr, "Could not get the buffer for a child of the archive " +
|
|
|
|
File->getFileName());
|
2015-10-02 02:02:21 +08:00
|
|
|
Result.push_back(MbOrErr.get());
|
|
|
|
}
|
|
|
|
return Result;
|
|
|
|
}
|
|
|
|
|
2015-09-24 23:11:50 +08:00
|
|
|
template <class ELFT>
|
|
|
|
SharedFile<ELFT>::SharedFile(MemoryBufferRef M)
|
2015-10-13 09:17:02 +08:00
|
|
|
: ELFFileBase<ELFT>(Base::SharedKind, M) {
|
2015-10-12 10:22:58 +08:00
|
|
|
AsNeeded = Config->AsNeeded;
|
|
|
|
}
|
2015-09-08 23:50:05 +08:00
|
|
|
|
2015-10-02 03:52:48 +08:00
|
|
|
template <class ELFT> void SharedFile<ELFT>::parseSoName() {
|
2015-10-01 23:47:50 +08:00
|
|
|
typedef typename ELFFile<ELFT>::Elf_Dyn Elf_Dyn;
|
|
|
|
typedef typename ELFFile<ELFT>::uintX_t uintX_t;
|
|
|
|
const Elf_Shdr *DynamicSec = nullptr;
|
|
|
|
|
|
|
|
const ELFFile<ELFT> Obj = this->ELFObj;
|
|
|
|
for (const Elf_Shdr &Sec : Obj.sections()) {
|
|
|
|
uint32_t Type = Sec.sh_type;
|
|
|
|
if (Type == SHT_DYNSYM)
|
2015-09-08 23:50:05 +08:00
|
|
|
this->Symtab = &Sec;
|
2015-10-01 23:47:50 +08:00
|
|
|
else if (Type == SHT_DYNAMIC)
|
|
|
|
DynamicSec = &Sec;
|
2015-09-08 23:50:05 +08:00
|
|
|
}
|
|
|
|
|
2015-10-02 03:52:48 +08:00
|
|
|
this->initStringTable();
|
2015-10-12 09:55:32 +08:00
|
|
|
this->SoName = this->getName();
|
2015-10-01 23:47:50 +08:00
|
|
|
|
2015-10-12 23:49:02 +08:00
|
|
|
if (!DynamicSec)
|
|
|
|
return;
|
|
|
|
auto *Begin =
|
|
|
|
reinterpret_cast<const Elf_Dyn *>(Obj.base() + DynamicSec->sh_offset);
|
|
|
|
const Elf_Dyn *End = Begin + DynamicSec->sh_size / sizeof(Elf_Dyn);
|
|
|
|
|
|
|
|
for (const Elf_Dyn &Dyn : make_range(Begin, End)) {
|
|
|
|
if (Dyn.d_tag == DT_SONAME) {
|
|
|
|
uintX_t Val = Dyn.getVal();
|
|
|
|
if (Val >= this->StringTable.size())
|
|
|
|
error("Invalid DT_SONAME entry");
|
|
|
|
this->SoName = StringRef(this->StringTable.data() + Val);
|
|
|
|
return;
|
2015-10-01 23:47:50 +08:00
|
|
|
}
|
|
|
|
}
|
2015-10-02 03:52:48 +08:00
|
|
|
}
|
2015-10-01 23:47:50 +08:00
|
|
|
|
2015-10-02 03:52:48 +08:00
|
|
|
template <class ELFT> void SharedFile<ELFT>::parse() {
|
|
|
|
Elf_Sym_Range Syms = this->getNonLocalSymbols();
|
2015-09-08 23:50:05 +08:00
|
|
|
uint32_t NumSymbols = std::distance(Syms.begin(), Syms.end());
|
|
|
|
SymbolBodies.reserve(NumSymbols);
|
|
|
|
for (const Elf_Sym &Sym : Syms) {
|
|
|
|
if (Sym.isUndefined())
|
|
|
|
continue;
|
|
|
|
|
|
|
|
ErrorOr<StringRef> NameOrErr = Sym.getName(this->StringTable);
|
|
|
|
error(NameOrErr.getError());
|
|
|
|
StringRef Name = *NameOrErr;
|
|
|
|
|
2015-10-12 04:59:12 +08:00
|
|
|
SymbolBodies.emplace_back(this, Name, Sym);
|
2015-09-08 23:50:05 +08:00
|
|
|
}
|
|
|
|
}
|
2015-09-04 04:03:54 +08:00
|
|
|
|
2015-10-12 23:31:09 +08:00
|
|
|
template <typename T>
|
|
|
|
static std::unique_ptr<InputFile> createELFFileAux(MemoryBufferRef MB) {
|
|
|
|
std::unique_ptr<T> Ret = llvm::make_unique<T>(MB);
|
|
|
|
|
|
|
|
if (!Config->FirstElf)
|
|
|
|
Config->FirstElf = Ret.get();
|
|
|
|
|
2015-10-14 00:20:50 +08:00
|
|
|
if (Config->EKind == ELFNoneKind) {
|
|
|
|
Config->EKind = Ret->getELFKind();
|
2015-10-12 23:31:09 +08:00
|
|
|
Config->EMachine = Ret->getEMachine();
|
|
|
|
}
|
|
|
|
|
|
|
|
return std::move(Ret);
|
|
|
|
}
|
|
|
|
|
|
|
|
template <template <class> class T>
|
|
|
|
std::unique_ptr<InputFile> lld::elf2::createELFFile(MemoryBufferRef MB) {
|
|
|
|
using namespace llvm;
|
|
|
|
|
|
|
|
std::pair<unsigned char, unsigned char> Type =
|
|
|
|
object::getElfArchType(MB.getBuffer());
|
|
|
|
if (Type.second != ELF::ELFDATA2LSB && Type.second != ELF::ELFDATA2MSB)
|
|
|
|
error("Invalid data encoding: " + MB.getBufferIdentifier());
|
|
|
|
|
|
|
|
if (Type.first == ELF::ELFCLASS32) {
|
|
|
|
if (Type.second == ELF::ELFDATA2LSB)
|
|
|
|
return createELFFileAux<T<object::ELF32LE>>(MB);
|
|
|
|
return createELFFileAux<T<object::ELF32BE>>(MB);
|
|
|
|
}
|
|
|
|
if (Type.first == ELF::ELFCLASS64) {
|
|
|
|
if (Type.second == ELF::ELFDATA2LSB)
|
|
|
|
return createELFFileAux<T<object::ELF64LE>>(MB);
|
|
|
|
return createELFFileAux<T<object::ELF64BE>>(MB);
|
|
|
|
}
|
|
|
|
error("Invalid file class: " + MB.getBufferIdentifier());
|
|
|
|
}
|
|
|
|
|
2015-07-25 05:03:07 +08:00
|
|
|
namespace lld {
|
|
|
|
namespace elf2 {
|
2015-10-12 09:55:32 +08:00
|
|
|
template class ELFFileBase<llvm::object::ELF32LE>;
|
|
|
|
template class ELFFileBase<llvm::object::ELF32BE>;
|
|
|
|
template class ELFFileBase<llvm::object::ELF64LE>;
|
|
|
|
template class ELFFileBase<llvm::object::ELF64BE>;
|
2015-09-17 04:45:57 +08:00
|
|
|
|
2015-10-12 23:27:09 +08:00
|
|
|
template class ObjectFile<llvm::object::ELF32LE>;
|
|
|
|
template class ObjectFile<llvm::object::ELF32BE>;
|
|
|
|
template class ObjectFile<llvm::object::ELF64LE>;
|
|
|
|
template class ObjectFile<llvm::object::ELF64BE>;
|
|
|
|
|
|
|
|
template class SharedFile<llvm::object::ELF32LE>;
|
|
|
|
template class SharedFile<llvm::object::ELF32BE>;
|
|
|
|
template class SharedFile<llvm::object::ELF64LE>;
|
|
|
|
template class SharedFile<llvm::object::ELF64BE>;
|
2015-10-12 23:31:09 +08:00
|
|
|
|
|
|
|
template std::unique_ptr<InputFile> createELFFile<ObjectFile>(MemoryBufferRef);
|
|
|
|
template std::unique_ptr<InputFile> createELFFile<SharedFile>(MemoryBufferRef);
|
2015-07-25 05:03:07 +08:00
|
|
|
}
|
|
|
|
}
|