317 Commits

Author SHA1 Message Date
Jay Foad
9255850e89 [LLVM] Remove unused variables after #112546 2024-10-16 16:15:34 +01:00
Jay Foad
d9c95efb6c
[LLVM] Make more use of IRBuilder::CreateIntrinsic. NFC. (#112546)
Convert almost every instance of:
  CreateCall(Intrinsic::getOrInsertDeclaration(...), ...)
to the equivalent CreateIntrinsic call.
2024-10-16 15:43:30 +01:00
Rahul Joshi
fa789dffb1
[NFC] Rename Intrinsic::getDeclaration to getOrInsertDeclaration (#111752)
Rename the function to reflect its correct behavior and to be consistent
with `Module::getOrInsertFunction`. This is also in preparation of
adding a new `Intrinsic::getDeclaration` that will have behavior similar
to `Module::getFunction` (i.e, just lookup, no creation).
2024-10-11 05:26:03 -07:00
Florian Mayer
5f36042508
[NFC] [HWASan] [MTE] factor out threadlong increment (#110340) 2024-10-08 15:53:01 -07: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
Vitaly Buka
083f0fa454
[NFC][hwasan] Remove code duplication in ShadowMapping::init (#109618)
The goal to is to reorder this function to make
initialization in following order:
1. Defaults
2. Target specific overrides
3. Explicit copt<> overrides
2024-09-23 16:55:42 -07:00
Vitaly Buka
8dbb739ffb
[NFC][hwasan] Use enum class in ShadowMapping (#109617) 2024-09-23 15:51:56 -07:00
Vitaly Buka
c9e2c38f2c
[NFC][hwasan] Convert ShadowMapping into class (#109616)
In the next patch we can switch to enum.
2024-09-23 15:34:12 -07:00
Vitaly Buka
10266279c3 [NFC][hwasan] Add a few of {} 2024-09-22 18:12:59 -07:00
Florian Mayer
0cab475d11
[NFC] [HWASan] pull removeFnAttributes into function (#109488) 2024-09-20 20:37:13 -07:00
Florian Mayer
cdf29709d7 [NFC] [HWASan] fix LLVM style guide violations 2024-09-20 16:29:45 -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
2ae968a0d9
[Instrumentation] Move out to Utils (NFC) (#108532)
Utility functions have been moved out to Utils. Minor opportunity to
drop the header where not needed.
2024-09-15 21:07:40 -07: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
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
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
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
Vitaly Buka
0954205235
[ubsan][hwasan] Let mixing filters (#100680)
Now the check will be enabled only if each filter is satisfied.
2024-07-26 11:54:09 -07:00
Stephen Tozer
d75f9dd1d2 Revert "[IR][NFC] Update IRBuilder to use InsertPosition (#96497)"
Reverts the above commit, as it updates a common header function and
did not update all callsites:

  https://lab.llvm.org/buildbot/#/builders/29/builds/382

This reverts commit 6481dc57612671ebe77fe9c34214fba94e1b3b27.
2024-06-24 18:00:22 +01:00
Stephen Tozer
6481dc5761
[IR][NFC] Update IRBuilder to use InsertPosition (#96497)
Uses the new InsertPosition class (added in #94226) to simplify some of
the IRBuilder interface, and removes the need to pass a BasicBlock
alongside a BasicBlock::iterator, using the fact that we can now get the
parent basic block from the iterator even if it points to the sentinel.
This patch removes the BasicBlock argument from each constructor or call
to setInsertPoint.

This has no functional effect, but later on as we look to remove the
`Instruction *InsertBefore` argument from instruction-creation
(discussed
[here](https://discourse.llvm.org/t/psa-instruction-constructors-changing-to-iterator-only-insertion/77845)),
this will simplify the process by allowing us to deprecate the
InsertPosition constructor directly and catch all the cases where we use
instructions rather than iterators.
2024-06-24 17:27:43 +01:00
Florian Mayer
088b98a458
[HWASan] add optimization remarks for ignoreAccess (#94551) 2024-06-06 10:26:12 -07:00
Evgenii Stepanov
79a3260975
[hwasan] Remove memory attrs from instrumented functions. (#92974)
HWASan instrumentation makes writeonly attribute on function parameters,
as well as most memory(*) attributes invalid. This causes
miscompilations with LTO, when more optimizations are run after the
HWASan pass.
2024-05-21 17:15:08 -07:00
Nikita Popov
71fbbb69d6 [IR] Move GlobalValue::getGUID() out of line (NFC)
Avoid including MD5.h in a core IR header.
2024-05-15 10:49:25 +09:00
Florian Mayer
2a4f1f4a8f
Document FP relative offsets (#91031) 2024-05-07 12:23:00 -07:00
Florian Mayer
022dc6bab5
[NFC] [HWASan] factor out debug record annotation (#90252)
This will also be used by stack MTE
2024-04-26 13:11:12 -07:00
Thurston Dang
744d469500
[hwasan] Optimize outlined memaccess for fixed shadow on Aarch64 (#88544)
The HWASan transform currently always uses x20 to pass the shadow base to hwasan_check_memaccess_shortgranules, even if the shadow base is a constant known at compile time (e.g., for Fuchsia, KHWASan, or via -hwasan-mapping-offset).  This patch uses the fixed shadow variant of the hwasan_check_memaccess_shortgranules intrinsic (introduced in 365bddf634), allowing the shadow base to be materialized inside the memaccess callee.

We currently only support this optimization for AArch64; it is a no-op on other platforms due to lack of support for lowering the intrinsic.

Note: when a binary is instrumented with -hwasan-mapping-offset, it is necessary to specify HWASAN_OPTIONS=fixed_shadow_base=... (see ea991a11b2a3d2bfa545adbefb71cd17e8970a43) at runtime to ensure the shadow is mapped appropriately.
2024-04-24 10:38:12 -07:00
Vitaly Buka
c4a799b056 [NFC][hwasan] Use DEBUG_TYPE instead of "hwasan" 2024-04-19 17:43:10 -07:00
Vitaly Buka
c60aa430dc
[NFCI][sanitizers][metadata] Exctract create{Unlikely,Likely}BranchWeights (#89464)
We have a lot of repeated code with random constants.
Particular values are not important, the one just needs to be
bigger then another.

UR_NONTAKEN_WEIGHT is selected as it's the most common one.
2024-04-19 17:03:23 -07:00
Vitaly Buka
9c4aca2b2e
[HWASAN] Emit optimization remarks (#88332)
Similar to #88304

SelHWAsan is optimization. We may want to diagnose compiler decisions.
Remarks is the tool for that https://llvm.org/docs/Remarks.html.
2024-04-11 11:13:12 -07:00
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