Skip to content

Commit 34bd861

Browse files
committed
[CHERI] Rename target-specific RelExpr entries to match upstream naming convention.
1 parent eb99bc0 commit 34bd861

File tree

6 files changed

+66
-64
lines changed

6 files changed

+66
-64
lines changed

lld/ELF/Arch/Cheri.cpp

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -496,8 +496,8 @@ void MipsCheriCapTableSection::addEntry(Symbol &sym, RelExpr expr,
496496
idx.firstUse = SymbolAndOffset(isec, offset);
497497
assert(!idx.firstUse->symOrSec.isNull());
498498
switch (expr) {
499-
case R_MIPS_CHERI_CAPTAB_INDEX_SMALL_IMMEDIATE:
500-
case R_MIPS_CHERI_CAPTAB_INDEX_CALL_SMALL_IMMEDIATE:
499+
case RE_MIPS_CHERI_CAPTAB_INDEX_SMALL_IMMEDIATE:
500+
case RE_MIPS_CHERI_CAPTAB_INDEX_CALL_SMALL_IMMEDIATE:
501501
idx.needsSmallImm = true;
502502
break;
503503
default:
@@ -509,8 +509,8 @@ void MipsCheriCapTableSection::addEntry(Symbol &sym, RelExpr expr,
509509
// not used as a function pointer and therefore does not need a unique
510510
// address (plt stub) across all DSOs.
511511
switch (expr) {
512-
case R_MIPS_CHERI_CAPTAB_INDEX_CALL:
513-
case R_MIPS_CHERI_CAPTAB_INDEX_CALL_SMALL_IMMEDIATE:
512+
case RE_MIPS_CHERI_CAPTAB_INDEX_CALL:
513+
case RE_MIPS_CHERI_CAPTAB_INDEX_CALL_SMALL_IMMEDIATE:
514514
if (!sym.isFunc() && !sym.isUndefWeak()) {
515515
CheriCapRelocLocation loc{isec, offset};
516516
std::string msg = "call relocation against non-function symbol " +

lld/ELF/Arch/Mips.cpp

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -121,7 +121,7 @@ RelExpr MIPS<ELFT>::getRelExpr(RelType type, const Symbol &s,
121121
case R_MICROMIPS_GPREL7_S2:
122122
return RE_MIPS_GOTREL;
123123
case R_MIPS_CHERI_CAPTABLEREL16:
124-
return R_MIPS_CHERI_CAPTAB_REL;
124+
return RE_MIPS_CHERI_CAPTAB_REL;
125125
case R_MIPS_26:
126126
case R_MICROMIPS_26_S1:
127127
return R_PLT;
@@ -210,25 +210,25 @@ RelExpr MIPS<ELFT>::getRelExpr(RelType type, const Symbol &s,
210210
return R_ABS_CAP;
211211
case R_MIPS_CHERI_CAPTAB_LO16:
212212
case R_MIPS_CHERI_CAPTAB_HI16:
213-
return R_MIPS_CHERI_CAPTAB_INDEX;
213+
return RE_MIPS_CHERI_CAPTAB_INDEX;
214214
case R_MIPS_CHERI_CAPCALL_LO16:
215215
case R_MIPS_CHERI_CAPCALL_HI16:
216-
return R_MIPS_CHERI_CAPTAB_INDEX_CALL;
216+
return RE_MIPS_CHERI_CAPTAB_INDEX_CALL;
217217
case R_MIPS_CHERI_CAPTAB_CLC11:
218218
case R_MIPS_CHERI_CAPTAB20:
219-
return R_MIPS_CHERI_CAPTAB_INDEX_SMALL_IMMEDIATE;
219+
return RE_MIPS_CHERI_CAPTAB_INDEX_SMALL_IMMEDIATE;
220220
case R_MIPS_CHERI_CAPCALL_CLC11:
221221
case R_MIPS_CHERI_CAPCALL20:
222-
return R_MIPS_CHERI_CAPTAB_INDEX_CALL_SMALL_IMMEDIATE;
222+
return RE_MIPS_CHERI_CAPTAB_INDEX_CALL_SMALL_IMMEDIATE;
223223
case R_MIPS_CHERI_CAPTAB_TLS_GD_LO16:
224224
case R_MIPS_CHERI_CAPTAB_TLS_GD_HI16:
225-
return R_MIPS_CHERI_CAPTAB_TLSGD;
225+
return RE_MIPS_CHERI_CAPTAB_TLSGD;
226226
case R_MIPS_CHERI_CAPTAB_TLS_LDM_LO16:
227227
case R_MIPS_CHERI_CAPTAB_TLS_LDM_HI16:
228-
return R_MIPS_CHERI_CAPTAB_TLSLD;
228+
return RE_MIPS_CHERI_CAPTAB_TLSLD;
229229
case R_MIPS_CHERI_CAPTAB_TLS_TPREL_LO16:
230230
case R_MIPS_CHERI_CAPTAB_TLS_TPREL_HI16:
231-
return R_MIPS_CHERI_CAPTAB_TPREL;
231+
return RE_MIPS_CHERI_CAPTAB_TPREL;
232232
default:
233233
Err(ctx) << getErrorLoc(ctx, loc) << "unknown relocation (" << type.v
234234
<< ") against symbol " << &s;

lld/ELF/Arch/RISCV.cpp

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -397,13 +397,14 @@ RelExpr RISCV::getRelExpr(const RelType type, const Symbol &s,
397397
case R_RISCV_CHERI_TLS_GD_CAPTAB_PCREL_HI20:
398398
return R_TLSGD_PC;
399399
case R_RISCV_CHERIOT_COMPARTMENT_HI:
400-
return isPCCRelative(ctx, loc, &s) ? R_PC : R_CHERIOT_COMPARTMENT_CGPREL_HI;
400+
return isPCCRelative(ctx, loc, &s) ? R_PC
401+
: RE_CHERIOT_COMPARTMENT_CGPREL_HI;
401402
case R_RISCV_CHERIOT_COMPARTMENT_LO_I:
402-
return R_CHERIOT_COMPARTMENT_CGPREL_LO_I;
403+
return RE_CHERIOT_COMPARTMENT_CGPREL_LO_I;
403404
case R_RISCV_CHERIOT_COMPARTMENT_LO_S:
404-
return R_CHERIOT_COMPARTMENT_CGPREL_LO_S;
405+
return RE_CHERIOT_COMPARTMENT_CGPREL_LO_S;
405406
case R_RISCV_CHERIOT_COMPARTMENT_SIZE:
406-
return R_CHERIOT_COMPARTMENT_SIZE;
407+
return RE_CHERIOT_COMPARTMENT_SIZE;
407408
default:
408409
Err(ctx) << getErrorLoc(ctx, loc) << "unknown relocation (" << type.v
409410
<< ") against symbol " << &s;

lld/ELF/InputSection.cpp

Lines changed: 13 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1020,53 +1020,53 @@ uint64_t InputSectionBase::getRelocTargetVA(Ctx &ctx, const Relocation &r,
10201020
assert(r.sym->isUndefined() &&
10211021
"cannot encode non-null derived capability yet");
10221022
return 0;
1023-
case R_MIPS_CHERI_CAPTAB_INDEX:
1024-
case R_MIPS_CHERI_CAPTAB_INDEX_SMALL_IMMEDIATE:
1025-
case R_MIPS_CHERI_CAPTAB_INDEX_CALL:
1026-
case R_MIPS_CHERI_CAPTAB_INDEX_CALL_SMALL_IMMEDIATE:
1023+
case RE_MIPS_CHERI_CAPTAB_INDEX:
1024+
case RE_MIPS_CHERI_CAPTAB_INDEX_SMALL_IMMEDIATE:
1025+
case RE_MIPS_CHERI_CAPTAB_INDEX_CALL:
1026+
case RE_MIPS_CHERI_CAPTAB_INDEX_CALL_SMALL_IMMEDIATE:
10271027
assert(a == 0 && "capability table index relocs should not have addends");
10281028
return r.sym->getMipsCheriCapTableOffset(ctx, this, r.offset);
1029-
case R_MIPS_CHERI_CAPTAB_REL:
1029+
case RE_MIPS_CHERI_CAPTAB_REL:
10301030
if (!ctx.sym.mipsCheriCapabilityTable) {
10311031
error("cannot compute difference between non-existent "
10321032
"CheriCapabilityTable and symbol " + toStr(ctx, *r.sym));
10331033
return r.sym->getVA(ctx, a);
10341034
}
10351035
return r.sym->getVA(ctx, a) - ctx.sym.mipsCheriCapabilityTable->getVA(ctx);
1036-
case R_MIPS_CHERI_CAPTAB_TLSGD:
1036+
case RE_MIPS_CHERI_CAPTAB_TLSGD:
10371037
assert(a == 0 && "capability table index relocs should not have addends");
10381038
return ctx.in.mipsCheriCapTable->getDynTlsOffset(*r.sym);
1039-
case R_MIPS_CHERI_CAPTAB_TLSLD:
1039+
case RE_MIPS_CHERI_CAPTAB_TLSLD:
10401040
assert(a == 0 && "capability table index relocs should not have addends");
10411041
return ctx.in.mipsCheriCapTable->getTlsIndexOffset();
1042-
case R_MIPS_CHERI_CAPTAB_TPREL:
1042+
case RE_MIPS_CHERI_CAPTAB_TPREL:
10431043
assert(a == 0 && "capability table index relocs should not have addends");
10441044
return ctx.in.mipsCheriCapTable->getTlsOffset(*r.sym);
10451045
// LO_I is used for both PCC and CGP-relative addresses. For backwards
10461046
// compatibility, the symbol may be a CGP-relative symbol. In newer code, it
10471047
// will always be the symbol containing the accompanying HI relocation.
1048-
case R_CHERIOT_COMPARTMENT_CGPREL_LO_I: {
1048+
case RE_CHERIOT_COMPARTMENT_CGPREL_LO_I: {
10491049
if (isPCCRelative(ctx, nullptr, r.sym)) {
10501050
if (const Relocation *hiRel = getRISCVPCRelHi20(ctx, this, r)) {
10511051
if (isPCCRelative(ctx, nullptr, hiRel->sym))
10521052
return getRelocTargetVA(ctx, *hiRel, r.sym->getVA(ctx));
10531053
return getBiasedCGPOffsetLo12(ctx, *hiRel->sym);
10541054
}
1055-
fatal("R_CHERIOT_COMPARTMENT_CGPREL_LO_I relocation points to " +
1055+
fatal("RE_CHERIOT_COMPARTMENT_CGPREL_LO_I relocation points to " +
10561056
r.sym->getName() +
10571057
" without an associated R_RISCV_PCREL_HI20 relocation");
10581058
}
10591059
return getBiasedCGPOffsetLo12(ctx, *r.sym);
10601060
}
10611061
// Reached only for CGP-relative relocations. PCC-relative addresses are
10621062
// calculated with the R_PC and R_PC_INDIRECT cases.
1063-
case R_CHERIOT_COMPARTMENT_CGPREL_LO_S:
1063+
case RE_CHERIOT_COMPARTMENT_CGPREL_LO_S:
10641064
return getBiasedCGPOffsetLo12(ctx, *r.sym);
1065-
case R_CHERIOT_COMPARTMENT_CGPREL_HI:
1065+
case RE_CHERIOT_COMPARTMENT_CGPREL_HI:
10661066
return (getBiasedCGPOffset(ctx, *r.sym) -
10671067
getBiasedCGPOffsetLo12(ctx, *r.sym)) >>
10681068
11;
1069-
case R_CHERIOT_COMPARTMENT_SIZE:
1069+
case RE_CHERIOT_COMPARTMENT_SIZE:
10701070
return r.sym->getSize(ctx);
10711071
default:
10721072
llvm_unreachable("invalid expression");

lld/ELF/Relocations.cpp

Lines changed: 24 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -215,10 +215,10 @@ bool lld::elf::needsGot(RelExpr expr) {
215215
// returns false for TLS variables even though then need a captable entry,
216216
// because TLS variables use the captable differently than regular variables.
217217
static bool needsMipsCheriCapTable(RelExpr expr) {
218-
return oneof<R_MIPS_CHERI_CAPTAB_INDEX,
219-
R_MIPS_CHERI_CAPTAB_INDEX_SMALL_IMMEDIATE,
220-
R_MIPS_CHERI_CAPTAB_INDEX_CALL,
221-
R_MIPS_CHERI_CAPTAB_INDEX_CALL_SMALL_IMMEDIATE>(expr);
218+
return oneof<RE_MIPS_CHERI_CAPTAB_INDEX,
219+
RE_MIPS_CHERI_CAPTAB_INDEX_SMALL_IMMEDIATE,
220+
RE_MIPS_CHERI_CAPTAB_INDEX_CALL,
221+
RE_MIPS_CHERI_CAPTAB_INDEX_CALL_SMALL_IMMEDIATE>(expr);
222222
}
223223

224224
// True if this expression is of the form Sym - X, where X is a position in the
@@ -227,7 +227,7 @@ static bool isRelExpr(RelExpr expr) {
227227
return oneof<R_PC, R_GOTREL, R_GOTPLTREL, RE_ARM_PCA, RE_MIPS_GOTREL,
228228
RE_PPC64_CALL, RE_PPC64_RELAX_TOC, RE_AARCH64_PAGE_PC,
229229
R_RELAX_GOT_PC, RE_RISCV_PC_INDIRECT, RE_PPC64_RELAX_GOT_PC,
230-
RE_LOONGARCH_PAGE_PC, R_MIPS_CHERI_CAPTAB_REL>(expr);
230+
RE_LOONGARCH_PAGE_PC, RE_MIPS_CHERI_CAPTAB_REL>(expr);
231231
}
232232

233233
static RelExpr toPlt(RelExpr expr) {
@@ -1060,21 +1060,22 @@ bool RelocationScanner::isStaticLinkTimeConstant(RelExpr e, RelType type,
10601060
const Symbol &sym,
10611061
uint64_t relOff) const {
10621062
// These expressions always compute a constant
1063-
if (oneof<
1064-
R_GOTPLT, R_GOT_OFF, R_RELAX_HINT, RE_MIPS_GOT_LOCAL_PAGE,
1065-
RE_MIPS_GOTREL, RE_MIPS_GOT_OFF, RE_MIPS_GOT_OFF32, RE_MIPS_GOT_GP_PC,
1066-
RE_AARCH64_GOT_PAGE_PC, RE_AARCH64_AUTH_GOT_PAGE_PC, R_GOT_PC,
1067-
R_GOTONLY_PC, R_GOTPLTONLY_PC, R_PLT_PC, R_PLT_GOTREL, R_PLT_GOTPLT,
1068-
R_GOTPLT_GOTREL, R_GOTPLT_PC, RE_PPC32_PLTREL, RE_PPC64_CALL_PLT,
1069-
RE_PPC64_RELAX_TOC, RE_RISCV_ADD, RE_AARCH64_GOT_PAGE,
1070-
RE_AARCH64_AUTH_GOT, RE_AARCH64_AUTH_GOT_PC, RE_LOONGARCH_PLT_PAGE_PC,
1071-
RE_LOONGARCH_GOT, RE_LOONGARCH_GOT_PAGE_PC, R_MIPS_CHERI_CAPTAB_INDEX,
1072-
R_MIPS_CHERI_CAPTAB_INDEX_SMALL_IMMEDIATE,
1073-
R_MIPS_CHERI_CAPTAB_INDEX_CALL,
1074-
R_MIPS_CHERI_CAPTAB_INDEX_CALL_SMALL_IMMEDIATE,
1075-
R_MIPS_CHERI_CAPTAB_REL, R_CHERIOT_COMPARTMENT_CGPREL_HI,
1076-
R_CHERIOT_COMPARTMENT_CGPREL_LO_I, R_CHERIOT_COMPARTMENT_CGPREL_LO_S,
1077-
R_CHERIOT_COMPARTMENT_SIZE>(e))
1063+
if (oneof<R_GOTPLT, R_GOT_OFF, R_RELAX_HINT, RE_MIPS_GOT_LOCAL_PAGE,
1064+
RE_MIPS_GOTREL, RE_MIPS_GOT_OFF, RE_MIPS_GOT_OFF32,
1065+
RE_MIPS_GOT_GP_PC, RE_AARCH64_GOT_PAGE_PC,
1066+
RE_AARCH64_AUTH_GOT_PAGE_PC, R_GOT_PC, R_GOTONLY_PC,
1067+
R_GOTPLTONLY_PC, R_PLT_PC, R_PLT_GOTREL, R_PLT_GOTPLT,
1068+
R_GOTPLT_GOTREL, R_GOTPLT_PC, RE_PPC32_PLTREL, RE_PPC64_CALL_PLT,
1069+
RE_PPC64_RELAX_TOC, RE_RISCV_ADD, RE_AARCH64_GOT_PAGE,
1070+
RE_AARCH64_AUTH_GOT, RE_AARCH64_AUTH_GOT_PC,
1071+
RE_LOONGARCH_PLT_PAGE_PC, RE_LOONGARCH_GOT,
1072+
RE_LOONGARCH_GOT_PAGE_PC, RE_MIPS_CHERI_CAPTAB_INDEX,
1073+
RE_MIPS_CHERI_CAPTAB_INDEX_SMALL_IMMEDIATE,
1074+
RE_MIPS_CHERI_CAPTAB_INDEX_CALL,
1075+
RE_MIPS_CHERI_CAPTAB_INDEX_CALL_SMALL_IMMEDIATE,
1076+
RE_MIPS_CHERI_CAPTAB_REL, RE_CHERIOT_COMPARTMENT_CGPREL_HI,
1077+
RE_CHERIOT_COMPARTMENT_CGPREL_LO_I,
1078+
RE_CHERIOT_COMPARTMENT_CGPREL_LO_S, RE_CHERIOT_COMPARTMENT_SIZE>(e))
10781079
return true;
10791080

10801081
// Cheri capability relocations are never static link time constants since
@@ -1418,17 +1419,17 @@ static unsigned handleMipsTlsRelocation(Ctx &ctx, RelType type, Symbol &sym,
14181419
c.addReloc(ctx, {expr, type, offset, addend, &sym});
14191420
return 1;
14201421
}
1421-
if (expr == R_MIPS_CHERI_CAPTAB_TLSLD) {
1422+
if (expr == RE_MIPS_CHERI_CAPTAB_TLSLD) {
14221423
ctx.in.mipsCheriCapTable->addTlsIndex();
14231424
c.addReloc(ctx, {expr, type, offset, addend, &sym});
14241425
return 1;
14251426
}
1426-
if (expr == R_MIPS_CHERI_CAPTAB_TLSGD) {
1427+
if (expr == RE_MIPS_CHERI_CAPTAB_TLSGD) {
14271428
ctx.in.mipsCheriCapTable->addDynTlsEntry(sym);
14281429
c.addReloc(ctx, {expr, type, offset, addend, &sym});
14291430
return 1;
14301431
}
1431-
if (expr == R_MIPS_CHERI_CAPTAB_TPREL) {
1432+
if (expr == RE_MIPS_CHERI_CAPTAB_TPREL) {
14321433
ctx.in.mipsCheriCapTable->addTlsEntry(sym);
14331434
c.addReloc(ctx, {expr, type, offset, addend, &sym});
14341435
return 1;

lld/ELF/Relocations.h

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -125,18 +125,18 @@ enum RelExpr {
125125
RE_RISCV_ADD,
126126
RE_RISCV_LEB128,
127127
RE_RISCV_PC_INDIRECT,
128-
R_MIPS_CHERI_CAPTAB_INDEX,
129-
R_MIPS_CHERI_CAPTAB_INDEX_SMALL_IMMEDIATE,
130-
R_MIPS_CHERI_CAPTAB_INDEX_CALL,
131-
R_MIPS_CHERI_CAPTAB_INDEX_CALL_SMALL_IMMEDIATE,
132-
R_MIPS_CHERI_CAPTAB_REL, // relative offset to _CHERI_CAPABILITY_TABLE_
133-
R_MIPS_CHERI_CAPTAB_TLSGD,
134-
R_MIPS_CHERI_CAPTAB_TLSLD,
135-
R_MIPS_CHERI_CAPTAB_TPREL,
136-
R_CHERIOT_COMPARTMENT_CGPREL_HI,
137-
R_CHERIOT_COMPARTMENT_CGPREL_LO_S,
138-
R_CHERIOT_COMPARTMENT_CGPREL_LO_I,
139-
R_CHERIOT_COMPARTMENT_SIZE,
128+
RE_MIPS_CHERI_CAPTAB_INDEX,
129+
RE_MIPS_CHERI_CAPTAB_INDEX_SMALL_IMMEDIATE,
130+
RE_MIPS_CHERI_CAPTAB_INDEX_CALL,
131+
RE_MIPS_CHERI_CAPTAB_INDEX_CALL_SMALL_IMMEDIATE,
132+
RE_MIPS_CHERI_CAPTAB_REL, // relative offset to _CHERI_CAPABILITY_TABLE_
133+
RE_MIPS_CHERI_CAPTAB_TLSGD,
134+
RE_MIPS_CHERI_CAPTAB_TLSLD,
135+
RE_MIPS_CHERI_CAPTAB_TPREL,
136+
RE_CHERIOT_COMPARTMENT_CGPREL_HI,
137+
RE_CHERIOT_COMPARTMENT_CGPREL_LO_S,
138+
RE_CHERIOT_COMPARTMENT_CGPREL_LO_I,
139+
RE_CHERIOT_COMPARTMENT_SIZE,
140140
// Same as R_PC but with page-aligned semantics.
141141
RE_LOONGARCH_PAGE_PC,
142142
// Same as R_PLT_PC but with page-aligned semantics.

0 commit comments

Comments
 (0)