[Bug c++/64697] C++11 thread_local: relocation truncated to fit: R_X86_64_PC32 against undefined symbol `TLS init function for N::ptd'

cvs-commit at gcc dot gnu.org gcc-bugzilla@gcc.gnu.org
Fri Oct 1 09:02:21 GMT 2021


https://gcc.gnu.org/bugzilla/show_bug.cgi?id=64697

--- Comment #27 from CVS Commits <cvs-commit at gcc dot gnu.org> ---
The releases/gcc-10 branch has been updated by Eric Botcazou
<ebotcazou@gcc.gnu.org>:

https://gcc.gnu.org/g:48e24ff39b16c072cd58bdad1a5668794453af5f

commit r10-10158-g48e24ff39b16c072cd58bdad1a5668794453af5f
Author: Eric Botcazou <ebotcazou@adacore.com>
Date:   Fri Oct 1 10:49:34 2021 +0200

    Fix PR c++/64697 at -O1 or above

    The BFD fix eliminates the link failure and working code is generated at
    -O0, but _not_ when optimization is enabled because the optimizer changes:

            movq    .refptr._ZTH1s(%rip), %rax
            testq   %rax, %rax
            je      .L2
            call    _ZTH1s

    into:

            leaq    _ZTH1s(%rip), %rax
            testq   %rax, %rax
            je      .L2
            call    _ZTH1s

    and the leaq now also gets the relocation overflow.  So the fix is to
    teach legitimate_pic_address_disp_p to reject the transformation when
    the symbol is an external weak function, which yields:

            cmpq    $0, .refptr._ZTH1s(%rip)
            je      .L2
            call    _ZTH1s

    and the cmpq keeps a relocation that does not overflow.

    gcc/
            PR c++/64697
            * config/i386/i386.c (legitimate_pic_address_disp_p): For PE-COFF
do
            not return true for external weak function symbols in medium model.


More information about the Gcc-bugs mailing list