[llvm-bugs] [Bug 35242] New: lld fails with can't create dynamic relocation R_X86_64_TLSLD against symbol: getI()::i in readonly segment

via llvm-bugs llvm-bugs at lists.llvm.org
Wed Nov 8 03:01:09 PST 2017


https://bugs.llvm.org/show_bug.cgi?id=35242

            Bug ID: 35242
           Summary: lld fails with can't create dynamic relocation
                    R_X86_64_TLSLD against symbol: getI()::i in readonly
                    segment
           Product: lld
           Version: unspecified
          Hardware: PC
                OS: Linux
            Status: NEW
          Severity: normal
          Priority: P
         Component: ELF
          Assignee: unassignedbugs at nondot.org
          Reporter: teemperor at gmail.com
                CC: llvm-bugs at lists.llvm.org

Created attachment 19383
  --> https://bugs.llvm.org/attachment.cgi?id=19383&action=edit
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=https://bugs.archlinux.org/ --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
###########################################################

-- 
You are receiving this mail because:
You are on the CC list for the bug.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.llvm.org/pipermail/llvm-bugs/attachments/20171108/37871a1b/attachment.html>


More information about the llvm-bugs mailing list