Make fetchIfLazy only fetch an object file. NFC.

Previously, fetchIfLazy did more than the name says. Now, setting
to UsedInRegularObj is moved to another function.

llvm-svn: 329092
This commit is contained in:
Rui Ueyama 2018-04-03 18:01:18 +00:00
parent d5b1f7892f
commit cc013f62c1
3 changed files with 29 additions and 18 deletions

View File

@ -1017,6 +1017,20 @@ static void excludeLibs(opt::InputArgList &Args) {
Sym->VersionId = VER_NDX_LOCAL;
}
// Force Sym to be entered in the output. Used for -u or equivalent.
template <class ELFT> static void handleUndefined(StringRef Name) {
Symbol *Sym = Symtab->find(Name);
if (!Sym)
return;
// Since symbol S may not be used inside the program, LTO may
// eliminate it. Mark the symbol as "used" to prevent it.
Sym->IsUsedInRegularObj = true;
if (Sym->isLazy())
Symtab->fetchLazy<ELFT>(Sym);
}
// 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) {
@ -1081,16 +1095,12 @@ template <class ELFT> void LinkerDriver::link(opt::InputArgList &Args) {
// Handle the `--undefined <sym>` options.
for (StringRef S : Config->Undefined)
if (Symbol *Sym = Symtab->find(S))
if (InputFile *F = Symtab->fetchIfLazy(Sym))
Symtab->addFile<ELFT>(F);
handleUndefined<ELFT>(S);
// If an entry symbol is in a static archive, pull out that file now
// to complete the symbol table. After this, no new names except a
// few linker-synthesized ones will be added to the symbol table.
if (Symbol *Sym = Symtab->find(Config->Entry))
if (InputFile *F = Symtab->fetchIfLazy(Sym))
Symtab->addFile<ELFT>(F);
handleUndefined<ELFT>(Config->Entry);
// Return if there were name resolution errors.
if (errorCount())

View File

@ -314,8 +314,8 @@ Symbol *SymbolTable::addUndefined(StringRef Name, uint8_t Binding,
// Symbols.h for the details.
if (Binding == STB_WEAK)
S->Type = Type;
else if (InputFile *F = Symtab->fetchIfLazy(S))
addFile<ELFT>(F);
else
fetchLazy<ELFT>(S);
}
return S;
}
@ -574,15 +574,16 @@ void SymbolTable::addLazyObject(StringRef Name, LazyObjFile &Obj) {
addFile<ELFT>(F);
}
InputFile *SymbolTable::fetchIfLazy(Symbol *Sym) {
// Mark the symbol not to be eliminated by LTO
// even if it is a bitcode symbol.
Sym->IsUsedInRegularObj = true;
if (LazyArchive *L = dyn_cast<LazyArchive>(Sym))
return L->fetch();
if (LazyObject *L = dyn_cast<LazyObject>(Sym))
return cast<LazyObjFile>(L->File)->fetch();
return nullptr;
template <class ELFT> void SymbolTable::fetchLazy(Symbol *Sym) {
if (auto *S = dyn_cast<LazyArchive>(Sym)) {
if (InputFile *File = S->fetch())
addFile<ELFT>(File);
return;
}
auto *S = cast<LazyObject>(Sym);
if (InputFile *File = cast<LazyObjFile>(S->File)->fetch())
addFile<ELFT>(File);
}
// Initialize DemangledSyms with a map from demangled symbols to symbol

View File

@ -77,7 +77,7 @@ public:
uint8_t Visibility, bool CanOmitFromDynSym,
InputFile *File);
InputFile *fetchIfLazy(Symbol *Sym);
template <class ELFT> void fetchLazy(Symbol *Sym);
void scanVersionScript();