Skip to content

rt: fix veneer limit position in linker script #434

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

Merged
merged 1 commit into from
Apr 28, 2022

Conversation

luojia65
Copy link
Contributor

@luojia65 luojia65 commented Apr 26, 2022

This pull request fixes a CMSE related bug. If we define #[cmse_nonsecure_call] segments it would generate functions in .gnu.sgstubs, but we would eventually found out that for unknown reason __veneer_base == __veneer_limit, where SAU configuration to this segment would be impossible.
The reason for this bug is unknown, but after this pull request it would link into correct limit value.

I wrote an example for this fix: https://github.com/IoTS-P/trustzone-m-rs/tree/sgstub-fixed . Before this pull request, this project builds but it would print like SG function stub region is at 0x10005fc0 .. 0x10005fc0, resulting in secure fault. After this pull request, it would print SG function stub region is at 0x10005fc0 .. 0x10005fe0 and runs successfully.

@luojia65 luojia65 requested a review from a team as a code owner April 26, 2022 08:41
@rust-highfive
Copy link

Thanks for the pull request, and welcome! The Rust team is excited to review your changes, and you should hear from @thalesfragoso (or someone else) soon.

Please see the contribution instructions for more information.

@rust-highfive rust-highfive added S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. T-cortex-m labels Apr 26, 2022
@therealprof
Copy link
Contributor

Looks good to me. Second opinion?

@jannic
Copy link
Member

jannic commented Apr 27, 2022

Related issue, which explains why this workaround is necessary:
https://bugs.launchpad.net/gcc-arm-embedded/+bug/1930219
(Some more context here: https://answers.launchpad.net/gcc-arm-embedded/+question/697333)

thejpster
thejpster previously approved these changes Apr 27, 2022
adamgreig
adamgreig previously approved these changes Apr 27, 2022
Copy link
Member

@adamgreig adamgreig left a comment

Choose a reason for hiding this comment

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

Ugh, how weird. I think this is fine then but we should leave a comment behind for the benefit of future readers, something like this?

@jannic
Copy link
Member

jannic commented Apr 27, 2022

BTW, I'm not even sure it's a linker bug. The linker puts the veneer directly into the output section .gnu.sgstubs, it's not imported by the input section *(.gnu.sgstubs*).

For verification, this linker script still works:

  .gnu.sgstubs : ALIGN(32)
  {
    __veneer_base = .;
  } > FLASH
  __veneer_limit = .;

Whereas this causes an error arm-none-eabi-ld: no address assigned to the veneers output section .gnu.sgstubs:

  .gnu.sgstubs_renamed : ALIGN(32)
  {
    __veneer_base = .;
    *(.gnu.sgstubs*);
  } > FLASH
  __veneer_limit = .;

As far as I can tell, there is no way to specify at which location within the section the veneer will be placed. What can be observed is that the linker places the veneer at the very end of the section. So if __veneer_limit = .; is placed within the output section description, the linker will place the veneer after that.

Conclusion: This pull request seems to be the correct solution. (And *(.gnu.sgstubs*) could be removed to avoid confusion, however I'm not sure if that would have undesired side effects.)

@adamgreig
Copy link
Member

adamgreig commented Apr 27, 2022

So if __veneer_limit = .; is placed within the output section description, the linker will place the veneer after that.

Ah, I guess that explains it! OK, perfect, I think this PR is fine then. Thanks for explaining.

The comment should perhaps reflect that instead, just because otherwise someone might try and move it back inside one day. We could also add a comment to *(.gnu.sgstubs*) to say it's not actually used by the linker but kept as a talisman against future misfortune.

@luojia65 luojia65 dismissed stale reviews from adamgreig and thejpster via 9328a46 April 28, 2022 02:30
@luojia65
Copy link
Contributor Author

luojia65 commented Apr 28, 2022

Hello! I accepted change from @adamgreig and I'm afraid that everyone have to review this pull request again before it's getting merged on GitHub :)

add description and hints on linker behavior at symbol `__veneer_limit`

Co-authored-by: Adam Greig <[email protected]>
Copy link
Member

@adamgreig adamgreig left a comment

Choose a reason for hiding this comment

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

Thanks!

bors r+

@bors
Copy link
Contributor

bors bot commented Apr 28, 2022

@bors bors bot merged commit 6c28c81 into rust-embedded:master Apr 28, 2022
@luojia65 luojia65 deleted the fix-sgstub branch May 22, 2022 12:54
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. T-cortex-m
Projects
None yet
Development

Successfully merging this pull request may close these issues.

7 participants