[lld] r249365 - [elf2] Ignore __tls_get_addr when static linking.
Michael Spencer via llvm-commits
llvm-commits at lists.llvm.org
Tue Oct 6 13:41:11 PDT 2015
On Tue, Oct 6, 2015 at 11:55 AM, Rafael EspĂndola
<rafael.espindola at gmail.com> wrote:
> On 5 October 2015 at 20:45, Michael J. Spencer via llvm-commits
> <llvm-commits at lists.llvm.org> wrote:
>> Author: mspencer
>> Date: Mon Oct 5 19:45:42 2015
>> New Revision: 249365
>>
>> URL: http://llvm.org/viewvc/llvm-project?rev=249365&view=rev
>> Log:
>> [elf2] Ignore __tls_get_addr when static linking.
>>
>> Added:
>> lld/trunk/test/elf2/tls-static.s
>> Modified:
>> lld/trunk/ELF/SymbolTable.cpp
>>
>> Modified: lld/trunk/ELF/SymbolTable.cpp
>> URL: http://llvm.org/viewvc/llvm-project/lld/trunk/ELF/SymbolTable.cpp?rev=249365&r1=249364&r2=249365&view=diff
>> ==============================================================================
>> --- lld/trunk/ELF/SymbolTable.cpp (original)
>> +++ lld/trunk/ELF/SymbolTable.cpp Mon Oct 5 19:45:42 2015
>> @@ -133,6 +133,13 @@ template <class ELFT> void SymbolTable::
>> // Given that the symbol is effectively unused, we just create a dummy
>> // hidden one to avoid the undefined symbol error.
>> addIgnoredSym<ELFT>("_GLOBAL_OFFSET_TABLE_");
>> +
>> + // __tls_get_addr is defined by the dynamic linker for dynamic ELFs. For
>> + // static linking the linker is required to optimize away any references to
>> + // __tls_get_addr, so it's not defined anywhere. Create a hidden definition
>> + // to avoid the undefined symbol error.
>> + if (Config->Static)
>
>
> That is the wrong variable to check. -static doesn't mean that the
> produced output is static:
>
> $ ld test2.o -o test2.so -shared -Bstatic
> $ ld test.o test2.so -shared -Bstatic -o t
> $ file test2.so t
> test2.so: ELF 64-bit LSB shared object, x86-64, version 1 (SYSV),
> dynamically linked, not stripped
> t: ELF 64-bit LSB shared object, x86-64, version 1 (SYSV),
> dynamically linked, not stripped
>
> gold does treat -static differently from -Bstatic but bfd does not and
> the manual says so explicitly.
>
> Also, we can produce a static binary without -static.
>
> What you need to do is move this after all the files have been seen
> and we know if we are producing a static program or not.
>
> Please fix and add tests for both cases (has -static and produces a
> shared, no -static and produce a static).
>
> Cheers,
> Rafael
Should be fixed in r249462.
- Michael Spencer
More information about the llvm-commits
mailing list