Skip to content

Conversation

@xdoardo
Copy link
Collaborator

@xdoardo xdoardo commented Jun 5, 2025

This PR introduces a new __builtin_cheriot_sealing_type built-in command in clang, that should replace the CHERIOT_EMIT_STATIC_SEALING_TYPE macro, as referenced in #6:

__builtin_cheriot_sealing_type("MySealingType")

Note that, differently from the suggested syntax in the issue quoted above, the built-in uses a string to specify the name of the type, rather than using a raw identifier. This choice was made in order to avoid inserting custom code in the parser.

The side effects of this call is that two new entries,

__import.sealing_type.<current_compartment>.MySealingType

and

__export.sealing_type.<current_compartment>.MySealingType

are generated, respectively in the .compartment_imports and .compartment_exports sections. The value of the import is a sequence of two words: the address of the export and 0. The value of the export reproduces the value generated in the original macro.


if (!GV) {
llvm::StructType *opaqueType = llvm::StructType::create(
CGM.getModule().getContext(), "__Opaque_" + SealingTypeName);

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Do we need to define a new type here? The global should just be opaque.

Copy link
Collaborator Author

@xdoardo xdoardo Jun 5, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It appears to me that there is no built-in opaque struct type that can be used this way. So, this PR now produces a new type only once. I also added a comment explaining the role of the global.

@xdoardo xdoardo force-pushed the cheriot-emit-static-sealing-type branch 2 times, most recently from 3b13e4a to 59297a3 Compare June 5, 2025 13:14
auto PrefixedImportName =
CHERIoTSealingKeyTypeAttr::getSealingTypeSymbolName(CompartmentName,
SealingTypeName);
auto *Mod = &CGM.getModule();
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No need to take the address here

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

= CGM.getModule() uses a deleted constructor:

llvm-project/clang/lib/CodeGen/CGBuiltin.cpp:6166:10: error: call to implicitly-deleted copy constructor of 'llvm::Module'
 6166 |     auto Mod = CGM.getModule();

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The way to do it is auto &Mod = CGM.getModule();

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

struct CompartmentExport {
/// The compartment name for the object.
std::string CompartmentName;
std::variant<FunctionCompartmentExport, SealingKeyCompartmentExport> Object;
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Alternatively, you could just have two vectors, one for FunctionCompartmentExport's and one for SealingKeyCompartmentExport's ;-)

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Changed that way.

@xdoardo xdoardo force-pushed the cheriot-emit-static-sealing-type branch 3 times, most recently from c8766db to 355a4b1 Compare June 10, 2025 12:33
@xdoardo
Copy link
Collaborator Author

xdoardo commented Jun 10, 2025

Latest commit also adds a warning emitted when the built-in is used but no compartment name is given.

@resistor
Copy link
Collaborator

Latest commit also adds a warning emitted when the built-in is used but no compartment name is given.

Any particular reason it's a warning rather than an error?

@xdoardo xdoardo force-pushed the cheriot-emit-static-sealing-type branch from 2d406ca to 3ee26b4 Compare June 11, 2025 10:38
@xdoardo xdoardo force-pushed the cheriot-emit-static-sealing-type branch from 3ee26b4 to aabac6c Compare June 11, 2025 10:48
@xdoardo
Copy link
Collaborator Author

xdoardo commented Jun 11, 2025

I made into an error with the latest commit. Indeed, it would not make any sense to generate symbols in the __import.sealing_type..<sealing_key> format.

@xdoardo xdoardo merged commit 2aa7cfa into CHERIoT-Platform:cheriot Jun 11, 2025
7 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants