Skip to content

Fix LTO & -O2 offset out of range #90865

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

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

Conversation

swift-tk
Copy link
Collaborator

@swift-tk swift-tk commented May 30, 2025

The arch.shared_interrupt.lto.speed compile fail on apollo5 platform.
Remove ldr instruction and pass function pointer by input operand.

This PR could fix #90777.

@github-actions github-actions bot added the area: ARM ARM (32-bit) Architecture label May 30, 2025
@swift-tk swift-tk force-pushed the ap5-fix-lto branch 2 times, most recently from 1ed5678 to 5ba0c64 Compare May 30, 2025 13:33
Copy link

@swift-tk
Copy link
Collaborator Author

This wouldn’t work for platform that can take only two input operands… Any suggestion on making the two function pointer less PC relative so it doesn’t exceed ldr offset?

@wearyzen
Copy link
Collaborator

This wouldn’t work for platform that can take only two input operands… Any suggestion on making the two function pointer less PC relative so it doesn’t exceed ldr offset?

@swift-tk I haven't tried this but I think preloading the pointers in r4 r5 could work, something like :

register uintptr_t __unlock_reg  __asm__("r6");
__unlock_reg = (uintptr_t)arch_irq_unlock_outlined;

and then

__asm__ volatile(
...
"movs  r0, #0       \n"
"blx   r6           \n"
...
)

@swift-tk
Copy link
Collaborator Author

swift-tk commented Jul 1, 2025

@wearyzen Thanks for the help, the compile seems to pass now.

@swift-tk swift-tk force-pushed the ap5-fix-lto branch 2 times, most recently from 4878eae to 106caf8 Compare July 1, 2025 07:20
The arch.shared_interrupt.lto.speed compile fail on apollo5 platform.
Remove ldr instruction and pass function pointer by register.

Signed-off-by: Swift Tian <[email protected]>
Copy link

sonarqubecloud bot commented Jul 1, 2025

@swift-tk
Copy link
Collaborator Author

swift-tk commented Jul 1, 2025

The modified version works on apollo5 platform, but for some reason, qemu_cortex_m0/nrf51822 still tries to use r5 and r6 as input operands when they are in the clobber list.. Thus emits impossible operand constraints... Deleting them from clobber seems to do the trick for compile but failed twister tests. I think those entry point in r5 and r6 eventually gets lost.

Using volatile keyword on register value wouldn't work as they gets optimized out....

@wearyzen
Copy link
Collaborator

wearyzen commented Jul 1, 2025

Hi @swift-tk I tried to reproduce the error today with west build -p always -b apollo510_evb tests/kernel/interrupt -T arch.shared_interrupt.lto.speed but wasn't able to. Could you try to rebase your branch to main and try reproducing the issue without this fix? I think we don't need any change at all for this if rebased to main.

@swift-tk
Copy link
Collaborator Author

swift-tk commented Jul 1, 2025

Hi @swift-tk I tried to reproduce the error today with west build -p always -b apollo510_evb tests/kernel/interrupt -T arch.shared_interrupt.lto.speed but wasn't able to. Could you try to rebase your branch to main and try reproducing the issue without this fix? I think we don't need any change at all for this if rebased to main.

There was a workaround merged to main to allow us merge our blocked PRs, but it is not ideal. I think it is better to try solving it fundamentally.
The commit is a54197b.
The issue might appear again even with this if there are other changes in tree.

Please also see #90777 (comment) for the root cause.

Copy link
Member

@stephanosio stephanosio left a comment

Choose a reason for hiding this comment

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

See #92569

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
area: ARM ARM (32-bit) Architecture
Projects
None yet
Development

Successfully merging this pull request may close these issues.

arch.shared_interrupt.lto.speed compile fail on apollo5 platform
3 participants