Skip to content

Sometimes, R_RISCV_CHERIOT_COMPARTMENT_HI relocations are broken during compartment linking #108

@davidchisnall

Description

@davidchisnall

Building this example fails, specifically in linking the firmware image with all of the demo code in the same compartment.

Specifically, in the set_secret function, prior to linking the compartment (in secret.cc.o), we see this:

00000022 <.LBB0_4>:
      22: 17 05 00 00  	auipcc	ca0, 0
			00000022:  R_RISCV_CHERIOT_COMPARTMENT_HI	template parameter object for (anonymous namespace)::DebugContext<23u>{char [23]{(char)74, (char)97, (char)118, (char)97, (char)83, (char)99, (char)114, (char)105, (char)112, (char)116, (char)32, (char)99, (char)111, (char)109, (char)112, (char)97, (char)114, (char)116, (char)109, (char)101, (char)110, (char)116}}
			00000022:  R_RISCV_RELAX	*ABS*
      26: 5b 15 05 00  	cincoffset	ca0, ca0, 0
			00000026:  R_RISCV_CHERIOT_COMPARTMENT_LO_I	.LBB0_4
			00000026:  R_RISCV_RELAX	*ABS*
      2a: 5b 25 05 00  	csetbounds	ca0, ca0, 0
			0000002a:  R_RISCV_CHERIOT_COMPARTMENT_SIZE	template parameter object for (anonymous namespace)::DebugContext<23u>{char [23]{(char)74, (char)97, (char)118, (char)97, (char)83, (char)99, (char)114, (char)105, (char)112, (char)116, (char)32, (char)99, (char)111, (char)109, (char)112, (char)97, (char)114, (char)116, (char)109, (char)101, (char)110, (char)116}}

But in the insecure_js.compartment file, we see this:

000013ac <.LBB0_4>:
; .LBB0_4():
; 				debug_log_message_write(
    13ac: 17 05 00 00  	auipcc	ca0, 0
			000013ac:  R_RISCV_CHERIOT_COMPARTMENT_HI	*ABS*
			000013ac:  R_RISCV_RELAX	*ABS*
    13b0: 5b 15 05 00  	cincoffset	ca0, ca0, 0
			000013b0:  R_RISCV_CHERIOT_COMPARTMENT_LO_I	.LBB0_4
			000013b0:  R_RISCV_RELAX	*ABS*
    13b4: 5b 25 05 00  	csetbounds	ca0, ca0, 0
			000013b4:  R_RISCV_CHERIOT_COMPARTMENT_SIZE	*ABS*

Note that the R_RISCV_CHERIOT_COMPARTMENT_HI relocation has been replaced. I have a couple of guesses about why this may happen, both may be wrong:

  • Something in GC is deleting the string from the template parameter and so the relocation becomes dangling.
  • The linker is determining that the string is <4 KiB away and so processing the relocation.

Unfortunately, RISC-V relocations that use AUIPC expect to find the address of the symbol when via the HI reloc when processing the LO one (so the reloc on the cincoffset is pointing at .LBB0_4 to find the symbol in the reloc for that instruction).

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions