281 Commits

Author SHA1 Message Date
Vitaly Buka
0646344062
[HWASAN][UBSAN] Reverse random logic (#88070)
It feels more intuitive to make higher P to keep more checks.
2024-04-08 17:23:47 -07:00
Vitaly Buka
18380c522a
[UBSAN][HWASAN] Remove redundant flags (#87709)
Presense of `cutoff-hot` or `random-skip-rate`
should be enough to trigger optimization.
2024-04-04 14:32:30 -07:00
Vitaly Buka
e628581aaa
[NFC][HWASAN][UBSAN] Remove cl:init from few opts (#87692)
They are supposed to be used with `getNumOccurrences`.
2024-04-04 14:30:04 -07:00
Vitaly Buka
03f54725c3
[HWASAN][UBSAN] Don't use default profile-summary-cutoff-hot (#87691)
Default cutoff is not usefull here. Decision to
enable or not sanitizer causes more significant
performance impact, than a typical optimizations
which rely on `profile-summary-cutoff-hot`.
2024-04-04 14:25:53 -07:00
Vitaly Buka
9a0ae08104
[NFC][HWASAN] Simplify selectiveInstrumentationShouldSkip (#87670) 2024-04-04 12:21:50 -07:00
Florian Mayer
39e8137467
[NFC] [HWASan] add example for ring buffer wrap (#87029)
Also another move comment to correct place.
2024-03-28 18:23:48 -07:00
Vitaly Buka
70e8cf0c31
[HWASAN] Don't instrument loads from global if globals are not tagged (#86774) 2024-03-27 13:43:18 -07:00
Vitaly Buka
453a63caeb
[NFC][HWASAN] Promote InstrumentGlobals to member (#86773) 2024-03-27 13:38:21 -07:00
Florian Mayer
880eb339ca
[NFC] [HWASan] make getAndroidSlotPtr function generic (#86200)
This is so we can use a different slot for stack MTE.
2024-03-26 13:46:08 -07:00
Florian Mayer
b0b8b16bb8
[NFC] [HWASan] Add link to proof for address calculation (#86367) 2024-03-26 13:41:13 -07:00
Florian Mayer
85ccfb5ed5
[HWASan] [NFC] pull logic to get sanitizer ptr out of hwasan (#86024)
Also some drive by cleanup removing an unnnecessary argument and a
redundant condition.
2024-03-21 12:42:55 -07:00
Florian Mayer
e28d3e9b4e [NFC] [hwasan] factor get[PC|FP] out of HWASan class (#84404)
Also be consistent about naming SP / FP.

This is to prepare for stack history buffer for memtag-stack
2024-03-19 16:14:14 -07:00
Stephen Tozer
ffd08c7759
[RemoveDIs][NFC] Rename DPValue -> DbgVariableRecord (#85216)
This is the major rename patch that prior patches have built towards.
The DPValue class is being renamed to DbgVariableRecord, which reflects
the updated terminology for the "final" implementation of the RemoveDI
feature. This is a pure string substitution + clang-format patch. The
only manual component of this patch was determining where to perform
these string substitutions: `DPValue` and `DPV` are almost exclusively
used for DbgRecords, *except* for:

- llvm/lib/target, where 'DP' is used to mean double-precision, and so
appears as part of .td files and in variable names. NB: There is a
single existing use of `DPValue` here that refers to debug info, which
I've manually updated.
- llvm/tools/gold, where 'LDPV' is used as a prefix for symbol
visibility enums.

Outside of these places, I've applied several basic string
substitutions, with the intent that they only affect DbgRecord-related
identifiers; I've checked them as I went through to verify this, with
reasonable confidence that there are no unintended changes that slipped
through the cracks. The substitutions applied are all case-sensitive,
and are applied in the order shown:

```
  DPValue -> DbgVariableRecord
  DPVal -> DbgVarRec
  DPV -> DVR
```

Following the previous rename patches, it should be the case that there
are no instances of any of these strings that are meant to refer to the
general case of DbgRecords, or anything other than the DPValue class.
The idea behind this patch is therefore that pure string substitution is
correct in all cases as long as these assumptions hold.
2024-03-19 20:07:07 +00:00
Florian Mayer
c20596ca2b
[NFC] [hwasan] also be more consistent when getting pointer types (#84399) 2024-03-19 08:38:53 -07:00
Florian Mayer
58a20a0b96
[MTE] fix bug that prevented stack coloring with MTE (#84422) 2024-03-14 09:26:58 -07:00
Florian Mayer
0bb30f9896
[NFC] [hwasan] factor out some opt handling (#84414) 2024-03-13 10:56:26 -07:00
Florian Mayer
672fc89347
[NFC] [hwasan] factor out selective instrumentation logic (#84408)
sanitizeFunction is long enough already.
2024-03-11 18:18:49 -07:00
Florian Mayer
03c6c73b02 [NFC] [hwasan] remove unused method 2024-03-08 13:28:18 -08:00
Florian Mayer
9d3bf9b639 [NFC] [hwasan] consistent naming for cl::opt 2024-03-07 16:42:41 -08:00
Florian Mayer
3e5afba8ef
[NFC] [hwasan] be consistent about how to get integer types (#84396) 2024-03-07 15:41:12 -08:00
Kirill Stoimenov
4258b0e13f
[HWASAN] Follow up for #83503 implement selective instrumentation (#83942)
1. Change tests to use IR instead of -stats to avoid depending on Debug
mode
2. Add SkipInstrumentationRandomRate 
3. Remove HWASAN from stat strings
2024-03-06 16:16:59 -08:00
Kirill Stoimenov
56754478e7 Reapply "[HWASAN] Implement selective instrumentation based on profiling information (#83503)"
Added REQUIRES: asserts, which should fix the build problem.

This reverts commit f6f79d46e580b34b2c98bd9bda7ede3a38f43f77.
2024-03-04 18:16:38 +00:00
Kirill Stoimenov
f6f79d46e5 Revert "[HWASAN] Implement selective instrumentation based on profiling information (#83503)"
Broke a build bot: https://lab.llvm.org/buildbot/#/builders/124/builds/9846

This reverts commit e7c3cd245665042bbae163f7280aceed35f0fee5.
2024-03-01 17:17:37 +00:00
Kirill Stoimenov
e7c3cd2456
[HWASAN] Implement selective instrumentation based on profiling information (#83503) 2024-02-29 17:34:32 -08:00
Vitaly Buka
699c408c88 [NFC][HWASAN] Fix misleading name 2024-02-21 15:32:18 -08:00
Orlando Cazalet-Hyams
d860ea96b1
[HWASAN] Update dbg.assign intrinsics in HWAsan pass (#79864)
llvm.dbg.assign intrinsics have 2 {value, expression} pairs; fix hwasan to
update the second expression.

Fixes #76545. This is #78606 rebased and with the addition of DPValue handling.
Note the addition of --try-experimental-debuginfo-iterators in the tests and
some shuffling of code in MemoryTaggingSupport.cpp.
2024-02-13 09:11:09 +00:00
Florian Mayer
0d6ed8399f [NFC] reorder AND to check cheaper condition first 2024-02-02 14:06:13 -08:00
Jeremy Morse
fe0e632b00
[DebugInfo][RemoveDIs] Support DPValues in HWAsan (#78731)
This patch extends HWASAN to support maintenance of debug-info that
isn't stored as intrinsics, but is instead in a DPValue object. This is
straight-forwards: we collect any such objects in StackInfoBuilder, and
apply the same operations to them as we would to dbg.value and similar
intrinsics.

I've also replaced some calls to getNextNode with debug-info skipping
next calls, and use iterators for instruction insertion rather than
instruction pointers. This avoids any difference in output between
intrinsic / non-intrinsic debug-info, but also means that any debug-info
comes before code inserted by HWAsan, rather than afterwards. See the
test modifications, where the variable assignment (presented as a
dbg.value) jumps up over all the code inserted by HWAsan. Seeing how the
code inserted by HWAsan is always (AFAIUI) given the source-location of
the instruction being instrumented, I don't believe this will have any
effect on which lines variable assignments become visible on; it may
extend the number of instructions covered by the assignments though.
2024-01-24 10:38:35 +00:00
gulfemsavrun
7fe951ad8a
Revert "Reapply [hwasan] Update dbg.assign intrinsics in HWAsan pass … (#79186)
…#78606"

This reverts commit 13c6f1ea2e7eb15fe492d8fca4fa1857c6f86370 because it
causes an assertion in DebugInfoMetadata.cpp:1968 in Clang Linux
builders for Fuchsia.

https://logs.chromium.org/logs/fuchsia/buildbucket/cr-buildbucket/8758111613576762817/+/u/clang/build/stdout
2024-01-23 10:12:10 -08:00
OCHyams
13c6f1ea2e Reapply [hwasan] Update dbg.assign intrinsics in HWAsan pass #78606
llvm.dbg.assign intrinsics have 2 {value, expression} pairs; fix hwasan to update
the second expression.

Fixes #76545
2024-01-23 11:24:21 +00:00
gulfemsavrun
b00aa1c77b
Revert "Reapply [hwasan] Update dbg.assign intrinsics in HWAsan pass … (#79053)
…#78606"

This reverts commit 76160718df7c1f31ff50a4964d749c2b9d83f9cf because it
caused an assertion failure in emitDbgValue function in Codegen in Clang
Linux toolchain builders for Fuchsia.
https://logs.chromium.org/logs/fuchsia/buildbucket/cr-buildbucket/8758181086086431185/+/u/clang/build/stdout
2024-01-22 12:44:46 -08:00
OCHyams
76160718df Reapply [hwasan] Update dbg.assign intrinsics in HWAsan pass #78606
llvm.dbg.assign intrinsics have 2 {value, expression} pairs; fix hwasan to update
the second expression.

Fixes #76545
2024-01-22 17:07:44 +00:00
Orlando Cazalet-Hyams
5266c1285b
Revert "[hwasan] Update dbg.assign intrinsics in HWAsan pass" (#78971)
Reverts llvm/llvm-project#78606

https://lab.llvm.org/buildbot/#/builders/77/builds/33963
2024-01-22 13:30:50 +00:00
Orlando Cazalet-Hyams
a590f2315f
[hwasan] Update dbg.assign intrinsics in HWAsan pass (#78606)
llvm.dbg.assign intrinsics have 2 {value, expression} pairs; fix hwasan to update
the second expression.

Fixes #76545
2024-01-22 11:38:00 +00:00
Nikita Popov
6c2fbc3a68
[IRBuilder] Add CreatePtrAdd() method (NFC) (#77582)
This abstracts over the common pattern of creating a gep with i8 element
type.
2024-01-12 14:21:21 +01:00
Youngsuk Kim
6989859254 [llvm][HWASan] Replace calls to Type::getPointerTo (NFC)
If `Type::getPointerTo` is called solely to support an unnecessary
pointer-cast, remove the call entirely.

Otherwise, replace with IRB.getPtrTy().

Clean-up work towards removing method `Type::getPointerTo`.
2023-11-28 14:45:59 -06:00
Fangrui Song
107185fa85
[sanitizer] Remove unneeded pointer casts and migrate away from getInt8PtrTy. NFC (#72327)
After opaque pointer migration, getInt8PtrTy() is considered legacy.
Replace it with getPtrTy(), and while here, remove some unneeded pointer
casts.
2023-11-15 10:48:58 -08:00
Simon Pilgrim
3ca4fe80d4 [Transforms] Use StringRef::starts_with/ends_with instead of startswith/endswith. NFC.
startswith/endswith wrap starts_with/ends_with and will eventually go away (to more closely match string_view)
2023-11-06 16:50:18 +00:00
Youngsuk Kim
7523b89643 [llvm] Remove no-op ptr-to-ptr bitcasts (NFC)
Opaque pointer cleanup effort. NFC.
2023-10-25 19:01:05 -05:00
Kirill Stoimenov
844c731f2d
[HWASAN] Mark built-ins as not built-ins to prevent optimizations (#68936)
The other 3 sanitizers (ASAN, TSAN and MSAN) all use
maybeMarkSanitizerLibraryCallNoBuiltin to make disable optimizations
which inline functions like memcmp for example. The lack of this
optimization was allowing ExpandMemCmpPass to convert a memcmp call to
inlined assembly and cause a false negative in HWASAN.
2023-10-13 11:43:29 -07:00
Thurston Dang
3f608ab710 [hwasan] Replace &LI with *LI, to fix build breakage
My patch (b3b6edefdb) broke the build
(https://lab.llvm.org/buildbot/#/builders/5/builds/37053) because it incorrectly assumed LoopInfo could not be null
and used a reference. This fixes forward by replacing &LI with *LI.
2023-09-28 19:34:21 +00:00
Thurston Dang
b3b6edefdb
[hwasan] Update (Post-)DominatorTreeAnalysis and LoopAnalysis incrementally (#66935)
HWAddressSanitizerPass::run sanitizes functions one by one. The
sanitization of each function - which may split blocks via
insertShadowTagCheck - may result in some cached analyses are invalid.
This matters because sanitizeFunction(F', FAM) may indirectly call the
global stack safety analysis, hence we need to make sure the analyses of
F are up to date.

Bug report: https://github.com/llvm/llvm-project/issues/66934
2023-09-28 09:09:38 -07:00
Vitaly Buka
be601928e1 [HWASAN] Inline fast pass of instrumentMemAccessOutline
Usually pointer tag will match tag in the shadow, so we can keep
inlining this check keeping the rest in outlined part.

It imroves performance by about 25%, but increases code size by 30%.
Existing outlining reduces performance by 30%, but saves code size by 80%.
So we still significantly reduce code size with minimal performance loss.

Reviewed By: fmayer

Differential Revision: https://reviews.llvm.org/D159172
2023-08-31 21:26:48 -07:00
Vitaly Buka
c6aaf2e521 [NFC][HWASAN] Extract insertShadowTagCheck()
Reviewed By: fmayer

Differential Revision: https://reviews.llvm.org/D159165
2023-08-31 13:22:51 -07:00
Vitaly Buka
b80fa58bdc [NFC][hwasan] Rename local variable 2023-08-31 12:25:46 -07:00
Vitaly Buka
bb637396db [test][HWASAN] Precommit -hwasan-inline-fast-path-checks tests
Reviewed By: fmayer

Differential Revision: https://reviews.llvm.org/D159157
2023-08-31 11:24:36 -07:00
Vitaly Buka
5a902312f1 [NFC][hwasan] Make most class functions private 2023-08-29 15:57:49 -07:00
Florian Mayer
9a67c6beb2 [NFC] [HWASan] simplify code
Reviewed By: vitalybuka

Differential Revision: https://reviews.llvm.org/D156382
2023-07-26 17:05:19 -07:00
Florian Mayer
12982d250d [NFC] [HWASan] remove unused include 2023-07-26 14:34:31 -07:00
Florian Mayer
6cc9244baa Enable hwasan-use-after-scope by default
This has been in use for a long time without any issues.

Reviewed By: vitalybuka

Differential Revision: https://reviews.llvm.org/D156267
2023-07-25 17:36:15 -07:00