Skip to content

Commit d69cbed

Browse files
[LLVM][rtsan] Add LLVM attribute sanitize_realtime_unsafe
1 parent a3816b5 commit d69cbed

File tree

8 files changed

+45
-19
lines changed

8 files changed

+45
-19
lines changed

llvm/docs/LangRef.rst

Lines changed: 22 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -354,7 +354,7 @@ added in the future:
354354
not be used lightly but only for specific situations such as an
355355
alternative to the *register pinning* performance technique often
356356
used when implementing functional programming languages. At the
357-
moment only X86, AArch64, and RISCV support this convention. The
357+
moment only X86, AArch64, and RISCV support this convention. The
358358
following limitations exist:
359359

360360
- On *X86-32* only up to 4 bit type parameters are supported. No
@@ -685,10 +685,10 @@ implementation defined, the optimizer can't do the latter. The former is
685685
challenging as many commonly expected properties, such as
686686
``ptrtoint(v)-ptrtoint(v) == 0``, don't hold for non-integral types.
687687
Similar restrictions apply to intrinsics that might examine the pointer bits,
688-
such as :ref:`llvm.ptrmask<int_ptrmask>`.
688+
such as :ref:`llvm.ptrmask<int_ptrmask>`.
689689

690690
The alignment information provided by the frontend for a non-integral pointer
691-
(typically using attributes or metadata) must be valid for every possible
691+
(typically using attributes or metadata) must be valid for every possible
692692
representation of the pointer.
693693

694694
.. _globalvars:
@@ -1677,10 +1677,10 @@ Currently, only the following parameter attributes are defined:
16771677
- The range is allowed to wrap.
16781678
- The empty range is represented using ``0,0``.
16791679
- Otherwise, ``a`` and ``b`` are not allowed to be equal.
1680-
1681-
This attribute may only be applied to parameters or return values with integer
1680+
1681+
This attribute may only be applied to parameters or return values with integer
16821682
or vector of integer types.
1683-
1683+
16841684
For vector-typed parameters, the range is applied element-wise.
16851685

16861686
.. _gc:
@@ -2315,6 +2315,11 @@ example:
23152315
This attribute indicates that RealtimeSanitizer checks
23162316
(realtime safety analysis - no allocations, syscalls or exceptions) are enabled
23172317
for this function.
2318+
``sanitize_realtime_unsafe``
2319+
This attribute indicates that RealtimeSanitizer should error immediately
2320+
if the attributed function is called during invocation of a function
2321+
attributed with ``sanitize_realtime``.
2322+
This attribute is incompatible with the ``sanitize_realtime`` attribute.
23182323
``speculative_load_hardening``
23192324
This attribute indicates that
23202325
`Speculative Load Hardening <https://llvm.org/docs/SpeculativeLoadHardening.html>`_
@@ -14342,7 +14347,7 @@ Arguments:
1434214347
""""""""""
1434314348
The first 4 arguments are similar to ``llvm.instrprof.increment``. The indexing
1434414349
is specific to callsites, meaning callsites are indexed from 0, independent from
14345-
the indexes used by the other intrinsics (such as
14350+
the indexes used by the other intrinsics (such as
1434614351
``llvm.instrprof.increment[.step]``).
1434714352

1434814353
The last argument is the called value of the callsite this intrinsic precedes.
@@ -14356,7 +14361,7 @@ a buffer LLVM can use to perform counter increments (i.e. the lowering of
1435614361
``llvm.instrprof.increment[.step]``. The address range following the counter
1435714362
buffer, ``<num-counters>`` x ``sizeof(ptr)`` - sized, is expected to contain
1435814363
pointers to contexts of functions called from this function ("subcontexts").
14359-
LLVM does not dereference into that memory region, just calculates GEPs.
14364+
LLVM does not dereference into that memory region, just calculates GEPs.
1436014365

1436114366
The lowering of ``llvm.instrprof.callsite`` consists of:
1436214367

@@ -14925,8 +14930,8 @@ integer bit width or any vector of integer elements.
1492514930
Overview:
1492614931
"""""""""
1492714932

14928-
Return ``-1`` if ``%a`` is signed less than ``%b``, ``0`` if they are equal, and
14929-
``1`` if ``%a`` is signed greater than ``%b``. Vector intrinsics operate on a per-element basis.
14933+
Return ``-1`` if ``%a`` is signed less than ``%b``, ``0`` if they are equal, and
14934+
``1`` if ``%a`` is signed greater than ``%b``. Vector intrinsics operate on a per-element basis.
1493014935

1493114936
Arguments:
1493214937
""""""""""
@@ -14954,8 +14959,8 @@ integer bit width or any vector of integer elements.
1495414959
Overview:
1495514960
"""""""""
1495614961

14957-
Return ``-1`` if ``%a`` is unsigned less than ``%b``, ``0`` if they are equal, and
14958-
``1`` if ``%a`` is unsigned greater than ``%b``. Vector intrinsics operate on a per-element basis.
14962+
Return ``-1`` if ``%a`` is unsigned less than ``%b``, ``0`` if they are equal, and
14963+
``1`` if ``%a`` is unsigned greater than ``%b``. Vector intrinsics operate on a per-element basis.
1495914964

1496014965
Arguments:
1496114966
""""""""""
@@ -21552,9 +21557,9 @@ Semantics:
2155221557
""""""""""
2155321558

2155421559
The '``llvm.vp.minimum``' intrinsic performs floating-point minimum (:ref:`minimum <i_minimum>`)
21555-
of the first and second vector arguments on each enabled lane, the result being
21560+
of the first and second vector arguments on each enabled lane, the result being
2155621561
NaN if either argument is a NaN. -0.0 is considered to be less than +0.0 for this
21557-
intrinsic. The result on disabled lanes is a :ref:`poison value <poisonvalues>`.
21562+
intrinsic. The result on disabled lanes is a :ref:`poison value <poisonvalues>`.
2155821563
The operation is performed in the default floating-point environment.
2155921564

2156021565
Examples:
@@ -29187,7 +29192,7 @@ Semantics:
2918729192
""""""""""
2918829193

2918929194
The intrinsic ``@llvm.allow.ubsan.check()`` returns either ``true`` or
29190-
``false``, depending on compiler options.
29195+
``false``, depending on compiler options.
2919129196

2919229197
For each evaluation of a call to this intrinsic, the program must be valid and
2919329198
correct both if it returns ``true`` and if it returns ``false``.
@@ -29246,13 +29251,13 @@ Semantics:
2924629251
""""""""""
2924729252

2924829253
The intrinsic ``@llvm.allow.runtime.check()`` returns either ``true`` or
29249-
``false``, depending on compiler options.
29254+
``false``, depending on compiler options.
2925029255

2925129256
For each evaluation of a call to this intrinsic, the program must be valid and
2925229257
correct both if it returns ``true`` and if it returns ``false``.
2925329258

2925429259
When used in a branch condition, it allows us to choose between
29255-
two alternative correct solutions for the same problem.
29260+
two alternative correct solutions for the same problem.
2925629261

2925729262
If the intrinsic is evaluated as ``true``, program should execute a guarded
2925829263
check. If the intrinsic is evaluated as ``false``, the program should avoid any

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_SANITIZE_REALTIME_UNSAFE = 97,
762763
};
763764

764765
enum ComdatSelectionKindCodes {

llvm/include/llvm/IR/Attributes.td

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -300,6 +300,10 @@ def SanitizeNumericalStability : EnumAttr<"sanitize_numerical_stability", [FnAtt
300300
/// RealtimeSanitizer is on.
301301
def SanitizeRealtime : EnumAttr<"sanitize_realtime", [FnAttr]>;
302302

303+
/// RealtimeSanitizer should error if an realtime_unsafe function is called
304+
/// during a sanitize_realtime function.
305+
def SanitizeRealtimeUnsafe : EnumAttr<"sanitize_realtime_unsafe", [FnAttr]>;
306+
303307
/// Speculative Load Hardening is enabled.
304308
///
305309
/// Note that this uses the default compatibility (always compatible during
@@ -389,6 +393,7 @@ def : CompatRule<"isEqual<SanitizeHWAddressAttr>">;
389393
def : CompatRule<"isEqual<SanitizeMemTagAttr>">;
390394
def : CompatRule<"isEqual<SanitizeNumericalStabilityAttr>">;
391395
def : CompatRule<"isEqual<SanitizeRealtimeAttr>">;
396+
def : CompatRule<"isEqual<SanitizeRealtimeUnsafeAttr>">;
392397
def : CompatRule<"isEqual<SafeStackAttr>">;
393398
def : CompatRule<"isEqual<ShadowCallStackAttr>">;
394399
def : CompatRule<"isEqual<UseSampleProfileAttr>">;

llvm/lib/Bitcode/Reader/BitcodeReader.cpp

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2143,6 +2143,8 @@ static Attribute::AttrKind getAttrFromCode(uint64_t Code) {
21432143
return Attribute::SanitizeNumericalStability;
21442144
case bitc::ATTR_KIND_SANITIZE_REALTIME:
21452145
return Attribute::SanitizeRealtime;
2146+
case bitc::ATTR_KIND_SANITIZE_REALTIME_UNSAFE:
2147+
return Attribute::SanitizeRealtimeUnsafe;
21462148
case bitc::ATTR_KIND_SPECULATIVE_LOAD_HARDENING:
21472149
return Attribute::SpeculativeLoadHardening;
21482150
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
@@ -845,6 +845,8 @@ static uint64_t getAttrKindEncoding(Attribute::AttrKind Kind) {
845845
return bitc::ATTR_KIND_SANITIZE_NUMERICAL_STABILITY;
846846
case Attribute::SanitizeRealtime:
847847
return bitc::ATTR_KIND_SANITIZE_REALTIME;
848+
case Attribute::SanitizeRealtimeUnsafe:
849+
return bitc::ATTR_KIND_SANITIZE_REALTIME_UNSAFE;
848850
case Attribute::SpeculativeLoadHardening:
849851
return bitc::ATTR_KIND_SPECULATIVE_LOAD_HARDENING;
850852
case Attribute::SwiftError:

llvm/lib/Transforms/Utils/CodeExtractor.cpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -951,6 +951,7 @@ Function *CodeExtractor::constructFunction(const ValueSet &inputs,
951951
case Attribute::SanitizeHWAddress:
952952
case Attribute::SanitizeMemTag:
953953
case Attribute::SanitizeRealtime:
954+
case Attribute::SanitizeRealtimeUnsafe:
954955
case Attribute::SpeculativeLoadHardening:
955956
case Attribute::StackProtect:
956957
case Attribute::StackProtectReq:

llvm/test/Bitcode/attributes.ll

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

514+
; CHECK: define void @f93() #54
515+
define void @f93() sanitize_realtime_unsafe {
516+
ret void;
517+
}
518+
514519
; CHECK: define void @f87() [[FNRETTHUNKEXTERN:#[0-9]+]]
515520
define void @f87() fn_ret_thunk_extern { ret void }
516521

@@ -606,6 +611,7 @@ define void @initializes(ptr initializes((-4, 0), (4, 8)) %a) {
606611
; CHECK: attributes #51 = { uwtable(sync) }
607612
; CHECK: attributes #52 = { nosanitize_bounds }
608613
; CHECK: attributes #53 = { sanitize_realtime }
614+
; CHECK: attributes #54 = { sanitize_realtime_unsafe }
609615
; CHECK: attributes [[FNRETTHUNKEXTERN]] = { fn_ret_thunk_extern }
610616
; CHECK: attributes [[SKIPPROFILE]] = { skipprofile }
611617
; 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.sanitize_realtime_unsafe() sanitize_realtime_unsafe
1996+
; CHECK: declare void @f.sanitize_realtime_unsafe() #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 = { sanitize_realtime_unsafe }
2122+
; CHECK: attributes #54 = { builtin }
21192123

21202124
;; Metadata
21212125

0 commit comments

Comments
 (0)