1569 Commits

Author SHA1 Message Date
davidtrevelyan
4102625380
[rtsan][llvm][NFC] Rename sanitize_realtime_unsafe attr to sanitize_realtime_blocking (#113155)
# What

This PR renames the newly-introduced llvm attribute
`sanitize_realtime_unsafe` to `sanitize_realtime_blocking`. Likewise,
sibling variables such as `SanitizeRealtimeUnsafe` are renamed to
`SanitizeRealtimeBlocking` respectively. There are no other functional
changes.


# Why?

- There are a number of problems that can cause a function to be
real-time "unsafe",
- we wish to communicate what problems rtsan detects and *why* they're
unsafe, and
- a generic "unsafe" attribute is, in our opinion, too broad a net -
which may lead to future implementations that need extra contextual
information passed through them in order to communicate meaningful
reasons to users.
- We want to avoid this situation and make the runtime library boundary
API/ABI as simple as possible, and
- we believe that restricting the scope of attributes to names like
`sanitize_realtime_blocking` is an effective means of doing so.

We also feel that the symmetry between `[[clang::blocking]]` and
`sanitize_realtime_blocking` is easier to follow as a developer.

# Concerns

- I'm aware that the LLVM attribute `sanitize_realtime_unsafe` has been
part of the tree for a few weeks now (introduced here:
https://github.com/llvm/llvm-project/pull/106754). Given that it hasn't
been released in version 20 yet, am I correct in considering this to not
be a breaking change?
2024-10-26 13:06:11 +01:00
Vitaly Buka
cf8d24531e
[msan] Reduces overhead of #113200, by 10% (#113201)
CTMark #113200 size overhead was 5.3%, now it's 4.7%.

The patch affects only signed integers.

https://alive2.llvm.org/ce/z/Lv5hyi

* The patch replaces code which extracted sign bit,
maximized/minimized it, then packed it back, with
simple sign bit flip. The another way to think about
transformation is as a subtraction of MIN_SINT from
A/B. Then we map MIN_SINT to 0, 0 to -MIN_SINT, and
MAX_SINT to MAX_UINT.

* Then to maximize/minimize A/B we don't need
to extract sign bit, we can apply shadow the
same way as to other bits.

* After sign bit flip, we had to switch to unsigned
version of the predicates.

* After change above  getHighestPossibleValue/getLowestPossibleValue
became very similar, so we can combine into a single function.

* Because the function does sign bit flip and
requires unsigned predicates used for returned values,
there is no point in keeping it as a member of class,
to hide, we switch to function local lambda.
2024-10-24 20:46:49 -07:00
Vitaly Buka
c77d8edf80
Revert "Revert "[msan] Switch to -msan-handle-icmp-exact my default"" (#113379)
Reverts llvm/llvm-project#113376

Fixed with #113378
2024-10-22 14:05:35 -07:00
Vitaly Buka
c3aa8b7dd6
Revert "[msan] Switch to -msan-handle-icmp-exact my default" (#113376)
Reverts llvm/llvm-project#113200

Breaks bots, see llvm/llvm-project#113200
2024-10-22 13:05:59 -07:00
Vitaly Buka
395093ec15
[msan] Switch to -msan-handle-icmp-exact my default (#113200)
Fixes #111212.

This grows .text by 5.3% on CTMark, (or 2.6% large internal binary)
Perf regressed by 1.6%. We will try to improve in follow up patches.

It worth to pay some performance regression to fix
correctness to avoid stuff like #111212.
2024-10-22 12:35:18 -07:00
Vitaly Buka
54cf62d19d
[nfc][msan] Generate test with update_test_checks.py (#113199)
PR is to:
1. Simplify test update in #113200
2. Make tests more comprehensive, currently interesting cases looks very
basic:

```
; CHECK-LABEL: @ICmpSGTAllOnes
; CHECK: icmp slt
; CHECK-NOT: call void @__msan_warning
; CHECK: icmp sgt
; CHECK-NOT: call void @__msan_warning
; CHECK: ret i1
```
2024-10-22 12:33:58 -07:00
Paul Walker
5bb34803a4 [NFC] Migrate tests to use autoupdate for CHECK lines. 2024-10-22 12:55:15 +00:00
Vitaly Buka
7dc2542ac2
[nfc][msan] Fix old typo in test (#113198) 2024-10-21 10:55:08 -07:00
Vitaly Buka
cafeacff2c
[nfc][msan] Remove RUN: duplicates (#113197) 2024-10-21 10:53:33 -07:00
Vitaly Buka
59528bbc73
[nfc][msan] Reorder flags in RUN: (#113196) 2024-10-21 10:52:15 -07:00
Vitaly Buka
fe7f5f9126
[NFC][Intrumentation] Don't brake long RUN: lines (#112281)
I find multiline 'RUN:' statements hard to read.

` *\\\n; RUN: *` -> ` ` for  ./llvm/test/Instrumentation/
2024-10-15 10:45:42 -07:00
k-kashapov
f032622dd2
[MSan] Copy tests for 32-bit architectures (#111835)
As discussed in https://github.com/llvm/llvm-project/pull/109284
Copied msan tests from 64-bit platforms to following 32-bit platforms:
* MIPS
* ARM
* RISCV
* PowerPC
* i386

Most of the tests have been copied form mips64.
Target triple and test contents have not been changed: to be done in
next PR.

---------

Co-authored-by: Kamil Kashapov <kashapov@ispras.ru>
2024-10-14 15:39:36 -07:00
Yuta Saito
d4efc3e097
[Coverage][WebAssembly] Add initial support for WebAssembly/WASI (#111332)
Currently, WebAssembly/WASI target does not provide direct support for
code coverage.
This patch set fixes several issues to unlock the feature. The main
changes are:

1. Port `compiler-rt/lib/profile` to WebAssembly/WASI.
2. Adjust profile metadata sections for Wasm object file format.
- [CodeGen] Emit `__llvm_covmap` and `__llvm_covfun` as custom sections
instead of data segments.
    - [lld] Align the interval space of custom sections at link time.
- [llvm-cov] Copy misaligned custom section data if the start address is
not aligned.
    - [llvm-cov] Read `__llvm_prf_names` from data segments
3. [clang] Link with profile runtime libraries if requested

See each commit message for more details and rationale.
This is part of the effort to add code coverage support in Wasm target
of Swift toolchain.
2024-10-15 02:41:43 +09:00
davidtrevelyan
4547d6042a
[llvm][rtsan] Add transform pass for sanitize_realtime_unsafe (#109543) 2024-10-03 06:32:21 -07:00
NAKAMURA Takumi
6c331e50e4
[MC/DC] Rework tvbitmap.update to get rid of the inlined function (#110792)
Per the discussion in #102542, it is safe to insert BBs under
`lowerIntrinsics()` since #69535 has made tolerant of modifying BBs.

So, I can get rid of using the inlined function `rmw_or`, introduced in
#96040.
2024-10-03 17:57:03 +09:00
Vitaly Buka
b2180481ec
[hwasan] Consider order of mapping copts (#109621)
Flags "-hwasan-mapping-offset" and
"-hwasan-mapping-offset-dynamic" are mutually
exclusive, use the last one.
2024-09-24 21:11:13 -07:00
Vitaly Buka
4ca4460bae [hwasan] Add "-hwasan-with-frame-record" (#109620)
It should not be implied form mapping settings.
No longer disable frame records for fixed offset.
2024-09-24 19:46:23 -07:00
Vitaly Buka
0673642cab
[hwasan] Replace "-hwasan-with-ifunc" and "-hwasan-with-tls" options (#109619)
Relationship between "-hwasan-mapping-offset",
"-hwasan-with-ifunc", and "-hwasan-with-tls" can
be to hard to understand.

Now we will have "-hwasan-mapping-offset",
presense of which will imply fixed shadow.

If "-hwasan-mapping-offset-dynamic" will set one
of 3 available dynamic shadows.

As-is "-hwasan-mapping-offset" has precedence over
"-hwasan-mapping-offset-dynamic". In follow up
patches we need to use the one with last
occurrence.
2024-09-23 17:13:25 -07:00
Pavel Skripkin
8a34f6dba1
[ASAN] Do not consider alignment during object size calculations (#109120)
It was found that ASAN logic optimizes away out-of-bound access
instrumentation for over-aligned arrays. See #108287 for complete code
examples.

Fix it by not considering alignment during object size calculation,
since out-of-bounds access for over-aligned object is still UB and
should be reported by ASAN.

Closes: #108287
2024-09-19 10:16:28 -07:00
Antonio Frighetto
942e872d5b [Instrumentation] Do not request sanitizers for naked functions
Sanitizers instrumentation may be incompatible with naked functions,
which lack of standard prologue/epilogue.
2024-09-17 09:23:39 +02:00
Antonio Frighetto
539f9161a2 [Instrumentation] Precommit tests for PR108552 (NFC) 2024-09-17 09:06:10 +02:00
Florian Mayer
9a2fd97d39
Reapply^2 "[HWASan] remove incorrectly inferred attributes" (#106622) (#106816)
This reverts commit 66927fb95abef9327b453d7213c5df7d641269be.

Filter functions this applies to, which I initially wanted to do in a
follow up to make reverts easier, but turns out without that it gets
really slow

Fleetbench proto: no significant movement
Fleetbench hashing: no significant movement
Fleetbench libc: no significant movement

2nd stage LLVM build:
https://lab.llvm.org/buildbot/#/builders/55/builds/1765/steps/9/logs/stdio
after this change: 80833.56user 3303.04system
previous build: 78430.21user 3258.04system
2024-09-04 10:41:09 -07:00
Arthur Eubanks
fb14f1df54
[PGO][Pipeline] Enable PGOForceFunctionAttrs in PGO optimization pipelines (#106790)
Remove flag that turns on the PGOForceFunctionAttrs pass and always add
it to default pipelines when using PGO.

This is NFC by default since PGOOpt->ColdOptType is by default
ColdFuncOpt::Default.

Remove -O2 RUN line in basic.ll since we now have the pipeline tests.
2024-09-03 10:35:08 -07:00
Florian Mayer
f81f283b36
Revert "Reapply "[HWASan] remove incorrectly inferred attributes" (#106622)" (#106758)
Reverts llvm/llvm-project#106624

caused timeouts
2024-08-30 09:38:44 -07:00
Florian Mayer
ddaf2e2d29
[HWASan] add OptimizationRemark for alloca safety (#105872) 2024-08-29 20:50:51 -07:00
Florian Mayer
12b0257f5a
Reapply "[HWASan] remove incorrectly inferred attributes" (#106622) (#106624)
This reverts commit 66927fb95abef9327b453d7213c5df7d641269be.

Fixed clang tests
2024-08-29 20:11:42 -07:00
Florian Mayer
66927fb95a
Revert "[HWASan] remove incorrectly inferred attributes" (#106622)
Reverts llvm/llvm-project#106565

Broke clang tests
2024-08-29 13:06:21 -07:00
Florian Mayer
f08f9cd971
[HWASan] remove incorrectly inferred attributes (#106565)
assume all functions used in a HWASan module potentially touch shadow
memory (and short granules).
2024-08-29 12:56:15 -07:00
Alexander Shaposhnikov
d23c24f336
[llvm][nsan] Skip function declarations (#105598)
Skip function declarations in the instrumentation pass.
2024-08-21 18:08:31 -07:00
Nikita Popov
472c79ca52
[IR] Check that arguments of naked function are not used (#104757)
Verify that the arguments of a naked function are not used. They can
only be referenced via registers/stack in inline asm, not as IR values.
Doing so will result in assertion failures in the backend.

There's probably more that we should verify, though I'm not completely
sure what the constraints are (would it be correct to require that naked
functions are exactly an inline asm call + unreachable, or is more
allowed?)

Fixes https://github.com/llvm/llvm-project/issues/104718.
2024-08-20 09:29:05 +02:00
Vitaly Buka
fa87eac3be
Reland "[asan] Catch initialization-order-fiasco in modules without…" (#104730)
Re-land https://github.com/llvm/llvm-project/pull/104621

After https://github.com/llvm/llvm-project/pull/104729 this patch will
not create unused module names, failing some test checks.

This reverts commit 34f941a2f96b804dd24c2a25770d899b018339ff.
2024-08-19 14:45:55 -07:00
Vitaly Buka
6a125c7e77
[asan] Better ___asan_gen_ names (#104728)
Use different suffixes for each of 3 types
of objects using `___asan_gen_`.
2024-08-19 14:41:15 -07:00
Vitaly Buka
f76b9b7e94
[NFC][asan] Don't cd after split-file (#104727)
Helps with copy-pasting of command line
with error.
2024-08-19 11:25:17 -07:00
Vitaly Buka
34f941a2f9
Revert "[asan] Catch initialization-order-fiasco in modules without globals" (#104665)
Reverts llvm/llvm-project#104621

To many bots are broken, see #104621.
2024-08-16 22:43:55 -07:00
Vitaly Buka
f44f026292
[asan] Catch initialization-order-fiasco in modules without globals (#104621)
Those modules still can have global constructors and access
globals in other modules which are not initialized yet.
2024-08-16 20:59:39 -07:00
Vitaly Buka
085b04b3a2
[asan] Pre-commit test with global constructor without any global (#104620)
In this test `@initializer()` can access globals
outside of the module, but Asan does nothing to
detect that.
2024-08-16 15:41:08 -07:00
gulfemsavrun
f5b81aa6ec
[InstrProf] Support conditional counter updates (#102542)
This patch adds support for conditional counter updates in single byte
counters mode to reduce the write contention by first checking whether
the counter is set before overwriting it.

---------

Co-authored-by: Juan Manuel Martinez Caamaño <jmartinezcaamao@gmail.com>
2024-08-16 12:33:50 -07:00
Chaitanya
62ced8116b
[Sanitizer] Make sanitizer passes idempotent (#99439)
This PR changes the sanitizer passes to be idempotent. 
When any sanitizer pass is run after it has already been run before,
double instrumentation is seen in the resulting IR. This happens because
there is no check in the pass, to verify if IR has been instrumented
before.

This PR checks if "nosanitize_*" module flag is already present and if
true, return early without running the pass again.
2024-08-12 11:16:44 +05:30
Thurston Dang
cb5ec3796a
[msan] Support vst{2,3,4}_lane instructions (#101215)
This generalizes MSan's Arm NEON vst support, to include the
lane-specific variants.

This also updates the test from
https://github.com/llvm/llvm-project/pull/100645.
2024-08-09 10:16:38 -07:00
Hari Limaye
94473f4db6
[IRBuilder] Generate nuw GEPs for struct member accesses (#99538)
Generate nuw GEPs for struct member accesses, as inbounds + non-negative
implies nuw.

Regression tests are updated using update scripts where possible, and by
find + replace where not.
2024-08-09 13:25:04 +01:00
Thurston Dang
4ce559d059
[msan] Support most Arm NEON vector shift instructions (#102507)
This adds support for the Arm NEON vector shift instructions that follow
the same pattern as x86 (handleVectorShiftIntrinsic).

VSLI is not supported because it does not follow the 2-argument pattern
expected by handleVectorShiftIntrinsic.

This patch also updates the arm64-vshift.ll MSan test that was
introduced in
5d0a12d3e9
2024-08-08 17:02:04 -07:00
Chris Apple
8acf8852e9
[LLVM][rtsan] Add RealtimeSanitizer transform pass (#101232)
Split from #100596.

Introduce the RealtimeSanitizer transform, which inserts the
rtsan_enter/exit functions at the appropriate places in an instrumented
function.
2024-08-08 16:32:54 -07:00
Jeremy Morse
bde243259b Revert "[Asan] Provide TTI hook to provide memory reference infromation of target intrinsics. (#97070)"
This reverts commit e8ad87c7d06afe8f5dde2e4c7f13c314cb3a99e9.
This reverts commit d3c9bb0cf811424dcb8c848cf06773dbdde19965.

A few buildbots trip up on asan-rvv-intrinsics.ll. I've also reverted
the follow-up commit d3c9bb0cf8.

https://lab.llvm.org/buildbot/#/builders/46/builds/2895
2024-08-08 12:26:05 +01:00
Yeting Kuo
e8ad87c7d0
[Asan] Provide TTI hook to provide memory reference infromation of target intrinsics. (#97070)
Previously asan considers target intrinsics as black boxes, so asan
could not instrument accurate check. This patch provide TTI hooks to
make targets describe their intrinsic informations to asan.

Note,
1. this patch renames InterestingMemoryOperand to MemoryRefInfo.
2. this patch does not support RVV indexed/segment load/store.
2024-08-08 13:40:26 +08:00
Thurston Dang
5d0a12d3e9
[msan] Precommit tests for Arm NEON vector shift (#101420)
MSan currently does not correctly instrument most (all?) Arm NEON vector
shift instructions. This patch shows the current state of
instrumentation.

A followup patch will apply handleVectorShiftIntrinsic to most of the
vector shift instructions and update this test accordingly.

Test forked from llvm/test/CodeGen/AArch64/arm64-vshift.ll.
2024-08-07 16:36:15 -07:00
Vitaly Buka
043ec2feae
[test][asan] Precommit test (#101769)
For #101772
2024-08-02 16:13:09 -07:00
NAKAMURA Takumi
891d89804b Fixup (#96126) mcdc.ll for aarch64. align is not 8. 2024-07-31 10:43:42 +09:00
NAKAMURA Takumi
d2f77eb8ec
[MC/DC][Coverage] Introduce "Bitmap Bias" for continuous mode (#96126)
`counter_bias` is incompatible to Bitmap. The distance between Counters
and Bitmap is different between on-memory sections and profraw image.

Reference to `__llvm_profile_bitmap_bias` is generated only if
`-fcoverge-mcdc` `-runtime-counter-relocation` are specified. The
current implementation rejected their options.

```
Runtime counter relocation is presently not supported for MC/DC bitmaps
```
2024-07-31 10:14:12 +09:00
Thurston Dang
bbde3f6e9d
[msan] Support vst1x_{2,3,4} and vst_{2,3,4} with floating-point parameters (#100644)
Cloning the vst_ intrinsics to apply them to the shadows did not work if
the arguments were floating-point, since the shadows are integers. This
patch changes MSan to create an intrinsic of the correct integer types.

Additionally, this patch adds support for vst1x_{2,3,4}; these can be
handled similarly to vst_{2,3,4}, since in all cases we are adapting the
corresponding intrinsic.
    
This also updates the tests.
2024-07-29 20:57:28 -07:00
Thurston Dang
460a86d8c7
[msan] Precommit tests for Arm NEON VST with lanes (#100645)
MSan does not yet correctly instrument the st{2,3,4}lane intrinsics but
the test should still pass.

st1lane does not map to an Arm NEON instruction and is already correctly
instrumented.
2024-07-29 16:10:08 -07:00