-
Notifications
You must be signed in to change notification settings - Fork 10
Description
Presently, when doing baremetal work, I can synthesize capabilities to a given symbol's address from PCC (usually the X root with a varied address) with two instructions and some relocations:
1:
auipcc %0, %cheriot_compartment_hi($SYMBOL)
cincoffset %0, %0, %cheriot_compartment_lo_i(1b)
This is a bit shorter than the more general sequence where provenance is instead in a GPR (%1):
lui %0, %hi($SYMBOL)
addi %0, %0, %lo($SYMBOL)
csetaddr %0, %1, %0
Two things to note:
- The former (because of
%cheriot_compartment_hi) works only with$SYMBOLs in sections, not absolute symbols, and probably in fact the same section as the instruction requesting relocation? - As an aside, I suspect the former works almost "by accident" for my baremetal uses, as the linker needs to know
pcc.base, not justpcc.address, and probably that's defaulting to0when we're not in a compartment or somesuch.
All that setup in place, it would be nice (TM) if I could use an analogous shorter sequence for non-X provenance caps, given that CHERIoT added auicgp. I can almost make this work with
1:
auicgp %0, %cheriot_compartment_hi($SYMBOL)
cincoffset %0, %0, %cheriot_compartment_lo_i(1b)
which, presumably, has the same works-due-to-defaults as the auipcc one, and definitely has the same constraint that $SYMBOL can't be absolute. That's much more of a concern for data pointers, because, for example, we generate MMIO addresses (__export_mem_...) as absolute symbols rather than needing to place them into (sorted!) sections. So I'd kind of like to be able to write
1:
auicgp %0, %hi($SYMBOL)
cincoffset %0, %0, %lo(1b)
I took a stab at patching llvm/lib/Target/RISCV/AsmParser/RISCVAsmParser.cpp to make auicgp accept %hi and things got further... but I'd surely prefer someone who knew what they were doing have a think about this first.
If they don't already exist, it might also be useful to have directives or some other explicit mechanism for informing the linker (via the assembler) about pcc.base or cgp.base rather than assuming them to be 0.