Skip to content

Commit 521123a

Browse files
committed
[CHERIoT] Update comments regarding the CHERIoT relocation pre-pass.
1 parent 95e7d56 commit 521123a

File tree

1 file changed

+23
-16
lines changed

1 file changed

+23
-16
lines changed

lld/ELF/Arch/RISCV.cpp

Lines changed: 23 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1056,23 +1056,28 @@ static void relaxCGP(Ctx &ctx, const InputSection &sec, size_t i, uint64_t loc,
10561056
}
10571057

10581058
/**
1059-
* Find all R_RISCV_CHERIOT_COMPARTMENT_LO_I relocations that are CGP-relative
1060-
* and rewrite them to be relative to the target of the current relocation.
1061-
* These relocations mirror the HI20/LO12 PC-relative relocations and are
1062-
* written as pairs where the first has the real relocation target as its
1063-
* symbol and the second has the location of the first as its target. This is
1064-
* necessary for PC-relative relocations because the final address depends on
1065-
* the location of the first instruction. For CHERIoT, both PCC and
1066-
* CGP-relative relocations use the same relocation types and we don't know
1067-
* whether it is relative to PCC or CGP until we know the target. That would
1068-
* be fine, except that relaxation can delete the AUICGP, which means that we
1069-
* then can't find the target. We void this by doing a pass to find these
1070-
* relocation targets and attaching them to the
1071-
* R_RISCV_CHERIOT_COMPARTMENT_LO_I relocations for the cases where the target
1072-
* is CGP-relative.
1059+
* Perform a substantial pre-pass of Cheriot relocations ahead of relaxation
1060+
* and relocation. This pre-pass has two goals:
1061+
* - Separate PCC-relative and CGP-relative relocations. This reduces
1062+
* complexity in relaxation and relocation by making the decision once upfront.
1063+
* - Resolve the target address for the second in a pair of relocations. This
1064+
* is required because relaxation may eliminate the first in a pair of
1065+
* relocations, which would leave the second one unable to be relocated.
10731066
*
1074-
* Note: If we ever get direct PC[C]-relative loads in RISC-V then other
1075-
* relocations will want to reuse this path.
1067+
* The specific post-conditions are:
1068+
* - All PCC-relative CHERIOT_COMPARTMENT_HI relocations are represented as
1069+
* INTERNAL_R_RISCV_CHERIOT_COMPARTMENT_PCCREL_HI.
1070+
* - All CGP-relative CHERIOT_COMPARTMENT_HI relocations are represented as
1071+
* R_RISCV_CHERIOT_COMPARTMENT_HI.
1072+
* - All PCC-relative CHERIOT_COMPARTMENT_LO_I relocations are represented as
1073+
* INTERNAL_R_RISCV_CHERIOT_COMPARTMENT_PCCREL_LO_I.
1074+
* - All CGP-relative CHERIOT_COMPARTMENT_LO_I relocations are represented as
1075+
* R_RISCV_CHERIOT_COMPARTMENT_LO_I.
1076+
* - The targets of all CHERIOT_COMPARTMENT_LO_I relocations are resolved to
1077+
* the target of their paired CHERIOT_COMPARTMENT_HI relocation.
1078+
* - PCC-relative CHERIOT_COMPARTMENT_LO_S relocations do not exist.
1079+
* - All CGP-relative CHERIOT_COMPARTMENT_LO_S relocations are represented as
1080+
* R_RISCV_CHERIOT_COMPARTMENT_LO_S.
10761081
*/
10771082
static bool rewriteCheriotLowRelocs(Ctx &ctx, InputSection &sec) {
10781083
bool modified = false;
@@ -1144,6 +1149,8 @@ static bool relax(Ctx &ctx, int pass, InputSection &sec) {
11441149
bool tlsdescRelax = false, toLeShortForm = false;
11451150

11461151
// On the first pass, do a scan of LO_I CHERIoT relocations
1152+
// FIXME: One the relocation scan loop is under target control, this should be
1153+
// applied outside of relaxation.
11471154
if (pass == 0)
11481155
changed |= rewriteCheriotLowRelocs(ctx, sec);
11491156

0 commit comments

Comments
 (0)