diff --git a/lld/ELF/Arch/Cheri.cpp b/lld/ELF/Arch/Cheri.cpp index 0fbcbdfef4bdf..1cb8d5d02bf38 100644 --- a/lld/ELF/Arch/Cheri.cpp +++ b/lld/ELF/Arch/Cheri.cpp @@ -393,6 +393,13 @@ void CheriCapRelocsSection::writeToImpl(uint8_t *buf) { } } + // For function relocs, use PCC bounds from the PT_CHERI_PCC segment. + if (config->emachine != EM_MIPS && (isFunc || isGnuIFunc)) { + targetOffset += targetVA - pccBase(); + targetVA = pccBase(); + targetSize = pccSize(); + } + // TODO: should we warn about symbols that are out-of-bounds? // mandoc seems to do it so I guess we need it // if (TargetOffset < 0 || TargetOffset > TargetSize) warn(...); @@ -952,5 +959,44 @@ void addRelativeCapabilityRelocation( addend); } +// Determine the required alignment for a single PT_CHERI_PCC segment. Apply +// the alignment to the first OutputSection and adjust the length of the padding +// section to align the end of the segment. Returns true if the alignment of +// the first OutputSection changed or the size of the padding section changed. +static bool alignPCCBounds(PhdrEntry *p, CheriPccPaddingSection &psec) { + OutputSection *first = p->firstSec; + OutputSection *last = p->lastSec; + + if (!first) + return false; + + assert(psec.getParent() == last && "padding section is not last"); + assert(psec.isNeeded() && "padding section is not enabled"); + + // Ignore existing padding. + uint64_t size = last->getVA() - first->getVA(); + uint64_t align = target->getCheriRequiredAlignment(size); + if (align == 0) + align = 1; + bool changed = false; + if (first->addralign < align) { + first->addralign = align; + changed = true; + } + uint64_t padSize = alignTo(size, align) - size; + if (psec.getSize() != padSize) { + psec.setSize(padSize); + changed = true; + } + return changed; +} + +bool cheriCapabilityBoundsAlign() { + // Align the PT_CHERI_PCC segment. + bool changed = false; + changed |= alignPCCBounds(in.cheriBounds, *in.pccPadding); + return changed; +} + } // namespace elf } // namespace lld diff --git a/lld/ELF/Arch/Cheri.h b/lld/ELF/Arch/Cheri.h index 1c5e181cfab1d..355ed880fce19 100644 --- a/lld/ELF/Arch/Cheri.h +++ b/lld/ELF/Arch/Cheri.h @@ -314,6 +314,12 @@ void addRelativeCapabilityRelocation( InputSectionBase &isec, uint64_t offsetInSec, llvm::PointerUnion symOrSec, int64_t addend, RelExpr expr, RelType type); + +// Align OutputSections as needed to ensure the bounds of capabilities +// such as PCC do not permit undesired access to portions of other +// OutputSections. Return true if the alignment of any OutputSection +// was modified. +bool cheriCapabilityBoundsAlign(); } // namespace elf } // namespace lld diff --git a/lld/ELF/Arch/Mips.cpp b/lld/ELF/Arch/Mips.cpp index c53b4619ce2ba..014b6419181ed 100644 --- a/lld/ELF/Arch/Mips.cpp +++ b/lld/ELF/Arch/Mips.cpp @@ -13,6 +13,7 @@ #include "Target.h" #include "lld/Common/ErrorHandler.h" #include "llvm/BinaryFormat/ELF.h" +#include "llvm/CHERI/cheri-compressed-cap/cheri_compressed_cap.h" using namespace llvm; using namespace llvm::object; @@ -26,6 +27,7 @@ template class MIPS final : public TargetInfo { MIPS(); uint32_t calcEFlags() const override; int getCapabilitySize() const override; + uint64_t getCheriRequiredAlignment(uint64_t len) const override; RelExpr getRelExpr(RelType type, const Symbol &s, const uint8_t *loc) const override; int64_t getImplicitAddend(const uint8_t *buf, RelType type) const override; @@ -89,6 +91,13 @@ template int MIPS::getCapabilitySize() const { return 0; } +template +uint64_t MIPS::getCheriRequiredAlignment(uint64_t len) const { + if ((config->eflags & EF_MIPS_MACH) == EF_MIPS_MACH_CHERI128) + return cc128_get_required_alignment(len); + return 1; +} + template RelExpr MIPS::getRelExpr(RelType type, const Symbol &s, const uint8_t *loc) const { diff --git a/lld/ELF/Arch/RISCV.cpp b/lld/ELF/Arch/RISCV.cpp index 3c141b74828dd..d684cafa3c52e 100644 --- a/lld/ELF/Arch/RISCV.cpp +++ b/lld/ELF/Arch/RISCV.cpp @@ -11,6 +11,7 @@ #include "Symbols.h" #include "SyntheticSections.h" #include "Target.h" +#include "llvm/CHERI/cheri-compressed-cap/cheri_compressed_cap.h" #include "llvm/Support/ELFAttributes.h" #include "llvm/Support/LEB128.h" #include "llvm/Support/RISCVAttributeParser.h" @@ -32,6 +33,7 @@ class RISCV final : public TargetInfo { RISCV(); uint32_t calcEFlags() const override; int getCapabilitySize() const override; + uint64_t getCheriRequiredAlignment(uint64_t len) const override; int64_t getImplicitAddend(const uint8_t *buf, RelType type) const override; void writeGotHeader(uint8_t *buf) const override; void writeGotPlt(uint8_t *buf, const Symbol &s) const override; @@ -155,6 +157,13 @@ int RISCV::getCapabilitySize() const { return config->is64 ? 16 : 8; } +uint64_t RISCV::getCheriRequiredAlignment(uint64_t len) const { + if (config->is64) + return cc128_get_required_alignment(len); + else + return cc64_get_required_alignment(len); +} + uint32_t RISCV::calcEFlags() const { // If there are only binary input files (from -b binary), use a // value of 0 for the ELF header flags. diff --git a/lld/ELF/OutputSections.h b/lld/ELF/OutputSections.h index c7931471a6ed3..077ace9e17abb 100644 --- a/lld/ELF/OutputSections.h +++ b/lld/ELF/OutputSections.h @@ -72,6 +72,9 @@ class OutputSection final : public SectionBase { uint64_t addr = 0; uint32_t shName = 0; + // Sections accessed using PCC on CHERI architectures. + bool cheriPcc = false; + void recordSection(InputSectionBase *isec); void commitSection(InputSection *isec); void finalizeInputSections(); diff --git a/lld/ELF/SyntheticSections.cpp b/lld/ELF/SyntheticSections.cpp index 4422db2a4a6ea..457574321211c 100644 --- a/lld/ELF/SyntheticSections.cpp +++ b/lld/ELF/SyntheticSections.cpp @@ -3990,6 +3990,7 @@ void InStruct::reset() { strTab.reset(); symTab.reset(); symTabShndx.reset(); + cheriBounds = nullptr; } constexpr char kMemtagAndroidNoteName[] = "Android"; @@ -4036,6 +4037,17 @@ size_t PackageMetadataNote::getSize() const { alignTo(config->packageMetadata.size() + 1, 4); } +void CheriPccPaddingSection::writeTo(uint8_t *buf) { memset(buf, 0, size); } + +uint64_t elf::pccBase() { return in.cheriBounds->firstSec->addr; } + +uint64_t elf::pccSize() { + PhdrEntry *phdr = in.cheriBounds; + OutputSection *first = phdr->firstSec; + OutputSection *last = phdr->lastSec; + return last->getVA() + last->size - first->getVA(); +} + InStruct elf::in; std::vector elf::partitions; diff --git a/lld/ELF/SyntheticSections.h b/lld/ELF/SyntheticSections.h index e99dfcc2d7169..0e3335a287270 100644 --- a/lld/ELF/SyntheticSections.h +++ b/lld/ELF/SyntheticSections.h @@ -1253,6 +1253,23 @@ class PackageMetadataNote final : public SyntheticSection { size_t getSize() const override; }; +class CheriPccPaddingSection final : public SyntheticSection { +public: + CheriPccPaddingSection() + : SyntheticSection(llvm::ELF::SHF_ALLOC, llvm::ELF::SHT_PROGBITS, + /*alignment=*/1, ".pad.cheri.pcc") {} + + void writeTo(uint8_t *buf) override; + void markNeeded() { needed = true; } + bool isNeeded() const override { return needed; } + size_t getSize() const override { return size; } + void setSize(uint64_t len) { size = len; } + +private: + uint64_t size = 0; + bool needed = false; +}; + InputSection *createInterpSection(); MergeInputSection *createCommentSection(); template void splitSections(); @@ -1313,6 +1330,7 @@ struct InStruct { std::unique_ptr gotPlt; std::unique_ptr igotPlt; std::unique_ptr mipsCheriCapTable; + std::unique_ptr pccPadding; std::unique_ptr capRelocs; // For per-file/per-function tables: std::unique_ptr mipsCheriCapTableMapping; @@ -1336,11 +1354,16 @@ struct InStruct { std::unique_ptr symTab; std::unique_ptr symTabShndx; + PhdrEntry *cheriBounds; + void reset(); }; LLVM_LIBRARY_VISIBILITY extern InStruct in; +uint64_t pccBase(); +uint64_t pccSize(); + } // namespace lld::elf #endif diff --git a/lld/ELF/Target.cpp b/lld/ELF/Target.cpp index 0cf0bb141cd0b..a7c6314eba02f 100644 --- a/lld/ELF/Target.cpp +++ b/lld/ELF/Target.cpp @@ -134,6 +134,11 @@ ErrorPlace elf::getErrorPlace(const uint8_t *loc) { TargetInfo::~TargetInfo() {} +uint64_t TargetInfo::getCheriRequiredAlignment(uint64_t len) const { + error("current target does not provide required Cheri alignment"); + return 1; +} + int64_t TargetInfo::getImplicitAddend(const uint8_t *buf, RelType type) const { internalLinkerError(getErrorLocation(buf), "cannot read addend for relocation " + toString(type)); diff --git a/lld/ELF/Target.h b/lld/ELF/Target.h index ed2cb654f8bf7..8b1dd60254d1f 100644 --- a/lld/ELF/Target.h +++ b/lld/ELF/Target.h @@ -30,6 +30,7 @@ class TargetInfo { public: virtual uint32_t calcEFlags() const { return 0; } virtual int getCapabilitySize() const { return 0; } + virtual uint64_t getCheriRequiredAlignment(uint64_t len) const; virtual RelExpr getRelExpr(RelType type, const Symbol &s, const uint8_t *loc) const = 0; virtual RelType getDynRel(RelType type) const { return 0; } diff --git a/lld/ELF/Writer.cpp b/lld/ELF/Writer.cpp index 257f8dbe86174..2245b8652fe08 100644 --- a/lld/ELF/Writer.cpp +++ b/lld/ELF/Writer.cpp @@ -61,6 +61,7 @@ template class Writer { void finalizeAddressDependentContent(); void optimizeBasicBlockJumps(); void sortInputSections(); + void sortCheriPccPaddingSection(); void sortOrphanSections(); void finalizeSections(); void checkExecuteOnly(); @@ -534,6 +535,11 @@ template void elf::createSyntheticSections() { in.iplt = std::make_unique(); add(*in.iplt); + if (config->isCheriAbi) { + in.pccPadding = std::make_unique(); + add(*in.pccPadding); + } + if (config->andFeatures) add(*make()); @@ -1463,6 +1469,50 @@ template void Writer::sortInputSections() { sortSection(osd->osec, order); } +// The CHERI PCC padding output section for each compartment must be placed +// immediately after the last section covered by the PCC bounds. +template void Writer::sortCheriPccPaddingSection() { + CheriPccPaddingSection *psec = in.pccPadding.get(); + if (!psec->isNeeded()) + return; + + // First, find and remove the existing padding output section. + auto isPaddingSection = [&](SectionCommand *cmd) { + auto *to = dyn_cast(cmd); + return to != nullptr && psec->getParent() == &to->osec; + }; + auto fromPos = llvm::find_if(script->sectionCommands, isPaddingSection); + assert(fromPos != script->sectionCommands.end() && + "PCC padding section not found"); + auto paddingSec = *fromPos; + script->sectionCommands.erase(fromPos); + + // Second, find the last CHERI PCC output section. + auto isPccSection = [&](SectionCommand *cmd) { + auto *to = dyn_cast(cmd); + return to != nullptr && to->osec.cheriPcc; + }; + + auto insertPos = llvm::find_if(script->sectionCommands, isPccSection); + assert(insertPos != script->sectionCommands.end() && + "did not find first PCC section"); + for (;;) { + auto nextPos = std::find_if(insertPos + 1, script->sectionCommands.end(), + isPccSection); + if (nextPos == script->sectionCommands.end()) + break; + insertPos = nextPos; + } + + // Change the flags of the padding output section to match the last CHERI PCC + // output section so it is treated as part of the same load segment. + cast(paddingSec)->osec.flags = + cast(*insertPos)->osec.flags; + + // Insert the padding output section in its new location. + script->sectionCommands.insert(insertPos + 1, paddingSec); +} + template void Writer::sortSections() { llvm::TimeTraceScope timeScope("Sort sections"); @@ -1495,6 +1545,9 @@ template void Writer::sortSections() { if (script->hasSectionsCommand) sortOrphanSections(); + if (config->isCheriAbi) + sortCheriPccPaddingSection(); + script->adjustSectionsAfterSorting(); } @@ -1676,6 +1729,12 @@ template void Writer::finalizeAddressDependentContent() { break; } + if (config->isCheriAbi && !config->relocatable) { + if (changed) + script->assignAddresses(); + changed |= cheriCapabilityBoundsAlign(); + } + if (config->fixCortexA53Errata843419) { if (changed) script->assignAddresses(); @@ -1814,6 +1873,76 @@ template void Writer::optimizeBasicBlockJumps() { is->trim(); } +// Which sections are covered by CHERI PCC bounds. Currently this includes +// executable sections, read-only data sections, and GOTs. +static bool isCheriBoundsSection(const OutputSection *sec) { + uint64_t flags = sec->flags; + + // Non-allocatable sections are not mapped into memory. + if (!(flags & SHF_ALLOC)) + return false; + + // Executable sections are fetched via PCC. + if (flags & SHF_EXECINSTR) + return true; + + // .got is accessed relative to PCC. + if (in.got && sec == in.got->getParent()) + return true; + if (in.mipsGot && sec == in.mipsGot->getParent()) + return true; + + // .got.plt is accessed relative to PCC. + if (sec == in.gotPlt->getParent()) + return true; + + // CHERI capability table is accessed relative to PCC. + if (in.mipsCheriCapTable && sec == in.mipsCheriCapTable->getParent()) + return true; + + // .rodata symbols are accessed relative to PCC. + if (sec->name.startswith(".rodata")) + return true; + + // The PCC padding section is included in PCC bounds. + if (sec == in.pccPadding->getParent()) + return true; + + return false; +} + +// Mark all output sections covered by CHERI PCC bounds. In addition, +// enable the padding section for the associated compartment. +static void markCheriPccSections() { + // Mark padding section as needed as long as there is at least one executable + // input section. + for (InputSectionBase *s : ctx.inputSections) { + // Ignore unused synthetic sections + if (isa(s)) { + auto *sec = cast(s); + if (!(sec->getParent() && sec->isNeeded())) + continue; + } + // Ignore empty input sections + if (s->getSize() == 0) + continue; + if ((s->flags & (SHF_ALLOC | SHF_EXECINSTR)) == (SHF_ALLOC | SHF_EXECINSTR)) + in.pccPadding->markNeeded(); + } + + // Mark all output sections accessed via PCC if there is at least one + // executable input section. + for (SectionCommand *cmd : script->sectionCommands) { + if (auto *osd = dyn_cast(cmd)) { + OutputSection &osec = osd->osec; + if (!in.pccPadding->isNeeded()) + continue; + if (isCheriBoundsSection(&osec)) + osec.cheriPcc = true; + } + } +} + // In order to allow users to manipulate linker-synthesized sections, // we had to add synthetic sections to the input section list early, // even before we make decisions whether they are needed. This allows @@ -2077,6 +2206,8 @@ template void Writer::finalizeSections() { if (in.mipsGot) in.mipsGot->build(); + if (config->isCheriAbi) + markCheriPccSections(); removeUnusedSyntheticSections(); script->diagnoseOrphanHandling(); script->diagnoseMissingSGSectionAddress(); @@ -2163,6 +2294,8 @@ template void Writer::finalizeSections() { finalizeSynthetic(in.mipsGot.get()); finalizeSynthetic(in.igotPlt.get()); finalizeSynthetic(in.gotPlt.get()); + if (config->isCheriAbi) + finalizeSynthetic(in.pccPadding.get()); finalizeSynthetic(in.relaIplt.get()); finalizeSynthetic(in.relaPlt.get()); finalizeSynthetic(in.plt.get()); @@ -2445,7 +2578,10 @@ SmallVector Writer::createPhdrs(Partition &part) { for (OutputSection *sec : outputSections) { if (sec->partition != partNo || !needsPtLoad(sec)) continue; - if (isRelroSection(sec)) { + // Treat a CHERI PCC padding section as relro if it is preceded by a relro + // section. + if (isRelroSection(sec) || (config->isCheriAbi && inRelroPhdr && + sec == in.pccPadding->getParent())) { inRelroPhdr = true; if (!relroEnd) relRo->add(sec); @@ -2458,6 +2594,19 @@ SmallVector Writer::createPhdrs(Partition &part) { } } + // Determine the sections PCC should cover for each compartment. + if (config->isCheriAbi) { + in.cheriBounds = make(PT_CHERI_PCC, PF_R | PF_X); + + for (OutputSection *sec : outputSections) { + if (sec->partition != partNo || !needsPtLoad(sec)) + continue; + if (!sec->cheriPcc) + continue; + in.cheriBounds->add(sec); + } + } + for (OutputSection *sec : outputSections) { if (!needsPtLoad(sec)) continue; @@ -2520,6 +2669,11 @@ SmallVector Writer::createPhdrs(Partition &part) { if (relRo->firstSec) ret.push_back(relRo); + if (config->isCheriAbi) { + if (in.cheriBounds->firstSec) + ret.push_back(in.cheriBounds); + } + // PT_GNU_EH_FRAME is a special section pointing on .eh_frame_hdr. if (part.ehFrame->isNeeded() && part.ehFrameHdr && part.ehFrame->getParent() && part.ehFrameHdr->getParent()) diff --git a/lld/test/ELF/cheri/__cap_relocs/capreloc-aether.s b/lld/test/ELF/cheri/__cap_relocs/capreloc-aether.s index e80908445df44..f4e8c23946879 100644 --- a/lld/test/ELF/cheri/__cap_relocs/capreloc-aether.s +++ b/lld/test/ELF/cheri/__cap_relocs/capreloc-aether.s @@ -8,6 +8,6 @@ .chericap data_end # CHECK: CHERI __cap_relocs [ -# CHECK-NEXT: 0x0100a0 Base: 0x10000 (data_begin+0) Length: 0 Perms: Constant -# CHECK-NEXT: 0x0100c0 Base: 0x20000 (data_end+0) Length: 0 Perms: Object +# CHECK-NEXT: 0x0100a0 Base: 0x10000 (data_begin) Length: 0 Perms: Constant +# CHECK-NEXT: 0x0100c0 Base: 0x20000 (data_end) Length: 0 Perms: Object # CHECK-NEXT: ] diff --git a/lld/test/ELF/cheri/cap-table/cap-table-global-init.c b/lld/test/ELF/cheri/cap-table/cap-table-global-init.c index ab88ed6b5b63a..e969f1b32b73d 100644 --- a/lld/test/ELF/cheri/cap-table/cap-table-global-init.c +++ b/lld/test/ELF/cheri/cap-table/cap-table-global-init.c @@ -22,10 +22,10 @@ int main(void) { } // CHECK-LABEL: SYMBOL TABLE: -// CHECK-DAG: 0000000000020358 l F .text 0000000000000038 .protected _start -// CHECK-DAG: 00000000000202f0 g F .text 0000000000000068 __start -// CHECK-DAG: 00000000000303d0 l .captable 0000000000000030 .hidden __cap_table_start -// CHECK-DAG: 0000000000030400 l .captable 0000000000000000 .hidden __cap_table_end -// CHECK-DAG: 00000000000303d0 l O .captable 0000000000000010 main@CAPTABLE -// CHECK-DAG: 00000000000303e0 l O .captable 0000000000000010 global@CAPTABLE -// CHECK-DAG: 00000000000303f0 l O .captable 0000000000000010 global2@CAPTABLE +// CHECK-DAG: 0000000000020468 l F .text 0000000000000038 .protected _start +// CHECK-DAG: 0000000000020400 g F .text 0000000000000068 __start +// CHECK-DAG: 00000000000304e0 l .captable 0000000000000030 .hidden __cap_table_start +// CHECK-DAG: 0000000000030510 l .captable 0000000000000000 .hidden __cap_table_end +// CHECK-DAG: 00000000000304e0 l O .captable 0000000000000010 main@CAPTABLE +// CHECK-DAG: 00000000000304f0 l O .captable 0000000000000010 global@CAPTABLE +// CHECK-DAG: 0000000000030500 l O .captable 0000000000000010 global2@CAPTABLE diff --git a/lld/test/ELF/cheri/cap-table/cap-table-init-relocs.s b/lld/test/ELF/cheri/cap-table/cap-table-init-relocs.s index eb76fac8d20c8..2bae7b3c70055 100644 --- a/lld/test/ELF/cheri/cap-table/cap-table-init-relocs.s +++ b/lld/test/ELF/cheri/cap-table/cap-table-init-relocs.s @@ -27,19 +27,19 @@ local_var: # ELF-PREEMPTIBLE-LEGACY-LOCAL-CAPRELOCS-LABEL: Sections: -# ELF-PREEMPTIBLE-LEGACY-LOCAL-CAPRELOCS: __cap_relocs 00000028 00000000000004b8 DATA -# ELF-PREEMPTIBLE-LEGACY-LOCAL-CAPRELOCS: .captable 00000020 00000000000204f0 DATA +# ELF-PREEMPTIBLE-LEGACY-LOCAL-CAPRELOCS: __cap_relocs 00000028 00000000000004f0 DATA +# ELF-PREEMPTIBLE-LEGACY-LOCAL-CAPRELOCS: .captable 00000020 0000000000020610 DATA # ELF-PREEMPTIBLE-LEGACY-LOCAL-CAPRELOCS-LABEL: SYMBOL TABLE: -# ELF-PREEMPTIBLE-LEGACY-LOCAL-CAPRELOCS: 00000000000204f0 l O .captable 0000000000000010 preemptible_var@CAPTABLE -# ELF-PREEMPTIBLE-LEGACY-LOCAL-CAPRELOCS: 0000000000020500 l O .captable 0000000000000010 local_var@CAPTABLE +# ELF-PREEMPTIBLE-LEGACY-LOCAL-CAPRELOCS: 0000000000020610 l O .captable 0000000000000010 preemptible_var@CAPTABLE +# ELF-PREEMPTIBLE-LEGACY-LOCAL-CAPRELOCS: 0000000000020620 l O .captable 0000000000000010 local_var@CAPTABLE # ELF-PREEMPTIBLE-LEGACY-LOCAL-CAPRELOCS-LABEL: CAPABILITY RELOCATION RECORDS: -# ELF-PREEMPTIBLE-LEGACY-LOCAL-CAPRELOCS-NEXT: 0x0000000000020500 Base: local_var (0x0000000000030518) Offset: 0x0000000000000000 Length: 0x0000000000000008 Permissions: 0x00000000 +# ELF-PREEMPTIBLE-LEGACY-LOCAL-CAPRELOCS-NEXT: 0x0000000000020620 Base: local_var (0x0000000000030638) Offset: 0x0000000000000000 Length: 0x0000000000000008 Permissions: 0x00000000 # ELF-PREEMPTIBLE-LEGACY-LOCAL-CAPRELOCS-EMPTY: # One relative reloc for the local __cap_reloc location and one R_MIPS_CHERI_CAPABILITY for the preemptible symbol # ELF-PREEMPTIBLE-LEGACY-LOCAL-ELF-RELOCS: Relocations [ # ELF-PREEMPTIBLE-LEGACY-LOCAL-ELF-RELOCS-NEXT: Section (7) .rel.dyn { -# ELF-PREEMPTIBLE-LEGACY-LOCAL-ELF-RELOCS-NEXT: 0x204F0 R_MIPS_CHERI_CAPABILITY/R_MIPS_NONE/R_MIPS_NONE preemptible_var{{$}} +# ELF-PREEMPTIBLE-LEGACY-LOCAL-ELF-RELOCS-NEXT: 0x20610 R_MIPS_CHERI_CAPABILITY/R_MIPS_NONE/R_MIPS_NONE preemptible_var{{$}} # ^---- preemptible_var@CAPTABLE # ELF-PREEMPTIBLE-LEGACY-LOCAL-ELF-RELOCS-NEXT: } # ELF-PREEMPTIBLE-LEGACY-LOCAL-ELF-RELOCS-NEXT: ] diff --git a/lld/test/ELF/cheri/cap-table/cap-table-negative-reloc-offset.c b/lld/test/ELF/cheri/cap-table/cap-table-negative-reloc-offset.c index df17419034f25..c2f5da1e21b37 100644 --- a/lld/test/ELF/cheri/cap-table/cap-table-negative-reloc-offset.c +++ b/lld/test/ELF/cheri/cap-table/cap-table-negative-reloc-offset.c @@ -153,8 +153,8 @@ int __start(void) { // CHECK-LABEL: SYMBOL TABLE: -// CHECK: [[__MAN_MACROS_ADDR:0000000000030820]] g O .data.rel.ro 0000000000000440 __man_macros -// CHECK: [[MAN_MACROS_ADDR:0000000000030c60]] g O .data.rel.ro 0000000000000010 man_macros +// CHECK: [[__MAN_MACROS_ADDR:0000000000030930]] g O .data.rel.ro 0000000000000440 __man_macros +// CHECK: [[MAN_MACROS_ADDR:0000000000030d70]] g O .data.rel.ro 0000000000000010 man_macros // CHECK-LABEL: CAPABILITY RELOCATION RECORDS: // CHECK: 0x[[MAN_MACROS_ADDR]] Base: __man_macros (0x[[__MAN_MACROS_ADDR]]) Offset: 0xffffffffffffd280 Length: 0x0000000000000440 Permissions: 0x4000000000000000 (Constant) diff --git a/lld/test/ELF/cheri/cap-table/cap-table-pointer.s b/lld/test/ELF/cheri/cap-table/cap-table-pointer.s index e56b40e0f737a..0a9a480eb3d9a 100644 --- a/lld/test/ELF/cheri/cap-table/cap-table-pointer.s +++ b/lld/test/ELF/cheri/cap-table/cap-table-pointer.s @@ -13,7 +13,7 @@ __start: // CHECK: Symbol { // CHECK: Name: _CHERI_CAPABILITY_TABLE_ ({{.+}}) -// CHECK-NEXT: Value: 0x20{{3F0|400}} +// CHECK-NEXT: Value: 0x204{{90|40}} // CHECK-NEXT: Size: [[#CAP_SIZE]] // CHECK-NEXT: Binding: Local (0x0) // CHECK-NEXT: Type: None (0x0) @@ -24,8 +24,8 @@ __start: // CHECK-NEXT: } // CHECK: CHERI __cap_relocs [ -// CHECK-NEXT: 0x0[[CAPTAB_ADDR:20(3f0|400)]] -// CHECK-SAME: (_CHERI_CAPABILITY_TABLE_@CAPTABLE) Base: 0x[[CAPTAB_ADDR]] (_CHERI_CAPABILITY_TABLE_@CAPTABLE+0) Length: [[#CAP_SIZE]] Perms: Object +// CHECK-NEXT: 0x0[[CAPTAB_ADDR:204(90|40)]] +// CHECK-SAME: (_CHERI_CAPABILITY_TABLE_@CAPTABLE) Base: 0x[[CAPTAB_ADDR]] (_CHERI_CAPABILITY_TABLE_@CAPTABLE) Length: [[#CAP_SIZE]] Perms: Object // CHECK-NEXT: ] // CHECK-NEXT: CHERI .captable [ // CHECK-NEXT: 0x0 _CHERI_CAPABILITY_TABLE_@CAPTABLE diff --git a/lld/test/ELF/cheri/cap-table/empty-cap-table-symbols.s b/lld/test/ELF/cheri/cap-table/empty-cap-table-symbols.s index a8ae9d24a6b0f..a5c332808e2e7 100644 --- a/lld/test/ELF/cheri/cap-table/empty-cap-table-symbols.s +++ b/lld/test/ELF/cheri/cap-table/empty-cap-table-symbols.s @@ -24,5 +24,5 @@ __start: # CHECK-NOT: .captable # CHECK-LABEL: SYMBOL TABLE: # CHECK-NEXT: 0000000000000000 l *ABS* 0000000000000000 .hidden _CHERI_CAPABILITY_TABLE_ -# CHECK-NEXT: 0000000000038220 l .got 0000000000000000 .hidden _gp -# CHECK-NEXT: 0000000000020210 g .text 0000000000000000 __start +# CHECK-NEXT: 0000000000038290 l .got 0000000000000000 .hidden _gp +# CHECK-NEXT: 0000000000020280 g .text 0000000000000000 __start diff --git a/lld/test/ELF/cheri/cap-table/experimental/per-file-table.c b/lld/test/ELF/cheri/cap-table/experimental/per-file-table.c index 7a91993695e62..1eeae2dfba3a2 100644 --- a/lld/test/ELF/cheri/cap-table/experimental/per-file-table.c +++ b/lld/test/ELF/cheri/cap-table/experimental/per-file-table.c @@ -21,20 +21,20 @@ // PER-FILE: ] // PER-FILE-LABEL: Relocations [ // PER-FILE-NEXT: Section ({{.+}}) .rel.dyn { -// PER-FILE-NEXT: 0x20A10 R_MIPS_CHERI_CAPABILITY/R_MIPS_NONE/R_MIPS_NONE global_int{{$}} -// PER-FILE-NEXT: 0x20A40 R_MIPS_CHERI_CAPABILITY/R_MIPS_NONE/R_MIPS_NONE global_int{{$}} -// PER-FILE-NEXT: 0x20A60 R_MIPS_CHERI_CAPABILITY/R_MIPS_NONE/R_MIPS_NONE global_int{{$}} +// PER-FILE-NEXT: 0x20A90 R_MIPS_CHERI_CAPABILITY/R_MIPS_NONE/R_MIPS_NONE global_int{{$}} +// PER-FILE-NEXT: 0x20AC0 R_MIPS_CHERI_CAPABILITY/R_MIPS_NONE/R_MIPS_NONE global_int{{$}} +// PER-FILE-NEXT: 0x20AE0 R_MIPS_CHERI_CAPABILITY/R_MIPS_NONE/R_MIPS_NONE global_int{{$}} // PER-FILE-NEXT: } // PER-FILE-NEXT: Section ({{.+}}) .rel.plt { -// PER-FILE-NEXT: 0x209E0 R_MIPS_CHERI_CAPABILITY_CALL/R_MIPS_NONE/R_MIPS_NONE extern_void_ptr{{$}} -// PER-FILE-NEXT: 0x209F0 R_MIPS_CHERI_CAPABILITY_CALL/R_MIPS_NONE/R_MIPS_NONE extern_char_ptr{{$}} -// PER-FILE-NEXT: 0x20A00 R_MIPS_CHERI_CAPABILITY_CALL/R_MIPS_NONE/R_MIPS_NONE extern_int{{$}} -// PER-FILE-NEXT: 0x20A30 R_MIPS_CHERI_CAPABILITY_CALL/R_MIPS_NONE/R_MIPS_NONE extern_char_ptr{{$}} -// PER-FILE-NEXT: 0x20A50 R_MIPS_CHERI_CAPABILITY_CALL/R_MIPS_NONE/R_MIPS_NONE extern_char_ptr{{$}} +// PER-FILE-NEXT: 0x20A60 R_MIPS_CHERI_CAPABILITY_CALL/R_MIPS_NONE/R_MIPS_NONE extern_void_ptr{{$}} +// PER-FILE-NEXT: 0x20A70 R_MIPS_CHERI_CAPABILITY_CALL/R_MIPS_NONE/R_MIPS_NONE extern_char_ptr{{$}} +// PER-FILE-NEXT: 0x20A80 R_MIPS_CHERI_CAPABILITY_CALL/R_MIPS_NONE/R_MIPS_NONE extern_int{{$}} +// PER-FILE-NEXT: 0x20AB0 R_MIPS_CHERI_CAPABILITY_CALL/R_MIPS_NONE/R_MIPS_NONE extern_char_ptr{{$}} +// PER-FILE-NEXT: 0x20AD0 R_MIPS_CHERI_CAPABILITY_CALL/R_MIPS_NONE/R_MIPS_NONE extern_char_ptr{{$}} // PER-FILE-NEXT: } // PER-FILE-NEXT: ] // PER-FILE-NEXT: CHERI __cap_relocs [ -// PER-FILE-NEXT: 0x020a20 (function3@CAPTABLE@file1.o.4) Base: 0x10{{.+}} (function3+0) Length: {{.+}} Perms: Function +// PER-FILE-NEXT: 0x020aa0 (function3@CAPTABLE@file1.o.4) Base: 0x10{{.+}} (function3) Length: {{.+}} Perms: Function // PER-FILE-NEXT: ] // PER-FILE-NEXT: CHERI .captable [ // PER-FILE-NEXT: 0x0 extern_void_ptr@CAPTABLE@file1.o R_MIPS_CHERI_CAPABILITY_CALL/R_MIPS_NONE/R_MIPS_NONE against extern_void_ptr @@ -55,12 +55,12 @@ // Less entries and relocations with a global captable: // GLOBAL: Relocations [ // GLOBAL-NEXT: Section (7) .rel.dyn { -// GLOBAL-NEXT: 0x208C0 R_MIPS_CHERI_CAPABILITY/R_MIPS_NONE/R_MIPS_NONE global_int{{$}} +// GLOBAL-NEXT: 0x20910 R_MIPS_CHERI_CAPABILITY/R_MIPS_NONE/R_MIPS_NONE global_int{{$}} // GLOBAL-NEXT: } // GLOBAL-NEXT: Section (8) .rel.plt { -// GLOBAL-NEXT: 0x20890 R_MIPS_CHERI_CAPABILITY_CALL/R_MIPS_NONE/R_MIPS_NONE extern_void_ptr{{$}} -// GLOBAL-NEXT: 0x208A0 R_MIPS_CHERI_CAPABILITY_CALL/R_MIPS_NONE/R_MIPS_NONE extern_char_ptr{{$}} -// GLOBAL-NEXT: 0x208B0 R_MIPS_CHERI_CAPABILITY_CALL/R_MIPS_NONE/R_MIPS_NONE extern_int{{$}} +// GLOBAL-NEXT: 0x208E0 R_MIPS_CHERI_CAPABILITY_CALL/R_MIPS_NONE/R_MIPS_NONE extern_void_ptr{{$}} +// GLOBAL-NEXT: 0x208F0 R_MIPS_CHERI_CAPABILITY_CALL/R_MIPS_NONE/R_MIPS_NONE extern_char_ptr{{$}} +// GLOBAL-NEXT: 0x20900 R_MIPS_CHERI_CAPABILITY_CALL/R_MIPS_NONE/R_MIPS_NONE extern_int{{$}} // GLOBAL-NEXT: } // GLOBAL-NEXT: ] // GLOBAL-LABEL: CHERI .captable [ diff --git a/lld/test/ELF/cheri/cap-table/experimental/per-function-table.c b/lld/test/ELF/cheri/cap-table/experimental/per-function-table.c index 805a60c30cd60..53621fb51596e 100644 --- a/lld/test/ELF/cheri/cap-table/experimental/per-function-table.c +++ b/lld/test/ELF/cheri/cap-table/experimental/per-function-table.c @@ -13,43 +13,43 @@ // CHECK-LABEL: DynamicSection [ // CHECK-NEXT: Tag Type Name/Value // PER-FUNCTION: 0x000000007000C002 MIPS_CHERI_FLAGS ABI_PLT CAPTABLE_PER_FUNC RELATIVE_CAPRELOCS {{$}} -// PER-FUNCTION: 0x000000007000C005 MIPS_CHERI_CAPTABLE_MAPPING 0x6E8 +// PER-FUNCTION: 0x000000007000C005 MIPS_CHERI_CAPTABLE_MAPPING 0x720 // PER-FUNCTION: 0x000000007000C006 MIPS_CHERI_CAPTABLE_MAPPINGSZ 0xA8 // PER-FILE: 0x000000007000C002 MIPS_CHERI_FLAGS ABI_PLT CAPTABLE_PER_FILE RELATIVE_CAPRELOCS {{$}} -// PER-FILE: 0x000000007000C005 MIPS_CHERI_CAPTABLE_MAPPING 0x6A8 +// PER-FILE: 0x000000007000C005 MIPS_CHERI_CAPTABLE_MAPPING 0x6E0 // PER-FILE: 0x000000007000C006 MIPS_CHERI_CAPTABLE_MAPPINGSZ 0xA8 // GLOBAL: 0x000000007000C002 MIPS_CHERI_FLAGS ABI_PLT RELATIVE_CAPRELOCS {{$}} // CHECK: ] // CHECK: Relocations [ // CHECK-NEXT: Section ({{.+}}) .rel.dyn { -// PER-FUNCTION-NEXT: 0x20960 R_MIPS_CHERI_CAPABILITY/R_MIPS_NONE/R_MIPS_NONE global_int{{$}} -// PER-FILE-NEXT: 0x20910 R_MIPS_CHERI_CAPABILITY/R_MIPS_NONE/R_MIPS_NONE global_int{{$}} -// GLOBAL-NEXT: 0x20840 R_MIPS_CHERI_CAPABILITY/R_MIPS_NONE/R_MIPS_NONE global_int{{$}} +// PER-FUNCTION-NEXT: 0x209A0 R_MIPS_CHERI_CAPABILITY/R_MIPS_NONE/R_MIPS_NONE global_int{{$}} +// PER-FILE-NEXT: 0x20990 R_MIPS_CHERI_CAPABILITY/R_MIPS_NONE/R_MIPS_NONE global_int{{$}} +// GLOBAL-NEXT: 0x20890 R_MIPS_CHERI_CAPABILITY/R_MIPS_NONE/R_MIPS_NONE global_int{{$}} // CHECK-NEXT: } // CHECK-NEXT: Section ({{.+}}) .rel.plt { -// PER-FUNCTION-NEXT: 0x20920 R_MIPS_CHERI_CAPABILITY_CALL/R_MIPS_NONE/R_MIPS_NONE extern_void_ptr{{$}} -// PER-FUNCTION-NEXT: 0x20930 R_MIPS_CHERI_CAPABILITY_CALL/R_MIPS_NONE/R_MIPS_NONE extern_char_ptr{{$}} -// PER-FUNCTION-NEXT: 0x20940 R_MIPS_CHERI_CAPABILITY_CALL/R_MIPS_NONE/R_MIPS_NONE extern_void_ptr{{$}} -// PER-FUNCTION-NEXT: 0x20950 R_MIPS_CHERI_CAPABILITY_CALL/R_MIPS_NONE/R_MIPS_NONE extern_int{{$}} -// PER-FUNCTION-NEXT: 0x20970 R_MIPS_CHERI_CAPABILITY_CALL/R_MIPS_NONE/R_MIPS_NONE extern_void_ptr{{$}} -// PER-FUNCTION-NEXT: 0x20990 R_MIPS_CHERI_CAPABILITY_CALL/R_MIPS_NONE/R_MIPS_NONE extern_char_ptr{{$}} -// PER-FUNCTION-NEXT: 0x209A0 R_MIPS_CHERI_CAPABILITY_CALL/R_MIPS_NONE/R_MIPS_NONE extern_int{{$}} - -// PER-FILE-NEXT: 0x208E0 R_MIPS_CHERI_CAPABILITY_CALL/R_MIPS_NONE/R_MIPS_NONE extern_void_ptr{{$}} -// PER-FILE-NEXT: 0x208F0 R_MIPS_CHERI_CAPABILITY_CALL/R_MIPS_NONE/R_MIPS_NONE extern_char_ptr{{$}} -// PER-FILE-NEXT: 0x20900 R_MIPS_CHERI_CAPABILITY_CALL/R_MIPS_NONE/R_MIPS_NONE extern_int{{$}} - -// GLOBAL-NEXT: 0x20810 R_MIPS_CHERI_CAPABILITY_CALL/R_MIPS_NONE/R_MIPS_NONE extern_void_ptr{{$}} -// GLOBAL-NEXT: 0x20820 R_MIPS_CHERI_CAPABILITY_CALL/R_MIPS_NONE/R_MIPS_NONE extern_char_ptr{{$}} -// GLOBAL-NEXT: 0x20830 R_MIPS_CHERI_CAPABILITY_CALL/R_MIPS_NONE/R_MIPS_NONE extern_int{{$}} +// PER-FUNCTION-NEXT: 0x20960 R_MIPS_CHERI_CAPABILITY_CALL/R_MIPS_NONE/R_MIPS_NONE extern_void_ptr{{$}} +// PER-FUNCTION-NEXT: 0x20970 R_MIPS_CHERI_CAPABILITY_CALL/R_MIPS_NONE/R_MIPS_NONE extern_char_ptr{{$}} +// PER-FUNCTION-NEXT: 0x20980 R_MIPS_CHERI_CAPABILITY_CALL/R_MIPS_NONE/R_MIPS_NONE extern_void_ptr{{$}} +// PER-FUNCTION-NEXT: 0x20990 R_MIPS_CHERI_CAPABILITY_CALL/R_MIPS_NONE/R_MIPS_NONE extern_int{{$}} +// PER-FUNCTION-NEXT: 0x209B0 R_MIPS_CHERI_CAPABILITY_CALL/R_MIPS_NONE/R_MIPS_NONE extern_void_ptr{{$}} +// PER-FUNCTION-NEXT: 0x209D0 R_MIPS_CHERI_CAPABILITY_CALL/R_MIPS_NONE/R_MIPS_NONE extern_char_ptr{{$}} +// PER-FUNCTION-NEXT: 0x209E0 R_MIPS_CHERI_CAPABILITY_CALL/R_MIPS_NONE/R_MIPS_NONE extern_int{{$}} + +// PER-FILE-NEXT: 0x20960 R_MIPS_CHERI_CAPABILITY_CALL/R_MIPS_NONE/R_MIPS_NONE extern_void_ptr{{$}} +// PER-FILE-NEXT: 0x20970 R_MIPS_CHERI_CAPABILITY_CALL/R_MIPS_NONE/R_MIPS_NONE extern_char_ptr{{$}} +// PER-FILE-NEXT: 0x20980 R_MIPS_CHERI_CAPABILITY_CALL/R_MIPS_NONE/R_MIPS_NONE extern_int{{$}} + +// GLOBAL-NEXT: 0x20860 R_MIPS_CHERI_CAPABILITY_CALL/R_MIPS_NONE/R_MIPS_NONE extern_void_ptr{{$}} +// GLOBAL-NEXT: 0x20870 R_MIPS_CHERI_CAPABILITY_CALL/R_MIPS_NONE/R_MIPS_NONE extern_char_ptr{{$}} +// GLOBAL-NEXT: 0x20880 R_MIPS_CHERI_CAPABILITY_CALL/R_MIPS_NONE/R_MIPS_NONE extern_int{{$}} // CHECK-NEXT: } // CHECK-NEXT: ] // CHECK-NEXT: CHERI __cap_relocs [ -// PER-FUNCTION-NEXT: 0x020980 (function3@CAPTABLE@x.6) Base: 0x10{{.+}} (function3+0) Length: {{.+}} Perms: Function -// PER-FILE-NEXT: 0x020920 (function3@CAPTABLE@per-function-table.c.tmp.o.4) Base: 0x10{{.+}} (function3+0) Length: {{[0-9]+}} Perms: Function -// GLOBAL-NEXT: 0x020850 (function3@CAPTABLE.4) Base: 0x10{{.+}} (function3+0) Length: {{.+}} Perms: Function +// PER-FUNCTION-NEXT: 0x0209c0 (function3@CAPTABLE@x.6) Base: 0x10{{.+}} (function3) Length: {{.+}} Perms: Function +// PER-FILE-NEXT: 0x0209a0 (function3@CAPTABLE@per-function-table.c.tmp.o.4) Base: 0x10{{.+}} (function3) Length: {{[0-9]+}} Perms: Function +// GLOBAL-NEXT: 0x0208a0 (function3@CAPTABLE.4) Base: 0x10{{.+}} (function3) Length: {{.+}} Perms: Function // CHECK-NEXT: ] // CHECK-NEXT: CHERI .captable [ // PER-FUNCTION-NEXT: 0x0 extern_void_ptr@CAPTABLE@function1 R_MIPS_CHERI_CAPABILITY_CALL/R_MIPS_NONE/R_MIPS_NONE against extern_void_ptr @@ -84,15 +84,15 @@ extern int global_int; // Check that the indices for the per-function table are correct (should be 0 or 16) // SYMBOLS-LABEL: SYMBOL TABLE: -// SYMBOLS: 0000000000020920 l O .captable 0000000000000010 extern_void_ptr@CAPTABLE@function1 -// SYMBOLS: 0000000000020930 l O .captable 0000000000000010 extern_char_ptr@CAPTABLE@function2 -// SYMBOLS: 0000000000020940 l O .captable 0000000000000010 extern_void_ptr@CAPTABLE@function4 -// SYMBOLS: 0000000000020950 l O .captable 0000000000000010 extern_int@CAPTABLE@function4 -// SYMBOLS: 0000000000020960 l O .captable 0000000000000010 global_int@CAPTABLE@function5 -// SYMBOLS: 0000000000020970 l O .captable 0000000000000010 extern_void_ptr@CAPTABLE@same_globals_as_function1 -// SYMBOLS: 0000000000020980 l O .captable 0000000000000010 function3@CAPTABLE@x.6 -// SYMBOLS: 0000000000020990 l O .captable 0000000000000010 extern_char_ptr@CAPTABLE@function3 -// SYMBOLS: 00000000000209a0 l O .captable 0000000000000010 extern_int@CAPTABLE@function3 +// SYMBOLS: 0000000000020960 l O .captable 0000000000000010 extern_void_ptr@CAPTABLE@function1 +// SYMBOLS: 0000000000020970 l O .captable 0000000000000010 extern_char_ptr@CAPTABLE@function2 +// SYMBOLS: 0000000000020980 l O .captable 0000000000000010 extern_void_ptr@CAPTABLE@function4 +// SYMBOLS: 0000000000020990 l O .captable 0000000000000010 extern_int@CAPTABLE@function4 +// SYMBOLS: 00000000000209a0 l O .captable 0000000000000010 global_int@CAPTABLE@function5 +// SYMBOLS: 00000000000209b0 l O .captable 0000000000000010 extern_void_ptr@CAPTABLE@same_globals_as_function1 +// SYMBOLS: 00000000000209c0 l O .captable 0000000000000010 function3@CAPTABLE@x.6 +// SYMBOLS: 00000000000209d0 l O .captable 0000000000000010 extern_char_ptr@CAPTABLE@function3 +// SYMBOLS: 00000000000209e0 l O .captable 0000000000000010 extern_int@CAPTABLE@function3 @@ -165,13 +165,13 @@ __attribute__((noinline)) static void *function3(void) { // Check that the mapping between functions + captable subsets is sensible: // READOBJ-MAPPING: CHERI .captable per-file/per-function mapping information [ -// READOBJ-MAPPING: Function start: 0x107C0 (function1) Function end: 0x107F0 .captable offset: 0x0 Length:0x10 -// READOBJ-MAPPING: Function start: 0x107F0 (function2) Function end: 0x10820 .captable offset: 0x10 Length:0x10 -// READOBJ-MAPPING: Function start: 0x10820 (function4) Function end: 0x10870 .captable offset: 0x20 Length:0x20 -// READOBJ-MAPPING: Function start: 0x10870 (function5) Function end: 0x1087C .captable offset: 0x40 Length:0x10 -// READOBJ-MAPPING: Function start: 0x10880 (same_globals_as_function1) Function end: 0x108B0 .captable offset: 0x50 Length:0x10 -// READOBJ-MAPPING: Function start: 0x108B0 (x) Function end: 0x108D0 .captable offset: 0x60 Length:0x10 -// READOBJ-MAPPING: Function start: 0x108D0 (function3) Function end: 0x10920 .captable offset: 0x70 Length:0x20 +// READOBJ-MAPPING: Function start: 0x10800 (function1) Function end: 0x10830 .captable offset: 0x0 Length:0x10 +// READOBJ-MAPPING: Function start: 0x10830 (function2) Function end: 0x10860 .captable offset: 0x10 Length:0x10 +// READOBJ-MAPPING: Function start: 0x10860 (function4) Function end: 0x108B0 .captable offset: 0x20 Length:0x20 +// READOBJ-MAPPING: Function start: 0x108B0 (function5) Function end: 0x108BC .captable offset: 0x40 Length:0x10 +// READOBJ-MAPPING: Function start: 0x108C0 (same_globals_as_function1) Function end: 0x108F0 .captable offset: 0x50 Length:0x10 +// READOBJ-MAPPING: Function start: 0x108F0 (x) Function end: 0x10910 .captable offset: 0x60 Length:0x10 +// READOBJ-MAPPING: Function start: 0x10910 (function3) Function end: 0x10960 .captable offset: 0x70 Length:0x20 // READOBJ-MAPPING: ] @@ -179,43 +179,43 @@ __attribute__((noinline)) static void *function3(void) { // RUN: llvm-objdump --full-contents --section-headers --syms --section=.captable_mapping %t.so | FileCheck %s --check-prefix MAPPING // MAPPING: Sections: // MAPPING-NEXT: Idx Name Size VMA Type -// MAPPING-NEXT: 9 .captable_mapping 000000a8 00000000000006e8 DATA +// MAPPING-NEXT: 9 .captable_mapping 000000a8 0000000000000720 DATA // MAPPING-EMPTY: // MAPPING-NEXT: SYMBOL TABLE: -// MAPPING: 00000000[[FUNCTION3_ADDR:000108d0]] l F .text 0000000000000050 function3 -// MAPPING: 00000000[[FUNCTION1_ADDR:000107c0]] g F .text 0000000000000030 function1 -// MAPPING: 00000000[[FUNCTION2_ADDR:000107f0]] g F .text 0000000000000030 .protected function2 -// MAPPING: 00000000[[FUNCTION4_ADDR:00010820]] g F .text 0000000000000050 .protected function4 -// MAPPING: 00000000[[FUNCTION5_ADDR:00010870]] g F .text 000000000000000c function5 +// MAPPING: 00000000[[FUNCTION3_ADDR:00010910]] l F .text 0000000000000050 function3 +// MAPPING: 00000000[[FUNCTION1_ADDR:00010800]] g F .text 0000000000000030 function1 +// MAPPING: 00000000[[FUNCTION2_ADDR:00010830]] g F .text 0000000000000030 .protected function2 +// MAPPING: 00000000[[FUNCTION4_ADDR:00010860]] g F .text 0000000000000050 .protected function4 +// MAPPING: 00000000[[FUNCTION5_ADDR:000108b0]] g F .text 000000000000000c function5 // MAPPING: 0000000000000000 *UND* 0000000000000000 global_int -// MAPPING: 00000000[[SAME_GLOBALS_ADDR:00010880]] g F .text 0000000000000030 same_globals_as_function1 -// MAPPING: 00000000[[X_ADDR:000108b0]] g F .text 0000000000000020 x +// MAPPING: 00000000[[SAME_GLOBALS_ADDR:000108c0]] g F .text 0000000000000030 same_globals_as_function1 +// MAPPING: 00000000[[X_ADDR:000108f0]] g F .text 0000000000000020 x // MAPPING: Contents of section .captable_mapping: -// MAPPING-NEXT: 06e8 00000000 [[FUNCTION1_ADDR]] -// MAPPING-SAME: 00000000 000107f0 -// MAPPING-NEXT: 06f8 00000000 00000010 -// Start addr 000107c0, size 0x20, captable index 0, size 1 +// MAPPING-NEXT: 0720 00000000 [[FUNCTION1_ADDR]] +// MAPPING-SAME: 00000000 00010830 +// MAPPING-NEXT: 0730 00000000 00000010 +// Start addr 000107F0, size 0x20, captable index 0, size 1 // MAPPING-SAME: 00000000 [[FUNCTION2_ADDR]] -// MAPPING-NEXT: 0708 00000000 00010820 +// MAPPING-NEXT: 0740 00000000 00010860 // MAPPING-SAME: 00000010 00000010 -// Start addr 000107f0, size 0x20, captable index 1, size 1 -// MAPPING-NEXT: 0718 00000000 [[FUNCTION4_ADDR]] -// MAPPING-SAME: 00000000 00010870 -// MAPPING-NEXT: 0728 00000020 00000020 -// Start addr 00010820, size 0x48, captable index 2, size 2 +// Start addr 00010820, size 0x20, captable index 1, size 1 +// MAPPING-NEXT: 0750 00000000 [[FUNCTION4_ADDR]] +// MAPPING-SAME: 00000000 000108b0 +// MAPPING-NEXT: 0760 00000020 00000020 +// Start addr 00010850, size 0x48, captable index 2, size 2 // MAPPING-SAME: 00000000 [[FUNCTION5_ADDR]] -// MAPPING-NEXT: 0738 00000000 0001087c +// MAPPING-NEXT: 0770 00000000 000108bc // MAPPING-SAME: 00000040 00000010 -// Start addr 00010870, size 0xc, captable index 4, size 1 -// MAPPING-NEXT: 0748 00000000 [[SAME_GLOBALS_ADDR]] -// MAPPING-SAME: 00000000 000108b0 -// MAPPING-NEXT: 0758 00000050 00000010 -// Start addr 00010880, size 0x20, captable index 5, size 1 +// Start addr 000108a0, size 0xc, captable index 4, size 1 +// MAPPING-NEXT: 0780 00000000 [[SAME_GLOBALS_ADDR]] +// MAPPING-SAME: 00000000 000108f0 +// MAPPING-NEXT: 0790 00000050 00000010 +// Start addr 000108b0, size 0x20, captable index 5, size 1 // MAPPING-SAME: 00000000 [[X_ADDR]] -// MAPPING-NEXT: 0768 00000000 000108d0 +// MAPPING-NEXT: 07a0 00000000 00010910 // MAPPING-SAME: 00000060 00000010 -// Start addr 000108b0, size 0x20, captable index 6, size 1 -// MAPPING-NEXT: 0778 00000000 [[FUNCTION3_ADDR]] -// MAPPING-SAME: 00000000 00010920 -// MAPPING-NEXT: 0788 00000070 00000020 -// Start addr 000108d0, size 0x48, captable index 7, size 2 +// Start addr 000108e0, size 0x20, captable index 6, size 1 +// MAPPING-NEXT: 07b0 00000000 [[FUNCTION3_ADDR]] +// MAPPING-SAME: 00000000 00010960 +// MAPPING-NEXT: 07c0 00000070 00000020 +// Start addr 00010900, size 0x48, captable index 7, size 2 diff --git a/lld/test/ELF/cheri/cap-table/fnptr-vs-call.c b/lld/test/ELF/cheri/cap-table/fnptr-vs-call.c index 9e57e45dead7f..bbba45188eeac 100644 --- a/lld/test/ELF/cheri/cap-table/fnptr-vs-call.c +++ b/lld/test/ELF/cheri/cap-table/fnptr-vs-call.c @@ -40,7 +40,7 @@ // RUN: llvm-readobj --dynamic-table -r %t-call1.so | FileCheck --check-prefix ONE-CALL %s // ONE-CALL-LABEL: DynamicSection [ // ONE-CALL-NEXT: Tag Type Name/Value -// ONE-CALL-NEXT: 0x0000000000000017 JMPREL 0x3F8 +// ONE-CALL-NEXT: 0x0000000000000017 JMPREL 0x430 // ONE-CALL-NEXT: 0x0000000000000002 PLTRELSZ 16 (bytes) // ONE-CALL-NEXT: 0x0000000070000032 MIPS_PLTGOT 0x0 // ONE-CALL-NEXT: 0x0000000000000014 PLTREL REL @@ -53,7 +53,7 @@ // RUN: llvm-readobj --dynamic-table -r %t-2calls.so | FileCheck --check-prefix TWO-CALLS %s // TWO-CALLS-LABEL: DynamicSection [ // TWO-CALLS-NEXT: Tag Type Name/Value -// TWO-CALLS-NEXT: 0x0000000000000017 JMPREL 0x448 +// TWO-CALLS-NEXT: 0x0000000000000017 JMPREL 0x480 // TWO-CALLS-NEXT: 0x0000000000000002 PLTRELSZ 32 (bytes) // TWO-CALLS-NEXT: 0x0000000070000032 MIPS_PLTGOT 0x0 // TWO-CALLS-NEXT: 0x0000000000000014 PLTREL REL @@ -83,10 +83,10 @@ // RUN: llvm-readobj --dynamic-table -r %t-all.so | FileCheck --check-prefix ALL %s // ALL-LABEL: DynamicSection [ // ALL-NEXT: Tag Type Name/Value -// ALL-NEXT: 0x0000000000000011 REL 0x4D0 +// ALL-NEXT: 0x0000000000000011 REL 0x508 // ALL-NEXT: 0x0000000000000012 RELSZ 32 (bytes) // ALL-NEXT: 0x0000000000000013 RELENT 16 (bytes) -// ALL-NEXT: 0x0000000000000017 JMPREL 0x4F0 +// ALL-NEXT: 0x0000000000000017 JMPREL 0x528 // ALL-NEXT: 0x0000000000000002 PLTRELSZ 16 (bytes) // ALL-NEXT: 0x0000000070000032 MIPS_PLTGOT 0x0 // ALL-NEXT: 0x0000000000000014 PLTREL REL diff --git a/lld/test/ELF/cheri/cap-table/global-capabilities.c b/lld/test/ELF/cheri/cap-table/global-capabilities.c index 7544dfa7c3492..a630acf5e1fbe 100644 --- a/lld/test/ELF/cheri/cap-table/global-capabilities.c +++ b/lld/test/ELF/cheri/cap-table/global-capabilities.c @@ -23,14 +23,14 @@ // RELOCS-NEXT: } // EXE-LABEL: CAPABILITY RELOCATION RECORDS: -// EXE-NEXT: 0x0000000000030470 Base: functions (0x00000000000404b0) Offset: 0x0000000000000000 Length: 0x0000000000000040 Permissions: 0x00000000 -// EXE-NEXT: 0x0000000000030480 Base: string (0x00000000000404a0) Offset: 0x0000000000000000 Length: 0x0000000000000010 Permissions: 0x00000000 -// EXE-NEXT: 0x0000000000040490 Base: func (0x00000000000203e0) Offset: 0x0000000000000000 Length: 0x0000000000000008 Permissions: 0x8000000000000000 (Function) -// EXE-NEXT: 0x00000000000404a0 Base: (0x0000000000010285) Offset: 0x0000000000000000 Length: 0x000000000000000e Permissions: 0x4000000000000000 (Constant) -// EXE-NEXT: 0x00000000000404b0 Base: (0x000000000001027f) Offset: 0x0000000000000000 Length: 0x0000000000000006 Permissions: 0x4000000000000000 (Constant) -// EXE-NEXT: 0x00000000000404c0 Base: func1 (0x00000000000203e8) Offset: 0x0000000000000000 Length: 0x0000000000000008 Permissions: 0x8000000000000000 (Function) -// EXE-NEXT: 0x00000000000404d0 Base: (0x0000000000010278) Offset: 0x0000000000000000 Length: 0x0000000000000007 Permissions: 0x4000000000000000 (Constant) -// EXE-NEXT: 0x00000000000404e0 Base: func2 (0x00000000000203f0) Offset: 0x0000000000000000 Length: 0x0000000000000008 Permissions: 0x8000000000000000 (Function) +// EXE-NEXT: 0x00000000000304f0 Base: functions (0x0000000000040530) Offset: 0x0000000000000000 Length: 0x0000000000000040 Permissions: 0x00000000 +// EXE-NEXT: 0x0000000000030500 Base: string (0x0000000000040520) Offset: 0x0000000000000000 Length: 0x0000000000000010 Permissions: 0x00000000 +// EXE-NEXT: 0x0000000000040510 Base: func (0x0000000000020460) Offset: 0x0000000000000000 Length: 0x0000000000000008 Permissions: 0x8000000000000000 (Function) +// EXE-NEXT: 0x0000000000040520 Base: (0x000000000001030d) Offset: 0x0000000000000000 Length: 0x000000000000000e Permissions: 0x4000000000000000 (Constant) +// EXE-NEXT: 0x0000000000040530 Base: (0x0000000000010307) Offset: 0x0000000000000000 Length: 0x0000000000000006 Permissions: 0x4000000000000000 (Constant) +// EXE-NEXT: 0x0000000000040540 Base: func1 (0x0000000000020468) Offset: 0x0000000000000000 Length: 0x0000000000000008 Permissions: 0x8000000000000000 (Function) +// EXE-NEXT: 0x0000000000040550 Base: (0x0000000000010300) Offset: 0x0000000000000000 Length: 0x0000000000000007 Permissions: 0x4000000000000000 (Constant) +// EXE-NEXT: 0x0000000000040560 Base: func2 (0x0000000000020470) Offset: 0x0000000000000000 Length: 0x0000000000000008 Permissions: 0x8000000000000000 (Function) void func(int a) { diff --git a/lld/test/ELF/cheri/cap-table/interposing_table.c b/lld/test/ELF/cheri/cap-table/interposing_table.c index b849ddc3a0eac..1e36cf8b5cfad 100644 --- a/lld/test/ELF/cheri/cap-table/interposing_table.c +++ b/lld/test/ELF/cheri/cap-table/interposing_table.c @@ -62,4 +62,4 @@ int __start(void) { // CHECK: SYMBOL TABLE: // CHECK: 0000000[[libc_interposing_addr:[0-9a-f]+]] l O .data 0000000000000540 .hidden __libc_interposing // CHECK: CAPABILITY RELOCATION RECORDS: -// CHECK: 0x0000000[[libc_interposing_addr]] Base: __wrap_accept (0x0000000000021020) Offset: 0x0000000000000000 Length: 0x0000000000000038 Permissions: 0x8000000000000000 (Function) +// CHECK: 0x0000000[[libc_interposing_addr]] Base: __wrap_accept (0x0000000000021050) Offset: 0x0000000000000000 Length: 0x0000000000000038 Permissions: 0x8000000000000000 (Function) diff --git a/lld/test/ELF/cheri/cap-table/jump-table-size.c b/lld/test/ELF/cheri/cap-table/jump-table-size.c index cd2b28167c5ae..92152355a4a94 100644 --- a/lld/test/ELF/cheri/cap-table/jump-table-size.c +++ b/lld/test/ELF/cheri/cap-table/jump-table-size.c @@ -16,16 +16,16 @@ // EXE: SYMBOL TABLE: -// EXE-DAG: 0000000000010278 l .rodata 0000000000000024 .LJTI0_0 -// EXE-DAG: 0000000000030340 l O .captable 00000000000000{{1|2}}0 .LJTI0_0@CAPTABLE +// EXE-DAG: 0000000000010300 l .rodata 0000000000000024 .LJTI0_0 +// EXE-DAG: 00000000000303c0 l O .captable 00000000000000{{1|2}}0 .LJTI0_0@CAPTABLE // __cap_relocs should contain length: // EXE: CAPABILITY RELOCATION RECORDS: -// EXE-NEXT: 0x0000000000030340 Base: .LJTI0_0 (0x0000000000010278) Offset: 0x0000000000000000 Length: 0x0000000000000024 Permissions: 0x4000000000000000 (Constant) +// EXE-NEXT: 0x00000000000303c0 Base: .LJTI0_0 (0x0000000000010300) Offset: 0x0000000000000000 Length: 0x0000000000000024 Permissions: 0x4000000000000000 (Constant) -// EXE: 202e4: 3c 01 00 00 lui $1, 0 -// EXE-NEXT: 202e8: 64 21 00 00 daddiu $1, $1, 0 -// EXE-NEXT: 202ec: d8 3a 08 00 clc $c1, $1, 0($c26) +// EXE: 20364: 3c 01 00 00 lui $1, 0 +// EXE-NEXT: 20368: 64 21 00 00 daddiu $1, $1, 0 +// EXE-NEXT: 2036c: d8 3a 08 00 clc $c1, $1, 0($c26) int __start(int i) { switch(i) { diff --git a/lld/test/ELF/cheri/cap-table/local-fn-ptr-in-plt-abi.c b/lld/test/ELF/cheri/cap-table/local-fn-ptr-in-plt-abi.c index 922b15f074fca..0e1696fa86e69 100644 --- a/lld/test/ELF/cheri/cap-table/local-fn-ptr-in-plt-abi.c +++ b/lld/test/ELF/cheri/cap-table/local-fn-ptr-in-plt-abi.c @@ -14,7 +14,7 @@ // Build a shared library that uses the function pointer: // RUN: ld.lld -shared %t-shlib.o -o %t-shlib.so // RUN: llvm-objdump --syms %t-shlib.so | FileCheck %s --check-prefix SHLIB-DUMP -// SHLIB-DUMP: 0000000000010380 g F .text 000000{{[0-9a-f]+}} use_callback +// SHLIB-DUMP: 0000000000010400 g F .text 000000{{[0-9a-f]+}} use_callback // Check that we emit a R_CHERI_CAPABILITY relocation instead of __cap_relocs for shlib/pie/dynamically linked exe // RUN: ld.lld -shared %t.o %t-shlib.so -o %t.so --verbose-cap-relocs 2>&1 | FileCheck %s -check-prefixes VERBOSE-MSG @@ -117,9 +117,9 @@ // STATIC-NEXT: DynamicSymbols [ // STATIC-NEXT: ] // STATIC-NEXT: CHERI __cap_relocs [ -// STATIC-NEXT: 0x0303c0 (return1@CAPTABLE.0) Base: 0x20368 (return1+0) Length: 12 Perms: Function -// STATIC-NEXT: 0x0303d0 (use_callback@CAPTABLE) Base: 0x20380 (use_callback+0) Length: {{[0-9]+}} Perms: Function -// STATIC-NEXT: 0x0303e0 (global_return2@CAPTABLE) Base: 0x202f0 (global_return2+0) Length: 12 Perms: Function +// STATIC-NEXT: 0x0304d0 (return1@CAPTABLE.0) Base: 0x20478 (return1) Length: 12 Perms: Function +// STATIC-NEXT: 0x0304e0 (use_callback@CAPTABLE) Base: 0x20490 (use_callback) Length: {{[0-9]+}} Perms: Function +// STATIC-NEXT: 0x0304f0 (global_return2@CAPTABLE) Base: 0x20400 (global_return2) Length: 12 Perms: Function // STATIC-NEXT: ] // STATIC-NEXT: CHERI .captable [ // STATIC-NEXT: 0x0 return1@CAPTABLE.0 diff --git a/lld/test/ELF/cheri/cap-table/non-preemptible-fn-ptr-unique-plt-abi.c b/lld/test/ELF/cheri/cap-table/non-preemptible-fn-ptr-unique-plt-abi.c index 184171d363cf0..99d638197100d 100644 --- a/lld/test/ELF/cheri/cap-table/non-preemptible-fn-ptr-unique-plt-abi.c +++ b/lld/test/ELF/cheri/cap-table/non-preemptible-fn-ptr-unique-plt-abi.c @@ -114,8 +114,8 @@ // CHECK-NEXT: ] // __cap_relocs should be empty other than the one global reference to callbacks // CHECK-NEXT: CHERI __cap_relocs [ -// CHECK-NEXT: 0x{{.+}} (check_if_default@CAPTABLE) Base: 0x{{.+}} (check_if_default+0) Length: {{.+}} Perms: Function -// CHECK-NEXT: 0x{{.+}} (callbacks@CAPTABLE.3) Base: 0x{{.+}} (callbacks+0) Length: 64 Perms: Constant +// CHECK-NEXT: 0x{{.+}} (check_if_default@CAPTABLE) Base: 0x{{.+}} (check_if_default) Length: {{.+}} Perms: Function +// CHECK-NEXT: 0x{{.+}} (callbacks@CAPTABLE.3) Base: 0x{{.+}} (callbacks) Length: 64 Perms: Constant // CHECK-NEXT: ] // CHECK-NEXT: CHERI .captable [ // CHECK-NEXT: 0x0 default_callback@CAPTABLE R_MIPS_CHERI_CAPABILITY/R_MIPS_NONE/R_MIPS_NONE against {{default_callback|__cheri_fnptr_default_callback}} @@ -134,14 +134,14 @@ // STATIC-NEXT: DynamicSymbols [ // STATIC-NEXT: ] // STATIC-NEXT: CHERI __cap_relocs [ -// STATIC-NEXT: 0x030600 (callbacks) Base: 0x203c0 (default_callback+0) Length: 12 Perms: Function -// STATIC-NEXT: 0x030610 Base: 0x20448 (static_callback+0) Length: 12 Perms: Function -// STATIC-NEXT: 0x030620 Base: 0x203c0 (default_callback+0) Length: 12 Perms: Function -// STATIC-NEXT: 0x030630 Base: 0x20448 (static_callback+0) Length: 12 Perms: Function -// STATIC-NEXT: 0x030640 (default_callback@CAPTABLE) Base: 0x203c0 (default_callback+0) Length: 12 Perms: Function -// STATIC-NEXT: 0x030650 (check_if_default@CAPTABLE) Base: 0x205d0 (check_if_default+0) Length: {{.+}} Perms: Function -// STATIC-NEXT: 0x030660 (static_callback@CAPTABLE.2) Base: 0x20448 (static_callback+0) Length: 12 Perms: Function -// STATIC-NEXT: 0x030670 (callbacks@CAPTABLE.3) Base: 0x30600 (callbacks+0) Length: 64 Perms: Constant +// STATIC-NEXT: 0x030640 (callbacks) Base: 0x20400 (default_callback) Length: 12 Perms: Function +// STATIC-NEXT: 0x030650 Base: 0x20488 (static_callback) Length: 12 Perms: Function +// STATIC-NEXT: 0x030660 Base: 0x20400 (default_callback) Length: 12 Perms: Function +// STATIC-NEXT: 0x030670 Base: 0x20488 (static_callback) Length: 12 Perms: Function +// STATIC-NEXT: 0x030680 (default_callback@CAPTABLE) Base: 0x20400 (default_callback) Length: 12 Perms: Function +// STATIC-NEXT: 0x030690 (check_if_default@CAPTABLE) Base: 0x20610 (check_if_default) Length: {{.+}} Perms: Function +// STATIC-NEXT: 0x0306a0 (static_callback@CAPTABLE.2) Base: 0x20488 (static_callback) Length: 12 Perms: Function +// STATIC-NEXT: 0x0306b0 (callbacks@CAPTABLE.3) Base: 0x30640 (callbacks) Length: 64 Perms: Constant // STATIC-NEXT: ] // STATIC-NEXT: CHERI .captable [ // STATIC-NEXT: 0x0 default_callback@CAPTABLE diff --git a/lld/test/ELF/cheri/cap-table/relaplt-link.c b/lld/test/ELF/cheri/cap-table/relaplt-link.c index ea55b69328316..1f12e1f09d672 100644 --- a/lld/test/ELF/cheri/cap-table/relaplt-link.c +++ b/lld/test/ELF/cheri/cap-table/relaplt-link.c @@ -94,7 +94,7 @@ // PURECAP-OBJ-NEXT: } // RUN: ld.lld -shared -o %t.so %t.o // RUN: llvm-readobj --dynamic-table --file-headers -r --sections %t.so | FileCheck --check-prefix PURECAP-SHLIB %s -// PURECAP-SHLIB: SectionHeaderCount: 20 +// PURECAP-SHLIB: SectionHeaderCount: 21 // PURECAP-SHLIB: Section { // PURECAP-SHLIB: Index: [[DYNSYM_INDEX:3]] // PURECAP-SHLIB-NEXT: Name: .dynsym @@ -155,7 +155,7 @@ // PURECAP-SHLIB-NEXT: } // RUN: llvm-strip -o - %t.so | llvm-readobj --file-headers - | FileCheck %s --check-prefix PURECAP-STRIPPED -// PURECAP-STRIPPED: SectionHeaderCount: 15 +// PURECAP-STRIPPED: SectionHeaderCount: 16 extern void* extern_function(void *); diff --git a/lld/test/ELF/cheri/cap-table/relocatable-output.c b/lld/test/ELF/cheri/cap-table/relocatable-output.c index bfde7ca20f42d..87d507a787e02 100644 --- a/lld/test/ELF/cheri/cap-table/relocatable-output.c +++ b/lld/test/ELF/cheri/cap-table/relocatable-output.c @@ -14,7 +14,7 @@ // RUN: ld.lld -o %t.exe %t-combined.o // This previously failed with a duplicate _CHERI_CAPABILITY_TABLE_ symbol error // RUN: llvm-objdump -t %t.exe | FileCheck %s -// CHECK: 0000000000030320 l .captable 00000000000000{{3|6}}0 .hidden _CHERI_CAPABILITY_TABLE_ +// CHECK: 0000000000030430 l .captable 00000000000000{{3|6}}0 .hidden _CHERI_CAPABILITY_TABLE_ #ifdef FIRST int global = 1; diff --git a/lld/test/ELF/cheri/cap-table/simple-global-access.c b/lld/test/ELF/cheri/cap-table/simple-global-access.c index 0dcc5b7bf089a..0d14c99f12bd8 100644 --- a/lld/test/ELF/cheri/cap-table/simple-global-access.c +++ b/lld/test/ELF/cheri/cap-table/simple-global-access.c @@ -17,8 +17,8 @@ // EXE-DAG: [[GLOBAL_CAPTAB:[0-9a-f]+]] l O .captable 00000000000000{{1|2}}0 global@CAPTABLE // EXE-DAG: [[GLOBAL2_CAPTAB:[0-9a-f]+]] l O .captable 00000000000000{{1|2}}0 global2@CAPTABLE // EXE-LABEL: CAPABILITY RELOCATION RECORDS: -// EXE-NEXT: 0x[[GLOBAL_CAPTAB]] Base: global (0x00000000000403{{3|6}}0) Offset: 0x0000000000000000 Length: 0x0000000000000004 Permissions: 0x00000000 -// EXE-NEXT: 0x[[GLOBAL2_CAPTAB]] Base: global2 (0x00000000000403{{3|6}}8) Offset: 0x0000000000000000 Length: 0x0000000000000008 Permissions: 0x00000000 +// EXE-NEXT: 0x[[GLOBAL_CAPTAB]] Base: global (0x00000000000403{{6|7}}0) Offset: 0x0000000000000000 Length: 0x0000000000000004 Permissions: 0x00000000 +// EXE-NEXT: 0x[[GLOBAL2_CAPTAB]] Base: global2 (0x00000000000403{{6|7}}8) Offset: 0x0000000000000000 Length: 0x0000000000000008 Permissions: 0x00000000 // EXE: 3c 01 00 00 lui $1, 0 // EXE-NEXT: 64 21 00 00 daddiu $1, $1, 0 diff --git a/lld/test/ELF/cheri/cap-table/unnamed-symbols.c b/lld/test/ELF/cheri/cap-table/unnamed-symbols.c index a93e5c0de8633..1bcc2c45d9f38 100644 --- a/lld/test/ELF/cheri/cap-table/unnamed-symbols.c +++ b/lld/test/ELF/cheri/cap-table/unnamed-symbols.c @@ -39,9 +39,9 @@ int __start(void) { return get_number(1) == get_ordinal(2); } #endif // CHECK-LABEL: CAPABILITY RELOCATION RECORDS: -// CHECK-NEXT: Base: t (0x00000000000404e0) Offset: 0x0000000000000000 Length: 0x0000000000000040 Permissions: 0x00000000 -// CHECK-NEXT: Base: t (0x0000000000040520) Offset: 0x0000000000000000 Length: 0x0000000000000040 Permissions: 0x00000000 -// CHECK-NEXT: Base: get_number (0x00000000000203d0) Offset: 0x0000000000000000 Length: 0x00000000000000{{.+}} Permissions: 0x8000000000000000 (Function) +// CHECK-NEXT: Base: t (0x0000000000040570) Offset: 0x0000000000000000 Length: 0x0000000000000040 Permissions: 0x00000000 +// CHECK-NEXT: Base: t (0x00000000000405b0) Offset: 0x0000000000000000 Length: 0x0000000000000040 Permissions: 0x00000000 +// CHECK-NEXT: Base: get_number (0x0000000000020460) Offset: 0x0000000000000000 Length: 0x00000000000000{{.+}} Permissions: 0x8000000000000000 (Function) // CHECK-NEXT: Base: get_ordinal (0x0000000000020{{.+}}) Offset: 0x0000000000000000 Length: 0x00000000000000{{.+}} Permissions: 0x8000000000000000 (Function) // CHECK-NEXT: Base: (0x0000000000010{{.+}}) Offset: 0x0000000000000000 Length: 0x0000000000000004 Permissions: 0x4000000000000000 (Constant) // CHECK-NEXT: Base: (0x0000000000010{{.+}}) Offset: 0x0000000000000000 Length: 0x0000000000000004 Permissions: 0x4000000000000000 (Constant) diff --git a/lld/test/ELF/cheri/cap-table/weak-symbols.c b/lld/test/ELF/cheri/cap-table/weak-symbols.c index cb6acfbeb44cd..0beef97815a43 100644 --- a/lld/test/ELF/cheri/cap-table/weak-symbols.c +++ b/lld/test/ELF/cheri/cap-table/weak-symbols.c @@ -32,30 +32,30 @@ int __start(void) { return 0; } // EXE-LABEL: SYMBOL TABLE -// DYNAMIC-EXE: 0000000000020730 l .preinit_array 0000000000000008 .hidden __preinit_array_start -// DYNAMIC-EXE: 0000000000020738 l .preinit_array 0000000000000000 .hidden __preinit_array_end -// DYNAMIC-EXE: 0000000000010620 l .text 0000000000000000 .hidden __init_array_start +// DYNAMIC-EXE: 0000000000020810 l .preinit_array 0000000000000008 .hidden __preinit_array_start +// DYNAMIC-EXE: 0000000000020818 l .preinit_array 0000000000000000 .hidden __preinit_array_end +// DYNAMIC-EXE: 0000000000010700 l .text 0000000000000000 .hidden __init_array_start // ^------- Start of .text segment (actual value doesn't matter as long as iteration terminates immediately) -// DYNAMIC-EXE: 0000000000010620 l .text 0000000000000000 .hidden __init_array_end -// DYNAMIC-EXE: 00000000000002d8 l .dynamic 0000000000000{{.+}} .hidden _DYNAMIC -// DYNAMIC-EXE: 0000000000030810 g .bss 0000000000000000 end -// DYNAMIC-EXE: 0000000000030810 g .bss 0000000000000000 _end -// DYNAMIC-EXE: 0000000000010730 g .text 0000000000000000 etext -// DYNAMIC-EXE: 0000000000010730 g .text 0000000000000000 _etext -// DYNAMIC-EXE: 0000000000030810 g .got 0000000000000000 edata -// DYNAMIC-EXE: 0000000000030810 g .got 0000000000000000 _edata -// DYNAMIC-EXE: 0000000000010728 g F .text 0000000000000008 __start - -// STATIC-EXE: 0000000000030520 l .preinit_array 0000000000000008 .hidden __preinit_array_start -// STATIC-EXE: 0000000000030528 l .preinit_array 0000000000000000 .hidden __preinit_array_end -// STATIC-EXE: 0000000000020410 l .text 0000000000000000 .hidden __init_array_start +// DYNAMIC-EXE: 0000000000010700 l .text 0000000000000000 .hidden __init_array_end +// DYNAMIC-EXE: 0000000000000310 l .dynamic 0000000000000{{.+}} .hidden _DYNAMIC +// DYNAMIC-EXE: 0000000000030900 g .bss 0000000000000000 end +// DYNAMIC-EXE: 0000000000030900 g .bss 0000000000000000 _end +// DYNAMIC-EXE: 0000000000010810 g .text 0000000000000000 etext +// DYNAMIC-EXE: 0000000000010810 g .text 0000000000000000 _etext +// DYNAMIC-EXE: 0000000000030900 g .pad.cheri.pcc 0000000000000000 edata +// DYNAMIC-EXE: 0000000000030900 g .pad.cheri.pcc 0000000000000000 _edata +// DYNAMIC-EXE: 0000000000010808 g F .text 0000000000000008 __start + +// STATIC-EXE: 0000000000030610 l .preinit_array 0000000000000008 .hidden __preinit_array_start +// STATIC-EXE: 0000000000030618 l .preinit_array 0000000000000000 .hidden __preinit_array_end +// STATIC-EXE: 0000000000020500 l .text 0000000000000000 .hidden __init_array_start // ^------- Start of .text segment (actual value doesn't matter as long as iteration terminates immediately) -// STATIC-EXE: 0000000000020410 l .text 0000000000000000 .hidden __init_array_end -// STATIC-EXE: 00000000000405f0 g .bss 0000000000000000 end -// STATIC-EXE: 00000000000405f0 g .bss 0000000000000000 _end -// STATIC-EXE: 0000000000020520 g .text 0000000000000000 etext -// STATIC-EXE: 0000000000020520 g .text 0000000000000000 _etext -// STATIC-EXE: 00000000000405f0 g .got 0000000000000000 edata -// STATIC-EXE: 00000000000405f0 g .got 0000000000000000 _edata +// STATIC-EXE: 0000000000020500 l .text 0000000000000000 .hidden __init_array_end +// STATIC-EXE: 0000000000040700 g .bss 0000000000000000 end +// STATIC-EXE: 0000000000040700 g .bss 0000000000000000 _end +// STATIC-EXE: 0000000000020610 g .text 0000000000000000 etext +// STATIC-EXE: 0000000000020610 g .text 0000000000000000 _etext +// STATIC-EXE: 0000000000040700 g .pad.cheri.pcc 0000000000000000 edata +// STATIC-EXE: 0000000000040700 g .pad.cheri.pcc 0000000000000000 _edata // STATIC-EXE: 0000000000000000 w *UND* 0000000000000000 _DYNAMIC -// STATIC-EXE: 0000000000020518 g F .text 0000000000000008 __start +// STATIC-EXE: 0000000000020608 g F .text 0000000000000008 __start diff --git a/lld/test/ELF/cheri/caprelocs-surrounding-symbol.s b/lld/test/ELF/cheri/caprelocs-surrounding-symbol.s index 16c1a02aad334..461d672852d0e 100644 --- a/lld/test/ELF/cheri/caprelocs-surrounding-symbol.s +++ b/lld/test/ELF/cheri/caprelocs-surrounding-symbol.s @@ -76,10 +76,10 @@ fn_reloc1: # OBJ-RELOCS-NEXT: } # LLD-OUTPUT-NEXT: Found better match for capability relocation against .Lfirst_fn_target+0: fn1+8 # EXE-RELOCS-NEXT: Relocation { -# EXE-RELOCS-NEXT: Location: 0x3440 (fn_reloc1) -# EXE-RELOCS-NEXT: Base: fn1 (0x1338) +# EXE-RELOCS-NEXT: Location: 0x3480 (fn_reloc1) +# EXE-RELOCS-NEXT: Base: fn1 (0x1370) # EXE-RELOCS-NEXT: Offset: 8 -# EXE-RELOCS-NEXT: Length: 12 +# EXE-RELOCS-NEXT: Length: 24 # EXE-RELOCS-NEXT: Permissions: Function (0x8000000000000000) # EXE-RELOCS-NEXT: } @@ -101,10 +101,10 @@ fn_reloc2: # OBJ-RELOCS-NEXT: } # LLD-OUTPUT-NEXT: Found better match for capability relocation against .Lsecond_fn_target+0: .Lfn2$start+8 # EXE-RELOCS-NEXT: Relocation { -# EXE-RELOCS-NEXT: Location: 0x3450 (fn_reloc2) -# EXE-RELOCS-NEXT: Base: .Lfn2$start (0x1344) -# EXE-RELOCS-NEXT: Offset: 8 -# EXE-RELOCS-NEXT: Length: 12 +# EXE-RELOCS-NEXT: Location: 0x3490 (fn_reloc2) +# EXE-RELOCS-NEXT: Base: fn1 (0x1370) +# EXE-RELOCS-NEXT: Offset: 20 +# EXE-RELOCS-NEXT: Length: 24 # EXE-RELOCS-NEXT: Permissions: Function (0x8000000000000000) # EXE-RELOCS-NEXT: } data_reloc1: @@ -117,8 +117,8 @@ data_reloc1: # OBJ-RELOCS-NEXT: } # LLD-OUTPUT-NEXT: Found better match for capability relocation against .Linside_obj1+0: obj1+16 # EXE-RELOCS-NEXT: Relocation { -# EXE-RELOCS-NEXT: Location: 0x3460 (data_reloc1) -# EXE-RELOCS-NEXT: Base: obj1 (0x3400) +# EXE-RELOCS-NEXT: Location: 0x34A0 (data_reloc1) +# EXE-RELOCS-NEXT: Base: obj1 (0x3438) # EXE-RELOCS-NEXT: Offset: 16 # EXE-RELOCS-NEXT: Length: 32 # EXE-RELOCS-NEXT: Permissions: Object (0x0) @@ -137,8 +137,8 @@ data_reloc2: # LLD-OUTPUT-NEXT: >>> defined in {{.+}}caprelocs-surrounding-symbol.s.tmp.o:(.relocs_section+0x30)) # LLD-OUTPUT-EMPTY: # EXE-RELOCS-NEXT: Relocation { -# EXE-RELOCS-NEXT: Location: 0x3470 (data_reloc2) -# EXE-RELOCS-NEXT: Base: obj2_subobject1 (0x3430) +# EXE-RELOCS-NEXT: Location: 0x34B0 (data_reloc2) +# EXE-RELOCS-NEXT: Base: obj2_subobject1 (0x3468) # EXE-RELOCS-NEXT: Offset: 0 # EXE-RELOCS-NEXT: Length: 16 # EXE-RELOCS-NEXT: Permissions: Object (0x0) @@ -152,8 +152,8 @@ data_reloc3: # OBJ-RELOCS-NEXT: Addend: 0x0 # OBJ-RELOCS-NEXT: } # EXE-RELOCS-NEXT: Relocation { -# EXE-RELOCS-NEXT: Location: 0x3480 (data_reloc3) -# EXE-RELOCS-NEXT: Base: obj2_subobject2 (0x3431) +# EXE-RELOCS-NEXT: Location: 0x34C0 (data_reloc3) +# EXE-RELOCS-NEXT: Base: obj2_subobject2 (0x3469) # EXE-RELOCS-NEXT: Offset: 0 # EXE-RELOCS-NEXT: Length: 15 # EXE-RELOCS-NEXT: Permissions: Object (0x0) @@ -169,8 +169,8 @@ data_reloc4: # LLD-OUTPUT-NEXT: Found better match for capability relocation against .Linside_obj2_subobject2+0: obj2+18 # LLD-OUTPUT-NEXT: Found better match for capability relocation against obj2+18: obj2_subobject2+1 # EXE-RELOCS-NEXT: Relocation { -# EXE-RELOCS-NEXT: Location: 0x3490 (data_reloc4) -# EXE-RELOCS-NEXT: Base: obj2_subobject2 (0x3431) +# EXE-RELOCS-NEXT: Location: 0x34D0 (data_reloc4) +# EXE-RELOCS-NEXT: Base: obj2_subobject2 (0x3469) # EXE-RELOCS-NEXT: Offset: 1 # EXE-RELOCS-NEXT: Length: 15 # EXE-RELOCS-NEXT: Permissions: Object (0x0) diff --git a/lld/test/ELF/cheri/dyn-relocs-in-exe.s b/lld/test/ELF/cheri/dyn-relocs-in-exe.s index aeb5ae7e95f08..3595743ee4bd4 100644 --- a/lld/test/ELF/cheri/dyn-relocs-in-exe.s +++ b/lld/test/ELF/cheri/dyn-relocs-in-exe.s @@ -43,5 +43,5 @@ dummy_shlib: # DYN-RELOCS: Dynamic Relocations { # DYN-RELOCS-NEXT: } # DYN-RELOCS: CHERI __cap_relocs [ -# DYN-RELOCS-NEXT: 0x{{.+}} (capsym) Base: 0x{{.+}} (__start+0) Length: 4 Perms: Function +# DYN-RELOCS-NEXT: 0x{{.+}} (capsym) Base: 0x{{.+}} (__start) Length: 4 Perms: Function # DYN-RELOCS: ] diff --git a/lld/test/ELF/cheri/dynamic-cap-reloc.s b/lld/test/ELF/cheri/dynamic-cap-reloc.s index fda9cd50f3cfb..7cd62c38811a7 100644 --- a/lld/test/ELF/cheri/dynamic-cap-reloc.s +++ b/lld/test/ELF/cheri/dynamic-cap-reloc.s @@ -43,24 +43,24 @@ local_ref_with_addend: # DYN-RELOCS-LABEL: DynamicSection [ # DYN-RELOCS: 0x000000007000C002 MIPS_CHERI_FLAGS ABI_PCREL RELATIVE_CAPRELOCS {{$}} -# DYN-RELOCS: 0x000000007000C000 MIPS_CHERI___CAPRELOCS 0x3E0 +# DYN-RELOCS: 0x000000007000C000 MIPS_CHERI___CAPRELOCS 0x418 # DYN-RELOCS: 0x000000007000C001 MIPS_CHERI___CAPRELOCSSZ 0x50 # DYN-RELOCS-LABEL: Dynamic Relocations { # the first two are for the __cap_relocs section (legacy mode) -# DYN-RELOCS-NEXT: 0x{{20490|30520}} R_MIPS_CHERI_CAPABILITY/R_MIPS_NONE/R_MIPS_NONE foo{{$}} # DYN-RELOCS-NEXT: 0x{{204D0|30560}} R_MIPS_CHERI_CAPABILITY/R_MIPS_NONE/R_MIPS_NONE foo{{$}} +# DYN-RELOCS-NEXT: 0x{{20510|305A0}} R_MIPS_CHERI_CAPABILITY/R_MIPS_NONE/R_MIPS_NONE foo{{$}} # DYN-RELOCS-NEXT: } # DYN-RELOCS-LABEL: CHERI __cap_relocs [ -# DYN-RELOCS-NEXT: 0x0204b0 (local_ref) Base: 0x10480 (bar+0) Length: 8 Perms: Function -# DYN-RELOCS-NEXT: 0x0204f0 (local_ref_with_addend) Base: 0x10480 (bar+4) Length: 8 Perms: Function +# DYN-RELOCS-NEXT: 0x0204f0 (local_ref) Base: 0x104c0 (bar) Length: 8 Perms: Function +# DYN-RELOCS-NEXT: 0x020530 (local_ref_with_addend) Base: 0x104c0 (bar+4) Length: 8 Perms: Function # DYN-RELOCS-NEXT: ] # DUMP-LABEL: CAPABILITY RELOCATION RECORDS: -# DUMP-NEXT: 0x00000000000204b0 Base: bar (0x0000000000010480) Offset: 0x0000000000000000 Length: 0x0000000000000008 Permissions: 0x8000000000000000 (Function) -# DUMP-NEXT: 0x00000000000204f0 Base: bar (0x0000000000010480) Offset: 0x0000000000000004 Length: 0x0000000000000008 Permissions: 0x8000000000000000 (Function) +# DUMP-NEXT: 0x00000000000204f0 Base: bar (0x00000000000104c0) Offset: 0x0000000000000000 Length: 0x0000000000000008 Permissions: 0x8000000000000000 (Function) +# DUMP-NEXT: 0x0000000000020530 Base: bar (0x00000000000104c0) Offset: 0x0000000000000004 Length: 0x0000000000000008 Permissions: 0x8000000000000000 (Function) # DUMP-EMPTY # DUMP-LABEL: Contents of section .data: diff --git a/lld/test/ELF/cheri/exception-table.ll b/lld/test/ELF/cheri/exception-table.ll index ff68b545ed0a5..748aa84f6495a 100644 --- a/lld/test/ELF/cheri/exception-table.ll +++ b/lld/test/ELF/cheri/exception-table.ll @@ -34,7 +34,7 @@ ; RUN: ld.lld -shared %t/mips.o %t/mips-override.o -o %t/mips.so ; RUN: llvm-readelf -r --section-mapping --sections --program-headers --cap-relocs %t/mips.so | FileCheck %s --check-prefixes=HEADERS,MIPS-RELOCS -; HEADERS-LABEL: There are 10 program headers, starting at +; HEADERS-LABEL: There are 11 program headers, starting at ; HEADERS-EMPTY: ; HEADERS-NEXT: Program Headers: ; HEADERS-NEXT: Type Offset VirtAddr PhysAddr FileSiz MemSiz Flg Align @@ -45,6 +45,7 @@ ; HEADERS-NEXT: LOAD 0x{{.+}} 0x{{.+}} 0x{{.+}} 0x{{.+}} 0x{{.+}} RW 0x10000 ; HEADERS-NEXT: DYNAMIC 0x{{.+}} 0x{{.+}} 0x{{.+}} 0x{{.+}} 0x{{.+}} R 0x8 ; HEADERS-NEXT: GNU_RELRO 0x{{.+}} 0x{{.+}} 0x{{.+}} 0x{{.+}} 0x{{.+}} R 0x1 +; HEADERS-NEXT: CHERI_PCC 0x{{.+}} 0x{{.+}} 0x{{.+}} 0x{{.+}} 0x{{.+}} R E 0x10 ; HEADERS-NEXT: GNU_STACK 0x{{.+}} 0x{{.+}} 0x{{.+}} 0x{{.+}} 0x{{.+}} RW 0x0 ; HEADERS-NEXT: OPTIONS 0x{{.+}} 0x{{.+}} 0x{{.+}} 0x{{.+}} 0x{{.+}} R 0x8 ; HEADERS-NEXT: ABIFLAGS 0x{{.+}} 0x{{.+}} 0x{{.+}} 0x{{.+}} 0x{{.+}} R 0x8 @@ -55,12 +56,13 @@ ; HEADERS-NEXT: 01 .MIPS.abiflags .MIPS.options .dynsym .hash .dynamic .dynstr .rel.dyn .rel.plt .eh_frame __cap_relocs {{$}} ; HEADERS-NEXT: 02 .text ; HEADERS-NEXT: 03 .gcc_except_table -; HEADERS-NEXT: 04 .data .captable .got +; HEADERS-NEXT: 04 .data .captable .got .pad.cheri.pcc ; HEADERS-NEXT: 05 .dynamic ; HEADERS-NEXT: 06 .gcc_except_table -; HEADERS-NEXT: 07 -; HEADERS-NEXT: 08 .MIPS.options -; HEADERS-NEXT: 09 .MIPS.abiflags +; HEADERS-NEXT: 07 .text .gcc_except_table .data .captable .got .pad.cheri.pcc +; HEADERS-NEXT: 08 +; HEADERS-NEXT: 09 .MIPS.options +; HEADERS-NEXT: 10 .MIPS.abiflags ; HEADERS-NEXT: None .bss .mdebug.abi64 .pdr .comment .symtab .shstrtab .strtab ; MIPS-RELOCS-LABEL: Relocation section '.rel.dyn' {{.+}} contains 2 entries: @@ -100,14 +102,14 @@ ; RV64-RELOCS-OVERRIDE: [[#%.16x,TEST_WEAK_OVERRIDE_ADDR:]] 8 FUNC GLOBAL DEFAULT 9 _Z9test_weakll{{$}} ; RV64-RELOCS: CHERI __cap_relocs [ -; RV64-RELOCS-NEXT: 0x002{{.+}} Base: 0x[[#%x,TEST_ADDR]] (.L_Z4testll$local+92) Length: 116 Perms: Code -; RV64-RELOCS-NEXT: 0x002{{.+}} Base: 0x[[#%x,TEST_ADDR]] (.L_Z4testll$local+72) Length: 116 Perms: Code -; RV64-RELOCS-NEXT: 0x002{{.+}} Base: 0x[[#%x,TEST2_ADDR]] (.L_Z5test2ll$local+72) Length: 124 Perms: Code +; RV64-RELOCS-NEXT: 0x002{{.+}} Base: 0x[[#%x,TEST_ADDR]] (.L_Z4testll$local+92) Length: 9184 Perms: Code +; RV64-RELOCS-NEXT: 0x002{{.+}} Base: 0x[[#%x,TEST_ADDR]] (.L_Z4testll$local+72) Length: 9184 Perms: Code +; RV64-RELOCS-NEXT: 0x002{{.+}} Base: 0x[[#%x,TEST_ADDR]] (.L_Z4testll$local+188) Length: 9184 Perms: Code ; Next one references the local symbol, and uses that length rather than the override: -; RV64-RELOCS-NEXT: 0x002{{.+}} Base: 0x[[#%x,TEST_WEAK_ADDR]] (.L_Z9test_weakll$local+28) Length: 52 Perms: Code -; RV64-RELOCS-NEXT: 0x003{{.+}} Base: 0x[[#%x,PLT0_ADDR:]] (+0) Length: 80 Perms: Code -; RV64-RELOCS-NEXT: 0x003{{.+}} Base: 0x[[#%x,PLT0_ADDR]] (+0) Length: 80 Perms: Code -; RV64-RELOCS-NEXT: 0x003{{.+}} Base: 0x[[#%x,PLT0_ADDR]] (+0) Length: 80 Perms: Code +; RV64-RELOCS-NEXT: 0x002{{.+}} Base: 0x[[#%x,TEST_ADDR]] (.L_Z4testll$local+268) Length: 9184 Perms: Code +; RV64-RELOCS-NEXT: 0x003{{.+}} Base: 0x[[#%x,TEST_ADDR]] (.L_Z4testll$local+304) Length: 9184 Perms: Code +; RV64-RELOCS-NEXT: 0x003{{.+}} Base: 0x[[#%x,TEST_ADDR]] (.L_Z4testll$local+304) Length: 9184 Perms: Code +; RV64-RELOCS-NEXT: 0x003{{.+}} Base: 0x[[#%x,TEST_ADDR]] (.L_Z4testll$local+304) Length: 9184 Perms: Code ; RV64-RELOCS-NEXT: ] ; IR was generated from the following code: diff --git a/lld/test/ELF/cheri/riscv/bsymbolic.s b/lld/test/ELF/cheri/riscv/bsymbolic.s index c19b0cac715f9..67dce44a60b21 100644 --- a/lld/test/ELF/cheri/riscv/bsymbolic.s +++ b/lld/test/ELF/cheri/riscv/bsymbolic.s @@ -9,8 +9,8 @@ # CHECK: Relocations [ # CHECK-NEXT: ] # CHECK-NEXT: CHERI __cap_relocs [ -# CHECK-NEXT: 0x003390 (data) Base: 0x3390 (data+0) Length: 32 Perms: Object -# CHECK-NEXT: 0x0033a0 Base: 0x12e8 (func+0) Length: 4 Perms: Function +# CHECK-NEXT: 0x0033d0 (data) Base: 0x33d0 (data) Length: 32 Perms: Object +# CHECK-NEXT: 0x0033e0 Base: 0x1320 (func) Length: 4 Perms: Function # CHECK-NEXT: ] .type func, @function diff --git a/lld/test/ELF/cheri/riscv/code-func-reloc.s b/lld/test/ELF/cheri/riscv/code-func-reloc.s index c26f5677bee90..01899bacd3388 100644 --- a/lld/test/ELF/cheri/riscv/code-func-reloc.s +++ b/lld/test/ELF/cheri/riscv/code-func-reloc.s @@ -9,9 +9,9 @@ # CHECK-NEXT: 0x3108 R_RISCV_RELATIVE - 0x30D0 # CHECK-NEXT: } # CHECK: CHERI __cap_relocs [ -# CHECK-NEXT: 0x0030d0 (data) Base: 0x1000 (func+0) Length: 4 Perms: Function -# CHECK-NEXT: 0x0030e0 Base: 0x1000 (func+0) Length: 4 Perms: Code -# CHECK-NEXT: 0x0030f0 Base: 0x30d0 (data+0) Length: 64 Perms: Object +# CHECK-NEXT: 0x0030d0 (data) Base: 0x1000 (func) Length: 4 Perms: Function +# CHECK-NEXT: 0x0030e0 Base: 0x1000 (func) Length: 4 Perms: Code +# CHECK-NEXT: 0x0030f0 Base: 0x30d0 (data) Length: 64 Perms: Object # CHECK-NEXT: ] .type func, @function diff --git a/lld/test/ELF/cheri/riscv/ifunc-nonpreemptible.s b/lld/test/ELF/cheri/riscv/ifunc-nonpreemptible.s index 83e2c576d9713..95faf80071a38 100644 --- a/lld/test/ELF/cheri/riscv/ifunc-nonpreemptible.s +++ b/lld/test/ELF/cheri/riscv/ifunc-nonpreemptible.s @@ -21,8 +21,8 @@ # RELOC32: Relocations [ # RELOC32-NEXT: ] # RELOC32: CHERI __cap_relocs [ -# RELOC32-NEXT: 0x012000 (fptr) Base: 0x11010 (func+0) Length: 16 Perms: Function -# RELOC32-NEXT: 0x012008 Base: 0x11000 (+0) Length: 4 Perms: GNU Indirect Function +# RELOC32-NEXT: 0x012000 (fptr) Base: 0x11000 (func) Length: 4608 Perms: Function +# RELOC32-NEXT: 0x012008 Base: 0x11000 () Length: 4608 Perms: GNU Indirect Function # RELOC32-NEXT: ] # GOTPLT32: section '.got.plt': # GOTPLT32-NEXT: 0x00012008 00000000 00000000 @@ -30,8 +30,8 @@ # RELOC64: Relocations [ # RELOC64-NEXT: ] # RELOC64: CHERI __cap_relocs [ -# RELOC64-NEXT: 0x012000 (fptr) Base: 0x11010 (func+0) Length: 16 Perms: Function -# RELOC64-NEXT: 0x012010 Base: 0x11000 (+0) Length: 4 Perms: GNU Indirect Function +# RELOC64-NEXT: 0x012000 (fptr) Base: 0x11000 (func) Length: 4128 Perms: Function +# RELOC64-NEXT: 0x012010 Base: 0x11000 () Length: 4128 Perms: GNU Indirect Function # RELOC64-NEXT: ] # GOTPLT64: section '.got.plt': # GOTPLT64-NEXT: 0x00012010 00000000 00000000 00000000 00000000 diff --git a/lld/test/ELF/cheri/riscv/pcc-padding.s b/lld/test/ELF/cheri/riscv/pcc-padding.s new file mode 100644 index 0000000000000..46c333922c62e --- /dev/null +++ b/lld/test/ELF/cheri/riscv/pcc-padding.s @@ -0,0 +1,169 @@ +# REQUIRES: riscv +# RUN: split-file %s %t + +# RUN: %riscv64_cheri_purecap_llvm-mc -filetype=obj %t/small_text.s -o %t/small_text.o +# RUN: %riscv64_cheri_purecap_llvm-mc -filetype=obj %t/big_text.s -o %t/big_text.o +# RUN: %riscv64_cheri_purecap_llvm-mc -filetype=obj %t/text_rodata.s -o %t/text_rodata.o +# RUN: %riscv64_cheri_purecap_llvm-mc -filetype=obj %t/rodata_only.s -o %t/rodata_only.o +# RUN: %riscv64_cheri_purecap_llvm-mc -filetype=obj %t/plt.s -o %t/plt.o +# RUN: %riscv64_cheri_purecap_llvm-mc -filetype=obj %t/plt_notext.s -o %t/plt_notext.o +# RUN: ld.lld --shared %t/small_text.o -o %t/small_text.so +# RUN: ld.lld --shared %t/big_text.o -o %t/big_text.so +# RUN: ld.lld --shared %t/text_rodata.o -o %t/text_rodata.so +# RUN: ld.lld --shared %t/rodata_only.o -o %t/rodata_only.so +# RUN: ld.lld --shared %t/plt.o -o %t/plt.so +# RUN: ld.lld --shared %t/plt_notext.o -o %t/plt_notext.so + +# RUN: llvm-readelf -t %t/small_text.so | FileCheck --check-prefix=SMALL_TEXT %s +# RUN: llvm-readelf -t %t/big_text.so | FileCheck --check-prefix=BIG_TEXT %s +# RUN: llvm-readelf -t %t/text_rodata.so | FileCheck --check-prefix=TEXT_RODATA %s +# RUN: llvm-readelf -t %t/rodata_only.so | FileCheck --check-prefix=RODATA_ONLY %s +# RUN: llvm-readelf -t %t/plt.so | FileCheck --check-prefix=PLT %s +# RUN: llvm-readelf -t %t/plt_notext.so | FileCheck --check-prefix=PLT_NOTEXT %s + +# small_text results in zero byte padding section :( +# SMALL_TEXT-LABEL: Section Headers: +# SMALL_TEXT: [ 5] .text +# SMALL_TEXT-NEXT: PROGBITS 0000000000001270 000270 000004 00 0 0 4 +# SMALL_TEXT-NEXT: [0000000000000006]: ALLOC, EXEC +# SMALL_TEXT-NEXT: [ 6] .pad.cheri.pcc +# SMALL_TEXT-NEXT: PROGBITS 0000000000001274 000274 000000 00 0 0 1 +# SMALL_TEXT-NEXT: [0000000000000006]: ALLOC, EXEC +# SMALL_TEXT-NEXT: [ 7] .dynamic +# SMALL_TEXT-NEXT: DYNAMIC 0000000000002278 000278 000070 10 4 0 8 + +# big_text results in actual padding +# BIG_TEXT-LABEL: Section Headers: +# BIG_TEXT: [ 5] .text +# BIG_TEXT-NEXT: PROGBITS 0000000000001270 000270 002004 00 0 0 16 +# BIG_TEXT-NEXT: [0000000000000006]: ALLOC, EXEC +# BIG_TEXT-NEXT: [ 6] .pad.cheri.pcc +# BIG_TEXT-NEXT: PROGBITS 0000000000003274 002274 00000c 00 0 0 1 +# BIG_TEXT-NEXT: [0000000000000006]: ALLOC, EXEC +# BIG_TEXT-NEXT: [ 7] .dynamic +# BIG_TEXT-NEXT: DYNAMIC 0000000000004280 002280 000070 10 4 0 8 + +# text_rodata triggers padding as well +# TEXT_RODATA-LABEL: Section Headers: +# TEXT_RODATA: [ 5] .rodata +# TEXT_RODATA-NEXT: PROGBITS 00000000000002a0 0002a0 002000 00 0 0 16 +# TEXT_RODATA-NEXT: [0000000000000002]: ALLOC +# TEXT_RODATA-NEXT: [ 6] .text +# TEXT_RODATA-NEXT: PROGBITS 00000000000032a0 0022a0 000004 00 0 0 4 +# TEXT_RODATA-NEXT: [0000000000000006]: ALLOC, EXEC +# TEXT_RODATA-NEXT: [ 7] .pad.cheri.pcc +# TEXT_RODATA-NEXT: PROGBITS 00000000000032a4 0022a4 00000c 00 0 0 1 +# TEXT_RODATA-NEXT: [0000000000000006]: ALLOC, EXEC +# TEXT_RODATA-NEXT: [ 8] .dynamic +# TEXT_RODATA-NEXT: DYNAMIC 00000000000042b0 0022b0 000070 10 4 0 8 +# TEXT_RODATA-NEXT: [0000000000000003]: WRITE, ALLOC + +# rodata_only should not result in a padding section +# RODATA_ONLY-LABEL: Section Headers: +# RODATA_ONLY-NOT: .pad.cheri.pcc + +# plt uses RW for the padding to match .got.plt +# PLT-LABEL: Section Headers: +# PLT: [11] .got.plt +# PLT-NEXT: PROGBITS 0000000000005460 002460 000030 00 0 0 16 +# PLT-NEXT: [0000000000000003]: WRITE, ALLOC +# PLT-NEXT: [12] .pad.cheri.pcc +# PLT-NEXT: PROGBITS 0000000000005490 002490 000010 00 0 0 1 +# PLT-NEXT: [0000000000000003]: WRITE, ALLOC + +# plt_notext still generates padding due to .iplt +# PLT_NOTEXT-LABEL: Section Headers: +# PLT_NOTEXT: [ 7] .text +# PLT_NOTEXT-NEXT: PROGBITS 0000000000003310 002310 000000 00 0 0 4 +# PLT_NOTEXT-NEXT: [0000000000000006]: ALLOC, EXEC +# PLT_NOTEXT-NEXT: [ 8] .iplt +# PLT_NOTEXT-NEXT: PROGBITS 0000000000003310 002310 000010 00 0 0 16 +# PLT_NOTEXT-NEXT: [0000000000000006]: ALLOC, EXEC +# PLT_NOTEXT: [11] .got.plt +# PLT_NOTEXT-NEXT: PROGBITS 00000000000053c0 0023c0 000010 00 0 0 16 +# PLT_NOTEXT-NEXT: [0000000000000003]: WRITE, ALLOC +# PLT_NOTEXT-NEXT: [12] .pad.cheri.pcc +# PLT_NOTEXT-NEXT: PROGBITS 00000000000053d0 0023d0 000010 00 0 0 1 +# PLT_NOTEXT-NEXT: [0000000000000003]: WRITE, ALLOC + +#--- small_text.s + + .global foo + .type foo, @function +foo: + ret + .size foo, . - foo + +#--- big_text.s + + .global foo + .type foo, @function +foo: + ret + .space 8192 + .size foo, . - foo + +#--- text_rodata.s + + .global foo + .type foo, @function +foo: + ret + .size foo, . - foo + + .rodata + .global bar + .type bar, @object +bar: + .space 8192 + .size bar, . - bar + +#--- rodata_only.s + + .rodata + .global bar + .type bar, @object +bar: + .space 8196 + .size bar, . - bar + +#--- plt.s + + .global foo + .type foo, @function +foo: + ccall baz@plt + ret + .size foo, . - foo + + .rodata + .global bar + .type bar, @object +bar: + .space 8192 + .size bar, . - bar + +#--- plt_notext.s + +# Using an empty function is a gross way of simulating an empty +# text section to ensure that padding is inserted if the only +# executable sections are synthetic sections. + + .text + .global foo + .type foo, STT_GNU_IFUNC + .hidden foo +foo: + .size foo, 0 + + .data + .type ptr, @object +ptr: .chericap foo + .size ptr, . - ptr + + .rodata + .global bar + .type bar, @object +bar: + .space 8192 + .size bar, . - bar diff --git a/lld/test/ELF/cheri/riscv/plt.s b/lld/test/ELF/cheri/riscv/plt.s index 76a5a1d478c76..181fc63d9dcd8 100644 --- a/lld/test/ELF/cheri/riscv/plt.s +++ b/lld/test/ELF/cheri/riscv/plt.s @@ -31,8 +31,8 @@ # RELOC32-NEXT: 0x13090 R_RISCV_JUMP_SLOT weak 0x0 # RELOC32-NEXT: } # RELOC32: CHERI __cap_relocs [ -# RELOC32-NEXT: 0x013088 Base: 0x11030 (+0) Length: 64 Perms: Code -# RELOC32-NEXT: 0x013090 Base: 0x11030 (+0) Length: 64 Perms: Code +# RELOC32-NEXT: 0x013088 Base: 0x11000 (_start+48) Length: 9216 Perms: Code +# RELOC32-NEXT: 0x013090 Base: 0x11000 (_start+48) Length: 9216 Perms: Code # RELOC32-NEXT: ] # GOTPLT32: section '.got.plt' # GOTPLT32-NEXT: 0x00013078 00000000 00000000 00000000 00000000 @@ -43,8 +43,8 @@ # RELOC64-NEXT: 0x13120 R_RISCV_JUMP_SLOT weak 0x0 # RELOC64-NEXT: } # RELOC64: CHERI __cap_relocs [ -# RELOC64-NEXT: 0x013110 Base: 0x11030 (+0) Length: 64 Perms: Code -# RELOC64-NEXT: 0x013120 Base: 0x11030 (+0) Length: 64 Perms: Code +# RELOC64-NEXT: 0x013110 Base: 0x11000 (_start+48) Length: 8496 Perms: Code +# RELOC64-NEXT: 0x013120 Base: 0x11000 (_start+48) Length: 8496 Perms: Code # RELOC64-NEXT: ] # GOTPLT64: section '.got.plt' # GOTPLT64-NEXT: 0x000130f0 00000000 00000000 00000000 00000000 diff --git a/lld/test/ELF/cheri/riscv/reloc-got.s b/lld/test/ELF/cheri/riscv/reloc-got.s index b9c99fbb01e0f..db465338fb056 100644 --- a/lld/test/ELF/cheri/riscv/reloc-got.s +++ b/lld/test/ELF/cheri/riscv/reloc-got.s @@ -21,51 +21,51 @@ # RUN: llvm-readobj -x .got %t | FileCheck --check-prefix=HEX64 %s # RUN: llvm-objdump -d --no-show-raw-insn %t | FileCheck --check-prefix=DIS64 %s -# SEC32: .got PROGBITS 00012230 000230 000018 -# SEC64: .got PROGBITS 00000000000123a0 0003a0 000030 +# SEC32: .got PROGBITS 00012280 000280 000018 +# SEC64: .got PROGBITS 00000000000123e0 0003e0 000030 # RELOC32: .rela.dyn { -# RELOC32-NEXT: 0x12238 R_RISCV_CHERI_CAPABILITY b 0x0 +# RELOC32-NEXT: 0x12288 R_RISCV_CHERI_CAPABILITY b 0x0 # RELOC32-NEXT: } # RELOC32: CHERI __cap_relocs [ -# RELOC32-NEXT: 0x012240 Base: 0x13248 (a+0) Length: 4 Perms: Object +# RELOC32-NEXT: 0x012290 Base: 0x13400 (a) Length: 4 Perms: Object # RELOC32-NEXT: ] # RELOC64: .rela.dyn { -# RELOC64-NEXT: 0x123B0 R_RISCV_CHERI_CAPABILITY b 0x0 +# RELOC64-NEXT: 0x123F0 R_RISCV_CHERI_CAPABILITY b 0x0 # RELOC64-NEXT: } # RELOC64: CHERI __cap_relocs [ -# RELOC64-NEXT: 0x0123c0 Base: 0x133d0 (a+0) Length: 4 Perms: Object +# RELOC64-NEXT: 0x012400 Base: 0x13410 (a) Length: 4 Perms: Object # RELOC64-NEXT: ] -# NM32: 00013248 d a -# NM64: 00000000000133d0 d a +# NM32: 00013400 d a +# NM64: 0000000000013410 d a ## .got[0] = _DYNAMIC ## .got[1] = 0 (relocated by R_RISCV_CHERI_CAPABILITY at run time) ## .got[2] = 0 (relocated by __cap_relocs at run time) # HEX32: section '.got': -# HEX32: 0x00012230 c0210100 00000000 00000000 00000000 -# HEX32: 0x00012240 00000000 00000000 +# HEX32: 0x00012280 10220100 00000000 00000000 00000000 +# HEX32: 0x00012290 00000000 00000000 # HEX64: section '.got': -# HEX64: 0x000123a0 c0220100 00000000 00000000 00000000 -# HEX64: 0x000123b0 00000000 00000000 00000000 00000000 -# HEX64: 0x000123c0 00000000 00000000 00000000 00000000 +# HEX64: 0x000123e0 f8220100 00000000 00000000 00000000 +# HEX64: 0x000123f0 00000000 00000000 00000000 00000000 +# HEX64: 0x00012400 00000000 00000000 00000000 00000000 -## &.got[2]-. = 0x12240-0x111b0 = 4096*1+144 -# DIS32: 111b0: auipcc ca0, 1 +## &.got[2]-. = 0x12290-0x11200 = 4096*1+144 +# DIS32: 11200: auipcc ca0, 1 # DIS32-NEXT: lc ca0, 144(ca0) -## &.got[1]-. = 0x12238-0x111b8 = 4096*1+128 -# DIS32: 111b8: auipcc ca0, 1 +## &.got[1]-. = 0x12288-0x11208 = 4096*1+128 +# DIS32: 11208: auipcc ca0, 1 # DIS32-NEXT: lc ca0, 128(ca0) -## &.got[2]-. = 0x123c0-0x112b0 = 4096*1+272 -# DIS64: 112b0: auipcc ca0, 1 -# DIS64-NEXT: lc ca0, 272(ca0) -## &.got[1]-. = 0x123b0-0x112b8 = 4096*1+248 -# DIS64: 112b8: auipcc ca0, 1 -# DIS64-NEXT: lc ca0, 248(ca0) +## &.got[2]-. = 0x12400-0x112e8 = 4096*1+280 +# DIS64: 112e8: auipcc ca0, 1 +# DIS64-NEXT: lc ca0, 280(ca0) +## &.got[1]-. = 0x123f0-0x112f0 = 4096*1+256 +# DIS64: 112f0: auipcc ca0, 1 +# DIS64-NEXT: lc ca0, 256(ca0) clgc ca0, a clgc ca0, b diff --git a/lld/test/ELF/cheri/riscv/tls.s b/lld/test/ELF/cheri/riscv/tls.s index 19fb3825d6b56..a0ae9996688c4 100644 --- a/lld/test/ELF/cheri/riscv/tls.s +++ b/lld/test/ELF/cheri/riscv/tls.s @@ -32,128 +32,128 @@ # RUN: llvm-objdump -d --no-show-raw-insn %t.64.so | FileCheck --check-prefix=RV64-SO-DIS %s # RV32-REL: .rela.dyn { -# RV32-REL-NEXT: 0x12248 R_RISCV_TLS_DTPMOD32 evar 0x0 -# RV32-REL-NEXT: 0x1224C R_RISCV_TLS_DTPREL32 evar 0x0 -# RV32-REL-NEXT: 0x12250 R_RISCV_TLS_TPREL32 evar 0x0 +# RV32-REL-NEXT: 0x12298 R_RISCV_TLS_DTPMOD32 evar 0x0 +# RV32-REL-NEXT: 0x1229C R_RISCV_TLS_DTPREL32 evar 0x0 +# RV32-REL-NEXT: 0x122A0 R_RISCV_TLS_TPREL32 evar 0x0 # RV32-REL-NEXT: } # RV32-SO-REL: .rela.dyn { -# RV32-SO-REL-NEXT: 0x2288 R_RISCV_TLS_DTPMOD32 - 0x0 -# RV32-SO-REL-NEXT: 0x2290 R_RISCV_TLS_TPREL32 - 0x4 -# RV32-SO-REL-NEXT: 0x2278 R_RISCV_TLS_DTPMOD32 evar 0x0 -# RV32-SO-REL-NEXT: 0x227C R_RISCV_TLS_DTPREL32 evar 0x0 -# RV32-SO-REL-NEXT: 0x2280 R_RISCV_TLS_TPREL32 evar 0x0 +# RV32-SO-REL-NEXT: 0x2498 R_RISCV_TLS_DTPMOD32 - 0x0 +# RV32-SO-REL-NEXT: 0x24A0 R_RISCV_TLS_TPREL32 - 0x4 +# RV32-SO-REL-NEXT: 0x2488 R_RISCV_TLS_DTPMOD32 evar 0x0 +# RV32-SO-REL-NEXT: 0x248C R_RISCV_TLS_DTPREL32 evar 0x0 +# RV32-SO-REL-NEXT: 0x2490 R_RISCV_TLS_TPREL32 evar 0x0 # RV32-SO-REL-NEXT: } # RV32-GOT: section '.got': -# RV32-GOT-NEXT: 0x00012240 e0210100 00000000 00000000 00000000 -# RV32-GOT-NEXT: 0x00012250 00000000 00000000 01000000 04000000 -# RV32-GOT-NEXT: 0x00012260 04000000 00000000 +# RV32-GOT-NEXT: 0x00012290 2c220100 00000000 00000000 00000000 +# RV32-GOT-NEXT: 0x000122a0 00000000 00000000 01000000 04000000 +# RV32-GOT-NEXT: 0x000122b0 04000000 00000000 # RV32-SO-GOT: section '.got': -# RV32-SO-GOT-NEXT: 0x00002270 10220000 00000000 00000000 00000000 -# RV32-SO-GOT-NEXT: 0x00002280 00000000 00000000 00000000 04000000 -# RV32-SO-GOT-NEXT: 0x00002290 00000000 00000000 +# RV32-SO-GOT-NEXT: 0x00002480 20240000 00000000 00000000 00000000 +# RV32-SO-GOT-NEXT: 0x00002490 00000000 00000000 00000000 04000000 +# RV32-SO-GOT-NEXT: 0x000024a0 00000000 00000000 -# 0x12248 - 0x111b4 = 0x1094 (GD evar) -# RV32-DIS: 111b4: auipcc ca0, 1 -# RV32-DIS-NEXT: cincoffset ca0, ca0, 148 +# 0x12298 - 0x11200 = 0x1098 (GD evar) +# RV32-DIS: 11200: auipcc ca0, 1 +# RV32-DIS-NEXT: cincoffset ca0, ca0, 152 -# 0x12250 - 0x111bc = 0x1094 (IE evar) -# RV32-DIS: 111bc: auipcc ca0, 1 -# RV32-DIS-NEXT: lw a0, 148(ca0) +# 0x122a0 - 0x11208 = 0x1098 (IE evar) +# RV32-DIS: 11208: auipcc ca0, 1 +# RV32-DIS-NEXT: lw a0, 152(ca0) -# 0x12258 - 0x111c4 = 0x1094 (GD lvar) -# RV32-DIS: 111c4: auipcc ca0, 1 -# RV32-DIS-NEXT: cincoffset ca0, ca0, 148 +# 0x122a8 - 0x11210 = 0x1098 (GD lvar) +# RV32-DIS: 11210: auipcc ca0, 1 +# RV32-DIS-NEXT: cincoffset ca0, ca0, 152 -# 0x12260 - 0x111cc = 0x1094 (IE lvar) -# RV32-DIS: 111cc: auipcc ca0, 1 -# RV32-DIS-NEXT: lw a0, 148(ca0) +# 0x122b0 - 0x11218 = 0x1098 (IE lvar) +# RV32-DIS: 11218: auipcc ca0, 1 +# RV32-DIS-NEXT: lw a0, 152(ca0) -# RV32-DIS: 111d4: lui a0, 0 +# RV32-DIS: 11220: lui a0, 0 # RV32-DIS-NEXT: cincoffset ca0, ctp, a0 # RV32-DIS-NEXT: cincoffset ca0, ca0, 4 -# 0x2278 - 0x11f0 = 0x1088 (GD evar) -# RV32-SO-DIS: 11f0: auipcc ca0, 1 +# 0x2488 - 0x1400 = 0x1088 (GD evar) +# RV32-SO-DIS: 1400: auipcc ca0, 1 # RV32-SO-DIS-NEXT: cincoffset ca0, ca0, 136 -# 0x2280 - 0x11f8 = 0x1088 (IE evar) -# RV32-SO-DIS: 11f8: auipcc ca0, 1 +# 0x2490 - 0x1408 = 0x1088 (IE evar) +# RV32-SO-DIS: 1408: auipcc ca0, 1 # RV32-SO-DIS-NEXT: lw a0, 136(ca0) -# 0x2288 - 0x1200 = 0x1088 (GD lvar) -# RV32-SO-DIS: 1200: auipcc ca0, 1 +# 0x2498 - 0x1410 = 0x1088 (GD lvar) +# RV32-SO-DIS: 1410: auipcc ca0, 1 # RV32-SO-DIS-NEXT: cincoffset ca0, ca0, 136 -# 0x2290 - 0x1208 = 0x1088 (IE lvar) -# RV32-SO-DIS: 1208: auipcc ca0, 1 +# 0x24a0 - 0x1418 = 0x1088 (IE lvar) +# RV32-SO-DIS: 1418: auipcc ca0, 1 # RV32-SO-DIS-NEXT: lw a0, 136(ca0) # RV64-REL: .rela.dyn { -# RV64-REL-NEXT: 0x123C0 R_RISCV_TLS_DTPMOD64 evar 0x0 -# RV64-REL-NEXT: 0x123C8 R_RISCV_TLS_DTPREL64 evar 0x0 -# RV64-REL-NEXT: 0x123D0 R_RISCV_TLS_TPREL64 evar 0x0 +# RV64-REL-NEXT: 0x123F0 R_RISCV_TLS_DTPMOD64 evar 0x0 +# RV64-REL-NEXT: 0x123F8 R_RISCV_TLS_DTPREL64 evar 0x0 +# RV64-REL-NEXT: 0x12400 R_RISCV_TLS_TPREL64 evar 0x0 # RV64-REL-NEXT: } # RV64-SO-REL: .rela.dyn { -# RV64-SO-REL-NEXT: 0x2430 R_RISCV_TLS_DTPMOD64 - 0x0 -# RV64-SO-REL-NEXT: 0x2440 R_RISCV_TLS_TPREL64 - 0x4 -# RV64-SO-REL-NEXT: 0x2410 R_RISCV_TLS_DTPMOD64 evar 0x0 -# RV64-SO-REL-NEXT: 0x2418 R_RISCV_TLS_DTPREL64 evar 0x0 -# RV64-SO-REL-NEXT: 0x2420 R_RISCV_TLS_TPREL64 evar 0x0 +# RV64-SO-REL-NEXT: 0x2460 R_RISCV_TLS_DTPMOD64 - 0x0 +# RV64-SO-REL-NEXT: 0x2470 R_RISCV_TLS_TPREL64 - 0x4 +# RV64-SO-REL-NEXT: 0x2440 R_RISCV_TLS_DTPMOD64 evar 0x0 +# RV64-SO-REL-NEXT: 0x2448 R_RISCV_TLS_DTPREL64 evar 0x0 +# RV64-SO-REL-NEXT: 0x2450 R_RISCV_TLS_TPREL64 evar 0x0 # RV64-SO-REL-NEXT: } # RV64-GOT: section '.got': -# RV64-GOT-NEXT: 0x000123b0 e8220100 00000000 00000000 00000000 -# RV64-GOT-NEXT: 0x000123c0 00000000 00000000 00000000 00000000 -# RV64-GOT-NEXT: 0x000123d0 00000000 00000000 00000000 00000000 -# RV64-GOT-NEXT: 0x000123e0 01000000 00000000 04000000 00000000 -# RV64-GOT-NEXT: 0x000123f0 04000000 00000000 00000000 00000000 +# RV64-GOT-NEXT: 0x000123e0 20230100 00000000 00000000 00000000 +# RV64-GOT-NEXT: 0x000123f0 00000000 00000000 00000000 00000000 +# RV64-GOT-NEXT: 0x00012400 00000000 00000000 00000000 00000000 +# RV64-GOT-NEXT: 0x00012410 01000000 00000000 04000000 00000000 +# RV64-GOT-NEXT: 0x00012420 04000000 00000000 00000000 00000000 # RV64-SO-GOT: section '.got': -# RV64-SO-GOT-NEXT: 0x00002400 38230000 00000000 00000000 00000000 -# RV64-SO-GOT-NEXT: 0x00002410 00000000 00000000 00000000 00000000 -# RV64-SO-GOT-NEXT: 0x00002420 00000000 00000000 00000000 00000000 -# RV64-SO-GOT-NEXT: 0x00002430 00000000 00000000 04000000 00000000 +# RV64-SO-GOT-NEXT: 0x00002430 70230000 00000000 00000000 00000000 # RV64-SO-GOT-NEXT: 0x00002440 00000000 00000000 00000000 00000000 +# RV64-SO-GOT-NEXT: 0x00002450 00000000 00000000 00000000 00000000 +# RV64-SO-GOT-NEXT: 0x00002460 00000000 00000000 04000000 00000000 +# RV64-SO-GOT-NEXT: 0x00002470 00000000 00000000 00000000 00000000 -# 0x123c0 - 0x112b8 = 0x1108 (GD evar) -# RV64-DIS: 112b8: auipcc ca0, 1 -# RV64-DIS-NEXT: cincoffset ca0, ca0, 264 +# 0x123f0 - 0x112f0 = 0x1100 (GD evar) +# RV64-DIS: 112f0: auipcc ca0, 1 +# RV64-DIS-NEXT: cincoffset ca0, ca0, 256 -# 0x123d0 - 0x112c0 = 0x1110 (IE evar) -# RV64-DIS: 112c0: auipcc ca0, 1 -# RV64-DIS-NEXT: ld a0, 272(ca0) +# 0x12400 - 0x112f8 = 0x1108 (IE evar) +# RV64-DIS: 112f8: auipcc ca0, 1 +# RV64-DIS-NEXT: ld a0, 264(ca0) -# 0x123e0 - 0x112c8 = 0x1118 (GD lvar) -# RV64-DIS: 112c8: auipcc ca0, 1 -# RV64-DIS-NEXT: cincoffset ca0, ca0, 280 +# 0x12410 - 0x11300 = 0x1110 (GD lvar) +# RV64-DIS: 11300: auipcc ca0, 1 +# RV64-DIS-NEXT: cincoffset ca0, ca0, 272 -# 0x123f0 - 0x112d0 = 0x1120 (IE lvar) -# RV64-DIS: 112d0: auipcc ca0, 1 -# RV64-DIS-NEXT: ld a0, 288(ca0) +# 0x12420 - 0x11308 = 0x1118 (IE lvar) +# RV64-DIS: 11308: auipcc ca0, 1 +# RV64-DIS-NEXT: ld a0, 280(ca0) -# RV64-DIS: 112d8: lui a0, 0 +# RV64-DIS: 11310: lui a0, 0 # RV64-DIS-NEXT: cincoffset ca0, ctp, a0 # RV64-DIS-NEXT: cincoffset ca0, ca0, 4 -# 0x2410 - 0x1318 = 0x10f8 (GD evar) -# RV64-SO-DIS: 1318: auipcc ca0, 1 -# RV64-SO-DIS-NEXT: cincoffset ca0, ca0, 248 +# 0x2440 - 0x1350 = 0x10f0 (GD evar) +# RV64-SO-DIS: 1350: auipcc ca0, 1 +# RV64-SO-DIS-NEXT: cincoffset ca0, ca0, 240 -# 0x2420 - 0x1320 = 0x1100 (IE evar) -# RV64-SO-DIS: 1320: auipcc ca0, 1 -# RV64-SO-DIS-NEXT: ld a0, 256(ca0) +# 0x2450 - 0x1358 = 0x10f8 (IE evar) +# RV64-SO-DIS: 1358: auipcc ca0, 1 +# RV64-SO-DIS-NEXT: ld a0, 248(ca0) -# 0x2430 - 0x1328 = 0x1108 (GD lvar) -# RV64-SO-DIS: 1328: auipcc ca0, 1 -# RV64-SO-DIS-NEXT: cincoffset ca0, ca0, 264 +# 0x2460 - 0x1360 = 0x1100 (GD lvar) +# RV64-SO-DIS: 1360: auipcc ca0, 1 +# RV64-SO-DIS-NEXT: cincoffset ca0, ca0, 256 -# 0x2440 - 0x1330 = 0x1110 (IE lvar) -# RV64-SO-DIS: 1330: auipcc ca0, 1 -# RV64-SO-DIS-NEXT: ld a0, 272(ca0) +# 0x2470 - 0x1368 = 0x1108 (IE lvar) +# RV64-SO-DIS: 1368: auipcc ca0, 1 +# RV64-SO-DIS-NEXT: ld a0, 264(ca0) .global _start _start: diff --git a/llvm/include/llvm/BinaryFormat/ELF.h b/llvm/include/llvm/BinaryFormat/ELF.h index 2154a72723ba5..c5c86676359e6 100644 --- a/llvm/include/llvm/BinaryFormat/ELF.h +++ b/llvm/include/llvm/BinaryFormat/ELF.h @@ -1421,6 +1421,8 @@ enum { PT_OPENBSD_NOBTCFI = 0x65a3dbe8, // Do not enforce branch target CFI. PT_OPENBSD_BOOTDATA = 0x65a41be6, // Section for boot arguments. + PT_CHERI_PCC = 0x64348450, + // ARM program header types. PT_ARM_ARCHEXT = 0x70000000, // Platform architecture compatibility info // These all contain stack unwind tables. diff --git a/llvm/lib/ObjectYAML/ELFYAML.cpp b/llvm/lib/ObjectYAML/ELFYAML.cpp index ae0cc32b189fc..60bdeaf22addd 100644 --- a/llvm/lib/ObjectYAML/ELFYAML.cpp +++ b/llvm/lib/ObjectYAML/ELFYAML.cpp @@ -70,6 +70,7 @@ void ScalarEnumerationTraits::enumeration( ECase(PT_GNU_STACK); ECase(PT_GNU_RELRO); ECase(PT_GNU_PROPERTY); + ECase(PT_CHERI_PCC); #undef ECase IO.enumFallback(Value); } diff --git a/llvm/tools/llvm-objdump/ELFDump.cpp b/llvm/tools/llvm-objdump/ELFDump.cpp index 5b08a4b128581..aff411e42f760 100644 --- a/llvm/tools/llvm-objdump/ELFDump.cpp +++ b/llvm/tools/llvm-objdump/ELFDump.cpp @@ -267,6 +267,9 @@ template void ELFDumper::printProgramHeaders() { case ELF::PT_GNU_STACK: outs() << " STACK "; break; + case ELF::PT_CHERI_PCC: + outs() << "CHERI_PCC "; + break; case ELF::PT_INTERP: outs() << " INTERP "; break; diff --git a/llvm/tools/llvm-readobj/ELFDumper.cpp b/llvm/tools/llvm-readobj/ELFDumper.cpp index 49f143f7a35e5..6f63bd941ad77 100644 --- a/llvm/tools/llvm-readobj/ELFDumper.cpp +++ b/llvm/tools/llvm-readobj/ELFDumper.cpp @@ -1473,6 +1473,8 @@ static StringRef segmentTypeToString(unsigned Arch, unsigned Type) { LLVM_READOBJ_ENUM_CASE(ELF, PT_OPENBSD_RANDOMIZE); LLVM_READOBJ_ENUM_CASE(ELF, PT_OPENBSD_WXNEEDED); LLVM_READOBJ_ENUM_CASE(ELF, PT_OPENBSD_BOOTDATA); + + LLVM_READOBJ_ENUM_CASE(ELF, PT_CHERI_PCC); default: return ""; } @@ -3465,6 +3467,7 @@ template void ELFDumper::printCheriCapRelocs() { break; } std::string BaseSymbol; + int64_t SymbolOffset = Offset; if (Base == 0) { // Base is 0 -> either it is really NULL or (more likely) there is a // dynamic relocation that will set the real address @@ -3485,6 +3488,13 @@ template void ELFDumper::printCheriCapRelocs() { BaseSymbol = it->second; // errs() << "BaseSymbol = SymbolNames[" << Base << "] = " << it->second << "\n"; } + if (Offset != 0 && !opts::ExpandRelocs) { + it = SymbolNames.find(Base + Offset); + if (it != SymbolNames.end()) { + BaseSymbol = it->second; + SymbolOffset = 0; + } + } } if (BaseSymbol.empty()) BaseSymbol = ""; @@ -3510,9 +3520,10 @@ template void ELFDumper::printCheriCapRelocs() { OS << left_justify((" (" + LocationSym + ")").str(), 16); OS << format(" Base: 0x%lx (", static_cast(Base)) << BaseSymbol; - if (Offset >= 0) + if (SymbolOffset > 0) OS << "+"; - OS << Offset; + if (SymbolOffset != 0) + OS << SymbolOffset; OS << format(") Length: %ld", static_cast(Length)); OS << " Perms: " << PermStr; OS << "\n";