Miscompilation on arm64 with GCC LTO

Sam James sam at gentoo.org
Wed May 10 15:01:29 CEST 2023


Niels Möller <nisse at lysator.liu.se> writes:

> Sam James <sam at gentoo.org> writes:
>
>> Note that Jannik identified the bad commit [0] as 18082:c5d0fcb06969 [4].
> [...]
>> [0] https://gmplib.org/list-archives/gmp-bugs/2020-December/004981.html
>> [1] https://gmplib.org/list-archives/gmp-bugs/2023-January/005223.html
>> [3] https://gcc.gnu.org/bugzilla/show_bug.cgi?id=3D109765
>> [4] https://gmplib.org/repo/gmp/rev/c5d0fcb06969
>
> It looks like that commit changes
>
>   adrp	x1, approx_tab
>   add	x1, x1, :lo12:approx_tab
>
> to
>
>   adrp	x1, :got:approx_tab
>   ldr	x1, [x1, #:got_lo12:approx_tab]
>
> and only when PIC is defined (via LEA_HI and LEA_LO m4 macros). I
> haven't double checked what assembly files actually look like after
> preprocessing, though.
>
> And something similar for __gmp_binvert_limb_table.
>
> But I have no clue about the arm64 abi. Is PIC defined in the failing
> build, or should it be?

I think it is set.

If I try with explicit ./configure --with-pic to be sure, it still
fails.

If I try with explicit ./configure --without-pic, I can't build gmp:
```
[...]
/usr/lib/gcc/aarch64-unknown-linux-gnu/14/../../../../aarch64-unknown-linux-gnu/bin/ld:
mpn/.libs/bdiv_q_1.o: relocation R_AARCH64_ADR_PREL_PG_HI21 against
symbol `__gmp_binvert_limb_table' which may bind externally can not be
used when making a shared object; recompile with -fPIC
mpn/.libs/bdiv_q_1.o: in function `__gmpn_bdiv_q_1':
```

with __gmp_binvert_limb_table being the symbol you and Jannik mentioned..

>
> Regards,
> /Niels

best,
sam
-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 377 bytes
Desc: not available
URL: <https://gmplib.org/list-archives/gmp-bugs/attachments/20230510/e23bd471/attachment.bin>


More information about the gmp-bugs mailing list