16470 Commits

Author SHA1 Message Date
Kirill Stoimenov
9de144eee5 [HWASAN] Remove GetRequestedSize check from Metadata::IsAllocated
After D143438 there is no point in this check as the size will never 0. Also this keeps it consistent with ASAN where there is not size check in LsanMetadata::allocated.

Reviewed By: MaskRay, vitalybuka

Differential Revision: https://reviews.llvm.org/D143442
2023-02-07 15:51:56 +00:00
Kirill Stoimenov
e403fd8705 [HWASAN] Add unlikely to if in HwasanAllocate. 2023-02-07 00:39:17 +00:00
Kirill Stoimenov
01176191d2 [HWASAN] Modify HwasanAllocate to set the size to 1 if requested size is 0
This should keep it consistent with LSAN and ASAN,

Reviewed By: vitalybuka, MaskRay

Differential Revision: https://reviews.llvm.org/D143438
2023-02-07 00:35:56 +00:00
Kirill Stoimenov
c6ea5b0cd1 [HWASAN] Modify HwasanAllocate to set the size to 1 if requested size is 0
This should keep it consistent with LSAN and ASAN,

Reviewed By: vitalybuka, MaskRay

Differential Revision: https://reviews.llvm.org/D143438
2023-02-07 00:01:20 +00:00
Kirill Stoimenov
914f86949a [HWASAN] Fix Metadata::IsAllocatedMetadata::IsAllocated to return true even if the requested size is 0.
Reviewed By: MaskRay

Differential Revision: https://reviews.llvm.org/D143438
2023-02-06 23:47:23 +00:00
Fangrui Song
39b8a27132 [sanitizer] Simplify with GET_CALLER_PC_BP. NFC 2023-02-04 11:30:14 -08:00
Douglas Yung
056769cdbc Revert "[Sanitizers] Fix read buffer overrun in scanning loader commands"
This reverts commit abbd4da2043856f443e3d1c8d2c7627cac93a6ac.

This change is breaking many bots including:
- http://45.33.8.238/linux/98629/step_10.txt
- https://buildkite.com/llvm-project/llvm-main/builds/6461#01861c4f-9d9c-4781-88f7-d6ccddcb4b06/919-8848
- https://lab.llvm.org/buildbot/#/builders/94/builds/13196
- https://lab.llvm.org/buildbot/#/builders/45/builds/10633
- https://lab.llvm.org/buildbot/#/builders/247/builds/1238
- https://lab.llvm.org/buildbot/#/builders/70/builds/33424
- https://lab.llvm.org/buildbot/#/builders/168/builds/11693
- https://lab.llvm.org/buildbot/#/builders/74/builds/17006
- https://lab.llvm.org/buildbot/#/builders/85/builds/14120
2023-02-04 10:19:57 -08:00
Sam James
ca50897a76
[compiler-rt] Fix FORTIFY_SOURCE -> _FORTIFY_SOURCE reference (NFC)
As pointed out by maskray.

Fixes: 8ab762557fb057af1a3015211ee116a975027e78
2023-02-04 18:05:26 +00:00
Sam James
8ab762557f [compiler-rt] Disable default config files for tests
Without this, if hardening measures like FORTIFY_SOURCE are are in
/etc/clang/*.cfg, many sanitizer tests will die before the sanitizer
can trap the problem being tested, because e.g. the _chk variants
of common functions will abort first.

This gets the number of failing tests down from 42->3 for me (and the
remaining 3 are unrelated).

See: 52ce6776cf98e993c6ec04ae54b52e1354fff917
See: 136f77805fd89cd30e69b3d1204fbf7efedd9a12
Closes: https://github.com/llvm/llvm-project/issues/60394

Reviewed By: MaskRay

Differential Revision: https://reviews.llvm.org/D143322
2023-02-04 18:04:23 +00:00
Mariusz Borsa
abbd4da204 [Sanitizers] Fix read buffer overrun in scanning loader commands
The fix only affects Darwin, but to write the test I had to modify
the MemoryMappingLayout class which is used by all OSes,
to allow for mocking of image header (this change should be NFC). Hence no [Darwin] in the subject
so I can get more eyes on it.

While looking for a memory gap to put the shadow area into, the sanitizer code
scans through the loaded images, and for each image it scans through its
loader command to determine the occupied memory ranges.

While doing so, if the 'segment load' (kLCSegment) loader comand is encountered, the command scanning function
returns success (true), but does not decrement the command list iterator counter.
The result is that the function is called again and again, with the iterator counter
now being too high. The command scanner keeps updating the loader command pointer,
by using the command size field.

If the loop counter is too high, the command pointer
lands into unintended area ( beyond <header addr>+sizeof(mac_header64)+header->sizeofcmds ),
and result depends on the random content found there.

The random content interpreted as loader command might contain a large integer value in the
cmdsize field - this value is added to the current loader command pointer,
which might now point to an inaccessible memory address. It can occasionally result
in a crash if it happens to run beyond the mapped memory segment.

Note that when the area after the loader command list
contains zeros or small integers only, the loop will end normally and the problem
will go unnoticed. So it happened until now since having a some big value
after the header area, falling into command size field is a pretty rare situation.

The fix makes sure that the iterator counter gets updated when the segment load (kLCSegment)
loader command is found too, and in the same code location so the updates will always go together.

Undo the changes in the sanitizer_procmaps_mac.cpp to see the test failing.

rdar://101161047
rdar://102819707

Differential Revision: https://reviews.llvm.org/D142164
2023-02-03 18:43:33 -08:00
Khem Raj
26800a2c7e [sanitizer] Undef _TIME_BITS along with _FILE_OFFSET_BITS on Linux
On 32-bit glibc>=2.34 systems using 64bit time_t build fails because
_FILE_OFFSET_BITS is undefined here but _TIME_BITS is still set to 64

Fixes

```
/usr/include/features-time64.h:26:5: error: "_TIME_BITS=64 is allowed
 only with _FILE_OFFSET_BITS=64"
| #   error "_TIME_BITS=64 is allowed only with _FILE_OFFSET_BITS=64"
|     ^
| 1 error generated.
```

Reviewed By: thesamesam, MaskRay

Differential Revision: https://reviews.llvm.org/D140812
2023-02-03 11:48:35 -08:00
Marco Elver
960b4c3b5d [SanitizerBinaryMetadata] Treat constant globals and non-escaping addresses specially
For atomics metadata, we can make data race analysis more efficient by
entirely ignoring functions that include memory accesses but which only
access non-escaping (non-shared) and/or non-mutable memory. Such
functions will not be considered to be covered by "atomics" metadata,
resulting in the following benefits:

  1. reduces "covered" metadata; and
  2. allows data race analysis to skip such functions.

Reviewed By: dvyukov

Differential Revision: https://reviews.llvm.org/D143159
2023-02-03 15:35:24 +01:00
Mitch Phillips
10939d1d58 [GWP-ASan] Remove thread clamping in tests.
It's better and easier for us to just have threads contend against each
other in the tests if it's more than the maximum supported number of
hardware threads available.

Specifically, the recoverable test fails on Android because the
GTEST_SKIP in a called function, and it only properly works from the
TEST_* harness function. Android tests run on cuttlefish, which can be a
single core with two hyperthreads.

Reviewed By: fmayer

Differential Revision: https://reviews.llvm.org/D143221
2023-02-02 15:40:07 -08:00
Kirill Stoimenov
b2aa0a4650 [LSAN] Enable more tests which are passing as is in HWASAN.
Reviewed By: vitalybuka

Differential Revision: https://reviews.llvm.org/D143126
2023-02-02 18:06:35 +00:00
Kirill Stoimenov
042f01b289 Revert "[LSAN] Enable more tests which are passing as is in HWASAN."
This reverts commit b4abbf17572dce3993402f2e00e72678518ef6e1.
2023-02-02 17:12:31 +00:00
Kirill Stoimenov
b4abbf1757 [LSAN] Enable more tests which are passing as is in HWASAN.
Reviewed By: vitalybuka

Differential Revision: https://reviews.llvm.org/D143126
2023-02-02 16:39:26 +00:00
Kirill Stoimenov
029b410df3 [HWASAN] Set os_id in Thread::Init to make sure that the thread can be found by GetThreadByOsIDLocked.
Reviewed By: vitalybuka

Differential Revision: https://reviews.llvm.org/D143125
2023-02-02 01:42:48 +00:00
Kirill Stoimenov
eb3be66028 [LSAN] Add GetUserAddr function which returns the user visible address of an internal pointer
For HWASAN this would be the tagged address. It is the same pointer when pointer tagging is not used. Coincidently this also fixes some test which rely on comparing pointers.

Reviewed By: vitalybuka

Differential Revision: https://reviews.llvm.org/D143121
2023-02-02 00:39:00 +00:00
Kirill Stoimenov
49b081c827 [LSAN] Enable some tests which are passing as is in HWASAN.
Reviewed By: vitalybuka

Differential Revision: https://reviews.llvm.org/D143114
2023-02-01 23:21:30 +00:00
Tim Northover
261752fbc6 [compiler-rt] initialize variables to silence warning. NFC.
They were being initialized anyway, I believe, but the logic was a bit
convoluted for the Clang warnings to detect so we were getting "variable 'EBX'
may be uninitialized when used here" later on.
2023-02-01 13:30:10 +00:00
H.J. Lu
742bcbf685 compiler-rt/lib: Add .Linterceptor_sigsetjmp
Older GNU assemblers generate R_X86_64_PC32 relocation against
defined non-weak global branch targets with default visibility.  A
linker may issue an error when building a shared library.  Add a local
alias, .Linterceptor_sigsetjmp, to __interceptor_sigsetjmp to avoid
R_X86_64_PC32 relocation for "jmp __interceptor_sigsetjmp" with older
GNU assemblers.

Fixes: https://github.com/llvm/llvm-project/issues/60426

Differential Revision: https://reviews.llvm.org/D142995
2023-01-31 14:30:55 -08:00
Teresa Johnson
5773c70231 [MemProf] Make test more resilient to cpu scheduling
Loosen up the matching so that occasional cpu migrations don't break the
test. This showed up occasionally in internal testing.

Differential Revision: https://reviews.llvm.org/D143000
2023-01-31 11:17:01 -08:00
David Spickett
cd173cbd7c [clang][compiler-rt] Support LLVM_ENABLE_PER_TARGET_RUNTIME_DIR on Arm Linux and BSD
The orginal single folder layout produced libraries in the form:
lib/linux/<libname>-<archname>.a

That archname for Arm depended on whether you had hard or soft float.
This is sometimes shown as "arm" (soft) vs. "armhf" (hard).

If this is set in a triple we do it in the final portion, the ABI.
"gnueabi" for soft float, "gnueabihf" for hard float.

Meaning that the expected triple is:
arm-unknown-linux-gnueabihf
Not this:
armhf-unknown-linux-gnueabihf

For the per target layout I have decided to rely on the ABI portion
of the triple instead of the arch name used for the old layout
(doing that would produce the invalid triple above).

This means that building with triple:
armv8l-unknown-linux-gnueabihf
Will result in libraries in:
lib/arm-unknown-linux-gnueabihf/

And clang will now know to look for "arm" instead of "armv8l".
Meaning that we can share libraries between an armv8 and armv7 build
as we did with the previous layout. In addition to handling spelling
differences e.g. "armv8l" with an "l" on some Linux distros.

compiler-rt will autodetect that the "armhf" and/or "arm" architecture
can be built. We then replace the given triple's architecture with that.
Then if the triple's float ABI doesn't match, we change that. That new
triple is then used as the folder name.

If you select to build only the given triple, with COMPILER_RT_DEFAULT_TARGET_ONLY,
compiler-rt will not autodetect the architecture and for that I assume you
know what you're doing. In that case the library path will use the unomdified triple.

From what I can tell, this is how most large builds e.g Android and
Arm's Embedded Toolchain for llvm do things. I assume that big endian "armeb"
builds would end up doing this too.

Bare metal builds will not be using per target runtime dirs so they
remain as they were.

Depends on D139536

Reviewed By: MaskRay, phosek

Differential Revision: https://reviews.llvm.org/D140011
2023-01-31 09:49:56 +00:00
Fangrui Song
ea7695dcca [hwasan] Support __lsan_default_options
Reviewed By: vitalybuka

Differential Revision: https://reviews.llvm.org/D142938
2023-01-30 15:07:46 -08:00
Kirill Stoimenov
3301f6e135 [LSAN][HWASAN] Run LSAN tests with HWASAN enabled
A lot of tests are disabled by using UNSUPPORTED. The plan is to remove UNSUPPORTED for tests that are fixed.

Reviewed By: vitalybuka

Differential Revision: https://reviews.llvm.org/D142676
2023-01-30 22:32:31 +00:00
Daniel Thornburgh
0eb01a9c45 [llvm-cov] Add split-file to compiler-rt test requirements.
Differential Revision: https://reviews.llvm.org/D136702
2023-01-30 13:36:02 -08:00
Hans Wennborg
3b9606b5cb Revert "[LSAN][HWASAN] Run LSAN tests with HWASAN enabled"
This broke the sanitizer tests on Mac, see e.g.
https://green.lab.llvm.org/green/job/clang-stage1-RA/32739/ and comment on the
code review.

> A lot of tests are disabled by using UNSUPPORTED. The plan is to remove UNSUPPORTED for tests that are fixed.
>
> Reviewed By: vitalybuka
>
> Differential Revision: https://reviews.llvm.org/D142676

This reverts commit f9a01630988716f1b52afe6727f34fe86c07c58a.
and follow-up commit bf47ffaa76fbda1ba96d41ee2681e45d2445be1e
(https://reviews.llvm.org/D142812).
2023-01-30 20:57:16 +01:00
Kirill Stoimenov
bf47ffaa76 [LSAN] Remove -fuse-ld=lld from HWASAN config
I needed that to make -fsanitize-hwaddress-experimental-aliasing work, but it looks like the test pass without it also. This should fix https://lab.llvm.org/buildbot/#/builders/192 failures.

Reviewed By: kstoimenov

Differential Revision: https://reviews.llvm.org/D142812
2023-01-28 16:08:33 +00:00
Kirill Stoimenov
b4b9786f4a [LSAN] Disable leak_check_before_thread_started for hwasan 2023-01-28 00:48:49 +00:00
Kirill Stoimenov
f9a0163098 [LSAN][HWASAN] Run LSAN tests with HWASAN enabled
A lot of tests are disabled by using UNSUPPORTED. The plan is to remove UNSUPPORTED for tests that are fixed.

Reviewed By: vitalybuka

Differential Revision: https://reviews.llvm.org/D142676
2023-01-28 00:07:19 +00:00
Daniel Thornburgh
a3b0dde4ed Reland: [llvm-cov] Look up object files using debuginfod
Reviewed By: gulfem

Differential Revision: https://reviews.llvm.org/D136702
2023-01-26 12:59:52 -08:00
Douglas Yung
bce910242e Revert "[llvm-cov] Look up object files using debuginfod"
This reverts commit efbc8bb18eda63007216ad0cb5a8de04963eddd5.

This change is causing failures when detecting curl on several build bots:
 - https://lab.llvm.org/buildbot/#/builders/247/builds/884
 - https://lab.llvm.org/buildbot/#/builders/231/builds/7688
 - https://lab.llvm.org/buildbot/#/builders/121/builds/27389
 - https://lab.llvm.org/buildbot/#/builders/230/builds/8464
 - https://lab.llvm.org/buildbot/#/builders/57/builds/24209
 - https://lab.llvm.org/buildbot/#/builders/127/builds/42722
2023-01-25 19:11:08 -08:00
Paul Kirth
f2916becc5 Reland [pgo] Avoid introducing relocations by using private alias
In many cases, we can use an alias to avoid a symbolic relocations,
instead of using the public, interposable symbol. When the instrumented
function is in a COMDAT, we can use a hidden alias, and still avoid
references to discarded sections.

Previous versions of this patch allowed the compiler to name the
generated alias, but that would only be valid when the functions were
local. Since the alias may be used across TUs we use a more
deterministic naming convention, and add a ".local" suffix to the alias
name just as we do for relative vtables aliases.

https://reviews.llvm.org/rG20894a478da224bdd69c91a22a5175b28bc08ed9
removed an incorrect assertion on Mach-O which caused assertion failures in LLD.

We prevent duplicate symbols under ThinLTO + PGO + CFI by disabling
alias generation when the target function has MD_type metadata used in
CFI.

Reviewed By: phosek

Differential Revision: https://reviews.llvm.org/D137982
2023-01-25 22:19:19 +00:00
Daniel Thornburgh
efbc8bb18e [llvm-cov] Look up object files using debuginfod
Reviewed By: gulfem

Differential Revision: https://reviews.llvm.org/D136702
2023-01-25 14:00:34 -08:00
Kirill Stoimenov
3348699221 [LSAN] Attempt to fix the ppc64 build by excluding unsupported test
Reviewed By: kstoimenov

Differential Revision: https://reviews.llvm.org/D142561
2023-01-25 17:06:24 +00:00
Muhammad Omair Javaid
37505da42f [compiler-rt] Remove XFAIL decorator trampoline_setup_test.c
This patch remove xfail decorator from
builtins/Unit/trampoline_setup_test.c as it is passing on Windows/AArch64
nowz. It is being skipped in code with __clang__ not defined.

https://lab.llvm.org/buildbot/#/builders/120/builds/3873
2023-01-25 06:18:23 +05:00
Kirill Stoimenov
f057314345 [HWASAN] Copy some ASAN independent unit tests from ASAN to LSAN
Reviewed By: vitalybuka

Differential Revision: https://reviews.llvm.org/D142504
2023-01-25 00:39:52 +00:00
Han Zhu
7a2f3d1886 [NFC] Update tsan_rtl.h comment after D142039 2023-01-24 10:47:02 -08:00
Marco Elver
5265adc737 [SanitizerBinaryMetadata] Declare callbacks extern weak
Declare callbacks extern weak (if no existing declaration exists), and
only call if the function address is non-null.

This allows to attach semantic metadata to binaries where no user of
that metadata exists, avoiding to have to link empty stub callbacks.

Once the binary is linked (statically or dynamically) against a tool
runtime that implements the callbacks, the respective callbacks will be
called. This vastly simplifies gradual deployment of tools using the
metadata, esp. avoiding having to recompile large codebases with
different compiler flags (which negatively impacts compiler caches).

Reviewed By: dvyukov, vitalybuka

Differential Revision: https://reviews.llvm.org/D142408
2023-01-24 12:54:20 +01:00
Vitaly Buka
5b190c4a2d Revert "[profile] Disable test which needs update after D141512"
Work around with -fno-slp-vectorize.

This reverts commit 31260a4ce43aab7c04f501095a9032de063ccaf9.
2023-01-23 17:35:38 -08:00
Kirill Stoimenov
2b0322ed56 [HWASAN] Fix PointsIntoChunk to untag pointers. Also added some checks where we know that the pointer should be untagged.
Reviewed By: vitalybuka

Differential Revision: https://reviews.llvm.org/D142389
2023-01-24 00:35:17 +00:00
Kirill Stoimenov
eba322e9d7 [Sanitizer] Make GetBlockBeginFastLocked parameters const.
Reviewed By: vitalybuka

Differential Revision: https://reviews.llvm.org/D142402
2023-01-24 00:01:35 +00:00
Kirill Stoimenov
cf6c43189f [HWASAN] Fix memory leaks in tests.
Reviewed By: vitalybuka

Differential Revision: https://reviews.llvm.org/D142383
2023-01-23 23:59:07 +00:00
Vitaly Buka
31260a4ce4 [profile] Disable test which needs update after D141512 2023-01-23 14:57:01 -08:00
Han Zhu
84bec0a219 [tsan] Always initialize tsan when building shared lib
Differential Revision: https://reviews.llvm.org/D142039
2023-01-23 10:30:18 -08:00
Dimitry Andric
abf399737e Revert "[compiler-rt][builtins] Skip building (b)float16 support on i386-freebsd"
This reverts commit 45368c75582f0bded1f06d5c82c1f2ee023fb186.

There were some unexpected failures in aarch64 and arm buildbots, I will
have to investigate why these suddenly fell over.
2023-01-23 11:22:28 +01:00
Dimitry Andric
45368c7558 [compiler-rt][builtins] Skip building (b)float16 support on i386-freebsd
Since bfloat16 and float16 support is not available for i386-freebsd,
the `truncdfbf2.c` and `truncsfbf2.c` builtin sources should be skipped
when targeting that platform, and `COMPILER_RT_HAS_FLOAT16` should not
be defined.

However, the CMake configuration stage runs its tests with the default
target, which normally is amd64-freebsd, so it will detect both bfloat16
and float16 support.

Move adding of the `COMPILER_RT_HAS_FLOAT16` define to the `foreach()`
loop where all the supported architectures are handled, and do not
enable it when targeting i386-freebsd.

Also remove the bfloat16 sources from the `i386_SOURCES` list, when
targeting i386-freebsd.

Differential Revision: https://reviews.llvm.org/D136044
2023-01-22 22:16:51 +01:00
Dmitry Vyukov
f7f01599ec sanmd: refine selection of functions for UAR checking
There are no intrinsic functions that leak arguments.
If the called function does not return, the current function
does not return as well, so no possibility of use-after-return.
Sanitizer function also don't leak or don't return.
It's safe to both pass pointers to local variables to them
and to tail-call them.

Reviewed By: melver

Differential Revision: https://reviews.llvm.org/D142190
2023-01-21 09:51:15 +01:00
Arthur Eubanks
2329a9266d Revert "sanmd: refine selection of functions for UAR checking"
This reverts commit 9d4f1a9eff27716069dc6a2d991baa228c197b85.

Breaks under -DCOMPILER_RT_BUILD_SANITIZERS=OFF
2023-01-20 13:40:50 -08:00
David Carlier
b4c840e70b [Sanitizers] intercept hexdump on FreeBSD.
Reviewers: vitalybuka
Reviewed-By: vitalybuka

Differential Revision: https://reviews.llvm.org/D110471
2023-01-20 18:00:38 +00:00