Create an instance of Target after reading all input files. NFC.

This change itself doesn't mean anything, but it helps D59780 because
in patch, we don't know whether we need to create a CET-aware PLT or
not until we read all input files.

llvm-svn: 357194
This commit is contained in:
Rui Ueyama 2019-03-28 17:38:53 +00:00
parent 8521ba37d7
commit f28825bc06
5 changed files with 26 additions and 19 deletions

View File

@ -29,7 +29,6 @@ public:
PPC::PPC() {
NoneRel = R_PPC_NONE;
GotBaseSymOff = 0x8000;
GotBaseSymInGotPlt = false;
}

View File

@ -208,7 +208,6 @@ PPC64::PPC64() {
PltEntrySize = 4;
GotPltEntrySize = 8;
GotBaseSymInGotPlt = false;
GotBaseSymOff = 0x8000;
GotHeaderEntriesNum = 1;
GotPltHeaderEntriesNum = 2;
PltHeaderSize = 60;

View File

@ -1454,11 +1454,6 @@ static const char *LibcallRoutineNames[] = {
// Do actual linking. Note that when this function is called,
// all linker scripts have already been parsed.
template <class ELFT> void LinkerDriver::link(opt::InputArgList &Args) {
Target = getTarget();
Config->MaxPageSize = getMaxPageSize(Args);
Config->ImageBase = getImageBase(Args);
// If a -hash-style option was not given, set to a default value,
// which varies depending on the target.
if (!Args.hasArg(OPT_hash_style)) {
@ -1616,12 +1611,21 @@ template <class ELFT> void LinkerDriver::link(opt::InputArgList &Args) {
// We do not want to emit debug sections if --strip-all
// or -strip-debug are given.
if (Config->Strip != StripPolicy::None)
if (Config->Strip != StripPolicy::None) {
llvm::erase_if(InputSections, [](InputSectionBase *S) {
return S->Name.startswith(".debug") || S->Name.startswith(".zdebug");
});
}
// The Target instance handles target-specific stuff, such as applying
// relocations or writing a PLT section. It also contains target-dependent
// values such as a default image base address.
Target = getTarget();
Config->EFlags = Target->calcEFlags();
Config->EFlags = Target->calcEFlags();
Config->MaxPageSize = getMaxPageSize(Args);
Config->ImageBase = getImageBase(Args);
if (Config->EMachine == EM_ARM) {
// FIXME: These warnings can be removed when lld only uses these features

View File

@ -86,8 +86,6 @@ public:
uint64_t getImageBase() const;
// Offset of _GLOBAL_OFFSET_TABLE_ from base of .got or .got.plt section.
uint64_t GotBaseSymOff = 0;
// True if _GLOBAL_OFFSET_TABLE_ is relative to .got.plt, false if .got.
bool GotBaseSymInGotPlt = true;

View File

@ -214,17 +214,24 @@ void elf::addReservedSymbols() {
// the .got section.
// We do not allow _GLOBAL_OFFSET_TABLE_ to be defined by input objects as the
// correctness of some relocations depends on its value.
StringRef GotTableSymName =
StringRef GotSymName =
(Config->EMachine == EM_PPC64) ? ".TOC." : "_GLOBAL_OFFSET_TABLE_";
if (Symbol *S = Symtab->find(GotTableSymName)) {
if (S->isDefined())
if (Symbol *S = Symtab->find(GotSymName)) {
if (S->isDefined()) {
error(toString(S->File) + " cannot redefine linker defined symbol '" +
GotTableSymName + "'");
else
ElfSym::GlobalOffsetTable = Symtab->addDefined(
GotTableSymName, STV_HIDDEN, STT_NOTYPE, Target->GotBaseSymOff,
/*Size=*/0, STB_GLOBAL, Out::ElfHeader,
/*File=*/nullptr);
GotSymName + "'");
return;
}
uint64_t GotOff = 0;
if (Config->EMachine == EM_PPC || Config->EMachine == EM_PPC64)
GotOff = 0x8000;
ElfSym::GlobalOffsetTable =
Symtab->addDefined(GotSymName, STV_HIDDEN, STT_NOTYPE, GotOff,
/*Size=*/0, STB_GLOBAL, Out::ElfHeader,
/*File=*/nullptr);
}
// __ehdr_start is the location of ELF file headers. Note that we define