<html>
<head>
<base href="https://bugs.llvm.org/">
</head>
<body><table border="1" cellspacing="0" cellpadding="8">
<tr>
<th>Bug ID</th>
<td><a class="bz_bug_link
bz_status_NEW "
title="NEW - lld fails with can't create dynamic relocation R_X86_64_TLSLD against symbol: getI()::i in readonly segment"
href="https://bugs.llvm.org/show_bug.cgi?id=35242">35242</a>
</td>
</tr>
<tr>
<th>Summary</th>
<td>lld fails with can't create dynamic relocation R_X86_64_TLSLD against symbol: getI()::i in readonly segment
</td>
</tr>
<tr>
<th>Product</th>
<td>lld
</td>
</tr>
<tr>
<th>Version</th>
<td>unspecified
</td>
</tr>
<tr>
<th>Hardware</th>
<td>PC
</td>
</tr>
<tr>
<th>OS</th>
<td>Linux
</td>
</tr>
<tr>
<th>Status</th>
<td>NEW
</td>
</tr>
<tr>
<th>Severity</th>
<td>normal
</td>
</tr>
<tr>
<th>Priority</th>
<td>P
</td>
</tr>
<tr>
<th>Component</th>
<td>ELF
</td>
</tr>
<tr>
<th>Assignee</th>
<td>unassignedbugs@nondot.org
</td>
</tr>
<tr>
<th>Reporter</th>
<td>teemperor@gmail.com
</td>
</tr>
<tr>
<th>CC</th>
<td>llvm-bugs@lists.llvm.org
</td>
</tr></table>
<p>
<div>
<pre>Created <span class=""><a href="attachment.cgi?id=19383" name="attach_19383" title="test.o">attachment 19383</a> <a href="attachment.cgi?id=19383&action=edit" title="test.o">[details]</a></span>
test.o
LLD 5.0 (and the latest master build I have around) both fail to link the given
.o into a shared library with the following errors:
###########################################################
> g++ -shared -o outlib.so test.o
/usr/bin/ld: error: can't create dynamic relocation R_X86_64_TLSLD against
symbol: getI()::i in readonly segment
>>> defined in test.o
>>> referenced by test.cpp
>>> test.o:(foo())
/usr/bin/ld: error: can't create dynamic relocation R_X86_64_DTPOFF32 against
symbol: getI()::i in readonly segment
>>> defined in test.o
>>> referenced by test.cpp
>>> test.o:(foo())
collect2: error: ld returned 1 exit status
###########################################################
Both gold and the GNU linker don't produce any error with the same GCC
invocation.
The problem can also be ovserved from source with GCC 7.2 and this minimal
reproducer:
###########################################################
> g++ -fPIC -O2 -shared -o outlib.so test.cpp
/usr/bin/ld: error: can't create dynamic relocation R_X86_64_TLSLD against
symbol: getI()::i in readonly segment
>>> defined in /tmp/ccwDtRiy.o
>>> referenced by test.cpp
>>> /tmp/ccwDtRiy.o:(foo())
/usr/bin/ld: error: can't create dynamic relocation R_X86_64_DTPOFF32 against
symbol: getI()::i in readonly segment
>>> defined in /tmp/ccwDtRiy.o
>>> referenced by test.cpp
>>> /tmp/ccwDtRiy.o:(foo())
collect2: error: ld returned 1 exit status
###########################################################
> cat test.cpp
inline int& getI() {
thread_local int i = 0;
return i;
};
int foo() {
return getI();
}
###########################################################
> ld --version
LLD 5.0.0 (compatible with GNU linkers)
###########################################################
> g++ -v
Using built-in specs.
COLLECT_GCC=g++
COLLECT_LTO_WRAPPER=/usr/lib/gcc/x86_64-pc-linux-gnu/7.2.0/lto-wrapper
Target: x86_64-pc-linux-gnu
Configured with: /build/gcc/src/gcc/configure --prefix=/usr --libdir=/usr/lib
-
-libexecdir=/usr/lib --mandir=/usr/share/man --infodir=/usr/share/info --with-
bugurl=<a href="https://bugs.archlinux.org/">https://bugs.archlinux.org/</a> --enable-
languages=c,c++,ada,fortran,go,lto,objc,obj-c++ --enable-shared --enable-
threads=posix --enable-libmpx --with-system-zlib --with-isl --enable-
__cxa_atexit --disable-libunwind-exceptions --enable-clocale=gnu --disable-
libstdcxx-pch --disable-libssp --enable-gnu-unique-object --enable-linker-
build-id --enable-lto --enable-plugin --enable-install-libiberty
--with-linker-
hash-style=gnu --enable-gnu-indirect-function --disable-multilib --disable-
werror --enable-checking=release --enable-default-pie --enable-default-ssp
Thread model: posix
gcc version 7.2.0 (GCC)
###########################################################
> readelf -s test.o
Symbol table '.symtab' contains 14 entries:
Num: Value Size Type Bind Vis Ndx Name
0: 0000000000000000 0 NOTYPE LOCAL DEFAULT UND
1: 0000000000000000 0 FILE LOCAL DEFAULT ABS test.cpp
2: 0000000000000000 0 SECTION LOCAL DEFAULT 2
3: 0000000000000000 0 SECTION LOCAL DEFAULT 4
4: 0000000000000000 0 SECTION LOCAL DEFAULT 5
5: 0000000000000000 0 SECTION LOCAL DEFAULT 6
6: 0000000000000000 0 SECTION LOCAL DEFAULT 8
7: 0000000000000000 0 SECTION LOCAL DEFAULT 9
8: 0000000000000000 0 SECTION LOCAL DEFAULT 7
9: 0000000000000000 0 SECTION LOCAL DEFAULT 1
10: 0000000000000000 27 FUNC GLOBAL DEFAULT 2 _Z3foov
11: 0000000000000000 0 NOTYPE GLOBAL DEFAULT UND
_GLOBAL_OFFSET_TABLE_
12: 0000000000000000 4 TLS UNIQUE DEFAULT 6 _ZZ4getIvE1i
13: 0000000000000000 0 NOTYPE GLOBAL DEFAULT UND __tls_get_addr
###########################################################</pre>
</div>
</p>
<hr>
<span>You are receiving this mail because:</span>
<ul>
<li>You are on the CC list for the bug.</li>
</ul>
</body>
</html>