Skip to content

Conversation

@resistor
Copy link
Collaborator

@resistor resistor commented Nov 6, 2025

  • [ELF][CHERI] Add addPltEntry infrastructure for cross-compartment calls
  • [NFC][ELF][CHERI] Centralise cap relocs code in addPltEntry
  • [NFC][ELF][CHERI] Add useRelativeCheriRelocs guard in addPltEntry
  • [NFCI][ELF][CHERI] Push addCapabilityRelocation into addRelativeReloc
  • [NFCI][ELF][CHERI] Move non-zero addend check to addCapabilityRelocation
  • [NFC][ELF][CHERI] Stop passing R_CHERI_CAPABILITY to addReloc
  • [NFC][ELF][CHERI] Fix relocation name in comments and add TODO
  • [NFC][ELF][CHERI] Rename R_CHERI_CAPABILITY to R_ABS_CAP
  • [NFCI][ELF][CHERI][Mips] Infer isCallExpr from RelType
  • [ELF][CHERI][Mips] Drop PLT ABI static binary verbose message
  • [NFC][ELF][CHERI][Mips] Extract new needsCheriMipsTrampoline
  • [NFC][ELF][CHERI] Extract new addRelativeCapabilityRelocation
  • [NFC][ELF][CHERI] Use new addRelativeCapabilityRelocation
  • [NFC][ELF][CHERI] Rename useRelativeCheriRelocs to useRelativeElfCheriRelocs
  • [ELF][Mips][RISCV] Support CHERI_CAPABILITY(_CALL) in relocate
  • [NFCI][ELF][CHERI] Teach addSymbolReloc to handle capabilities and use
  • [NFC][ELF][CHERI][Mips] Extract new getCheriMipsTrampolineSym
  • [ELF][CHERI][Mips] Move trampoline handling to addRelativeCapabilityRelocation
  • [NFCI][ELF][CHERI][Mips] Make MipsCheriCapTableSection more like addGotEntry
  • [ELf][CHERI] Handle shard for R_ABS_CAP in addRelativeReloc
  • [ELF][Mips][RISCV] Teach getDynRel about cheriCapRel
  • [ELF][CHERI] Follow R_ABS for R_ABS_CAP in processAux
  • [NFC][ELF][CHERI] Remove now-unused addCapabilityRelocation
  • [NFC][ELF] De-template processAux
  • [NFC][ELF] Drop a gratuitous whitespace diff
  • [NFC][ELF] Don't reimplement addReloc in GotSection
  • [NFC][ELF][CHERI][Mips] Use addReloc via new addConstant for captable
  • [NFC][ELF][CHERI][Mips] More closely follow MIPS GOT for captable
  • [NFC][ELF][CHERI] Fold addNullDerivedCapability into addReloc
  • [NFC][ELF][CHERI] Remove stray prototype
  • [RISCV][CHERI] Support both Xcheri and Zcheri assembly in runtime libs. ([RISCV][CHERI] Support both Xcheri and Zcheri assembly in runtime libs. CTSRD-CHERI/llvm-project#780)
  • Utils: add missing dep for llvm/CodeGen/GenVT.inc
  • [Headers] Declare start/stop/end symbols as arrays in cheri_init_globals.h
  • [Headers] Trap on caprelocs with unknown permissions
  • [llvm-objdump][llvm-readobj] Be strict for decoding caprelocs permissions
  • [Headers] Skip IRELATIVE-style caprelocs in cheri_init_globals.h
  • [llvm-objdump][llvm-readobj] Decode IRELATIVE-style caprelocs permissions
  • [ELF][CHERI] Set non-zero size for IFUNC canonical PLT on CHERI
  • [ELF][CHERI] Support emitting IRELATIVE-style caprelocs
  • [Headers] Add new caprelocs permission for code pointers

jrtc27 added 30 commits November 6, 2025 23:08
These will need to add PLT entries for non-preemptible symbols, but not
for IFUNCs, which was the real thing we can't support. Teach addPltEntry
to be able to create cap relocs for non-preemptible symbols and push the
IFUNC check down into CheriCapRelocsSection where it belongs.
This will allow the entire block to be guarded by !AArch64 for Morello.
We don't currently permit this bool to be true, but Morello LLD does
(and it's implicitly true there for dynamically-linked binaries) and
shouldn't run this block.
Our use of cap relocs here is equivalent to a relative relocation, so
teach addRelativeReloc how to handle capabilities and align more with
upstream in addGotEntry.

Passing R_CHERI_CAPABILITY rather than R_ABS in the preemptible case
shouldn't matter as I don't think it's read, but is now more consistent.
The intent is that R_ABS is an absolute address and R_CHERI_CAPABILITY
is an absolute capability, and for relative ELF relocs (whether using a
CBuildCap-like or a Morello fragment format) we can add static internal
relocations to write out the capability/fragment bits in the same place
as is done for the addend for Elf_Rel relocations, rather than littering
extra relocation additions throughout.
Passing R_CHERI_CAPABILITY to addReloc here is a hack; it should really
be R_ADDEND since expr here is for the addend not the whole relocation,
but we pass R_CHERI_CAPABILITY to mean "R_ADDEND but it's for a
capability" so we can do this check. Instead, push it to the sole caller
that actually passes R_CHERI_CAPABILITY today (the one that is used for
capability relocations in input files, which is the case we need to
overwrite the addend for on MIPS).
This is now entirely equivalent to R_ADDEND, so switch to that,
mirroring how normal dynamic absolute relocations are added.
These are the actual target relocations and not the RelExpr.
We want capabilities to follow R_ABS as closely as possible so rename it
to match what it really is and move it into the generic range.
Keeping this message is going to be annoying for upcoming refactorings
and CHERI MIPS is dead, so sacrifice it.
These call sites were using addCapabilityRelocation with the expectation
that it would only ever create a relative relocation (i.e. a capreloc).
Now that there's a dedicated function for that, call it directly rather
than it looking like it could end up with a relocation against a symbol.
…iRelocs

The point of this is to control whether we are using real ELF
relocations to encode what are logically relative relocations, rather
than caprelocs. Whichever is the case, we still need some form of
relative relocation. Make that clearer, as the current name makes some
of the code look very strange (in particular, the calls to the new
addRelativeCapabilityRelocation).
Currently we use symbolicRel as addendRelType for symbolic capability
relocations, but this is an annoying special case to have. Instead,
allow passing the original type through and treat it as a way to write
the addend (or, in future, a word of the raw capability bits, or in the
case of Morello downstream, the fragment).
…elocation

The special trampoline handling, at the end of the day, is just ensuring
that we don't use caprelocs for function pointers that need a trampoline
at run time, and caprelocs are just how we encode relative relocations.
Moving it here hides that implementation detail. The one downside of
this is that we lose "Using trampoline for function pointer against ..."
messages for symbols that were already preemptible, but that's not very
interesting as nothing was actually being done differently there. As a
result the message is tweaked to reflect what it (now) represents.
…otEntry

Rather than use addCapabilityRelocation, expand out the various
conditions more like is done in addGotEntry.
All current calls leave shard as false, but this will not be true in
future. We don't currently have the ability to shard caprelocs so we
pretend it's sharded by taking relocMutex.
Currently R_ABS_CAP has special handling before the point where this is
called in processAux, but that will soon change.
With the right helpers hooked we need almost no special support any more
in processAux.
This was only templated downstream as it called addCapabilityRelocation,
which used to be a template.
Treating addConstant as an alias for the equivalent function will let us
more easily extend both.
Since isStaticLinkTimeConstant will return true for these we don't need
the early return, we can just let the static relocation be added just
like for GOT indices.

Note also, now that CHERI-RISC-V is using the normal GOT, we don't need
to take relocMutex, as parallel execution is disabled for MIPS (its GOT
implementation also isn't parallel-safe).

Also use addReloc like is now done upstream for the MIPS GOT.
This is now treated as an implementation detail for how a static
R_ABS_CAP is internally implemented. This infrastructure can also be
reused in future for relative relocations.
Left over from a previous version of the commit.

Fixes: 950bd69 ("[NFCI][ELF][CHERI] Teach addSymbolReloc to handle capabilities and use")
qwattash and others added 10 commits November 6, 2025 23:08
…s. (CTSRD-CHERI#780)

This is in preparation for standard CHERI encodings.
Use the unprefixed instruction mnemonics in compiler-rt and libunwind,
to support both xcheri and RVY.
This is error-prone in case new bit patterns are allocated, as will
shortly be done. We can't fix that problem for existing versions, but we
can avoid it going forwards.
…ions

We don't know what future bit patterns will mean, so don't even try, as
that's likely to be misleading.
This requires the run time to opt in though so we don't silently leave
IRELATIVE capabilities uninitialised.
Code pointers are like function pointers, but they should not be wrapped
in trampolines when c18n is enabled. They are mainly used for C++
exceptions landing pads, among other things.

This permissions should be OR'ed with the existing 'function' permission
when used.

Note that, absent a c18n implementation, which will need to have custom
handling of function relocations and so cannot use this implementation,
the two can be treated identically.
@resistor resistor merged commit 5d4bc78 into CHERIoT-Platform:cheriot Nov 6, 2025
12 checks passed
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.

5 participants