Page MenuHomePhabricator

[Clang interpreter] Avoid storing pointers at unaligned locations

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



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

Unit TestsFailed

50 msx64 debian > Flang.Semantics::resolve102.f90
Script: -- : 'RUN: at line 1'; /mnt/disks/ssd0/agent/llvm-project/flang/test/Semantics/ /mnt/disks/ssd0/agent/llvm-project/flang/test/Semantics/resolve102.f90 /mnt/disks/ssd0/agent/llvm-project/build/tools/flang/test/Semantics/Output/resolve102.f90.tmp /mnt/disks/ssd0/agent/llvm-project/build/bin/f18 -intrinsic-module-directory /mnt/disks/ssd0/agent/llvm-project/build/tools/flang/include/flang
110 msx64 windows > Clang.CodeGenCXX::attr-retain.cpp
Script: -- : 'RUN: at line 1'; c:\ws\w1\llvm-project\premerge-checks\build\bin\clang.exe -cc1 -internal-isystem c:\ws\w1\llvm-project\premerge-checks\build\lib\clang\13.0.0\include -nostdsysteminc -emit-llvm -triple x86_64-pc-windows-gnu -Werror C:\ws\w1\llvm-project\premerge-checks\clang\test\CodeGenCXX\attr-retain.cpp -o - | c:\ws\w1\llvm-project\premerge-checks\build\bin\filecheck.exe C:\ws\w1\llvm-project\premerge-checks\clang\test\CodeGenCXX\attr-retain.cpp

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.


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