From 3f11c8c97ef3ad587b1b1c6e079c390b533ba9b7 Mon Sep 17 00:00:00 2001 From: Rui Ueyama Date: Thu, 24 Dec 2015 08:41:12 +0000 Subject: [PATCH] Split functions and add comments. NFC. llvm-svn: 256369 --- lld/ELF/InputFiles.cpp | 46 ++++++++++++++++++++++++++---------------- lld/ELF/InputFiles.h | 1 + lld/ELF/Target.cpp | 9 +++++++-- 3 files changed, 37 insertions(+), 19 deletions(-) diff --git a/lld/ELF/InputFiles.cpp b/lld/ELF/InputFiles.cpp index c0fbe03d1b12..3c7f5ba4d824 100644 --- a/lld/ELF/InputFiles.cpp +++ b/lld/ELF/InputFiles.cpp @@ -110,6 +110,9 @@ void elf2::ObjectFile::parse(DenseSet &Comdats) { initializeSymbols(); } +// Sections with SHT_GROUP and comdat bits define comdat section groups. +// They are identified and deduplicated by group name. This function +// returns a group name. template StringRef ObjectFile::getShtGroupSignature(const Elf_Shdr &Sec) { const ELFFile &Obj = this->ELFObj; @@ -222,27 +225,36 @@ void elf2::ObjectFile::initializeSections(DenseSet &Comdats) { break; } default: - ErrorOr NameOrErr = this->ELFObj.getSectionName(&Sec); - error(NameOrErr); - StringRef Name = *NameOrErr; - if (Name == ".note.GNU-stack") - Sections[I] = &InputSection::Discarded; - else if (Name == ".eh_frame") - Sections[I] = - new (this->EHAlloc.Allocate()) EHInputSection(this, &Sec); - else if (Config->EMachine == EM_MIPS && Name == ".reginfo") - Sections[I] = - new (this->Alloc) MipsReginfoInputSection(this, &Sec); - else if (shouldMerge(Sec)) - Sections[I] = - new (this->MAlloc.Allocate()) MergeInputSection(this, &Sec); - else - Sections[I] = new (this->Alloc) InputSection(this, &Sec); - break; + Sections[I] = createInputSection(Sec); } } } +template InputSectionBase * +elf2::ObjectFile::createInputSection(const Elf_Shdr &Sec) { + ErrorOr NameOrErr = this->ELFObj.getSectionName(&Sec); + error(NameOrErr); + StringRef Name = *NameOrErr; + + // .note.GNU-stack is a marker section to control the presence of + // PT_GNU_STACK segment in outputs. Since the presence of the segment + // is controlled only by the command line option (-z execstack) in LLD, + // .note.GNU-stack is ignored. + if (Name == ".note.GNU-stack") + return &InputSection::Discarded; + + // A MIPS object file has a special section that contains register + // usage info, which needs to be handled by the linker specially. + if (Config->EMachine == EM_MIPS && Name == ".reginfo") + return new (this->Alloc) MipsReginfoInputSection(this, &Sec); + + if (Name == ".eh_frame") + return new (this->EHAlloc.Allocate()) EHInputSection(this, &Sec); + if (shouldMerge(Sec)) + return new (this->MAlloc.Allocate()) MergeInputSection(this, &Sec); + return new (this->Alloc) InputSection(this, &Sec); +} + template void elf2::ObjectFile::initializeSymbols() { this->initStringTable(); Elf_Sym_Range Syms = this->getNonLocalSymbols(); diff --git a/lld/ELF/InputFiles.h b/lld/ELF/InputFiles.h index d30268bd260b..8363acb9f2b9 100644 --- a/lld/ELF/InputFiles.h +++ b/lld/ELF/InputFiles.h @@ -124,6 +124,7 @@ public: private: void initializeSections(llvm::DenseSet &Comdats); void initializeSymbols(); + InputSectionBase *createInputSection(const Elf_Shdr &Sec); SymbolBody *createSymbolBody(StringRef StringTable, const Elf_Sym *Sym); diff --git a/lld/ELF/Target.cpp b/lld/ELF/Target.cpp index ea15ef939665..a80c672b8d28 100644 --- a/lld/ELF/Target.cpp +++ b/lld/ELF/Target.cpp @@ -1453,9 +1453,14 @@ bool MipsTargetInfo::isRelRelative(uint32_t Type) const { } } +// _gp is a MIPS-specific ABI-defined symbol which points to +// a location that is relative to GOT. This function returns +// the value for the symbol. template typename ELFFile::uintX_t getMipsGpAddr() { - const unsigned GPOffset = 0x7ff0; - return Out::Got->getVA() ? (Out::Got->getVA() + GPOffset) : 0; + unsigned GPOffset = 0x7ff0; + if (uint64_t V = Out::Got->getVA()) + return V + GPOffset; + return 0; } template uint32_t getMipsGpAddr();