Skip to content

Commit b143b24

Browse files
authored
[LLVM][rtsan] Add sanitize_realtime attribute for the realtime sanitizer (#100596)
Add a new "sanitize_realtime" attribute, which will correspond to the nonblocking function effect in clang. This is used in the realtime sanitizer transform. Please see the [reviewer support document](https://github.com/realtime-sanitizer/radsan/blob/doc/review-support/doc/review.md) for what our next steps are. The original discourse thread can be found [here](https://discourse.llvm.org/t/rfc-nolock-and-noalloc-attributes/76837)
1 parent fd7d788 commit b143b24

File tree

8 files changed

+27
-2
lines changed

8 files changed

+27
-2
lines changed

llvm/docs/LangRef.rst

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2309,6 +2309,10 @@ example:
23092309
This attribute indicates that MemTagSanitizer checks
23102310
(dynamic address safety analysis based on Armv8 MTE) are enabled for
23112311
this function.
2312+
``sanitize_realtime``
2313+
This attribute indicates that RealtimeSanitizer checks
2314+
(realtime safety analysis - no allocations, syscalls or exceptions) are enabled
2315+
for this function.
23122316
``speculative_load_hardening``
23132317
This attribute indicates that
23142318
`Speculative Load Hardening <https://llvm.org/docs/SpeculativeLoadHardening.html>`_

llvm/include/llvm/Bitcode/LLVMBitCodes.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -758,6 +758,7 @@ enum AttributeKindCodes {
758758
ATTR_KIND_SANITIZE_NUMERICAL_STABILITY = 93,
759759
ATTR_KIND_INITIALIZES = 94,
760760
ATTR_KIND_HYBRID_PATCHABLE = 95,
761+
ATTR_KIND_SANITIZE_REALTIME = 96,
761762
};
762763

763764
enum ComdatSelectionKindCodes {

llvm/include/llvm/IR/Attributes.td

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -297,6 +297,9 @@ def SanitizeMemTag : EnumAttr<"sanitize_memtag", [FnAttr]>;
297297
/// NumericalStabilitySanitizer is on.
298298
def SanitizeNumericalStability : EnumAttr<"sanitize_numerical_stability", [FnAttr]>;
299299

300+
/// RealtimeSanitizer is on.
301+
def SanitizeRealtime : EnumAttr<"sanitize_realtime", [FnAttr]>;
302+
300303
/// Speculative Load Hardening is enabled.
301304
///
302305
/// Note that this uses the default compatibility (always compatible during
@@ -385,6 +388,7 @@ def : CompatRule<"isEqual<SanitizeMemoryAttr>">;
385388
def : CompatRule<"isEqual<SanitizeHWAddressAttr>">;
386389
def : CompatRule<"isEqual<SanitizeMemTagAttr>">;
387390
def : CompatRule<"isEqual<SanitizeNumericalStabilityAttr>">;
391+
def : CompatRule<"isEqual<SanitizeRealtimeAttr>">;
388392
def : CompatRule<"isEqual<SafeStackAttr>">;
389393
def : CompatRule<"isEqual<ShadowCallStackAttr>">;
390394
def : CompatRule<"isEqual<UseSampleProfileAttr>">;

llvm/lib/Bitcode/Reader/BitcodeReader.cpp

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2141,6 +2141,8 @@ static Attribute::AttrKind getAttrFromCode(uint64_t Code) {
21412141
return Attribute::SanitizeMemory;
21422142
case bitc::ATTR_KIND_SANITIZE_NUMERICAL_STABILITY:
21432143
return Attribute::SanitizeNumericalStability;
2144+
case bitc::ATTR_KIND_SANITIZE_REALTIME:
2145+
return Attribute::SanitizeRealtime;
21442146
case bitc::ATTR_KIND_SPECULATIVE_LOAD_HARDENING:
21452147
return Attribute::SpeculativeLoadHardening;
21462148
case bitc::ATTR_KIND_SWIFT_ERROR:

llvm/lib/Bitcode/Writer/BitcodeWriter.cpp

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -843,6 +843,8 @@ static uint64_t getAttrKindEncoding(Attribute::AttrKind Kind) {
843843
return bitc::ATTR_KIND_SANITIZE_MEMORY;
844844
case Attribute::SanitizeNumericalStability:
845845
return bitc::ATTR_KIND_SANITIZE_NUMERICAL_STABILITY;
846+
case Attribute::SanitizeRealtime:
847+
return bitc::ATTR_KIND_SANITIZE_REALTIME;
846848
case Attribute::SpeculativeLoadHardening:
847849
return bitc::ATTR_KIND_SPECULATIVE_LOAD_HARDENING;
848850
case Attribute::SwiftError:

llvm/lib/Transforms/Utils/CodeExtractor.cpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -959,6 +959,7 @@ Function *CodeExtractor::constructFunction(const ValueSet &inputs,
959959
case Attribute::SanitizeThread:
960960
case Attribute::SanitizeHWAddress:
961961
case Attribute::SanitizeMemTag:
962+
case Attribute::SanitizeRealtime:
962963
case Attribute::SpeculativeLoadHardening:
963964
case Attribute::StackProtect:
964965
case Attribute::StackProtectReq:

llvm/test/Bitcode/attributes.ll

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -505,6 +505,12 @@ define void @f86() nosanitize_bounds
505505
ret void;
506506
}
507507

508+
; CHECK: define void @f92() #53
509+
define void @f92() sanitize_realtime
510+
{
511+
ret void;
512+
}
513+
508514
; CHECK: define void @f87() [[FNRETTHUNKEXTERN:#[0-9]+]]
509515
define void @f87() fn_ret_thunk_extern { ret void }
510516

@@ -599,6 +605,7 @@ define void @initializes(ptr initializes((-4, 0), (4, 8)) %a) {
599605
; CHECK: attributes #50 = { disable_sanitizer_instrumentation }
600606
; CHECK: attributes #51 = { uwtable(sync) }
601607
; CHECK: attributes #52 = { nosanitize_bounds }
608+
; CHECK: attributes #53 = { sanitize_realtime }
602609
; CHECK: attributes [[FNRETTHUNKEXTERN]] = { fn_ret_thunk_extern }
603610
; CHECK: attributes [[SKIPPROFILE]] = { skipprofile }
604611
; CHECK: attributes [[OPTDEBUG]] = { optdebug }

llvm/test/Bitcode/compatibility.ll

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1562,7 +1562,7 @@ exit:
15621562
; CHECK: select <2 x i1> <i1 true, i1 false>, <2 x i8> <i8 2, i8 3>, <2 x i8> <i8 3, i8 2>
15631563

15641564
call void @f.nobuiltin() builtin
1565-
; CHECK: call void @f.nobuiltin() #52
1565+
; CHECK: call void @f.nobuiltin() #53
15661566

15671567
call fastcc noalias ptr @f.noalias() noinline
15681568
; CHECK: call fastcc noalias ptr @f.noalias() #12
@@ -1989,6 +1989,9 @@ declare void @f.allockind() allockind("alloc,uninitialized")
19891989
declare void @f.sanitize_numerical_stability() sanitize_numerical_stability
19901990
; CHECK: declare void @f.sanitize_numerical_stability() #51
19911991

1992+
declare void @f.sanitize_realtime() sanitize_realtime
1993+
; CHECK: declare void @f.sanitize_realtime() #52
1994+
19921995
; CHECK: declare nofpclass(snan) float @nofpclass_snan(float nofpclass(snan))
19931996
declare nofpclass(snan) float @nofpclass_snan(float nofpclass(snan))
19941997

@@ -2111,7 +2114,8 @@ define float @nofpclass_callsites(float %arg) {
21112114
; CHECK: attributes #49 = { nosanitize_bounds }
21122115
; CHECK: attributes #50 = { allockind("alloc,uninitialized") }
21132116
; CHECK: attributes #51 = { sanitize_numerical_stability }
2114-
; CHECK: attributes #52 = { builtin }
2117+
; CHECK: attributes #52 = { sanitize_realtime }
2118+
; CHECK: attributes #53 = { builtin }
21152119

21162120
;; Metadata
21172121

0 commit comments

Comments
 (0)