Skip to content

Commit 178fc47

Browse files
authored
[LLVM][rtsan] Add LLVM nosanitize_realtime attribute (#105447)
1 parent 34dee0a commit 178fc47

File tree

10 files changed

+42
-2
lines changed

10 files changed

+42
-2
lines changed

llvm/docs/LangRef.rst

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2189,6 +2189,10 @@ example:
21892189
``nosanitize_coverage``
21902190
This attribute indicates that SanitizerCoverage instrumentation is disabled
21912191
for this function.
2192+
``nosanitize_realtime``
2193+
This attribute indicates that the Realtime Sanitizer instrumentation is
2194+
disabled for this function.
2195+
This attribute is incompatible with the ``sanitize_realtime`` attribute.
21922196
``null_pointer_is_valid``
21932197
If ``null_pointer_is_valid`` is set, then the ``null`` address
21942198
in address-space 0 is considered to be a valid address for memory loads and
@@ -2315,6 +2319,7 @@ example:
23152319
This attribute indicates that RealtimeSanitizer checks
23162320
(realtime safety analysis - no allocations, syscalls or exceptions) are enabled
23172321
for this function.
2322+
This attribute is incompatible with the ``nosanitize_realtime`` attribute.
23182323
``speculative_load_hardening``
23192324
This attribute indicates that
23202325
`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
@@ -759,6 +759,7 @@ enum AttributeKindCodes {
759759
ATTR_KIND_INITIALIZES = 94,
760760
ATTR_KIND_HYBRID_PATCHABLE = 95,
761761
ATTR_KIND_SANITIZE_REALTIME = 96,
762+
ATTR_KIND_NO_SANITIZE_REALTIME = 97,
762763
};
763764

764765
enum ComdatSelectionKindCodes {

llvm/include/llvm/IR/Attributes.td

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -212,6 +212,9 @@ def NoSanitizeBounds : EnumAttr<"nosanitize_bounds", [FnAttr]>;
212212
/// No SanitizeCoverage instrumentation.
213213
def NoSanitizeCoverage : EnumAttr<"nosanitize_coverage", [FnAttr]>;
214214

215+
/// No SanitizeRealtime instrumentation.
216+
def NoSanitizeRealtime : EnumAttr<"nosanitize_realtime", [FnAttr]>;
217+
215218
/// Null pointer in address space zero is valid.
216219
def NullPointerIsValid : EnumAttr<"null_pointer_is_valid", [FnAttr]>;
217220

llvm/lib/Bitcode/Reader/BitcodeReader.cpp

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2093,6 +2093,8 @@ static Attribute::AttrKind getAttrFromCode(uint64_t Code) {
20932093
return Attribute::NoSanitizeBounds;
20942094
case bitc::ATTR_KIND_NO_SANITIZE_COVERAGE:
20952095
return Attribute::NoSanitizeCoverage;
2096+
case bitc::ATTR_KIND_NO_SANITIZE_REALTIME:
2097+
return Attribute::NoSanitizeRealtime;
20962098
case bitc::ATTR_KIND_NULL_POINTER_IS_VALID:
20972099
return Attribute::NullPointerIsValid;
20982100
case bitc::ATTR_KIND_OPTIMIZE_FOR_DEBUGGING:

llvm/lib/Bitcode/Writer/BitcodeWriter.cpp

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -795,6 +795,8 @@ static uint64_t getAttrKindEncoding(Attribute::AttrKind Kind) {
795795
return bitc::ATTR_KIND_NO_SANITIZE_BOUNDS;
796796
case Attribute::NoSanitizeCoverage:
797797
return bitc::ATTR_KIND_NO_SANITIZE_COVERAGE;
798+
case llvm::Attribute::NoSanitizeRealtime:
799+
return bitc::ATTR_KIND_NO_SANITIZE_REALTIME;
798800
case Attribute::NullPointerIsValid:
799801
return bitc::ATTR_KIND_NULL_POINTER_IS_VALID;
800802
case Attribute::OptimizeForDebugging:

llvm/lib/IR/Verifier.cpp

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2223,6 +2223,12 @@ void Verifier::verifyFunctionAttrs(FunctionType *FT, AttributeList Attrs,
22232223
"Attributes 'optdebug and optnone' are incompatible!", V);
22242224
}
22252225

2226+
Check(!(Attrs.hasFnAttr(Attribute::SanitizeRealtime) &&
2227+
Attrs.hasFnAttr(Attribute::NoSanitizeRealtime)),
2228+
"Attributes "
2229+
"'sanitize_realtime and nosanitize_realtime' are incompatible!",
2230+
V);
2231+
22262232
if (Attrs.hasFnAttr(Attribute::OptimizeForDebugging)) {
22272233
Check(!Attrs.hasFnAttr(Attribute::OptimizeForSize),
22282234
"Attributes 'optsize and optdebug' are incompatible!", V);

llvm/lib/Transforms/Utils/CodeExtractor.cpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -937,6 +937,7 @@ Function *CodeExtractor::constructFunction(const ValueSet &inputs,
937937
case Attribute::NoUnwind:
938938
case Attribute::NoSanitizeBounds:
939939
case Attribute::NoSanitizeCoverage:
940+
case Attribute::NoSanitizeRealtime:
940941
case Attribute::NullPointerIsValid:
941942
case Attribute::OptimizeForDebugging:
942943
case Attribute::OptForFuzzing:

llvm/test/Bitcode/attributes.ll

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -511,6 +511,12 @@ define void @f92() sanitize_realtime
511511
ret void;
512512
}
513513

514+
; CHECK: define void @f93() #54
515+
define void @f93() nosanitize_realtime
516+
{
517+
ret void;
518+
}
519+
514520
; CHECK: define void @f87() [[FNRETTHUNKEXTERN:#[0-9]+]]
515521
define void @f87() fn_ret_thunk_extern { ret void }
516522

@@ -606,6 +612,7 @@ define void @initializes(ptr initializes((-4, 0), (4, 8)) %a) {
606612
; CHECK: attributes #51 = { uwtable(sync) }
607613
; CHECK: attributes #52 = { nosanitize_bounds }
608614
; CHECK: attributes #53 = { sanitize_realtime }
615+
; CHECK: attributes #54 = { nosanitize_realtime }
609616
; CHECK: attributes [[FNRETTHUNKEXTERN]] = { fn_ret_thunk_extern }
610617
; CHECK: attributes [[SKIPPROFILE]] = { skipprofile }
611618
; 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() #53
1565+
; CHECK: call void @f.nobuiltin() #54
15661566

15671567
call fastcc noalias ptr @f.noalias() noinline
15681568
; CHECK: call fastcc noalias ptr @f.noalias() #12
@@ -1992,6 +1992,9 @@ declare void @f.sanitize_numerical_stability() sanitize_numerical_stability
19921992
declare void @f.sanitize_realtime() sanitize_realtime
19931993
; CHECK: declare void @f.sanitize_realtime() #52
19941994

1995+
declare void @f.nosanitize_realtime() nosanitize_realtime
1996+
; CHECK: declare void @f.nosanitize_realtime() #53
1997+
19951998
; CHECK: declare nofpclass(snan) float @nofpclass_snan(float nofpclass(snan))
19961999
declare nofpclass(snan) float @nofpclass_snan(float nofpclass(snan))
19972000

@@ -2115,7 +2118,8 @@ define float @nofpclass_callsites(float %arg) {
21152118
; CHECK: attributes #50 = { allockind("alloc,uninitialized") }
21162119
; CHECK: attributes #51 = { sanitize_numerical_stability }
21172120
; CHECK: attributes #52 = { sanitize_realtime }
2118-
; CHECK: attributes #53 = { builtin }
2121+
; CHECK: attributes #53 = { nosanitize_realtime }
2122+
; CHECK: attributes #54 = { builtin }
21192123

21202124
;; Metadata
21212125

llvm/test/Verifier/rtsan-attrs.ll

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
; RUN: not llvm-as -disable-output %s 2>&1 | FileCheck %s
2+
3+
; CHECK: Attributes 'sanitize_realtime and nosanitize_realtime' are incompatible!
4+
; CHECK-NEXT: ptr @sanitize_nosanitize
5+
define void @sanitize_nosanitize() #0 {
6+
ret void
7+
}
8+
9+
attributes #0 = { sanitize_realtime nosanitize_realtime }

0 commit comments

Comments
 (0)