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

Calling convention for arguments on the stack on Xtensa is incorrect for arguments narrower than 32 bits (LLVM-245) #66

Closed
kyrias opened this issue Apr 17, 2023 · 7 comments
Labels
Resolution: Done Status: Done Issue is done internally

Comments

@kyrias
Copy link

kyrias commented Apr 17, 2023

According to the ISA document function arguments passed on the stack are all essentially stored in 32-bit slots, which matches how GCC for Xtensa behaves. Meanwhile LLVM for Xtensa passes smaller arguments packed together. This means that passing more than 6 arguments to a function between code compiled by GCC and LLVM is currently broken.

E.g.:

GCC:
| 8-bit  | padding                | 16-bit         | padding        | 32-bit                         |

LLVM:
| 8-bit  | 16-bit         | 32-bit                         |

I see in CC_Xtensa_Custom that i8 and i16 are promoted to i32 for non-byval arguments:

// Promote i8 and i16
if (LocVT == MVT::i8 || LocVT == MVT::i16) {
LocVT = MVT::i32;
if (ArgFlags.isSExt())
LocInfo = CCValAssign::SExt;
else if (ArgFlags.isZExt())
LocInfo = CCValAssign::ZExt;
else
LocInfo = CCValAssign::AExt;
}

But the same promotion s not being done for byval ones:

if (ArgFlags.isByVal()) {
Align ByValAlign = ArgFlags.getNonZeroByValAlign();
unsigned Offset = State.AllocateStack(ArgFlags.getByValSize(), ByValAlign);
State.addLoc(CCValAssign::getMem(ValNo, ValVT, Offset, LocVT, LocInfo));
// Allocate rest of registers, because rest part is not used to pass
// arguments
while (State.AllocateReg(IntRegs)) {
}
return false;
}


I was considering trying to submit a patch for this, but I'm not sure if you're currently accepting patches for the Xtensa part, or if so how you're accepting them.

@github-actions github-actions bot changed the title Calling convention for arguments on the stack on Xtensa is incorrect for arguments narrower than 32 bits Calling convention for arguments on the stack on Xtensa is incorrect for arguments narrower than 32 bits (LLVM-245) Apr 17, 2023
@kyrias
Copy link
Author

kyrias commented Apr 24, 2023

@andreisfr Sorry for the direct ping but it seems like you committed the relevant code. Do you have any idea of what kind of timeline we're looking at to get this fixed? Would be good to have this ABI incompatibility resolved.

@igrr
Copy link
Member

igrr commented Apr 24, 2023

This issue has also been reported internally last week a few weeks ago by @MabezDev and the fix is now in progress (internal tracker is LLVM-244). Sorry for not leaving a comment here in time. I think we will have the fix merged this or worst case next week.

@kyrias
Copy link
Author

kyrias commented May 8, 2023

@igrr Ping?

@andreisfr
Copy link
Collaborator

Hi @kyrias , we preparing patch now with fixes, I hope in a few days we will update current version.

@andreisfr
Copy link
Collaborator

@kyrias , we applied fixes, PTAL.

@kyrias
Copy link
Author

kyrias commented May 10, 2023

@andreisfr The generated code from the xtensa_release_15.x branch looks correct now. 👍

@gerekon
Copy link
Collaborator

gerekon commented May 16, 2023

Should be fixed in df98377 and included into esp-16.0.0-20230515 release.

@kyrias Can we close this issue?

@kyrias kyrias closed this as completed May 17, 2023
@espressif-bot espressif-bot added Status: Done Issue is done internally Resolution: Done and removed Status: Opened labels May 19, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Resolution: Done Status: Done Issue is done internally
Projects
None yet
Development

No branches or pull requests

5 participants