Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

PowerPC ABI incompatibility with GNU on complex arguments #56023

Open
UmeshKalappa0 opened this issue Jun 14, 2022 · 10 comments
Open

PowerPC ABI incompatibility with GNU on complex arguments #56023

UmeshKalappa0 opened this issue Jun 14, 2022 · 10 comments
Assignees
Labels
ABI Application Binary Interface backend:PowerPC

Comments

@UmeshKalappa0
Copy link

UmeshKalappa0 commented Jun 14, 2022

We recently moved llvm from GCC and found that their is ABI difference in the two compilers. GNU passes and returns double complex in GP registers. LLVM passes an returns the value on the stack.

return double complex numbers (the assumption is this applies to complex, double complex, and long double complex).

https://godbolt.org/z/qqzzesK9r

Its case with ppc32 and we agree that the ABI insist the same semantics like LLVM ,can we have change the semantics like GCC with option ?

@llvmbot
Copy link
Member

llvmbot commented Jun 14, 2022

@llvm/issue-subscribers-backend-powerpc

@asl
Copy link
Collaborator

asl commented Jun 15, 2022

So, likely the issue should to be reported to GCC?

@UmeshKalappa0
Copy link
Author

UmeshKalappa0 commented Jun 15, 2022

@asl ,my bad http://refspecs.linux-foundation.org/elf/elfspec_ppc.pdf according to this ,
A struct, union, or long double, any of which shall be treated as
a pointer to the object, or to a copy of the object where necessary to
enforce call-by-value semantics. Only if the caller can ascertain that the
object is "constant" can it pass a pointer to the object itself.

I think GCC following like
to a copy of the object where necessary to
enforce call-by-value semantics.

So i guess we need to have this implementation in llvm too and same goes to return value .

@chmeeedalf and @nemanjai your thoughts here ?

@UmeshKalappa0
Copy link
Author

@asl ,
@nemanjai
and @chmeeedalf

We made the changes ,can i raise a review with llvm trunk ?

@kernigh
Copy link
Contributor

kernigh commented Jul 14, 2022

This is still a problem on ppc32. If I call csin(3) in libm, gcc compiled my call, and clang had compiled libm, then it segfaults.

The ppc32 ABI has 2 ways to pass complex args. The old version from 1995 (elfspec_ppc.pdf) predates C99 and doesn't mention complex args, but the new version from 2011 (Power-Arch-32-bit-ABI-supp-1.0-Unified.pdf) specifies ATR-PASS-COMPLEX-IN-STRUCT and ATR-PASS-COMPLEX-IN-GPRS. clang looks like ATR-PASS-COMPLEX-IN-STRUCT, but gcc looks like ATR-PASS-COMPLEX-IN-GPRS. These are not compatible.

I looked at cc -fno-stack-protector -fno-pie -O1 -S ctry.c, where ctry.c is,

float _Complex v1;
double _Complex v2;
float _Complex csinf(float _Complex);
double _Complex csin(double _Complex);
void f1(void) { v1 = csinf(v1); }
void f2(void) { v2 = csin(v2); }

clang main from July 12 (8fe076f) passes complex in structs. csinf(v1) returns a small struct, so it uses -maix-struct-return on Linux or -msvr4-struct-return on BSD. clang -target powerpc-linux calls csinf(v1) with r3 = address of return value, r4 = address of v1. clang -target powerpc-openbsd calls csinf(v1) with r3 = address of v1, and expects the return value in r3:r4. clang with either target calls csin(v2) with r3 = address of return value, r4 = address of v1.

gcc passes complex in general-purpose registers. gcc calls csinf(v1) with r3:r4 = v1, and expects the return value in r3:r4. gcc calls csin(v2) with r3:r4:r5:r6 = v2, and expects the return value in r3:r4:r5:r6. This is awkward because it doesn't use the floating-point registers. The ABI and gcc do align register pairs as odd-even, but don't align register quads. So, gcc calls f(int, float complex) with r3 = int, r5:r6 = float complex, skipping r4 to align the pair; but gcc calls g(int, double complex) with r3 = int, r4:r5:r6:r7 = double complex, without skipping registers.

@chmeeedalf
Copy link
Contributor

@asl , @nemanjai and @chmeeedalf

We made the changes ,can i raise a review with llvm trunk ?

Sorry for delay, I've been in the process of moving over the last couple months.

Please do submit a review for further discussion. It may get a wider audience there, too.

@thesamesam thesamesam added the ABI Application Binary Interface label Nov 5, 2022
@brad0
Copy link
Contributor

brad0 commented Nov 27, 2022

@kernigh

@brad0
Copy link
Contributor

brad0 commented Dec 25, 2022

ping.

@Long5hot
Copy link
Contributor

Long5hot commented Aug 2, 2023

@Long5hot Long5hot self-assigned this Aug 2, 2023
Long5hot added a commit to Long5hot/llvm-project that referenced this issue Jan 8, 2024
…x arguments

PR : llvm#56023

https://godbolt.org/z/1bsW1sKMs

newFlag: -fcomplex-ppc-gnu-abi

GNU uses GPRs for complex parameters and return values storing for PowerPC-32bit, which can be enabled which above flag.
Intent of this patch is to make clang compatible with GNU libraries of complex.
Long5hot added a commit to Long5hot/llvm-project that referenced this issue Jan 11, 2024
…x arguments

Fixes : llvm#56023

https://godbolt.org/z/1bsW1sKMs

newFlag : -fcomplex-ppc-gnu-abi

GNU uses GPRs for complex parameters and return values storing for PowerPC-32bit,
which can be enabled which above flag.
Intent of this patch is to make clang compatible with GNU libraries of complex.
Long5hot added a commit to Long5hot/llvm-project that referenced this issue Jan 17, 2024
…x arguments

Fixes : llvm#56023

https://godbolt.org/z/1bsW1sKMs

newFlag : -fcomplex-ppc-gnu-abi

GNU uses GPRs for complex parameters and return values storing for PowerPC-32bit,
which can be enabled which above flag.
Intent of this patch is to make clang compatible with GNU libraries of complex.
Long5hot added a commit to Long5hot/llvm-project that referenced this issue Jan 24, 2024
…x arguments

Fixes : llvm#56023

https://godbolt.org/z/1bsW1sKMs

newFlag : -fcomplex-ppc-gnu-abi

GNU uses GPRs for complex parameters and return values storing for PowerPC-32bit,
which can be enabled which above flag.
Intent of this patch is to make clang compatible with GNU libraries of complex.
@thesamesam
Copy link
Member

#77732

Long5hot added a commit to Long5hot/llvm-project that referenced this issue Mar 4, 2024
…x arguments

Fixes : llvm#56023

https://godbolt.org/z/1bsW1sKMs

newFlag : -fcomplex-ppc-gnu-abi

GNU uses GPRs for complex parameters and return values storing for PowerPC-32bit,
which can be enabled which above flag.
Intent of this patch is to make clang compatible with GNU libraries of complex.
Long5hot added a commit to Long5hot/llvm-project that referenced this issue Mar 15, 2024
…x arguments

Fixes : llvm#56023

https://godbolt.org/z/1bsW1sKMs

newFlag : -fcomplex-ppc-gnu-abi

GNU uses GPRs for complex parameters and return values storing for PowerPC-32bit,
which can be enabled which above flag.
Intent of this patch is to make clang compatible with GNU libraries of complex.

Following up with this patch : https://reviews.llvm.org/D146942
Long5hot added a commit to Long5hot/llvm-project that referenced this issue Mar 26, 2024
…x arguments

Fixes : llvm#56023

https://godbolt.org/z/1bsW1sKMs

newFlag : -fcomplex-ppc-gnu-abi

GNU uses GPRs for complex parameters and return values storing for PowerPC-32bit,
which can be enabled which above flag.
Intent of this patch is to make clang compatible with GNU libraries of complex.
Long5hot added a commit to Long5hot/llvm-project that referenced this issue Mar 26, 2024
…x arguments

Fixes : llvm#56023

https://godbolt.org/z/1bsW1sKMs

newFlag : -fcomplex-ppc-gnu-abi

GNU uses GPRs for complex parameters and return values storing for PowerPC-32bit,
which can be enabled which above flag.
Intent of this patch is to make clang compatible with GNU libraries of complex.
Long5hot added a commit to Long5hot/llvm-project that referenced this issue Mar 28, 2024
…x arguments

Fixes : llvm#56023

https://godbolt.org/z/1bsW1sKMs

newFlag : -fcomplex-ppc-gnu-abi

GNU uses GPRs for complex parameters and return values storing for PowerPC-32bit,
which can be enabled which above flag.
Intent of this patch is to make clang compatible with GNU libraries of complex.
Long5hot added a commit to Long5hot/llvm-project that referenced this issue Apr 24, 2024
…x arguments

Fixes : llvm#56023

https://godbolt.org/z/1bsW1sKMs

newFlag : -fcomplex-ppc-gnu-abi

GNU uses GPRs for complex parameters and return values storing for PowerPC-32bit,
which can be enabled which above flag.
Intent of this patch is to make clang compatible with GNU libraries of complex.

Following up with this patch : https://reviews.llvm.org/D146942
Long5hot added a commit to Long5hot/llvm-project that referenced this issue Apr 24, 2024
…x arguments

Fixes : llvm#56023

https://godbolt.org/z/1bsW1sKMs

newFlag : -fcomplex-ppc-gnu-abi

GNU uses GPRs for complex parameters and return values storing for PowerPC-32bit,
which can be enabled which above flag.
Intent of this patch is to make clang compatible with GNU libraries of complex.

Following up with this patch : https://reviews.llvm.org/D146942
Long5hot added a commit to Long5hot/llvm-project that referenced this issue Apr 28, 2024
…x arguments

Fixes : llvm#56023

https://godbolt.org/z/1bsW1sKMs

newFlag : -fcomplex-ppc-gnu-abi

GNU uses GPRs for complex parameters and return values storing for PowerPC-32bit,
which can be enabled which above flag.
Intent of this patch is to make clang compatible with GNU libraries of complex.

Following up with this patch : https://reviews.llvm.org/D146942
Long5hot added a commit to Long5hot/llvm-project that referenced this issue May 6, 2024
…x arguments

Fixes : llvm#56023

https://godbolt.org/z/1bsW1sKMs

newFlag : -fcomplex-ppc-gnu-abi

GNU uses GPRs for complex parameters and return values storing for PowerPC-32bit,
which can be enabled which above flag.
Intent of this patch is to make clang compatible with GNU libraries of complex.
Long5hot added a commit to Long5hot/llvm-project that referenced this issue Aug 8, 2024
…x arguments

Fixes : llvm#56023

https://godbolt.org/z/1bsW1sKMs

newFlag : -fcomplex-ppc-gnu-abi

GNU uses GPRs for complex parameters and return values storing for PowerPC-32bit,
which can be enabled which above flag.
Intent of this patch is to make clang compatible with GNU libraries of complex.

Following up with this patch : https://reviews.llvm.org/D146942
Long5hot added a commit to Long5hot/llvm-project that referenced this issue Aug 12, 2024
…x arguments

Fixes : llvm#56023

https://godbolt.org/z/1bsW1sKMs

newFlag : -fcomplex-ppc-gnu-abi

GNU uses GPRs for complex parameters and return values storing for PowerPC-32bit,
which can be enabled which above flag.
Intent of this patch is to make clang compatible with GNU libraries of complex.

Following up with this patch : https://reviews.llvm.org/D146942
Long5hot added a commit to Long5hot/llvm-project that referenced this issue Feb 5, 2025
…x arguments (llvm#77732)

Fixes : llvm#56023

https://godbolt.org/z/1bsW1sKMs

newFlag : -fcomplex-ppc-gnu-abi

GNU uses GPRs for complex parameters and return values storing for PowerPC-32bit,
which can be enabled which above flag.
Intent of this patch is to make clang compatible with GNU libraries of complex.

Following up with this patch : https://reviews.llvm.org/D146942
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
ABI Application Binary Interface backend:PowerPC
Projects
None yet
Development

No branches or pull requests

9 participants