Skip to content

Commit f9ec9dc

Browse files
jrtc27resistor
authored andcommitted
[ELF][NFC] Drop unwarranted XXX comments
RELRO sections are SHF_WRITE, so there's nothing wrong with the code here. This is how it's meant to work, and how things like GotSection are constructed.
1 parent 30a07f1 commit f9ec9dc

File tree

12 files changed

+174
-163
lines changed

12 files changed

+174
-163
lines changed

lld/ELF/Arch/Cheri.cpp

Lines changed: 64 additions & 64 deletions
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,7 @@ struct InMemoryCapRelocEntry {
5757
CheriCapRelocsSection::CheriCapRelocsSection(Ctx &ctx, StringRef name)
5858
: SyntheticSection(ctx, name, SHT_PROGBITS,
5959
(ctx.arg.isPic && !ctx.arg.relativeCapRelocsOnly)
60-
? SHF_ALLOC | SHF_WRITE /* XXX: actually RELRO */
60+
? SHF_ALLOC | SHF_WRITE
6161
: SHF_ALLOC,
6262
ctx.arg.wordsize) {
6363
this->entsize = ctx.arg.wordsize * 5;
@@ -603,16 +603,14 @@ void CheriCapRelocsSection::writeTo(uint8_t *buf) {
603603
invokeELFT(writeToImpl, buf);
604604
}
605605

606-
CheriCapTableSection::CheriCapTableSection(Ctx &ctx)
607-
: SyntheticSection(
608-
ctx, ".captable", SHT_PROGBITS,
609-
SHF_ALLOC | SHF_WRITE, /* XXX: actually RELRO for BIND_NOW*/
610-
ctx.arg.capabilitySize) {
606+
MipsCheriCapTableSection::MipsCheriCapTableSection(Ctx &ctx)
607+
: SyntheticSection(ctx, ".captable", SHT_PROGBITS, SHF_ALLOC | SHF_WRITE,
608+
ctx.arg.capabilitySize) {
611609
assert(ctx.arg.capabilitySize > 0);
612610
this->entsize = ctx.arg.capabilitySize;
613611
}
614612

615-
void CheriCapTableSection::writeTo(uint8_t *buf) {
613+
void MipsCheriCapTableSection::writeTo(uint8_t *buf) {
616614
// Capability part should be filled with all zeros and crt_init_globals fills
617615
// it in. For the TLS part, assignValuesAndAddCapTableSymbols adds any static
618616
// relocations needed, and should be procesed by relocateAlloc.
@@ -625,8 +623,8 @@ static Defined *findMatchingFunction(const InputSectionBase *isec,
625623
return isec->getEnclosingFunction(symOffset);
626624
}
627625

628-
CheriCapTableSection::CaptableMap &
629-
CheriCapTableSection::getCaptableMapForFileAndOffset(
626+
MipsCheriCapTableSection::CaptableMap &
627+
MipsCheriCapTableSection::getCaptableMapForFileAndOffset(
630628
const InputSectionBase *isec, uint64_t offset) {
631629
if (LLVM_LIKELY(ctx.arg.capTableScope == CapTableScopePolicy::All))
632630
return globalEntries;
@@ -648,47 +646,48 @@ CheriCapTableSection::getCaptableMapForFileAndOffset(
648646
return globalEntries;
649647
}
650648

651-
void CheriCapTableSection::addEntry(Symbol &sym, RelExpr expr,
652-
InputSectionBase *isec, uint64_t offset) {
649+
void MipsCheriCapTableSection::addEntry(Symbol &sym, RelExpr expr,
650+
InputSectionBase *isec,
651+
uint64_t offset) {
653652
// FIXME: can this be called from multiple threads?
654653
CapTableIndex idx;
655654
idx.needsSmallImm = false;
656655
idx.usedInCallExpr = false;
657656
idx.firstUse = SymbolAndOffset(isec, offset);
658657
assert(!idx.firstUse->symOrSec.isNull());
659658
switch (expr) {
660-
case R_CHERI_CAPABILITY_TABLE_INDEX_SMALL_IMMEDIATE:
661-
case R_CHERI_CAPABILITY_TABLE_INDEX_CALL_SMALL_IMMEDIATE:
662-
idx.needsSmallImm = true;
663-
break;
664-
default:
665-
break;
659+
case R_MIPS_CHERI_CAPTAB_INDEX_SMALL_IMMEDIATE:
660+
case R_MIPS_CHERI_CAPTAB_INDEX_CALL_SMALL_IMMEDIATE:
661+
idx.needsSmallImm = true;
662+
break;
663+
default:
664+
break;
666665
}
667666
// If the symbol is only ever referenced by the captable call relocations we
668667
// can emit a capability call relocation instead of a normal capability
669668
// relocation. This indicates to the runtime linker that the capability is
670669
// not used as a function pointer and therefore does not need a unique
671670
// address (plt stub) across all DSOs.
672671
switch (expr) {
673-
case R_CHERI_CAPABILITY_TABLE_INDEX_CALL:
674-
case R_CHERI_CAPABILITY_TABLE_INDEX_CALL_SMALL_IMMEDIATE:
675-
if (!sym.isFunc() && !sym.isUndefWeak()) {
676-
CheriCapRelocLocation loc{isec, offset};
677-
std::string msg = "call relocation against non-function symbol " +
678-
verboseToString(ctx, &sym, 0) + "\n>>> referenced by " +
679-
loc.toString(ctx);
680-
if (sym.isUndefined() &&
681-
ctx.arg.unresolvedSymbolsInShlib == UnresolvedPolicy::Ignore) {
682-
// Don't fail the build for shared libraries unless
683-
nonFatalWarning(msg);
684-
} else {
685-
warn(msg);
686-
}
672+
case R_MIPS_CHERI_CAPTAB_INDEX_CALL:
673+
case R_MIPS_CHERI_CAPTAB_INDEX_CALL_SMALL_IMMEDIATE:
674+
if (!sym.isFunc() && !sym.isUndefWeak()) {
675+
CheriCapRelocLocation loc{isec, offset};
676+
std::string msg = "call relocation against non-function symbol " +
677+
verboseToString(ctx, &sym, 0) + "\n>>> referenced by " +
678+
loc.toString(ctx);
679+
if (sym.isUndefined() &&
680+
ctx.arg.unresolvedSymbolsInShlib == UnresolvedPolicy::Ignore) {
681+
// Don't fail the build for shared libraries unless
682+
nonFatalWarning(msg);
683+
} else {
684+
warn(msg);
687685
}
688-
idx.usedInCallExpr = true;
689-
break;
690-
default:
691-
break;
686+
}
687+
idx.usedInCallExpr = true;
688+
break;
689+
default:
690+
break;
692691
}
693692
CaptableMap &entries = getCaptableMapForFileAndOffset(isec, offset);
694693
if (ctx.arg.zCapTableDebug) {
@@ -711,25 +710,25 @@ void CheriCapTableSection::addEntry(Symbol &sym, RelExpr expr,
711710
}
712711
}
713712

714-
void CheriCapTableSection::addDynTlsEntry(Symbol &sym) {
713+
void MipsCheriCapTableSection::addDynTlsEntry(Symbol &sym) {
715714
dynTlsEntries.map.insert(std::make_pair(&sym, CapTableIndex()));
716715
}
717716

718-
void CheriCapTableSection::addTlsIndex() {
717+
void MipsCheriCapTableSection::addTlsIndex() {
719718
dynTlsEntries.map.insert(std::make_pair(nullptr, CapTableIndex()));
720719
}
721720

722-
void CheriCapTableSection::addTlsEntry(Symbol &sym) {
721+
void MipsCheriCapTableSection::addTlsEntry(Symbol &sym) {
723722
tlsEntries.map.insert(std::make_pair(&sym, CapTableIndex()));
724723
}
725724

726-
uint32_t CheriCapTableSection::getIndex(const Symbol &sym,
727-
const InputSectionBase *isec,
728-
uint64_t offset) const {
725+
uint32_t MipsCheriCapTableSection::getIndex(const Symbol &sym,
726+
const InputSectionBase *isec,
727+
uint64_t offset) const {
729728
assert(valuesAssigned && "getIndex called before index assignment");
730729
const CaptableMap &entries =
731-
const_cast<CheriCapTableSection *>(this)->getCaptableMapForFileAndOffset(
732-
isec, offset);
730+
const_cast<MipsCheriCapTableSection *>(this)
731+
->getCaptableMapForFileAndOffset(isec, offset);
733732
auto it = entries.map.find(const_cast<Symbol *>(&sym));
734733
assert(entries.firstIndex != std::numeric_limits<uint64_t>::max() &&
735734
"First index not set yet?");
@@ -741,31 +740,31 @@ uint32_t CheriCapTableSection::getIndex(const Symbol &sym,
741740
return *it->second.index - entries.firstIndex;
742741
}
743742

744-
uint32_t CheriCapTableSection::getDynTlsOffset(const Symbol &sym) const {
743+
uint32_t MipsCheriCapTableSection::getDynTlsOffset(const Symbol &sym) const {
745744
assert(valuesAssigned && "getDynTlsOffset called before index assignment");
746745
auto it = dynTlsEntries.map.find(const_cast<Symbol *>(&sym));
747746
assert(it != dynTlsEntries.map.end());
748747
return *it->second.index * ctx.arg.wordsize;
749748
}
750749

751-
uint32_t CheriCapTableSection::getTlsIndexOffset() const {
750+
uint32_t MipsCheriCapTableSection::getTlsIndexOffset() const {
752751
assert(valuesAssigned && "getTlsIndexOffset called before index assignment");
753752
auto it = dynTlsEntries.map.find(nullptr);
754753
assert(it != dynTlsEntries.map.end());
755754
return *it->second.index * ctx.arg.wordsize;
756755
}
757756

758-
uint32_t CheriCapTableSection::getTlsOffset(const Symbol &sym) const {
757+
uint32_t MipsCheriCapTableSection::getTlsOffset(const Symbol &sym) const {
759758
assert(valuesAssigned && "getTlsOffset called before index assignment");
760759
auto it = tlsEntries.map.find(const_cast<Symbol *>(&sym));
761760
assert(it != tlsEntries.map.end());
762761
return *it->second.index * ctx.arg.wordsize;
763762
}
764763

765764
template <class ELFT>
766-
uint64_t CheriCapTableSection::assignIndices(uint64_t startIndex,
767-
CaptableMap &entries,
768-
const Twine &symContext) {
765+
uint64_t MipsCheriCapTableSection::assignIndices(uint64_t startIndex,
766+
CaptableMap &entries,
767+
const Twine &symContext) {
769768
// Usually StartIndex will be zero (one global captable) but if we are
770769
// compiling with per-file/per-function
771770
uint64_t smallEntryCount = 0;
@@ -875,7 +874,7 @@ uint64_t CheriCapTableSection::assignIndices(uint64_t startIndex,
875874
? ctx.in.relaPlt.get()
876875
: ctx.mainPart->relaDyn.get();
877876
addCapabilityRelocation<ELFT>(
878-
ctx, targetSym, elfCapabilityReloc, ctx.in.cheriCapTable.get(), off,
877+
ctx, targetSym, elfCapabilityReloc, ctx.in.mipsCheriCapTable.get(), off,
879878
R_CHERI_CAPABILITY, 0, it.second.usedInCallExpr,
880879
[&]() {
881880
return ("\n>>> referenced by " + refName + "\n>>> first used in " +
@@ -889,7 +888,7 @@ uint64_t CheriCapTableSection::assignIndices(uint64_t startIndex,
889888
}
890889

891890
template <class ELFT>
892-
void CheriCapTableSection::assignValuesAndAddCapTableSymbols() {
891+
void MipsCheriCapTableSection::assignValuesAndAddCapTableSymbols() {
893892
// First assign the global indices (which will usually be the only ones)
894893
uint64_t assignedEntries = assignIndices<ELFT>(0, globalEntries, "");
895894
if (LLVM_UNLIKELY(ctx.arg.capTableScope != CapTableScopePolicy::All)) {
@@ -980,22 +979,22 @@ void CheriCapTableSection::assignValuesAndAddCapTableSymbols() {
980979
}
981980

982981
template void
983-
CheriCapTableSection::assignValuesAndAddCapTableSymbols<ELF32LE>();
982+
MipsCheriCapTableSection::assignValuesAndAddCapTableSymbols<ELF32LE>();
984983
template void
985-
CheriCapTableSection::assignValuesAndAddCapTableSymbols<ELF32BE>();
984+
MipsCheriCapTableSection::assignValuesAndAddCapTableSymbols<ELF32BE>();
986985
template void
987-
CheriCapTableSection::assignValuesAndAddCapTableSymbols<ELF64LE>();
986+
MipsCheriCapTableSection::assignValuesAndAddCapTableSymbols<ELF64LE>();
988987
template void
989-
CheriCapTableSection::assignValuesAndAddCapTableSymbols<ELF64BE>();
988+
MipsCheriCapTableSection::assignValuesAndAddCapTableSymbols<ELF64BE>();
990989

991-
CheriCapTableMappingSection::CheriCapTableMappingSection(Ctx &ctx)
990+
MipsCheriCapTableMappingSection::MipsCheriCapTableMappingSection(Ctx &ctx)
992991
: SyntheticSection(ctx, ".captable_mapping", SHT_PROGBITS, SHF_ALLOC, 8) {
993992
assert(ctx.arg.capabilitySize > 0);
994993
this->entsize = sizeof(CaptableMappingEntry);
995994
static_assert(sizeof(CaptableMappingEntry) == 24, "");
996995
}
997996

998-
size_t CheriCapTableMappingSection::getSize() const {
997+
size_t MipsCheriCapTableMappingSection::getSize() const {
999998
assert(ctx.arg.capTableScope != CapTableScopePolicy::All);
1000999
if (!isNeeded()) return 0;
10011000
size_t count = 0;
@@ -1010,9 +1009,10 @@ size_t CheriCapTableMappingSection::getSize() const {
10101009
return count * sizeof(CaptableMappingEntry);
10111010
}
10121011

1013-
void CheriCapTableMappingSection::writeTo(uint8_t *buf) {
1012+
void MipsCheriCapTableMappingSection::writeTo(uint8_t *buf) {
10141013
assert(ctx.arg.capTableScope != CapTableScopePolicy::All);
1015-
if (!ctx.in.cheriCapTable) return;
1014+
if (!ctx.in.mipsCheriCapTable)
1015+
return;
10161016
if (!ctx.in.symTab) {
10171017
error("Cannot write " + this->name + " without .symtab section!");
10181018
return;
@@ -1025,14 +1025,14 @@ void CheriCapTableMappingSection::writeTo(uint8_t *buf) {
10251025
for (const SymbolTableEntry &ste : ctx.in.symTab->getSymbols()) {
10261026
Symbol *sym = ste.sym;
10271027
if (!sym->isDefined() || !sym->isFunc()) continue;
1028-
const CheriCapTableSection::CaptableMap *capTableMap = nullptr;
1028+
const MipsCheriCapTableSection::CaptableMap *capTableMap = nullptr;
10291029
if (ctx.arg.capTableScope == CapTableScopePolicy::Function) {
1030-
auto it = ctx.in.cheriCapTable->perFunctionEntries.find(sym);
1031-
if (it != ctx.in.cheriCapTable->perFunctionEntries.end())
1030+
auto it = ctx.in.mipsCheriCapTable->perFunctionEntries.find(sym);
1031+
if (it != ctx.in.mipsCheriCapTable->perFunctionEntries.end())
10321032
capTableMap = &it->second;
10331033
} else if (ctx.arg.capTableScope == CapTableScopePolicy::File) {
1034-
auto it = ctx.in.cheriCapTable->perFileEntries.find(sym->file);
1035-
if (it != ctx.in.cheriCapTable->perFileEntries.end())
1034+
auto it = ctx.in.mipsCheriCapTable->perFileEntries.find(sym->file);
1035+
if (it != ctx.in.mipsCheriCapTable->perFileEntries.end())
10361036
capTableMap = &it->second;
10371037
} else {
10381038
llvm_unreachable("Invalid mode!");

lld/ELF/Arch/Cheri.h

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -186,9 +186,9 @@ class CheriCapRelocsSection : public SyntheticSection {
186186
// +---------------------------------------+
187187
// TODO: TLS caps also need to be per file/function
188188

189-
class CheriCapTableSection : public SyntheticSection {
189+
class MipsCheriCapTableSection : public SyntheticSection {
190190
public:
191-
CheriCapTableSection(Ctx &ctx);
191+
MipsCheriCapTableSection(Ctx &ctx);
192192
// InputFile and Offset is needed in order to implement per-file/per-function
193193
// tables
194194
void addEntry(Symbol &sym, RelExpr expr, InputSectionBase *isec,
@@ -266,7 +266,7 @@ class CheriCapTableSection : public SyntheticSection {
266266
CaptableMap dynTlsEntries;
267267
CaptableMap tlsEntries;
268268
bool valuesAssigned = false;
269-
friend class CheriCapTableMappingSection;
269+
friend class MipsCheriCapTableMappingSection;
270270
};
271271

272272
// TODO: could shrink these to reduce size overhead but this is experimental
@@ -280,13 +280,13 @@ struct CaptableMappingEntry {
280280

281281
// Map from symbol vaddr -> captable subset so that RTLD can setup the correct
282282
// trampolines to initialize $cgp to the correct subset
283-
class CheriCapTableMappingSection : public SyntheticSection {
283+
class MipsCheriCapTableMappingSection : public SyntheticSection {
284284
public:
285-
CheriCapTableMappingSection(Ctx &ctx);
285+
MipsCheriCapTableMappingSection(Ctx &ctx);
286286
bool isNeeded() const override {
287287
if (ctx.arg.capTableScope == CapTableScopePolicy::All)
288288
return false;
289-
return ctx.in.cheriCapTable && ctx.in.cheriCapTable->isNeeded();
289+
return ctx.in.mipsCheriCapTable && ctx.in.mipsCheriCapTable->isNeeded();
290290
}
291291
void writeTo(uint8_t *buf) override;
292292
size_t getSize() const override;

lld/ELF/Arch/Mips.cpp

Lines changed: 5 additions & 5 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_CHERI_CAPABILITY_TABLE_REL;
124+
return R_MIPS_CHERI_CAPTAB_REL;
125125
case R_MIPS_26:
126126
case R_MICROMIPS_26_S1:
127127
return R_PLT;
@@ -210,16 +210,16 @@ RelExpr MIPS<ELFT>::getRelExpr(RelType type, const Symbol &s,
210210
return R_CHERI_CAPABILITY;
211211
case R_MIPS_CHERI_CAPTAB_LO16:
212212
case R_MIPS_CHERI_CAPTAB_HI16:
213-
return R_CHERI_CAPABILITY_TABLE_INDEX;
213+
return R_MIPS_CHERI_CAPTAB_INDEX;
214214
case R_MIPS_CHERI_CAPCALL_LO16:
215215
case R_MIPS_CHERI_CAPCALL_HI16:
216-
return R_CHERI_CAPABILITY_TABLE_INDEX_CALL;
216+
return R_MIPS_CHERI_CAPTAB_INDEX_CALL;
217217
case R_MIPS_CHERI_CAPTAB_CLC11:
218218
case R_MIPS_CHERI_CAPTAB20:
219-
return R_CHERI_CAPABILITY_TABLE_INDEX_SMALL_IMMEDIATE;
219+
return R_MIPS_CHERI_CAPTAB_INDEX_SMALL_IMMEDIATE;
220220
case R_MIPS_CHERI_CAPCALL_CLC11:
221221
case R_MIPS_CHERI_CAPCALL20:
222-
return R_CHERI_CAPABILITY_TABLE_INDEX_CALL_SMALL_IMMEDIATE;
222+
return R_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:
225225
return R_MIPS_CHERI_CAPTAB_TLSGD;

lld/ELF/Config.h

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -78,9 +78,9 @@ class SymbolTableBaseSection;
7878
class SymtabShndxSection;
7979
class SyntheticSection;
8080

81-
class CheriCapTableSection;
81+
class MipsCheriCapTableSection;
8282
class CheriCapRelocsSection;
83-
class CheriCapTableMappingSection;
83+
class MipsCheriCapTableMappingSection;
8484

8585
enum ELFKind : uint8_t {
8686
ELFNoneKind,
@@ -624,9 +624,9 @@ struct InStruct {
624624
std::unique_ptr<GotPltSection> gotPlt;
625625
std::unique_ptr<IgotPltSection> igotPlt;
626626
std::unique_ptr<RelroPaddingSection> relroPadding;
627-
std::unique_ptr<CheriCapTableSection> cheriCapTable;
627+
std::unique_ptr<MipsCheriCapTableSection> mipsCheriCapTable;
628628
std::unique_ptr<CheriCapRelocsSection> capRelocs;
629-
std::unique_ptr<CheriCapTableMappingSection> cheriCapTableMapping;
629+
std::unique_ptr<MipsCheriCapTableMappingSection> mipsCheriCapTableMapping;
630630
std::unique_ptr<SyntheticSection> armCmseSGSection;
631631
std::unique_ptr<PPC64LongBranchTargetSection> ppc64LongBranchTarget;
632632
std::unique_ptr<SyntheticSection> mipsAbiFlags;
@@ -713,7 +713,7 @@ struct Ctx : CommonLinkerContext {
713713
// _TLS_MODULE_BASE_ on targets that support TLSDESC.
714714
Defined *tlsModuleBase;
715715

716-
Defined *cheriCapabilityTable;
716+
Defined *mipsCheriCapabilityTable;
717717
};
718718
ElfSym sym{};
719719
std::unique_ptr<SymbolTable> symtab;

0 commit comments

Comments
 (0)