llvm-project/lld/test/elf/dynamic-undef.test

35 lines
1.9 KiB
Plaintext
Raw Normal View History

#
# This test creates a executable and tests the options that are used to
# to create an executable and a shared library
#
# This test will fail because there are unresolved symbols from the shared
# library and we are not passing --allow-shlib-undefined
RUN: not lld -flavor gnu -target x86_64-linux %p/Inputs/tls.x86-64 \
RUN: %p/Inputs/shared.so-x86-64 -o %t -e main 2> %t1
RUN: FileCheck -check-prefix=EXEC %s < %t1
# This test will pass because of --allow-shlib-undefined
RUN: lld -flavor gnu -target x86_64-linux %p/Inputs/tls.x86-64 \
[lld] [ELF] Support for general dynamic TLS relocations on X86_64 Summary: This patch adds support for the general dynamic TLS access model for X86_64 (see www.akkadia.org/drepper/tls.pdf). To properly support TLS, the patch also changes the __tls_get_addr atom to be a shared library atom instead of a regularly defined atom (the previous lld approach). This closely models the reality of a function that will be resolved at runtime by the dynamic linker and loader itself (ld.so). I was tempted to force LLD to link against ld.so itself to resolve these symbols, but since GNU ld does not need the ld.so library to resolve this symbol, I decided to mimic its behavior and keep hardwired a definition of __tls_get_addr in the lld code. This patch also moves some important logic that previously was only available to the MIPS lld backend to be used to all ELF backends. This logic, which now lives in the DefaultLayout class, will monitor which external (shared lib) symbols are really imported by the current module and will only populate the dynamic symbol table with used symbols, as opposed to the previous approach of dumping all shared lib symbols in the dynamic symbol table. This is important to this patch to avoid __tls_get_addr from getting injected into all dynamic symbol tables. By solving the previous problem of always adding __tls_get_addr, now the produced symbol tables are slightly smaller. But this impacted several tests that relied on hardwired/predefined sizes of the symbol table, requiring this patch to update such tests. Test Plan: Added a LIT test case that exercises a simple use case of TLS variable in a shared library. Reviewers: ruiu, rafael, Bigcheese, shankarke Reviewed By: Bigcheese, shankarke Subscribers: emaste, shankarke, joerg, kledzik, mcrosier, llvm-commits Projects: #lld Differential Revision: http://reviews.llvm.org/D5505 llvm-svn: 218633
2014-09-30 06:05:26 +08:00
RUN: %p/Inputs/shared.so-x86-64 -o %t -e main --allow-shlib-undefined \
RUN: --defsym=__tls_get_addr=0
# Building shared libraries should not fail when there is a undefined symbol.
# Test creation of shared library, this should pass because we are using
2014-03-28 06:11:58 +08:00
# shared option and by default, dynamic library wouldn't create undefined atoms
# from the input shared library
RUN: lld -flavor gnu -target x86_64-linux %p/Inputs/tls.x86-64 \
RUN: %p/Inputs/shared.so-x86-64 -o %t.usenoundefines -e main -shared
RUN: llvm-readobj -symbols %t.usenoundefines | FileCheck %s -check-prefix=SHLIB-NOUNDEF
# Test creation of shared library, this should fail because we are using
# shared option setting the options to use the shared library undefines to
# create undefined atoms from the input shared library
RUN: lld -flavor gnu -target x86_64-linux %p/Inputs/tls.x86-64 \
RUN: %p/Inputs/shared.so-x86-64 -o %t.useundefines -e main -shared \
RUN: --use-shlib-undefines --no-allow-shlib-undefined 2> %t2
RUN: llvm-readobj -symbols %t.useundefines | FileCheck -check-prefix=SHLIB-UNDEF-SYMBOLS %s
EXEC: Undefined symbol: {{.+[\\/]}}shared.so-x86-64: puts
SHLIB: Undefined symbol: {{.+[\\/]}}shared.so-x86-64: puts
EXEC-NOT: Undefined symbol: {{.+[\\/]}}shared.so-x86-64: weakfoo
SHLIB-NOT: Undefined symbol: {{.+[\\/]}}shared.so-x86-64: weakfoo
SHLIB-NOUNDEF-NOT: Name: puts
SHLIB-UNDEF-SYMBOLS: Name: puts