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

Wrong address derivation when compiling with -mno-relax flag in Cheriot #698

Closed
ajrn1998 opened this issue May 19, 2023 · 1 comment
Closed

Comments

@ajrn1998
Copy link

When adding more than one compilation unit to the same compartment and setting the -mno-relax flag when compiling these units, compilation and linking succeed. However, when trying to run the final elf file using the cheriot sail emulator a violation occurs as there is a wrong address derivation using the pair aupcc and jalr and the emulator jumps to that wrong address. Setting the flag -mrelax relaxes these two instructions into a single cjal instruction and the right address is derived. I believe that in the documentation it is mentioned that you rely on linker relaxation to optimise these relocations but should not the pair of aupcc and jalr still derive the right address even when that optimisation is not applied?

The issue can be replicated using the hello_world example. Simply add another file to the "hello" compartment. Let us say "other_compilation_unit.cc". Within this file, write the implementation of a simple function:

#include <debug.hh>
using Debug = ConditionalDebug<true, "Hello world compartment - Other compilation unit">;
void func_in_another_compilation_unit() {
    Debug::log("func_in_another_compilation_unit");
}

Call this function within the file "hello.cc" "say_hello" function. The rest of the files in other compartments may be compiled as usual but you should set the flag -mno-relax flag when compiling the files "hello.cc" and "other_compilation_unit.cc". Finally, run the Sail emulator with reg and instr trace enable and you should be able to see that the when the emulator tries to use the pair aupcc and jalr to branch to func_in_another_compilation_unit, it jumps to a different address causing a CHERI BoundsViolation.

@davidchisnall
Copy link
Member

Sorry, I missed this when it was opened. Please can you re-file it in the CHERIoT LLVM repository if it's still present?

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

No branches or pull requests

2 participants