Fix PR c++/64697 at -O1 or above
commit021ad8e5cf9ab66e1a0a41dce3a54586facb86e0
authorEric Botcazou <ebotcazou@adacore.com>
Fri, 1 Oct 2021 08:49:34 +0000 (1 10:49 +0200)
committerEric Botcazou <ebotcazou@adacore.com>
Fri, 1 Oct 2021 08:56:24 +0000 (1 10:56 +0200)
tree5f075ce4e78d8af86e42faa1b6c791ade269f624
parente705b8533aa0a00a65734eb5fd6344295723dccc
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.
gcc/config/i386/i386.c