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-06-27 17:47 UTC (History)
3 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 cvs-commit@gcc.gnu.org 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 cvs-commit@gcc.gnu.org 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)