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] Handle CALL_RM like CALL for 32-bit ELF #72758

Open
wants to merge 1 commit into
base: main
Choose a base branch
from

Conversation

kernigh
Copy link
Contributor

@kernigh kernigh commented Nov 18, 2023

If a function call has the strictfp attribute, its opcode changes from CALL to CALL_RM. If the call uses the secure PLT for 32-bit ELF, then it must getGlobalBaseReg() to set r30.


This fixes a bug that I described in (OpenBSD) macppc clang-16 -ftrapping-math crashes Xorg. The short version is that clang -ftrapping-math broke code like int main(void) { time(NULL); } by forgetting to set r30 before using the secure PLT.

Copy link

github-actions bot commented Nov 18, 2023

✅ With the latest revision this PR passed the C/C++ code formatter.

If a function call has the strictfp attribute, its opcode changes from
CALL to CALL_RM.  If the call uses the secure PLT for 32-bit ELF, then
it must getGlobalBaseReg() to set r30.
bob-beck pushed a commit to openbsd/src that referenced this pull request Nov 19, 2023
Handle CALL_RM like CALL for 32-bit ELF.  If a function call has the
strictfp attribute, its opcode changes from CALL to CALL_RM.  If a
call uses the secure PLT, then it must getGlobalBaseReg() to set r30.

After I rebuilt xenocara/lib/pixman with this change, Xorg stopped
crashing on my macppc.  pixman uses cc -ftrapping-math which puts
strictfp on each function call.

llvm/llvm-project#72758

ok jca@ tobhe@ deraadt@
@brad0
Copy link
Contributor

brad0 commented Nov 25, 2023

Ping.

@brad0
Copy link
Contributor

brad0 commented Dec 2, 2023

Ping.

@@ -0,0 +1,21 @@
; RUN: llc < %s -mtriple=powerpc-unknown-linux-gnu -mattr=+secure-plt -relocation-model=pic | FileCheck %s
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can we use auto generate script for it?

@brad0
Copy link
Contributor

brad0 commented Dec 8, 2023

@kernigh Ping.

2 similar comments
@brad0
Copy link
Contributor

brad0 commented Dec 20, 2023

@kernigh Ping.

@brad0
Copy link
Contributor

brad0 commented Jan 10, 2024

@kernigh Ping.

@@ -5475,7 +5475,8 @@ void PPCDAGToDAGISel::Select(SDNode *N) {
// generate secure plt code for TLS symbols.
getGlobalBaseReg();
} break;
case PPCISD::CALL: {
case PPCISD::CALL:
case PPCISD::CALL_RM: {
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Are your targeting this for SPE? SPE should have no floating point instructions? So round mode should not be a concern? For SPE, we may stop generate CALL_RM where it is generated. Note that CALL_RM performs worse than normal CALL even after instruction selection. They are selected to different instructions.

If for other PPC32 targets, the fix looks reasonable to me.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Are your targeting this for SPE?

This is not for SPE.

Copy link
Collaborator

@chenzheng1030 chenzheng1030 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM as long as @ecnelises's comment about the LIT case is addressed.

mordak pushed a commit to mordak/llvm-project that referenced this pull request Feb 11, 2024
Handle CALL_RM like CALL for 32-bit ELF.  If a function call has the
strictfp attribute, its opcode changes from CALL to CALL_RM.  If a
call uses the secure PLT, then it must getGlobalBaseReg() to set r30.

After I rebuilt xenocara/lib/pixman with this change, Xorg stopped
crashing on my macppc.  pixman uses cc -ftrapping-math which puts
strictfp on each function call.

llvm#72758

ok jca@ tobhe@ deraadt@
@brad0
Copy link
Contributor

brad0 commented Mar 3, 2024

It would be nice to get this in.

@chenzheng1030
Copy link
Collaborator

It would be nice to get this in.

Please let us know if need us to commit this pr. @kernigh

@brad0
Copy link
Contributor

brad0 commented Mar 4, 2024

Please let us know if need us to commit this pr. @kernigh

He does, but there was the issue of the test case being updated.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

4 participants