Skip to content

Commit 49f5b47

Browse files
authored
Merge branch 'cheriot' into 20250625-cheriot_import_loadglobal
2 parents 2ede531 + 988843c commit 49f5b47

29 files changed

+308
-76
lines changed

clang/include/clang/Basic/DiagnosticGroups.td

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -172,6 +172,9 @@ def CheriPedantic : DiagGroup<"cheri-pedantic", [CHERICapabilityToIntegerCast, C
172172
// Warnings/Errors for bugs in the MIPS/CHERI backend
173173
def MIPSCHERIBugs: DiagGroup<"mips-cheri-bugs">;
174174

175+
// Generally useful CHERI errors
176+
def CHERIMissingCompartment: DiagGroup<"cheri-missing-compartment">;
177+
175178
def C99Compat : DiagGroup<"c99-compat">;
176179
def C23Compat : DiagGroup<"c23-compat">;
177180
def : DiagGroup<"c2x-compat", [C23Compat]>;

clang/include/clang/Basic/DiagnosticSemaKinds.td

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -157,8 +157,8 @@ def err_cheriot_invalid_sealed_declaration
157157
: Error<"cannot declare a sealed variable as %0">;
158158
def err_cheriot_invalid_sealing_key_type_name
159159
: Error<"the sealing key type name '%0' is not a valid identifier">;
160-
def err_cheriot_use_of_builtin_sealing_key_type_no_compartment
161-
: Error<"%0 used, but no compartment name given">;
160+
def warn_cheriot_use_of_builtin_sealing_key_type_no_compartment
161+
: Warning<"%0 used, but no compartment name given">,InGroup<CHERIMissingCompartment>,DefaultError;
162162

163163
// C99 variable-length arrays
164164
def ext_vla : Extension<"variable length arrays are a C99 feature">,

clang/lib/Basic/Targets/RISCV.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -306,9 +306,9 @@ void RISCVTargetInfo::getTargetDefines(const LangOptions &Opts,
306306

307307
// Macros for CHERIoT in the default and bare-metal ABIs.
308308
if (ABI == "cheriot" || ABI == "cheriot-baremetal")
309-
Builder.defineMacro("__CHERIOT__", "20250610");
309+
Builder.defineMacro("__CHERIOT__", "20250701");
310310
if (ABI == "cheriot-baremetal")
311-
Builder.defineMacro("__CHERIOT_BAREMETAL__", "20250610");
311+
Builder.defineMacro("__CHERIOT_BAREMETAL__", "20250701");
312312

313313
Builder.defineMacro("__riscv_clen", Twine(getCHERICapabilityWidth()));
314314
// TODO: _MIPS_CAP_ALIGN_MASK equivalent?

clang/lib/Sema/SemaChecking.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2938,7 +2938,7 @@ Sema::CheckBuiltinFunctionCall(FunctionDecl *FDecl, unsigned BuiltinID,
29382938
}
29392939
if (getLangOpts().CheriCompartmentName.empty()) {
29402940
Diag(Arg->getExprLoc(),
2941-
diag::err_cheriot_use_of_builtin_sealing_key_type_no_compartment)
2941+
diag::warn_cheriot_use_of_builtin_sealing_key_type_no_compartment)
29422942
<< Context.BuiltinInfo.getName(
29432943
Builtin::BI__builtin_cheriot_sealing_type);
29442944
}

clang/test/Preprocessor/init.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -391,8 +391,8 @@
391391
// Check for CHERIoT-specific defines
392392
// RUN: %clang_cc1 %s -o - "-triple" "riscv32-unknown-unknown" "-mframe-pointer=none" "-mcmodel=small" "-target-cpu" "cheriot" "-target-feature" "+xcheri" "-target-feature" "-64bit" "-target-feature" "-relax" "-target-feature" "-xcheri-rvc" "-target-feature" "-save-restore" "-target-abi" "cheriot" -E -dM < /dev/null | FileCheck -check-prefix CHERIOT %s
393393
// RUN: %clang_cc1 %s -o - "-triple" "riscv32-unknown-unknown" "-mframe-pointer=none" "-mcmodel=small" "-target-cpu" "cheriot" "-target-feature" "+xcheri" "-target-feature" "-64bit" "-target-feature" "-relax" "-target-feature" "-xcheri-rvc" "-target-feature" "-save-restore" "-target-abi" "cheriot-baremetal" -E -dM < /dev/null | FileCheck -check-prefixes CHERIOT,CHERIOT-BAREMETAL %s
394-
// CHERIOT-BAREMETAL: #define __CHERIOT_BAREMETAL__ 20250610
395-
// CHERIOT: #define __CHERIOT__ 20250610
394+
// CHERIOT-BAREMETAL: #define __CHERIOT_BAREMETAL__ 20250701
395+
// CHERIOT: #define __CHERIOT__ 20250701
396396

397397

398398
// RUN: %cheri128_cc1 -fgnuc-version=4.2.1 -E -dM -ffreestanding < /dev/null | FileCheck -check-prefixes CHERI-COMMON,CHERI-MIPS,CHERI128 %s

lldb/include/lldb/lldb-enumerations.h

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -195,11 +195,12 @@ enum Format {
195195
///< character arrays that can contain non printable
196196
///< characters
197197
eFormatAddressInfo, ///< Describe what an address points to (func + offset
198-
///< with file/line, symbol + offset, data, etc)
199-
eFormatHexFloat, ///< ISO C99 hex float string
200-
eFormatInstruction, ///< Disassemble an opcode
201-
eFormatVoid, ///< Do not print this
198+
///< with file/line, symbol + offset, data, etc)
199+
eFormatHexFloat, ///< ISO C99 hex float string
200+
eFormatInstruction, ///< Disassemble an opcode
201+
eFormatVoid, ///< Do not print this
202202
eFormatUnicode8,
203+
eFormatCheriotCapability,
203204
kNumFormats
204205
};
205206

lldb/source/Commands/CommandObjectMemory.cpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1354,6 +1354,7 @@ class CommandObjectMemoryWrite : public CommandObjectParsed {
13541354
case eFormatAddressInfo:
13551355
case eFormatHexFloat:
13561356
case eFormatInstruction:
1357+
case eFormatCheriotCapability:
13571358
case eFormatVoid:
13581359
result.AppendError("unsupported format for writing memory");
13591360
return;

lldb/source/Core/DumpDataExtractor.cpp

Lines changed: 110 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -413,6 +413,116 @@ lldb::offset_t lldb_private::DumpDataExtractor(
413413
}
414414

415415
switch (item_format) {
416+
case eFormatCheriotCapability: {
417+
if (item_byte_size != 8) {
418+
s->Printf("error: unsupported byte size (%" PRIu64
419+
") for cheriot capability format",
420+
(uint64_t)item_byte_size);
421+
return offset;
422+
}
423+
424+
// Extract the raw bits of the capability.
425+
uint64_t uval64 = DE.GetMaxU64(&offset, item_byte_size);
426+
uint32_t addr = uval64;
427+
uint32_t meta = (uval64 >> 32);
428+
unsigned B = meta & 0x1FF;
429+
unsigned T = (meta >> 9) & 0x1FF;
430+
unsigned E = (meta >> 18) & 0xF;
431+
unsigned otype = (meta >> 22) & 0x7;
432+
std::bitset<6> perms = (meta >> 25) & 0x3F;
433+
434+
bool GL = perms[5];
435+
bool LD = false;
436+
bool MC = false;
437+
bool SD = false;
438+
bool SL = false;
439+
bool LM = false;
440+
bool LG = false;
441+
bool SR = false;
442+
bool EX = false;
443+
bool U0 = false;
444+
bool SE = false;
445+
bool US = false;
446+
447+
// Cheriot capabilities pack 11 permissions into 6 bits,
448+
// so decoding is non-trivial.
449+
if (perms[4] && perms[3]) {
450+
LD = MC = SD = true;
451+
SL = perms[2];
452+
LM = perms[1];
453+
LD = perms[0];
454+
} else if (perms[4] && !perms[3] && perms[2]) {
455+
LD = MC = true;
456+
LM = perms[1];
457+
LG = perms[0];
458+
} else if (perms[4] && !perms[3] && !perms[2] && !perms[1] && !perms[0]) {
459+
SD = MC = true;
460+
} else if (perms[4] && !perms[3] && !perms[2]) {
461+
LD = perms[1];
462+
SD = perms[0];
463+
} else if (!perms[4] && perms[3]) {
464+
EX = LD = MC = true;
465+
SR = perms[2];
466+
LM = perms[1];
467+
LG = perms[0];
468+
} else {
469+
U0 = perms[2];
470+
SE = perms[1];
471+
US = perms[0];
472+
}
473+
474+
// Render the permissions to a string.
475+
std::string perm_string;
476+
perm_string += GL ? 'G' : '-';
477+
perm_string += ' ';
478+
perm_string += LD ? 'R' : '-';
479+
perm_string += SD ? 'W' : '-';
480+
perm_string += MC ? 'c' : '-';
481+
perm_string += LG ? 'g' : '-';
482+
perm_string += LM ? 'm' : '-';
483+
perm_string += SL ? 'l' : '-';
484+
perm_string += ' ';
485+
perm_string += EX ? 'X' : '-';
486+
perm_string += SR ? 'a' : '-';
487+
perm_string += ' ';
488+
perm_string += SE ? 'S' : '-';
489+
perm_string += US ? 'U' : '-';
490+
perm_string += U0 ? '0' : '-';
491+
492+
// Decode otype, and present with a semantic string if possible.
493+
if (otype != 0 && !EX)
494+
otype += 8;
495+
constexpr llvm::StringRef otypes[] = {
496+
"[unsealed]",
497+
"[IRQ inherit forward sentry]",
498+
"[IRQ disable forward sentry]",
499+
"[IRQ enable forward sentry]",
500+
"[IRQ disable return sentry]",
501+
"[IRQ enable return sentry]",
502+
};
503+
llvm::StringRef otype_str = (otype < sizeof(otypes)) ? otypes[otype] : "";
504+
505+
// Compute the base and top addresses for the bounds.
506+
unsigned e = (E != 15) ? E : 24;
507+
uint64_t a_top = addr >> (e + 9);
508+
uint64_t a_mid = (addr >> e) & 0x1FF;
509+
uint64_t a_hi = (a_mid < B) ? 1 : 0;
510+
uint64_t t_hi = (T < B) ? 1 : 0;
511+
uint64_t c_b = -a_hi;
512+
uint64_t c_t = t_hi - a_hi;
513+
uint64_t a_top_base = a_top + c_b;
514+
uint64_t a_top_top = a_top + c_t;
515+
uint64_t base = ((a_top_base << 9) + B) << e;
516+
uint64_t top = ((a_top_top << 9) + T) << e;
517+
uint64_t len = top - base;
518+
519+
s->Printf("0x%08" PRIx32 " (v:? 0x%08" PRIx64 "-0x%08" PRIx64
520+
" l:0x%" PRIx64 " o:0x%x%s p: %s)",
521+
addr, base, top, len, otype, otype_str.data(),
522+
perm_string.c_str());
523+
524+
break;
525+
}
416526
case eFormatBoolean:
417527
if (item_byte_size <= 8)
418528
s->Printf("%s", DE.GetMaxU64Bitfield(&offset, item_byte_size,

lldb/source/DataFormatters/FormatManager.cpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -72,6 +72,7 @@ static constexpr FormatInfo g_format_infos[] = {
7272
{eFormatInstruction, 'i', "instruction"},
7373
{eFormatVoid, 'v', "void"},
7474
{eFormatUnicode8, 'u', "unicode8"},
75+
{eFormatCheriotCapability, 'P', "cheriot capability"},
7576
};
7677

7778
static_assert((sizeof(g_format_infos) / sizeof(g_format_infos[0])) ==

lldb/source/Plugins/Process/gdb-remote/ProcessGDBRemote.cpp

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4743,6 +4743,10 @@ bool ParseRegisters(
47434743
"format and encoding for gdb type %s",
47444744
gdb_type.c_str());
47454745
}
4746+
4747+
if (gdb_type == "cheriot capability") {
4748+
reg_info.format = eFormatCheriotCapability;
4749+
}
47464750
}
47474751
}
47484752

0 commit comments

Comments
 (0)