aboutsummaryrefslogtreecommitdiff
path: root/contrib/llvm-project/lld/ELF/InputFiles.cpp
diff options
context:
space:
mode:
authorDimitry Andric <dim@FreeBSD.org>2022-03-20 11:40:34 +0000
committerDimitry Andric <dim@FreeBSD.org>2022-05-14 11:43:05 +0000
commit349cc55c9796c4596a5b9904cd3281af295f878f (patch)
tree410c5a785075730a35f1272ca6a7adf72222ad03 /contrib/llvm-project/lld/ELF/InputFiles.cpp
parentcb2ae6163174b90e999326ecec3699ee093a5d43 (diff)
parentc0981da47d5696fe36474fcf86b4ce03ae3ff818 (diff)
Merge llvm-project main llvmorg-14-init-10186-gff7f2cfa959b
This updates llvm, clang, compiler-rt, libc++, libunwind, lld, lldb and openmp to llvmorg-14-init-10186-gff7f2cfa959b. PR: 261742 MFC after: 2 weeks
Diffstat (limited to 'contrib/llvm-project/lld/ELF/InputFiles.cpp')
-rw-r--r--contrib/llvm-project/lld/ELF/InputFiles.cpp87
1 files changed, 33 insertions, 54 deletions
diff --git a/contrib/llvm-project/lld/ELF/InputFiles.cpp b/contrib/llvm-project/lld/ELF/InputFiles.cpp
index d5b9efbe18fc..e8a4188ec775 100644
--- a/contrib/llvm-project/lld/ELF/InputFiles.cpp
+++ b/contrib/llvm-project/lld/ELF/InputFiles.cpp
@@ -426,18 +426,7 @@ StringRef ObjFile<ELFT>::getShtGroupSignature(ArrayRef<Elf_Shdr> sections,
if (sec.sh_info >= symbols.size())
fatal(toString(this) + ": invalid symbol index");
const typename ELFT::Sym &sym = symbols[sec.sh_info];
- StringRef signature = CHECK(sym.getName(this->stringTable), this);
-
- // As a special case, if a symbol is a section symbol and has no name,
- // we use a section name as a signature.
- //
- // Such SHT_GROUP sections are invalid from the perspective of the ELF
- // standard, but GNU gold 1.14 (the newest version as of July 2017) or
- // older produce such sections as outputs for the -r option, so we need
- // a bug-compatibility.
- if (signature.empty() && sym.getType() == STT_SECTION)
- return getSectionName(sec);
- return signature;
+ return CHECK(sym.getName(this->stringTable), this);
}
template <class ELFT>
@@ -565,10 +554,9 @@ void ObjFile<ELFT>::initializeSections(bool ignoreComdats) {
const ELFFile<ELFT> &obj = this->getObj();
ArrayRef<Elf_Shdr> objSections = CHECK(obj.sections(), this);
+ StringRef shstrtab = CHECK(obj.getSectionStringTable(objSections), this);
uint64_t size = objSections.size();
this->sections.resize(size);
- this->sectionStringTable =
- CHECK(obj.getSectionStringTable(objSections), this);
std::vector<ArrayRef<Elf_Word>> selectedGroups;
@@ -624,7 +612,7 @@ void ObjFile<ELFT>::initializeSections(bool ignoreComdats) {
.second;
if (keepGroup) {
if (config->relocatable)
- this->sections[i] = createInputSection(sec);
+ this->sections[i] = createInputSection(i, sec, shstrtab);
selectedGroups.push_back(entries);
continue;
}
@@ -648,7 +636,7 @@ void ObjFile<ELFT>::initializeSections(bool ignoreComdats) {
case SHT_NULL:
break;
default:
- this->sections[i] = createInputSection(sec);
+ this->sections[i] = createInputSection(i, sec, shstrtab);
}
}
@@ -665,7 +653,7 @@ void ObjFile<ELFT>::initializeSections(bool ignoreComdats) {
const Elf_Shdr &sec = objSections[i];
if (sec.sh_type == SHT_REL || sec.sh_type == SHT_RELA)
- this->sections[i] = createInputSection(sec);
+ this->sections[i] = createInputSection(i, sec, shstrtab);
// A SHF_LINK_ORDER section with sh_link=0 is handled as if it did not have
// the flag.
@@ -849,21 +837,25 @@ template <class ELFT> static uint32_t readAndFeatures(const InputSection &sec) {
}
template <class ELFT>
-InputSectionBase *ObjFile<ELFT>::getRelocTarget(const Elf_Shdr &sec) {
- uint32_t idx = sec.sh_info;
- if (idx >= this->sections.size())
- fatal(toString(this) + ": invalid relocated section index: " + Twine(idx));
- InputSectionBase *target = this->sections[idx];
-
- // Strictly speaking, a relocation section must be included in the
- // group of the section it relocates. However, LLVM 3.3 and earlier
- // would fail to do so, so we gracefully handle that case.
- if (target == &InputSection::discarded)
- return nullptr;
-
- if (!target)
- fatal(toString(this) + ": unsupported relocation reference");
- return target;
+InputSectionBase *ObjFile<ELFT>::getRelocTarget(uint32_t idx, StringRef name,
+ const Elf_Shdr &sec) {
+ uint32_t info = sec.sh_info;
+ if (info < this->sections.size()) {
+ InputSectionBase *target = this->sections[info];
+
+ // Strictly speaking, a relocation section must be included in the
+ // group of the section it relocates. However, LLVM 3.3 and earlier
+ // would fail to do so, so we gracefully handle that case.
+ if (target == &InputSection::discarded)
+ return nullptr;
+
+ if (target != nullptr)
+ return target;
+ }
+
+ error(toString(this) + Twine(": relocation section ") + name + " (index " +
+ Twine(idx) + ") has invalid sh_info (" + Twine(info) + ")");
+ return nullptr;
}
// Create a regular InputSection class that has the same contents
@@ -874,8 +866,10 @@ static InputSection *toRegularSection(MergeInputSection *sec) {
}
template <class ELFT>
-InputSectionBase *ObjFile<ELFT>::createInputSection(const Elf_Shdr &sec) {
- StringRef name = getSectionName(sec);
+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) {
ARMAttributeParser attributes;
@@ -949,7 +943,7 @@ InputSectionBase *ObjFile<ELFT>::createInputSection(const Elf_Shdr &sec) {
// and the group is discarded, even though it's a violation of the
// spec. We handle that situation gracefully by discarding dangling
// relocation sections.
- InputSectionBase *target = getRelocTarget(sec);
+ InputSectionBase *target = getRelocTarget(idx, name, sec);
if (!target)
return nullptr;
@@ -963,22 +957,10 @@ InputSectionBase *ObjFile<ELFT>::createInputSection(const Elf_Shdr &sec) {
this->sections[sec.sh_info] = target;
}
- if (target->firstRelocation)
+ if (target->relSecIdx != 0)
fatal(toString(this) +
": multiple relocation sections to one section are not supported");
-
- if (sec.sh_type == SHT_RELA) {
- ArrayRef<Elf_Rela> rels = CHECK(getObj().relas(sec), this);
- target->firstRelocation = rels.begin();
- target->numRelocations = rels.size();
- target->areRelocsRela = true;
- } else {
- ArrayRef<Elf_Rel> rels = CHECK(getObj().rels(sec), this);
- target->firstRelocation = rels.begin();
- target->numRelocations = rels.size();
- target->areRelocsRela = false;
- }
- assert(isUInt<31>(target->numRelocations));
+ target->relSecIdx = idx;
// Relocation sections are usually removed from the output, so return
// `nullptr` for the normal case. However, if -r or --emit-relocs is
@@ -1072,11 +1054,6 @@ InputSectionBase *ObjFile<ELFT>::createInputSection(const Elf_Shdr &sec) {
return make<InputSection>(*this, sec, name);
}
-template <class ELFT>
-StringRef ObjFile<ELFT>::getSectionName(const Elf_Shdr &sec) {
- return CHECK(getObj().getSectionName(sec, sectionStringTable), this);
-}
-
// Initialize this->Symbols. this->Symbols is a parallel array as
// its corresponding ELF symbol table.
template <class ELFT> void ObjFile<ELFT>::initializeSymbols() {
@@ -1629,6 +1606,8 @@ static uint16_t getBitcodeMachineKind(StringRef path, const Triple &t) {
return EM_ARM;
case Triple::avr:
return EM_AVR;
+ case Triple::hexagon:
+ return EM_HEXAGON;
case Triple::mips:
case Triple::mipsel:
case Triple::mips64: