Skip to content

Commit e6c0666

Browse files
committed
[CHERIoT] Remove legacy handling of R_RISCV_CHERIOT_COMPARTMENT_LO_I without paired reloc.
This further simplifies control flow around CHERIoT relocation handling, and allows us to collapse the CGPREL_LO_I and CGPREL_LO_S RelExpr's together.
1 parent 5977d37 commit e6c0666

File tree

4 files changed

+7
-25
lines changed

4 files changed

+7
-25
lines changed

lld/ELF/Arch/RISCV.cpp

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -401,11 +401,10 @@ RelExpr RISCV::getRelExpr(const RelType type, const Symbol &s,
401401
case R_RISCV_CHERIOT_COMPARTMENT_HI:
402402
return isPCCRelative(ctx, loc, &s) ? R_PC : RE_CHERIOT_COMPARTMENT_CGPREL_HI;
403403
case R_RISCV_CHERIOT_COMPARTMENT_LO_I:
404-
return RE_CHERIOT_COMPARTMENT_CGPREL_LO_I;
404+
case R_RISCV_CHERIOT_COMPARTMENT_LO_S:
405+
return RE_CHERIOT_COMPARTMENT_CGPREL_LO;
405406
case INTERNAL_R_RISCV_CHERIOT_COMPARTMENT_PCCREL_LO_I:
406407
return RE_RISCV_PC_INDIRECT;
407-
case R_RISCV_CHERIOT_COMPARTMENT_LO_S:
408-
return RE_CHERIOT_COMPARTMENT_CGPREL_LO_S;
409408
case R_RISCV_CHERIOT_COMPARTMENT_SIZE:
410409
return RE_CHERIOT_COMPARTMENT_SIZE;
411410
default:

lld/ELF/InputSection.cpp

Lines changed: 3 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -1046,26 +1046,11 @@ uint64_t InputSectionBase::getRelocTargetVA(Ctx &ctx, const Relocation &r,
10461046
case RE_MIPS_CHERI_CAPTAB_TPREL:
10471047
assert(a == 0 && "capability table index relocs should not have addends");
10481048
return ctx.in.mipsCheriCapTable->getTlsOffset(*r.sym);
1049-
// LO_I is used for both PCC and CGP-relative addresses. For backwards
1050-
// compatibility, the symbol may be a CGP-relative symbol. In newer code, it
1051-
// will always be the symbol containing the accompanying HI relocation.
1052-
case RE_CHERIOT_COMPARTMENT_CGPREL_LO_I: {
1053-
if (isPCCRelative(ctx, nullptr, r.sym)) {
1054-
if (const Relocation *hiRel = getRISCVPCRelHi20(ctx, this, r)) {
1055-
if (isPCCRelative(ctx, nullptr, hiRel->sym))
1056-
fatal("RE_CHERIOT_COMPARTMENT_CGPREL_LO_I relocation used for "
1057-
"PCC-relative access!");
1058-
return getBiasedCGPOffsetLo12(ctx, *hiRel->sym);
1059-
}
1060-
fatal("RE_CHERIOT_COMPARTMENT_CGPREL_LO_I relocation points to " +
1061-
r.sym->getName() +
1062-
" without an associated R_RISCV_PCREL_HI20 relocation");
1063-
}
1064-
return getBiasedCGPOffsetLo12(ctx, *r.sym);
1065-
}
10661049
// Reached only for CGP-relative relocations. PCC-relative addresses are
10671050
// calculated with the R_PC and R_PC_INDIRECT cases.
1068-
case RE_CHERIOT_COMPARTMENT_CGPREL_LO_S:
1051+
case RE_CHERIOT_COMPARTMENT_CGPREL_LO:
1052+
if (isPCCRelative(ctx, nullptr, r.sym))
1053+
fatal("Malformed RE_CHERIOT_COMPARTMENT_CGPREL_LO_I relocation!");
10691054
return getBiasedCGPOffsetLo12(ctx, *r.sym);
10701055
case RE_CHERIOT_COMPARTMENT_CGPREL_HI:
10711056
return (getBiasedCGPOffset(ctx, *r.sym) -

lld/ELF/Relocations.cpp

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1073,8 +1073,7 @@ bool RelocationScanner::isStaticLinkTimeConstant(RelExpr e, RelType type,
10731073
RE_MIPS_CHERI_CAPTAB_INDEX_CALL,
10741074
RE_MIPS_CHERI_CAPTAB_INDEX_CALL_SMALL_IMMEDIATE,
10751075
RE_MIPS_CHERI_CAPTAB_REL, RE_CHERIOT_COMPARTMENT_CGPREL_HI,
1076-
RE_CHERIOT_COMPARTMENT_CGPREL_LO_I, RE_CHERIOT_COMPARTMENT_CGPREL_LO_S,
1077-
RE_CHERIOT_COMPARTMENT_SIZE>(e))
1076+
RE_CHERIOT_COMPARTMENT_CGPREL_LO, RE_CHERIOT_COMPARTMENT_SIZE>(e))
10781077
return true;
10791078

10801079
// Cheri capability relocations are never static link time constants since

lld/ELF/Relocations.h

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -134,8 +134,7 @@ enum RelExpr {
134134
RE_MIPS_CHERI_CAPTAB_TLSLD,
135135
RE_MIPS_CHERI_CAPTAB_TPREL,
136136
RE_CHERIOT_COMPARTMENT_CGPREL_HI,
137-
RE_CHERIOT_COMPARTMENT_CGPREL_LO_S,
138-
RE_CHERIOT_COMPARTMENT_CGPREL_LO_I,
137+
RE_CHERIOT_COMPARTMENT_CGPREL_LO,
139138
RE_CHERIOT_COMPARTMENT_SIZE,
140139
// Same as R_PC but with page-aligned semantics.
141140
RE_LOONGARCH_PAGE_PC,

0 commit comments

Comments
 (0)