[PATCH] D43658: Make undefined symbol in DSO to pull out object files from archive files.

Rafael Avila de Espindola via llvm-commits llvm-commits at lists.llvm.org
Thu Feb 22 17:05:49 PST 2018


I get errors from both gold and bfd if I try to link the included
testcase. Maybe it has been reduced a bit too much?

Cheers,
Rafael

Rui Ueyama via Phabricator <reviews at reviews.llvm.org> writes:

> ruiu created this revision.
> ruiu added a reviewer: rafael.
> Herald added subscribers: arichardson, emaste.
>
> We have an internal program that does't link without this patch. I don't
> know of any open-source program that needs this, but there might be.
> Since this patch improves compatibility with GNU linkers with a few lines
> of code, I think it's worth to be committed.
>
> The problem is about undefined symbols in DSOs. Some programs depend on
> the GNU linkers' behavior that they pull out object files from archive
> files to resolve undefined symbols in DSOs. We already allow that kind of
> "reverse" dependency (from DSOs to the main executable) for regular
> symbols, in particular, for "__progname" symbol, but that didn't work
> if the symbol is in an archive file. This patch is to make it work.
>
>
> https://reviews.llvm.org/D43658
>
> Files:
>   lld/ELF/SymbolTable.cpp
>   lld/test/ELF/shlib-undefined-archive.s
>
>
> Index: lld/test/ELF/shlib-undefined-archive.s
> ===================================================================
> --- /dev/null
> +++ lld/test/ELF/shlib-undefined-archive.s
> @@ -0,0 +1,18 @@
> +# REQUIRES: x86
> +
> +# Undefined symbols in a DSO should pull out object files from archives
> +# to resolve them.
> +
> +# RUN: echo '.globl foo' | llvm-mc -filetype=obj -triple=x86_64-linux-gnu -o %t1.o -
> +# RUN: ld.lld -shared -o %t.so %t1.o
> +
> +# RUN: llvm-mc -filetype=obj -triple=x86_64-linux-gnu -o %t2.o %s
> +# RUN: llvm-ar cru %t.a %t2.o
> +# RUN: ld.lld -o %t.exe %t.a %t.so
> +# RUN: llvm-nm -D %t.exe | FileCheck %s
> +
> +# CHECK: T foo
> +
> +.globl foo
> +foo:
> +  ret
> Index: lld/ELF/SymbolTable.cpp
> ===================================================================
> --- lld/ELF/SymbolTable.cpp
> +++ lld/ELF/SymbolTable.cpp
> @@ -599,9 +599,14 @@
>    for (InputFile *F : SharedFiles) {
>      for (StringRef U : cast<SharedFile<ELFT>>(F)->getUndefinedSymbols()) {
>        Symbol *Sym = find(U);
> -      if (!Sym || !Sym->isDefined())
> +      if (!Sym)
>          continue;
> -      Sym->ExportDynamic = true;
> +      if (auto *L = dyn_cast<Lazy>(Sym))
> +        if (InputFile *File = L->fetch())
> +          addFile<ELFT>(File);
> +
> +      if (Sym->isDefined())
> +        Sym->ExportDynamic = true;
>      }
>    }
>  }
>
>
> Index: lld/test/ELF/shlib-undefined-archive.s
> ===================================================================
> --- /dev/null
> +++ lld/test/ELF/shlib-undefined-archive.s
> @@ -0,0 +1,18 @@
> +# REQUIRES: x86
> +
> +# Undefined symbols in a DSO should pull out object files from archives
> +# to resolve them.
> +
> +# RUN: echo '.globl foo' | llvm-mc -filetype=obj -triple=x86_64-linux-gnu -o %t1.o -
> +# RUN: ld.lld -shared -o %t.so %t1.o
> +
> +# RUN: llvm-mc -filetype=obj -triple=x86_64-linux-gnu -o %t2.o %s
> +# RUN: llvm-ar cru %t.a %t2.o
> +# RUN: ld.lld -o %t.exe %t.a %t.so
> +# RUN: llvm-nm -D %t.exe | FileCheck %s
> +
> +# CHECK: T foo
> +
> +.globl foo
> +foo:
> +  ret
> Index: lld/ELF/SymbolTable.cpp
> ===================================================================
> --- lld/ELF/SymbolTable.cpp
> +++ lld/ELF/SymbolTable.cpp
> @@ -599,9 +599,14 @@
>    for (InputFile *F : SharedFiles) {
>      for (StringRef U : cast<SharedFile<ELFT>>(F)->getUndefinedSymbols()) {
>        Symbol *Sym = find(U);
> -      if (!Sym || !Sym->isDefined())
> +      if (!Sym)
>          continue;
> -      Sym->ExportDynamic = true;
> +      if (auto *L = dyn_cast<Lazy>(Sym))
> +        if (InputFile *File = L->fetch())
> +          addFile<ELFT>(File);
> +
> +      if (Sym->isDefined())
> +        Sym->ExportDynamic = true;
>      }
>    }
>  }


More information about the llvm-commits mailing list