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

csu: Add missing .cfi_undefined directives #1859

Merged
merged 1 commit into from
Sep 25, 2023

Conversation

arichardson
Copy link
Member

Without these libunwind attempts to unwind beyond _start which results in nonsense infinite backtraces. Found this by running the libunwind tests for RISCV and noticed that purecap was also missing these directives:

starting test1
Frame 1: _Z9backtracei+0x2e
Frame 2: _Z5test1i+0x40
Frame 3: main+0x28
Frame 4: __libc_start1+0x76
Frame 5: __start+0x18
Frame 6: _start+0x22
Frame 7: _Z9backtracei+0x2e
Frame 8: _start+0x22
Frame 9: _Z9backtracei+0x2e
Frame 10: _start+0x22
....

For RISC-V I added the directive to the C function rather than the assembly one but I could also add it to _start instead.

Without these libunwind attempts to unwind beyond _start which results
in nonsense infinite backtraces. Found this by running the libunwind
tests for RISCV and noticed that purecap was also missing these directives:
```
starting test1
Frame 1: _Z9backtracei+0x2e
Frame 2: _Z5test1i+0x40
Frame 3: main+0x28
Frame 4: __libc_start1+0x76
Frame 5: __start+0x18
Frame 6: _start+0x22
Frame 7: _Z9backtracei+0x2e
Frame 8: _start+0x22
Frame 9: _Z9backtracei+0x2e
Frame 10: _start+0x22
....
```

For RISC-V I added the directive to the C function rather than the
assembly one but I could also add it to _start instead.
@@ -76,6 +76,7 @@ _start(void *auxv,
void (*cleanup)(void), /* from shared loader */
struct Struct_Obj_Entry *obj) /* from shared loader */
{
__asm__ volatile(".cfi_undefined c30");
Copy link
Collaborator

Choose a reason for hiding this comment

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

This has changed upstream in a grosser way by rewriting all of _start in assembly.

It would be really nice if upstream LLVM would support some sort of function attribute to indicate a function that doesn't have a parent frame so that we could annotate these functions with that and LLVM would emit the proper .cfi_undefined directive for the relevant architecture.

@arichardson arichardson merged commit ab358d5 into CTSRD-CHERI:dev Sep 25, 2023
27 checks passed
@arichardson arichardson deleted the csu-cfi-undefined branch September 25, 2023 19:03
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

2 participants