aboutsummaryrefslogtreecommitdiff
path: root/ELF/InputFiles.cpp
diff options
context:
space:
mode:
authorDimitry Andric <dim@FreeBSD.org>2017-06-16 21:04:14 +0000
committerDimitry Andric <dim@FreeBSD.org>2017-06-16 21:04:14 +0000
commit15f7a1a3796209b21af2817fdf11ca9932165c70 (patch)
treeb27ac12a6f210080b2233100767c839224666505 /ELF/InputFiles.cpp
parent2079716dfb3fb7e4e24b8b2e85eb6780b981a0af (diff)
downloadsrc-15f7a1a3796209b21af2817fdf11ca9932165c70.tar.gz
src-15f7a1a3796209b21af2817fdf11ca9932165c70.zip
Vendor import of lld trunk r305575:vendor/lld/lld-trunk-r305575
Notes
Notes: svn path=/vendor/lld/dist/; revision=320021 svn path=/vendor/lld/lld-trunk-r305575/; revision=320022; tag=vendor/lld/lld-trunk-r305575
Diffstat (limited to 'ELF/InputFiles.cpp')
-rw-r--r--ELF/InputFiles.cpp37
1 files changed, 28 insertions, 9 deletions
diff --git a/ELF/InputFiles.cpp b/ELF/InputFiles.cpp
index 524246ed1d17..3d11239bf88f 100644
--- a/ELF/InputFiles.cpp
+++ b/ELF/InputFiles.cpp
@@ -205,13 +205,27 @@ template <class ELFT>
StringRef
elf::ObjectFile<ELFT>::getShtGroupSignature(ArrayRef<Elf_Shdr> Sections,
const Elf_Shdr &Sec) {
+ // Group signatures are stored as symbol names in object files.
+ // sh_info contains a symbol index, so we fetch a symbol and read its name.
if (this->Symbols.empty())
this->initSymtab(
Sections,
check(object::getSection<ELFT>(Sections, Sec.sh_link), toString(this)));
+
const Elf_Sym *Sym = check(
object::getSymbol<ELFT>(this->Symbols, Sec.sh_info), toString(this));
- return check(Sym->getName(this->StringTable), toString(this));
+ StringRef Signature = check(Sym->getName(this->StringTable), toString(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 neweset 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;
}
template <class ELFT>
@@ -287,8 +301,7 @@ void elf::ObjectFile<ELFT>::initializeSections(
check(this->getObj().sections(), toString(this));
uint64_t Size = ObjSections.size();
this->Sections.resize(Size);
-
- StringRef SectionStringTable =
+ this->SectionStringTable =
check(Obj.getSectionStringTable(ObjSections), toString(this));
for (size_t I = 0, E = ObjSections.size(); I < E; I++) {
@@ -318,7 +331,7 @@ void elf::ObjectFile<ELFT>::initializeSections(
// object files, we want to pass through basically everything.
if (IsNew) {
if (Config->Relocatable)
- this->Sections[I] = createInputSection(Sec, SectionStringTable);
+ this->Sections[I] = createInputSection(Sec);
continue;
}
@@ -342,7 +355,7 @@ void elf::ObjectFile<ELFT>::initializeSections(
case SHT_NULL:
break;
default:
- this->Sections[I] = createInputSection(Sec, SectionStringTable);
+ this->Sections[I] = createInputSection(Sec);
}
// .ARM.exidx sections have a reverse dependency on the InputSection they
@@ -386,10 +399,8 @@ InputSectionBase *toRegularSection(MergeInputSection *Sec) {
template <class ELFT>
InputSectionBase *
-elf::ObjectFile<ELFT>::createInputSection(const Elf_Shdr &Sec,
- StringRef SectionStringTable) {
- StringRef Name = check(
- this->getObj().getSectionName(&Sec, SectionStringTable), toString(this));
+elf::ObjectFile<ELFT>::createInputSection(const Elf_Shdr &Sec) {
+ StringRef Name = getSectionName(Sec);
switch (Sec.sh_type) {
case SHT_ARM_ATTRIBUTES:
@@ -521,6 +532,12 @@ elf::ObjectFile<ELFT>::createInputSection(const Elf_Shdr &Sec,
return make<InputSection>(this, &Sec, Name);
}
+template <class ELFT>
+StringRef elf::ObjectFile<ELFT>::getSectionName(const Elf_Shdr &Sec) {
+ return check(this->getObj().getSectionName(&Sec, SectionStringTable),
+ toString(this));
+}
+
template <class ELFT> void elf::ObjectFile<ELFT>::initializeSymbols() {
SymbolBodies.reserve(this->Symbols.size());
for (const Elf_Sym &Sym : this->Symbols)
@@ -804,6 +821,8 @@ static uint8_t getBitcodeMachineKind(StringRef Path, const Triple &T) {
case Triple::arm:
case Triple::thumb:
return EM_ARM;
+ case Triple::avr:
+ return EM_AVR;
case Triple::mips:
case Triple::mipsel:
case Triple::mips64: