Re: Miscompilation on arm64 with GCC LTO

2023-07-03 Thread Marc Glisse

On Mon, 8 May 2023, Arsen Arsenović wrote:


gmp-6.2.1 when built with gcc 12/13/14 (trunk as of today) combined with
-O2 -flto or -O3 -flto is miscompiled, causing a few issues:
1. `make check` for gmp fails the 't-constants' test


I am definitely not a pro of aarch64 or LTO, but from a diff of configure 
output with/without LTO, I notice that -flto prevents GMP from 
understanding that RODATA can use .section .rodata, so it uses .text 
instead and that fails. If I add -ffat-lto-objects, then configure can 
detect the proper RODATA incantation and everything works.


Now it may very well be that GMP could write its assembler in a way that 
works both for .text and for .section .rodata, I don't know what the right 
fix is, but it seemed worth recording this piece of information.


--
Marc Glisse
___
gmp-bugs mailing list
gmp-bugs@gmplib.org
https://gmplib.org/mailman/listinfo/gmp-bugs


Re: Miscompilation on arm64 with GCC LTO

2023-05-10 Thread Sam James

Niels Möller  writes:

> Sam James  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
>
>   adrpx1, approx_tab
>   add x1, x1, :lo12:approx_tab
>
> to
>
>   adrpx1, :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


signature.asc
Description: PGP signature
___
gmp-bugs mailing list
gmp-bugs@gmplib.org
https://gmplib.org/mailman/listinfo/gmp-bugs


Re: Miscompilation on arm64 with GCC LTO

2023-05-10 Thread Sam James

Torbjörn Granlund  writes:

> Have you tried using a recent GMP snapshot?
> If not, please do.
>
> https://gmplib.org/download/snapshot/


gmp-6.2.99-20221117121717.tar.zst seems to fail for the same way for me,
with t-constants failing and GCC hanging/erroring in the same way too.
___
gmp-bugs mailing list
gmp-bugs@gmplib.org
https://gmplib.org/mailman/listinfo/gmp-bugs


Re: Miscompilation on arm64 with GCC LTO

2023-05-10 Thread Arsen Arsenović
Hi,

Torbjörn Granlund  writes:

> He surely has some patience issues.
>
> Please let Sam know about mailing list moderation and perhaps about that
> the earth is round and thus have different time zones; sending three
> copies of the same message within a couple of hours is not appreciated.

Heh, my apologies.  We've had odd mail delivery problems in the past
(mail gets dropped as a result of some part of the chain misinterpreting
some bits of the email body as headers if some lines contain colons), so
there's some paranoia around it now.

We didn't mean to spam you, and didn't realize mail for subscribers also
gets queued for moderation.

Sorry about that, again.  Thank you for working on GMP.

Have a lovely day!
-- 
Arsen Arsenović


signature.asc
Description: PGP signature
___
gmp-bugs mailing list
gmp-bugs@gmplib.org
https://gmplib.org/mailman/listinfo/gmp-bugs


Re: Miscompilation on arm64 with GCC LTO

2023-05-10 Thread Torbjörn Granlund
Have you tried using a recent GMP snapshot?
If not, please do.

https://gmplib.org/download/snapshot/

-- 
Torbjörn
Please encrypt, key id 0xC8601622
___
gmp-bugs mailing list
gmp-bugs@gmplib.org
https://gmplib.org/mailman/listinfo/gmp-bugs


Re: Miscompilation on arm64 with GCC LTO

2023-05-10 Thread Niels Möller
Sam James  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?

Regards,
/Niels

-- 
Niels Möller. PGP key CB4962D070D77D7FCB8BA36271D8F1FF368C6677.
Internet email is subject to wholesale government surveillance.
___
gmp-bugs mailing list
gmp-bugs@gmplib.org
https://gmplib.org/mailman/listinfo/gmp-bugs


Re: Miscompilation on arm64 with GCC LTO

2023-05-09 Thread Torbjörn Granlund
Arsen Arsenović  writes:

  I'm forwarding a message from Sam James, a fellow Gentoo developer, as
  he seems to be having some mail delivery issues.

He surely has some patience issues.

Please let Sam know about mailing list moderation and perhaps about that
the earth is round and thus have different time zones; sending three
copies of the same message within a couple of hours is not appreciated.


-- 
Torbjörn
Please encrypt, key id 0xC8601622
___
gmp-bugs mailing list
gmp-bugs@gmplib.org
https://gmplib.org/mailman/listinfo/gmp-bugs