summaryrefslogtreecommitdiff
path: root/lld/ELF/InputFiles.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'lld/ELF/InputFiles.cpp')
-rw-r--r--lld/ELF/InputFiles.cpp67
1 files changed, 30 insertions, 37 deletions
diff --git a/lld/ELF/InputFiles.cpp b/lld/ELF/InputFiles.cpp
index 4da371c619f4..b5510b3b2736 100644
--- a/lld/ELF/InputFiles.cpp
+++ b/lld/ELF/InputFiles.cpp
@@ -13,6 +13,7 @@
#include "SymbolTable.h"
#include "Symbols.h"
#include "SyntheticSections.h"
+#include "Target.h"
#include "lld/Common/CommonLinkerContext.h"
#include "lld/Common/DWARF.h"
#include "llvm/ADT/STLExtras.h"
@@ -217,24 +218,7 @@ template <class ELFT> static void doParseFile(InputFile *file) {
}
// Add symbols in File to the symbol table.
-void elf::parseFile(InputFile *file) {
- switch (config->ekind) {
- case ELF32LEKind:
- doParseFile<ELF32LE>(file);
- return;
- case ELF32BEKind:
- doParseFile<ELF32BE>(file);
- return;
- case ELF64LEKind:
- doParseFile<ELF64LE>(file);
- return;
- case ELF64BEKind:
- doParseFile<ELF64BE>(file);
- return;
- default:
- llvm_unreachable("unknown ELFT");
- }
-}
+void elf::parseFile(InputFile *file) { invokeELFT(doParseFile, file); }
// Concatenates arguments to construct a string representing an error location.
static std::string createFileLineMsg(StringRef path, unsigned line) {
@@ -401,14 +385,15 @@ uint32_t ObjFile<ELFT>::getSectionIndex(const Elf_Sym &sym) const {
}
template <class ELFT> void ObjFile<ELFT>::parse(bool ignoreComdats) {
+ object::ELFFile<ELFT> obj = this->getObj();
// Read a section table. justSymbols is usually false.
if (this->justSymbols)
initializeJustSymbols();
else
- initializeSections(ignoreComdats);
+ initializeSections(ignoreComdats, obj);
// Read a symbol table.
- initializeSymbols();
+ initializeSymbols(obj);
}
// Sections with SHT_GROUP and comdat bits define comdat section groups.
@@ -490,12 +475,12 @@ template <class ELFT> void ObjFile<ELFT>::initializeJustSymbols() {
static void addDependentLibrary(StringRef specifier, const InputFile *f) {
if (!config->dependentLibraries)
return;
- if (fs::exists(specifier))
- driver->addFile(specifier, /*withLOption=*/false);
- else if (Optional<std::string> s = findFromSearchPaths(specifier))
+ if (Optional<std::string> s = searchLibraryBaseName(specifier))
driver->addFile(*s, /*withLOption=*/true);
- else if (Optional<std::string> s = searchLibraryBaseName(specifier))
+ else if (Optional<std::string> s = findFromSearchPaths(specifier))
driver->addFile(*s, /*withLOption=*/true);
+ else if (fs::exists(specifier))
+ driver->addFile(specifier, /*withLOption=*/false);
else
error(toString(f) +
": unable to find library from dependent library specifier: " +
@@ -541,9 +526,8 @@ static void handleSectionGroup(ArrayRef<InputSectionBase *> sections,
}
template <class ELFT>
-void ObjFile<ELFT>::initializeSections(bool ignoreComdats) {
- const ELFFile<ELFT> &obj = this->getObj();
-
+void ObjFile<ELFT>::initializeSections(bool ignoreComdats,
+ const llvm::object::ELFFile<ELFT> &obj) {
ArrayRef<Elf_Shdr> objSections = getELFShdrs<ELFT>();
StringRef shstrtab = CHECK(obj.getSectionStringTable(objSections), this);
uint64_t size = objSections.size();
@@ -602,7 +586,8 @@ void ObjFile<ELFT>::initializeSections(bool ignoreComdats) {
.second;
if (keepGroup) {
if (config->relocatable)
- this->sections[i] = createInputSection(i, sec, shstrtab);
+ this->sections[i] = createInputSection(
+ i, sec, check(obj.getSectionName(sec, shstrtab)));
selectedGroups.push_back(entries);
continue;
}
@@ -626,7 +611,8 @@ void ObjFile<ELFT>::initializeSections(bool ignoreComdats) {
case SHT_NULL:
break;
default:
- this->sections[i] = createInputSection(i, sec, shstrtab);
+ this->sections[i] =
+ createInputSection(i, sec, check(obj.getSectionName(sec, shstrtab)));
}
}
@@ -891,10 +877,8 @@ InputSectionBase *ObjFile<ELFT>::getRelocTarget(uint32_t idx,
template <class ELFT>
InputSectionBase *ObjFile<ELFT>::createInputSection(uint32_t idx,
const Elf_Shdr &sec,
- StringRef shstrtab) {
- StringRef name = CHECK(getObj().getSectionName(sec, shstrtab), this);
-
- if (config->emachine == EM_ARM && sec.sh_type == SHT_ARM_ATTRIBUTES) {
+ StringRef name) {
+ if (sec.sh_type == SHT_ARM_ATTRIBUTES && config->emachine == EM_ARM) {
ARMAttributeParser attributes;
ArrayRef<uint8_t> contents = check(this->getObj().getSectionContents(sec));
if (Error e = attributes.parse(contents, config->ekind == ELF32LEKind
@@ -918,7 +902,7 @@ InputSectionBase *ObjFile<ELFT>::createInputSection(uint32_t idx,
}
}
- if (config->emachine == EM_RISCV && sec.sh_type == SHT_RISCV_ATTRIBUTES) {
+ if (sec.sh_type == SHT_RISCV_ATTRIBUTES && config->emachine == EM_RISCV) {
RISCVAttributeParser attributes;
ArrayRef<uint8_t> contents = check(this->getObj().getSectionContents(sec));
if (Error e = attributes.parse(contents, support::little)) {
@@ -1040,7 +1024,8 @@ InputSectionBase *ObjFile<ELFT>::createInputSection(uint32_t idx,
// Initialize this->Symbols. this->Symbols is a parallel array as
// its corresponding ELF symbol table.
-template <class ELFT> void ObjFile<ELFT>::initializeSymbols() {
+template <class ELFT>
+void ObjFile<ELFT>::initializeSymbols(const object::ELFFile<ELFT> &obj) {
ArrayRef<InputSectionBase *> sections(this->sections);
SymbolTable &symtab = *elf::symtab;
@@ -1053,7 +1038,11 @@ template <class ELFT> void ObjFile<ELFT>::initializeSymbols() {
for (size_t i = 0, end = firstGlobal; i != end; ++i) {
const Elf_Sym &eSym = eSyms[i];
- uint32_t secIdx = getSectionIndex(eSym);
+ uint32_t secIdx = eSym.st_shndx;
+ if (LLVM_UNLIKELY(secIdx == SHN_XINDEX))
+ secIdx = check(getExtendedSymbolTableIndex<ELFT>(eSym, i, shndxTable));
+ else if (secIdx >= SHN_LORESERVE)
+ secIdx = 0;
if (LLVM_UNLIKELY(secIdx >= sections.size()))
fatal(toString(this) + ": invalid section index: " + Twine(secIdx));
if (LLVM_UNLIKELY(eSym.getBinding() != STB_LOCAL))
@@ -1093,7 +1082,11 @@ template <class ELFT> void ObjFile<ELFT>::initializeSymbols() {
Twine(firstGlobal) + ")");
continue;
}
- uint32_t secIdx = getSectionIndex(eSym);
+ uint32_t secIdx = eSym.st_shndx;
+ if (LLVM_UNLIKELY(secIdx == SHN_XINDEX))
+ secIdx = check(getExtendedSymbolTableIndex<ELFT>(eSym, i, shndxTable));
+ else if (secIdx >= SHN_LORESERVE)
+ secIdx = 0;
if (LLVM_UNLIKELY(secIdx >= sections.size()))
fatal(toString(this) + ": invalid section index: " + Twine(secIdx));
InputSectionBase *sec = sections[secIdx];