Bug 27239 - gdb/cp-support.c:1619:(.text+0x5502): relocation truncated to fit: R_X86_64_PC32 against undefined symbol `TLS init function for thread_local_segv_handler'
Summary: gdb/cp-support.c:1619:(.text+0x5502): relocation truncated to fit: R_X86_64_P...
Status: RESOLVED FIXED
Alias: None
Product: gdb
Classification: Unclassified
Component: threads (show other bugs)
Version: HEAD
: P2 normal
Target Milestone: 10.2
Assignee: Not yet assigned to anyone
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2021-01-25 13:25 UTC by Christian Biesinger
Modified: 2021-11-22 07:37 UTC (History)
23 users (show)

See Also:
Host:
Target:
Build:
Last reconfirmed:


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description Christian Biesinger 2021-01-25 13:25:27 UTC
With gdb HEAD (technically users/simark/update-gnulib @ 636b2c309a209d717930145883f5aa709a0fff52) on cygwin64 I get this link error:

make: Entering directory '/home/Christian/binutils-gdb/cygwin-obj/gdb'
  CXXLD  gdb.exe
cp-support.o: in function `gdb_demangle(char const*, int)':
/home/Christian/binutils-gdb/cygwin-obj/gdb/../../gdb/cp-support.c:1619:(.text+0x5502): relocation truncated to fit: R_X86_64_PC32 against undefined symbol `TLS init function for thread_local_segv_handler'
/home/Christian/binutils-gdb/cygwin-obj/gdb/../../gdb/cp-support.c:1619:(.text+0x551b): relocation truncated to fit: R_X86_64_PC32 against undefined symbol `TLS init function for thread_local_segv_handler'
collect2: error: ld returned 1 exit status
make: *** [Makefile:1881: gdb.exe] Error 1
make: Leaving directory '/home/Christian/binutils-gdb/cygwin-obj/gdb'

$ g++ -v
Using built-in specs.
COLLECT_GCC=g++
COLLECT_LTO_WRAPPER=/usr/lib/gcc/x86_64-pc-cygwin/10/lto-wrapper.exe
Target: x86_64-pc-cygwin
Configured with: /mnt/share/cygpkgs/gcc/gcc.x86_64/src/gcc-10.2.0/configure --srcdir=/mnt/share/cygpkgs/gcc/gcc.x86_64/src/gcc-10.2.0 --prefix=/usr --exec-prefix=/usr --localstatedir=/var --sysconfdir=/etc --docdir=/usr/share/doc/gcc --htmldir=/usr/share/doc/gcc/html -C --build=x86_64-pc-cygwin --host=x86_64-pc-cygwin --target=x86_64-pc-cygwin --without-libiconv-prefix --without-libintl-prefix --libexecdir=/usr/lib --with-gcc-major-version-only --enable-shared --enable-shared-libgcc --enable-static --enable-version-specific-runtime-libs --enable-bootstrap --enable-__cxa_atexit --with-dwarf2 --with-tune=generic --enable-languages=c,c++,fortran,lto,objc,obj-c++ --enable-graphite --enable-threads=posix --enable-libatomic --enable-libgomp --enable-libquadmath --enable-libquadmath-support --disable-libssp --enable-libada --disable-symvers --with-gnu-ld --with-gnu-as --with-cloog-include=/usr/include/cloog-isl --without-libiconv-prefix --without-libintl-prefix --with-system-zlib --enable-linker-build-id --with-default-libstdcxx-abi=gcc4-compatible --enable-libstdcxx-filesystem-ts
Thread model: posix
Supported LTO compression algorithms: zlib zstd
gcc version 10.2.0 (GCC)

$ ld -v
GNU ld (GNU Binutils) 2.35.1


I've seen a similar error on more esoteric platforms. I believe it is a toolchain bug somewhere relating to extern thread_local variables. However, it may make sense to rework this code not to require extern variables (using getters/setters or somesuch).

See also:
https://sourceware.org/pipermail/gdb-patches/2020-November/173579.html
and response:
https://sourceware.org/pipermail/gdb-patches/2020-December/173679.html
Comment 1 Hannes Domani 2021-01-25 17:39:42 UTC
The related binutils bug is PR26757.
Comment 2 Sourceware Commits 2021-03-12 17:22:05 UTC
The master branch has been updated by Christian Biesinger <cbiesinger@sourceware.org>:

https://sourceware.org/git/gitweb.cgi?p=binutils-gdb.git;h=fece451c2aca57b095e7e4063e342781cf74aa75

commit fece451c2aca57b095e7e4063e342781cf74aa75
Author: Christian Biesinger <cbiesinger@google.com>
Date:   Tue Mar 9 08:16:23 2021 -0600

    Use RAII to set the per-thread SIGSEGV handler
    
    This avoids using a thread-local extern variable, which causes link errors
    on some platforms, notably Cygwin.  But I think this is a better pattern
    even outside of working around linker bugs because it encapsulates direct
    access to the variable inside the class, instead of having a global extern
    variable.
    
    The cygwin link error is:
    cp-support.o: in function `gdb_demangle(char const*, int)':
    /home/Christian/binutils-gdb/obj/gdb/../../gdb/cp-support.c:1619:(.text+0x6472): relocation truncated to fit: R_X86_64_PC32 against undefined symbol `TLS init function for thread_local_segv_handler'
    /home/Christian/binutils-gdb/obj/gdb/../../gdb/cp-support.c:1619:(.text+0x648b): relocation truncated to fit: R_X86_64_PC32 against undefined symbol `TLS init function for thread_local_segv_handler'
    collect2: error: ld returned 1 exit status
    
    2021-03-12  Christian Biesinger  <cbiesinger@google.com>
    
            PR threads/27239
            * cp-support.c: Use scoped_segv_handler_restore.
            * event-top.c (thread_local_segv_handler): Made static.
            (scoped_segv_handler_restore::scoped_segv_handler_restore):
            New function.
            (scoped_segv_handler_restore::~scoped_segv_handler_restore): New
            function.
            * event-top.h (class scoped_segv_handler_restore): New class.
            (thread_local_segv_handler): Removed.
Comment 3 Sourceware Commits 2021-03-12 17:29:36 UTC
The gdb-10-branch branch has been updated by Christian Biesinger <cbiesinger@sourceware.org>:

https://sourceware.org/git/gitweb.cgi?p=binutils-gdb.git;h=1ee63759b094c15300f9cd74da20830a6e1137c7

commit 1ee63759b094c15300f9cd74da20830a6e1137c7
Author: Christian Biesinger <cbiesinger@google.com>
Date:   Tue Mar 9 08:16:23 2021 -0600

    Use RAII to set the per-thread SIGSEGV handler
    
    This avoids using a thread-local extern variable, which causes link errors
    on some platforms, notably Cygwin.  But I think this is a better pattern
    even outside of working around linker bugs because it encapsulates direct
    access to the variable inside the class, instead of having a global extern
    variable.
    
    The cygwin link error is:
    cp-support.o: in function `gdb_demangle(char const*, int)':
    /home/Christian/binutils-gdb/obj/gdb/../../gdb/cp-support.c:1619:(.text+0x6472): relocation truncated to fit: R_X86_64_PC32 against undefined symbol `TLS init function for thread_local_segv_handler'
    /home/Christian/binutils-gdb/obj/gdb/../../gdb/cp-support.c:1619:(.text+0x648b): relocation truncated to fit: R_X86_64_PC32 against undefined symbol `TLS init function for thread_local_segv_handler'
    collect2: error: ld returned 1 exit status
    
    2021-03-12  Christian Biesinger  <cbiesinger@google.com>
    
            PR threads/27239
            * cp-support.c: Use scoped_segv_handler_restore.
            * event-top.c (thread_local_segv_handler): Made static.
            (scoped_segv_handler_restore::scoped_segv_handler_restore):
            New function.
            (scoped_segv_handler_restore::~scoped_segv_handler_restore): New
            function.
            * event-top.h (class scoped_segv_handler_restore): New class.
            (thread_local_segv_handler): Removed.
Comment 4 Christian Biesinger 2021-03-13 12:57:25 UTC
gdb should build now.
Comment 5 Ahmed Sayeed 2021-06-27 17:47:44 UTC Comment hidden (spam)
Comment 6 Ucel Sani 2021-08-10 11:45:28 UTC Comment hidden (spam)
Comment 7 ribevi 2021-08-27 17:57:38 UTC Comment hidden (spam)
Comment 8 Buran Levent 2021-08-28 18:31:10 UTC Comment hidden (spam)
Comment 9 james robin 2021-09-06 09:10:07 UTC Comment hidden (spam)
Comment 10 Mehmet gelisin 2021-09-10 19:40:44 UTC Comment hidden (spam)
Comment 11 johnb6174 2021-09-14 17:29:30 UTC Comment hidden (spam)
Comment 12 Kylan 2021-09-26 13:31:50 UTC Comment hidden (spam)
Comment 13 Gulsen Engin 2021-10-09 11:00:59 UTC Comment hidden (spam)
Comment 14 oficaj3 2021-10-10 16:10:31 UTC Comment hidden (spam)
Comment 15 Canerkin 2021-10-18 19:58:00 UTC Comment hidden (spam)
Comment 16 progonsaytu 2021-10-19 07:14:21 UTC Comment hidden (spam)
Comment 17 fiteva 2021-10-23 13:46:20 UTC Comment hidden (spam)
Comment 18 glassmtech 2021-10-24 10:02:18 UTC Comment hidden (spam)
Comment 19 Kuka Kim 2021-10-29 10:57:06 UTC Comment hidden (spam)
Comment 20 Huracan 2021-10-29 12:07:18 UTC Comment hidden (spam)
Comment 21 gepaw 2021-11-02 15:21:46 UTC Comment hidden (spam)
Comment 22 paneki 2021-11-06 21:12:13 UTC Comment hidden (spam)
Comment 23 tesaso8237@funboxcn.comxecana8007@funboxcn.com 2021-11-16 19:05:02 UTC Comment hidden (spam)
Comment 24 tesaso8237@funboxcn.comxecana8007@funboxcn.com 2021-11-16 19:08:51 UTC Comment hidden (spam)
Comment 25 gexed96894 2021-11-22 07:37:57 UTC Comment hidden (spam)