335 Commits

Author SHA1 Message Date
Nikita Popov
c23b4fbdbb
[IR] Remove size argument from lifetime intrinsics (#150248)
Now that #149310 has restricted lifetime intrinsics to only work on
allocas, we can also drop the explicit size argument. Instead, the size
is implied by the alloca.

This removes the ability to only mark a prefix of an alloca alive/dead.
We never used that capability, so we should remove the need to handle
that possibility everywhere (though many key places, including stack
coloring, did not actually respect this).
2025-08-08 11:09:34 +02:00
shuffle2
7b5a44c605
[hwasan] Add hwasan-all-globals option (#149621)
hwasan-globals does not instrument globals with custom sections, because
existing code may use `__start_`/`__stop_` symbols to iterate over
globals in such a way which will cause hwasan assertions.

Introduce new hwasan-all-globals option, which instruments all
user-defined globals (but not those globals which are generated by the
hwasan instrumentation itself), including those with custom sections.

fixes #142442
2025-07-31 11:38:42 -07:00
Florian Mayer
057b1c2729
[NFC] [HWASan] remove unneeded pointer cast (#150510)
The first argument to a lifetime intrinsic now has to be an alloca
2025-07-25 13:06:31 -07:00
Florian Mayer
0d35e1771e [NFC] [HWASan] remove unnecessary bool return in instrumentLandingPads 2025-07-24 17:38:53 -07:00
Florian Mayer
5f1c89af24
[NFC] [HWASan] remove unused bool return value (#150516) 2025-07-24 14:42:08 -07:00
Nikita Popov
b59aaf7da7
[Sanitizers] Remove handling for lifetimes on non-alloca insts (NFC) (#149994)
After #149310 the pointer argument of lifetime.start/lifetime.end is
guaranteed to be an alloca, so we don't need to go through
findAllocaForValue() anymore, and don't have to have special handling
for the case where it fails.
2025-07-23 09:48:32 +02:00
Jeremy Morse
57a5f9c47e
[DebugInfo][RemoveDIs] Suppress getNextNonDebugInfoInstruction (#144383)
There are no longer debug-info instructions, thus we don't need this
skipping. Horray!
2025-07-15 15:34:10 +01:00
Usama Hameed
cc400d4417
[HWASan][bugfix] Fix kernel check in ShadowMapping::init (#142226)
The function currently checks for the command line argument only to
check if compiling for kernel. This is incorrect as the setting can also
be passed programatically.
2025-06-02 10:39:15 -07:00
Peter Collingbourne
645f0e6723
IR: Make Module::getOrInsertGlobal() return a GlobalVariable.
After pointer element types were removed this function can only return
a GlobalVariable, so reflect that in the type and comments and clean
up callers.

Reviewers: nikic

Reviewed By: nikic

Pull Request: https://github.com/llvm/llvm-project/pull/141323
2025-05-27 12:23:12 -07:00
Florian Mayer
a76cf062a5
[HWASan] fix missing BTI attribute on personality function thunks (#139138)
This used to work because the BTI attribute was taken from the module in
the CodeGen.

e15d67cfc2e5775cc79281aa860f3ad3be628f39 changed that to actually look
at the function attributes. This led to crashes for BTI, because we did
not emit the proper landing pads for the thunk.
2025-05-08 14:02:30 -07:00
Rahul Joshi
74b7abf154
[IRBuilder] Add new overload for CreateIntrinsic (#131942)
Add a new `CreateIntrinsic` overload with no `Types`, useful for
creating calls to non-overloaded intrinsics that don't need additional
mangling.
2025-03-31 08:10:34 -07:00
Guy David
3168110607
[AddressSanitizer] Remove memory effects from functions (#130495)
If left as-is, subsequent optimizations might utilize the possible
memory effects and optimize-out the instrumentation. Think of the
following case:
```
  store i8 4, ptr %shadow
  call void @llvm.lifetime.start.p0(i64 4, ptr %local)
  %28 = call void @foo(ptr %local)
  store i8 -8, ptr %shadow
  call void @llvm.lifetime.end.p0(i64 4, ptr %local)
```

where `foo` is an external function with `memory(argmem: write)`. A pass
such as DeadStoreElimination is allowed to remove the initial store,
which might fail sanitizer checks within `foo`.

My first attempt was to add a `memory(readwrite)` at the call-site
level, but unfortunately the current implementation of
`getMemoryEffects` doesn't exactly give it "precedence" as specified,
but rather restricts the access specified by the call-site and not the
other way around as well.
2025-03-15 20:55:29 +02:00
Nikita Popov
979c275097
[IR] Store Triple in Module (NFC) (#129868)
The module currently stores the target triple as a string. This means
that any code that wants to actually use the triple first has to
instantiate a Triple, which is somewhat expensive. The change in #121652
caused a moderate compile-time regression due to this. While it would be
easy enough to work around, I think that architecturally, it makes more
sense to store the parsed Triple in the module, so that it can always be
directly queried.

For this change, I've opted not to add any magic conversions between
std::string and Triple for backwards-compatibilty purses, and instead
write out needed Triple()s or str()s explicitly. This is because I think
a decent number of them should be changed to work on Triple as well, to
avoid unnecessary conversions back and forth.

The only interesting part in this patch is that the default triple is
Triple("") instead of Triple() to preserve existing behavior. The former
defaults to using the ELF object format instead of unknown object
format. We should fix that as well.
2025-03-06 10:27:47 +01:00
Thurston Dang
df07121d54
[hwasan][NFCI] Rename ClRandomSkipRate to ClRandomKeepRate (#126990)
The meaning of ClRandomSkipRate was inverted in
https://github.com/llvm/llvm-project/pull/88070 but the variable name
was not changed. This patch fixes it to avoid confusion.

Additionally, it elaborates the flag description to mention the
interaction between the random keep rate and hotness cutoff.
2025-02-12 18:43:00 -08:00
Yingwei Zheng
9fbd5fbcc6
[IR][NFC] Switch to use LifetimeIntrinsic (#125528) 2025-02-04 02:18:33 +08:00
Thurston Dang
4f42e16516
[hwasan] Omit tag check for null pointers (#122206)
If the pointer to be checked is statically known to be zero, the tag
check will always pass since:
1) the tag is zero
2) shadow memory for address 0 is initialized to 0 and never updated.
We can therefore elide the tag check.

We perform the elision in two places:
1) the HWASan pass
2) when lowering the CHECK_MEMACCESS intrinsic. Conceivably, the HWASan
pass may encounter a "cannot currently statically prove to be null"
pointer (and is therefore unable to omit the intrinsic) that later
optimization passes convert into a statically known-null pointer. As a
last line of defense, we perform elision here too.

This also updates the tests from
https://github.com/llvm/llvm-project/pull/122186
2025-01-09 13:48:26 -08:00
Ryan Mansfield
67efbd0bf1
[LLVM] Fix various cl::desc typos and whitespace issues (NFC) (#121955) 2025-01-08 11:07:23 +01:00
Kazu Hirata
4d12a14357
[Instrumentation] Remove unused includes (NFC) (#115117)
Identified with misc-include-cleaner.
2024-11-06 08:36:34 -08:00
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