This is an archive of the discontinued LLVM Phabricator instance.

[Clang interpreter] Avoid storing pointers at unaligned locations
ClosedPublic

Authored by jrtc27 on Feb 26 2021, 7:27 PM.

Details

Summary

The Clang interpreter's bytecode uses a packed stream of bytes
representation, but also wants to have some opcodes take pointers as
arguments, which are currently embedded in the bytecode directly.

However, CHERI, and thus Arm's upcoming experimental Morello prototype,
provide spatial memory safety for C/C++ by implementing language-level
(and sub-language-level) pointers as capabilities, which track bounds,
permissions and validity in hardware. This uses tagged memory with a
single tag bit at every capability-aligned address, and so storing
pointers to unaligned addresses results in the tag being stripped,
leading to a tag fault when the pointer is ultimately dereferenced at a
later point.

In order to support a stricter C/C++ implementation like CHERI, we no
longer store pointers directly in the bytecode, instead storing them in
a table and embedding the index in the bytecode.

Diff Detail

Event Timeline

jrtc27 created this revision.Feb 26 2021, 7:27 PM
jrtc27 requested review of this revision.Feb 26 2021, 7:27 PM
Herald added a project: Restricted Project. · View Herald TranscriptFeb 26 2021, 7:27 PM
Herald added a subscriber: cfe-commits. · View Herald Transcript
jrtc27 updated this revision to Diff 326872.Feb 26 2021, 7:30 PM

Reworked code slightly to make it look nicer after clang-format uglified it

Is there any way I can usefully test this? As far as I can tell there's only a single constexpr test in the tree that uses the new interpreter, and it's pretty trivial?

nand added a comment.Mar 3 2021, 12:45 AM

The patches implementing more features/control flow constructs have not yet been committed, so if the pre-existing test passes, the functionality should be fine. Adjustments can be made later on when those patches are rebased.

clang/lib/AST/Interp/Program.h
51

This works for now, but in the future we might want to have a unique integer - pointer mapping for all types that need to be stored in the bytecode.

nand accepted this revision.Mar 3 2021, 12:46 AM
This revision is now accepted and ready to land.Mar 3 2021, 12:46 AM
This revision was landed with ongoing or failed builds.Jul 28 2021, 8:04 AM
This revision was automatically updated to reflect the committed changes.