[lld] r329092 - Make fetchIfLazy only fetch an object file. NFC.
Chandler Carruth via llvm-commits
llvm-commits at lists.llvm.org
Tue Apr 3 11:51:01 PDT 2018
On Tue, Apr 3, 2018 at 11:04 AM Rui Ueyama via llvm-commits <
llvm-commits at lists.llvm.org> wrote:
> Author: ruiu
> Date: Tue Apr 3 11:01:18 2018
> New Revision: 329092
>
> URL: http://llvm.org/viewvc/llvm-project?rev=329092&view=rev
> Log:
> 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.
>
> Modified:
> lld/trunk/ELF/Driver.cpp
> lld/trunk/ELF/SymbolTable.cpp
> lld/trunk/ELF/SymbolTable.h
>
> Modified: lld/trunk/ELF/Driver.cpp
> URL:
> http://llvm.org/viewvc/llvm-project/lld/trunk/ELF/Driver.cpp?rev=329092&r1=329091&r2=329092&view=diff
>
> ==============================================================================
> --- lld/trunk/ELF/Driver.cpp (original)
> +++ lld/trunk/ELF/Driver.cpp Tue Apr 3 11:01:18 2018
> @@ -1017,6 +1017,20 @@ static void excludeLibs(opt::InputArgLis
> 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);
>
Because this template is only defined in the other .cpp file, we can't
actually instantiate it here. As a consequence, I'm seeing link failures of
lld after this commit.
> +}
> +
> // 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:
>
> // 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())
>
> Modified: lld/trunk/ELF/SymbolTable.cpp
> URL:
> http://llvm.org/viewvc/llvm-project/lld/trunk/ELF/SymbolTable.cpp?rev=329092&r1=329091&r2=329092&view=diff
>
> ==============================================================================
> --- lld/trunk/ELF/SymbolTable.cpp (original)
> +++ lld/trunk/ELF/SymbolTable.cpp Tue Apr 3 11:01:18 2018
> @@ -314,8 +314,8 @@ Symbol *SymbolTable::addUndefined(String
> // 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(StringRe
> 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
>
> Modified: lld/trunk/ELF/SymbolTable.h
> URL:
> http://llvm.org/viewvc/llvm-project/lld/trunk/ELF/SymbolTable.h?rev=329092&r1=329091&r2=329092&view=diff
>
> ==============================================================================
> --- lld/trunk/ELF/SymbolTable.h (original)
> +++ lld/trunk/ELF/SymbolTable.h Tue Apr 3 11:01:18 2018
> @@ -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();
>
>
>
> _______________________________________________
> llvm-commits mailing list
> llvm-commits at lists.llvm.org
> http://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-commits
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20180403/64aaf2f5/attachment-0001.html>
More information about the llvm-commits
mailing list