@@ -57,7 +57,7 @@ struct InMemoryCapRelocEntry {
5757CheriCapRelocsSection::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
765764template <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
891890template <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
982981template void
983- CheriCapTableSection ::assignValuesAndAddCapTableSymbols<ELF32LE>();
982+ MipsCheriCapTableSection ::assignValuesAndAddCapTableSymbols<ELF32LE>();
984983template void
985- CheriCapTableSection ::assignValuesAndAddCapTableSymbols<ELF32BE>();
984+ MipsCheriCapTableSection ::assignValuesAndAddCapTableSymbols<ELF32BE>();
986985template void
987- CheriCapTableSection ::assignValuesAndAddCapTableSymbols<ELF64LE>();
986+ MipsCheriCapTableSection ::assignValuesAndAddCapTableSymbols<ELF64LE>();
988987template 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!" );
0 commit comments