Skip to content

Commit f28825b

Browse files
committedMar 28, 2019
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
1 parent 8521ba3 commit f28825b

File tree

5 files changed

+26
-19
lines changed

5 files changed

+26
-19
lines changed
 

‎lld/ELF/Arch/PPC.cpp

-1
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,6 @@ class PPC final : public TargetInfo {
2929

3030
PPC::PPC() {
3131
NoneRel = R_PPC_NONE;
32-
GotBaseSymOff = 0x8000;
3332
GotBaseSymInGotPlt = false;
3433
}
3534

‎lld/ELF/Arch/PPC64.cpp

-1
Original file line numberDiff line numberDiff line change
@@ -208,7 +208,6 @@ PPC64::PPC64() {
208208
PltEntrySize = 4;
209209
GotPltEntrySize = 8;
210210
GotBaseSymInGotPlt = false;
211-
GotBaseSymOff = 0x8000;
212211
GotHeaderEntriesNum = 1;
213212
GotPltHeaderEntriesNum = 2;
214213
PltHeaderSize = 60;

‎lld/ELF/Driver.cpp

+10-6
Original file line numberDiff line numberDiff line change
@@ -1454,11 +1454,6 @@ static const char *LibcallRoutineNames[] = {
14541454
// Do actual linking. Note that when this function is called,
14551455
// all linker scripts have already been parsed.
14561456
template <class ELFT> void LinkerDriver::link(opt::InputArgList &Args) {
1457-
Target = getTarget();
1458-
1459-
Config->MaxPageSize = getMaxPageSize(Args);
1460-
Config->ImageBase = getImageBase(Args);
1461-
14621457
// If a -hash-style option was not given, set to a default value,
14631458
// which varies depending on the target.
14641459
if (!Args.hasArg(OPT_hash_style)) {
@@ -1616,12 +1611,21 @@ template <class ELFT> void LinkerDriver::link(opt::InputArgList &Args) {
16161611

16171612
// We do not want to emit debug sections if --strip-all
16181613
// or -strip-debug are given.
1619-
if (Config->Strip != StripPolicy::None)
1614+
if (Config->Strip != StripPolicy::None) {
16201615
llvm::erase_if(InputSections, [](InputSectionBase *S) {
16211616
return S->Name.startswith(".debug") || S->Name.startswith(".zdebug");
16221617
});
1618+
}
16231619

1620+
// The Target instance handles target-specific stuff, such as applying
1621+
// relocations or writing a PLT section. It also contains target-dependent
1622+
// values such as a default image base address.
1623+
Target = getTarget();
1624+
1625+
Config->EFlags = Target->calcEFlags();
16241626
Config->EFlags = Target->calcEFlags();
1627+
Config->MaxPageSize = getMaxPageSize(Args);
1628+
Config->ImageBase = getImageBase(Args);
16251629

16261630
if (Config->EMachine == EM_ARM) {
16271631
// FIXME: These warnings can be removed when lld only uses these features

‎lld/ELF/Target.h

-2
Original file line numberDiff line numberDiff line change
@@ -86,8 +86,6 @@ class TargetInfo {
8686

8787
uint64_t getImageBase() const;
8888

89-
// Offset of _GLOBAL_OFFSET_TABLE_ from base of .got or .got.plt section.
90-
uint64_t GotBaseSymOff = 0;
9189
// True if _GLOBAL_OFFSET_TABLE_ is relative to .got.plt, false if .got.
9290
bool GotBaseSymInGotPlt = true;
9391

‎lld/ELF/Writer.cpp

+16-9
Original file line numberDiff line numberDiff line change
@@ -214,17 +214,24 @@ void elf::addReservedSymbols() {
214214
// the .got section.
215215
// We do not allow _GLOBAL_OFFSET_TABLE_ to be defined by input objects as the
216216
// correctness of some relocations depends on its value.
217-
StringRef GotTableSymName =
217+
StringRef GotSymName =
218218
(Config->EMachine == EM_PPC64) ? ".TOC." : "_GLOBAL_OFFSET_TABLE_";
219-
if (Symbol *S = Symtab->find(GotTableSymName)) {
220-
if (S->isDefined())
219+
220+
if (Symbol *S = Symtab->find(GotSymName)) {
221+
if (S->isDefined()) {
221222
error(toString(S->File) + " cannot redefine linker defined symbol '" +
222-
GotTableSymName + "'");
223-
else
224-
ElfSym::GlobalOffsetTable = Symtab->addDefined(
225-
GotTableSymName, STV_HIDDEN, STT_NOTYPE, Target->GotBaseSymOff,
226-
/*Size=*/0, STB_GLOBAL, Out::ElfHeader,
227-
/*File=*/nullptr);
223+
GotSymName + "'");
224+
return;
225+
}
226+
227+
uint64_t GotOff = 0;
228+
if (Config->EMachine == EM_PPC || Config->EMachine == EM_PPC64)
229+
GotOff = 0x8000;
230+
231+
ElfSym::GlobalOffsetTable =
232+
Symtab->addDefined(GotSymName, STV_HIDDEN, STT_NOTYPE, GotOff,
233+
/*Size=*/0, STB_GLOBAL, Out::ElfHeader,
234+
/*File=*/nullptr);
228235
}
229236

230237
// __ehdr_start is the location of ELF file headers. Note that we define

0 commit comments

Comments
 (0)
Please sign in to comment.