-
Notifications
You must be signed in to change notification settings - Fork 10
[CHERIoT] Add the __builtin_cheriot_sealing_type clang built-in
#169
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[CHERIoT] Add the __builtin_cheriot_sealing_type clang built-in
#169
Conversation
clang/lib/CodeGen/CGBuiltin.cpp
Outdated
|
|
||
| if (!GV) { | ||
| llvm::StructType *opaqueType = llvm::StructType::create( | ||
| CGM.getModule().getContext(), "__Opaque_" + SealingTypeName); |
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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.
3b13e4a to
59297a3
Compare
clang/lib/CodeGen/CGBuiltin.cpp
Outdated
| auto PrefixedImportName = | ||
| CHERIoTSealingKeyTypeAttr::getSealingTypeSymbolName(CompartmentName, | ||
| SealingTypeName); | ||
| auto *Mod = &CGM.getModule(); |
There was a problem hiding this comment.
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
There was a problem hiding this comment.
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();
There was a problem hiding this comment.
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();
There was a problem hiding this comment.
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; |
There was a problem hiding this comment.
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 ;-)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Changed that way.
c8766db to
355a4b1
Compare
|
Latest commit also adds a warning emitted when the built-in is used but no compartment name is given. |
355a4b1 to
2d406ca
Compare
Any particular reason it's a warning rather than an error? |
2d406ca to
3ee26b4
Compare
3ee26b4 to
aabac6c
Compare
|
I made into an error with the latest commit. Indeed, it would not make any sense to generate symbols in the |
This PR introduces a new
__builtin_cheriot_sealing_typebuilt-in command in clang, that should replace theCHERIOT_EMIT_STATIC_SEALING_TYPEmacro, as referenced in #6: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,
and
are generated, respectively in the
.compartment_importsand.compartment_exportssections. The value of the import is a sequence of two words: the address of the export and0. The value of the export reproduces the value generated in the original macro.