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

Can't take address of interrupts enabled / disabled function #57

Open
rmn30 opened this issue Dec 9, 2024 · 5 comments · May be fixed by #89
Open

Can't take address of interrupts enabled / disabled function #57

rmn30 opened this issue Dec 9, 2024 · 5 comments · May be fixed by #89

Comments

@rmn30
Copy link

rmn30 commented Dec 9, 2024

I wanted to write some test code along the following lines to get hold of a sealed capability with interrupt disabling sentry type:

[[cheri::interrupt_state(disabled)]] void some_id_function() {
  // blah
}
//...
Capability idSentry = {&some_id_function};

This compiles but I get a linker error:

error: ld.lld: error: Compartment 'isa_test' imports library function 
'__library_export_<mangled name of some_id_function>' 
as cross-compartment call

This is obviously a bit unusual but is it something we could / should support?

@resistor
Copy link
Collaborator

@rmn30 Any chance you could post a self-contained test for this?

@rmn30
Copy link
Author

rmn30 commented Dec 12, 2024

The easiest way to reproduce is to edit the hello world example in cheriot-rtos/examples/01.hello_world but I will take a look if I can narrow it down.

@rmn30
Copy link
Author

rmn30 commented Dec 13, 2024

The error is produced at https://github.com/CHERIoT-Platform/llvm-project/blob/cheriot/lld/ELF/Writer.cpp#L3257 , so the question is why is isLibcall false? This comes from a test on the low bit of 'start' from the import table entry so why is that not set?

@rmn30
Copy link
Author

rmn30 commented Dec 13, 2024

If you compile the following:

void (*f)() = 0;

[[cheri::interrupt_state(disabled)]] void id_function(void) {
}

/// Thread entry point.
void __attribute__((cheri_compartment("hello"))) say_hello()
{
        f = &id_function;
}

Like follows:

clang++ -S -std=c++20 -Qunused-arguments -target riscv32-unknown-unknown -mcpu=cheriot -mabi=cheriot -mxcheri-rvc -mrelax -fshort-wchar -nostdinc -Oz -g -ffunction-sections -fdata-sections -fomit-frame-pointer -fno-builtin -fno-exceptions -fno-asynchronous-unwind-tables -fno-c++-static-destructors -fno-rtti -Werror -cheri-compartment=hello -o hello.S hello.cc

and look at the end of the resulting .S you will see the import table entry for id_function:

       .section        .compartment_imports,"aG",@progbits,__library_import_hello__Z11id_functionv,comdat
        .type   __library_import_hello__Z11id_functionv,@object
        .weak   __library_import_hello__Z11id_functionv
        .p2align        3
__library_import_hello__Z11id_functionv:
        .word   __library_export_hello__Z11id_functionv
        .word   0
        .size   __library_import_hello__Z11id_functionv, 8

Apparently the +1 that indicates this is a library import should be in the third last line ( .word __library_export_hello__Z11id_functionv) as like this https://github.com/CHERIoT-Platform/llvm-project/blob/cheriot/llvm/test/CodeGen/RISCV/cheri/cheri-mcu-call-libcall.ll#L44 .

@resistor
Copy link
Collaborator

@rmn30 I believe this should fix the issue you're seeing, can you confirm when you have a chance? #89

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