Commit Graph

12233 Commits

Author SHA1 Message Date
Fangrui Song
a5519b99bc [sanitizer] Don't intercept LFS64 symbols on musl
LFS64 symbols in musl are for glibc-ABI-compat and not intended for linking
(correct usage will not create LFS64 references). The next release 1.2.4 will
disallow linking against LFS64 symbols[1].

For sanitizers, let's just remove LFS64 interceptors. In case of erroneous LFS64
references, asan/tsan will detect fewer problems and msan may have false
positives.

[1]: https://git.musl-libc.org/cgit/musl/commit/?id=246f1c811448f37a44b41cd8df8d0ef9736d95f4

Reviewed By: thesamesam

Differential Revision: https://reviews.llvm.org/D141186
2023-01-09 12:43:23 -08:00
Fangrui Song
8e0c1aaf6b [msan] Use SizeClassAllocator64 for AArch64
Now that D137666 requires 48-bit VMA for AArch64, we can switch to
SizeClassAllocator64 for a slightly more efficient allocator
(asan/lsan already switched by default).

It seems that we can pick kSpaceBeg = 0xE00000000000ULL to support both Linux
("app-15") and FreeBSD ("high memory").

Reviewed By: #sanitizers, vitalybuka

Differential Revision: https://reviews.llvm.org/D140792
2023-01-09 19:49:08 +00:00
Thurston Dang
df3af581e7 tsan: increase app mappings for aarch64 48-bit
Currently, tsan's memory mappings include 4GB
for high app, 20GB for mid app, and 8GB for low
app. The high app and mid app mappings are
too small for large programs, especially if ASLR
entropy (mmap_rnd_bits) is set higher. The low app
region (for non-PIE) is too small for some of tcmalloc's
internal tests (this does not affect normal apps,
since tsan will replace malloc).

This CL increases the memory mappings to 4TB for
high app, 1.3TB for mid app, and 10TB for low app. Note
that tsan's 44-bit pointer compression/decompression imposes
a 16TB limit on the combined size of the app mappings, making
this set of mappings more or less maximal.

Differential Revision: https://reviews.llvm.org/D140923
2023-01-09 18:45:43 +00:00
Alex Brachet
70ab8e8ad9 [compiler-rt] Move up undefined macro checks
Previously HWCAP_ATOMIC and others were being used before checking if
they were defined. This moves up all the ifndef checks to define these
macros if they are not yet defined.

Differential Revision: https://reviews.llvm.org/D141285
2023-01-09 15:54:11 +00:00
Pavel Iliin
a22f1458f6 [AArch64][compiler-rt] Option to build compiler-rt without FMV support.
This commit adds compiler-rt cmake option COMPILER_RT_DISABLE_AARCH64_FMV
which, when enabled, doesn't include function multiversioning features
initilization code in 'builtins' build.

Differential Revision: https://reviews.llvm.org/D141199
2023-01-08 19:16:57 +00:00
Kirill Stoimenov
f547c173f2 [LSAN][NFC] Removed FinishThreadLocked from the LSAN interface.
It is only used in the LSAN specific part.

Reviewed By: vitalybuka

Differential Revision: https://reviews.llvm.org/D140109
2023-01-06 00:28:40 +00:00
Freddy Ye
27b8f54f51 [X86] Support -march=emeraldrapids
Reviewed By: pengfei, skan

Differential Revision: https://reviews.llvm.org/D140950
2023-01-05 20:27:32 +08:00
Freddy Ye
f2891086f4 [X86] Modify model value of meteorlake.
Reviewed By: pengfei

Differential Revision: https://reviews.llvm.org/D140943
2023-01-05 20:08:34 +08:00
Fangrui Song
fb32a69855 [sanitizer] Move {,__}pthread_mutex_{lock,unlock} interceptors to tsan
These interceptors are pure forwarders for other sanitizers. Move them beside
tsan-specific pthread_mutex_{trylock,timedlock} interceptors.

While here, guard `__pthread_mutex_{lock,unlock}` (D46793) under `#if !__GLIBC_PREREQ(2, 34)`.

In glibc>=2.34 [1], `__pthread_mutex_{lock,unlock}` only have non-default-version definitions
(unversioned `__pthread_mutex_lock` causes a linker error. Program preloading is not expected).
In glibc>=2.36 [2], `dlsym(RTLD_NEXT, "__pthread_mutex_lock")` returns nullptr, so the interceptor won't work.

Fix https://github.com/llvm/llvm-project/issues/59820

[1]: https://sourceware.org/git/?p=glibc.git;a=commit;h=99f841c441feeaa9a3d97fd91bb3d6ec8073c982
[2]: https://sourceware.org/git/?p=glibc.git;a=commit;h=efa7936e4c91b1c260d03614bb26858fbb8a0204

Reviewed By: melver, vitalybuka

Differential Revision: https://reviews.llvm.org/D140957
2023-01-04 12:04:19 -08:00
Blue Gaston
0b857c568c Fix to D140567 2023-01-04 09:50:27 -07:00
Fangrui Song
de5416cb59 [dfsan] Support Linux AArch64
compiler-rt/cmake/Modules/AllSupportedArchDefs.cmake:ALL_DFSAN_SUPPORTED_ARCH
allows AArch64 but currently the instrumentation will crash.

Port Linux AArch64 memory mappings from msan but use
SizeClassAllocator64 for a slightly more efficient allocator (used by
asan/lsan). Change dfsan/lit.cfg.py to allow Linux aarch64. All tests
should pass.

* dfsan/origin_invalid.c uses x86_64 assembly. Just make it x86_64 specific.
* dfsan/interceptors.c our mallinfo interceptor takes an argument
  instead of returning a struct. This does not work on AArch64 which
  uses different registers for the two function types. Disable AArch64
  as msan/Linux/mallinfo.cpp does.

Reviewed By: #sanitizers, vitalybuka

Differential Revision: https://reviews.llvm.org/D140770
2023-01-03 13:17:39 -08:00
Blue Gaston
3efb0274b7 [Sanitizers] Fix procmap tests for apple arm64
As part of effort to enable sanitizer common unit tests on arm64 apple devices.
Add kModuleArchARM64 as expected Arch

Differential Revision: https://reviews.llvm.org/D140567
2023-01-03 12:28:57 -07:00
Fangrui Song
99fc4d3d16 [msan] Remove non-working MSAN_LINUX_X86_64_OLD_MAPPING
r249754 (2015) added this macro (not set anywhere) for an escape hatch.
This old layout has been non-working for many years (Linux
arch/x86/include/asm/elf.h ELF_ET_DYN_BASE is outside the APP range):

    FATAL: Code 0x558547327980 is out of application range. Non-PIE build?
    FATAL: MemorySanitizer can not mmap the shadow memory.
    FATAL: Make sure to compile with -fPIE and to link with -pie.
    FATAL: Disabling ASLR is known to cause this error.
    FATAL: If running under GDB, try 'set disable-randomization off'.

Non-pie doesn't work either.
2022-12-30 19:43:19 -08:00
Fangrui Song
2468b3f572 [XRay] Unsupport version<2 sled entry
For many features we expect clang and compiler-rt to have a version lock
relation, yet for XRaySledEntry we have kept version<2 compatibility for more
than 2 years (I migrated away the last user mips in 2020-09 (D87977)).
I think it's fair to call an end to version<2 now. This should discourage more
work on version<2 (e.g. D140725).

Reviewed By: ianlevesque

Differential Revision: https://reviews.llvm.org/D140739
2022-12-28 18:08:30 -08:00
Pavel Iliin
fe5cf480ee Reland "[AArch64] FMV support and necessary target features dependencies."
This relands commits e43924a751,
a43f36142c,
bf94eac6a3 with MSan buildbot
https://lab.llvm.org/buildbot/#/builders/5/builds/30139
use-of-uninitialized-value errors fixed.

Differential Revision: https://reviews.llvm.org/D127812
2022-12-27 19:18:07 +00:00
Youling Tang
2b15c63fb7 [compiler-rt] Fix build errors when using gcc on LoongArch
- GCC does not recognize $fcsr0, uses $r0 instead.
- GCC does not implement __builtin_thread_pointer, which can be
  obtained directly through $tp.

Reviewed By: SixWeining

Differential Revision: https://reviews.llvm.org/D140545
2022-12-26 09:33:54 +08:00
Bastian Kersting
ba0ec6f15f Add Soft/Hard RSS Limits to Scudo Standalone
Reviewed By: vitalybuka

Differential Revision: https://reviews.llvm.org/D126752
2022-12-22 19:45:14 -08:00
Vitaly Buka
ad1eb251d6 [scudo] Fix return type of GetRSS() 2022-12-22 19:41:28 -08:00
Lang Hames
a0a51a805f [ORC][ORC-RT] Add SimplePackedSerialization support for optionals.
This allows optionals to be serialized and deserialized, and used as arguments
and return values in SPS wrapper functions.

Serialization of optional values is indicated by use of the SPSOptional tag.
SPSOptionals are serialized serialized as a bool (false for no value, true for
value) plus the serialization of the contained value if any. Serialization
to/from std::optional is included in this commit.

This commit includes updates to SimplePackedSerialization in both ORC and the
ORC runtime.

, std::optional serialization.
2022-12-22 17:37:32 -08:00
Blue Gaston
1293e93ee3 [Sanitizer] Fix page alignment for mmap calls
We are in the process of enabling sanitizer_common unit tests on arm64 for apple devices. rdar://101436019

The test `CompactRingBuffer.int64` is failing on arm64 with the error:

```==17265==ERROR: SanitizerTool failed to deallocate 0xfffffffffffff000 (-4096) bytes at address 0x000105c30000
SanitizerTool: CHECK failed: sanitizer_posix.cpp:63 "(("unable to unmap" && 0)) != (0)" (0x0, 0x0) (tid=157296)```

If page size is sufficiently larger than alignment then this code:
   UnmapOrDie((void*)end, map_end - end);
end is will be greater than map_end causing the value passed to UnmapOrDie to be negative.

This is caused when GetPageSizeCached returns 16k and alignment is 8k.
map_size and what is mapped by mmap uses size and alignment which is smaller than what is calculated by end using the actual page size.
Therefore, map_end ends up being less than end.
The call to mmap is allocating sufficent page-aligned memory, because it calls RoundUp within MmapOrDieOnFatalError.
But this size is not being captured by map_size.

We can address this by rounding up map_size here to be page-aligned. This ensures that map_end will be greater than or equal to end and that it will match mmaps use of page-aligned value, and the
subsequent call to munmap will also be page-aligned.

Differential Revision: https://reviews.llvm.org/D140353
2022-12-22 13:25:41 -05:00
Mitch Phillips
5b97612a11 Add aligned_alloc to symbolizer symbols list.
New symbol used by libcxx as of https://reviews.llvm.org/D138196, needs
to be added to the symbol deps list.
2022-12-22 09:53:24 -08:00
Mitch Phillips
744486ec21 Revert "[AArch64] FMV support and necessary target features dependencies."
This reverts commit e43924a751.

Reason: Patch broke the MSan buildbots. More information is available on
the original phabricator review: https://reviews.llvm.org/D127812
2022-12-20 17:16:32 -08:00
Mitch Phillips
df2bdb7043 Revert "[AArch64][compiler-rt] Fix HWCAP_CPUID not defined in some cases."
This reverts commit a43f36142c.

Reason: Depends on reverted change https://reviews.llvm.org/D127812
2022-12-20 17:15:38 -08:00
Pavel Iliin
a43f36142c [AArch64][compiler-rt] Fix HWCAP_CPUID not defined in some cases.
Define HWCAP_CPUID to fix commit e43924a751.
2022-12-20 19:15:27 +00:00
Yaneury Fermin
5a1525c576 [scudo][standalone] Precommit pages
On Fuchsia, this CL changes garbage collection
to precommit all pages if the |Buffer| doesn't
fit into the static buffer size.

A test program (scudotest) was used that deliberately
grows a size class high water mark to the point where
the pre-allocated static buffer is no longer used for
garbage collection.

Traces showed that precommiting the Vmar removes ~30 page faults
and ~.22ms of wall time.*

Before: https://ui.perfetto.dev/#!/?s=7da19fc3f59448eef51fd6fd03283bb87b702cf1a565bcbe6c9c28371671
After: https://ui.perfetto.dev/#!/?s=97707cd99b2c9efd1e6569b2deb97e3d16f8be532c59a0cc12463c37fbb1d8

*: Use the added `zx_vmar_op_range` as a reference point to observe
the differences.

For more context, see https://fxbug.dev/115594.

Reviewed By: Chia-hungDuan

Differential Revision: https://reviews.llvm.org/D140320
2022-12-20 17:37:49 +00:00
Pavel Iliin
e43924a751 [AArch64] FMV support and necessary target features dependencies.
This is Function Multi Versioning (FMV) implementation for AArch64 target in
accordance with Beta Arm C Language Extensions specification
https://github.com/ARM-software/acle/blob/main/main/acle.md#function-multi-versioning
It supports new "target_version" function attribute and extends existing
"target_clones" one. Also missing dependencies for target features were added.

Differential Revision: https://reviews.llvm.org/D127812
2022-12-20 15:42:25 +00:00
Archibald Elliott
ecaab107e4 [compiler-rt] Add TargetParser to symbolizer 2022-12-20 13:45:39 +00:00
Luke Nicholson
ab17a08d0f [fuchsia] Tune PrimaryGroupSizeLog to reduce fragmentation.
21U is the default group size, which demonstrates ~15mb reduction
in heap size for some highly fragmented heaps on Fuchsia, and
a general 5mb savings when devices are under no load.

Microbenchmarks show no performance regressions, but most of our
benchmarks perform no significant mallocs. So we are choosing the
default setting, and monitoring for potential performance
issues.

Reviewed By: Chia-hungDuan

Differential Revision: https://reviews.llvm.org/D140311
2022-12-20 02:33:52 +00:00
Ganesh Gopalasubramanian
1f057e365f [X86] AMD Zen 4 Initial enablement
Reviewed By: RKSimon
Differential Revision: https://reviews.llvm.org/D139073
2022-12-17 16:15:22 +05:30
Mitch Phillips
4ec480dea2 Reland "Delete sanitizer_common-based ('old') scudo: o7"
This reverts commit 78f786d02a.

Internal use cases have been migrated.

This has been on life support for a long time. Now that -fsanitize=scudo
is scudo_standalone, this can be removed.

Tests are sticking around for now to be reused for scudo_standalone
later on.
2022-12-15 15:35:45 -08:00
Kirill Stoimenov
bfdc1a795a [HWASAN] Added dtls_ member variable which is needed by __lsan::GetThreadRangesLocked.
Reviewed By: vitalybuka

Differential Revision: https://reviews.llvm.org/D140065
2022-12-15 00:20:29 +00:00
Wiktor Garbacz
6efa850b09 TSAN: (Re)Mark shadow memory nondumpable after a reset
Shadow memory was not marked as non-dumpable after a reset resulting in process taking a very long time to generate a coredump.

Reviewed By: vitalybuka

Differential Revision: https://reviews.llvm.org/D139425
2022-12-14 11:29:35 -08:00
Dominic Chen
3d3bc72c04 [scudo] Reland: Fix and enable more warnings for standalone build
Differential Revision: https://reviews.llvm.org/D122761
2022-12-14 10:30:02 -08:00
Haowei Wu
beb3fa2d2e Revert "Reland "[compiler-rt][test] Heed COMPILER_RT_DEBUG when compiling unittests""
This reverts commit 255c3e3dcb, which
breaks Msan-x86_64-Test.
2022-12-13 16:38:12 -08:00
Kirill Stoimenov
e43e0ffbe7 [LSAN][NFC] Eliminated GetThreadRegistryLocked from the LSAN interface to avoid the need to implement it in HWASAN.
Reviewed By: vitalybuka

Differential Revision: https://reviews.llvm.org/D139976
2022-12-14 00:15:40 +00:00
Kirill Stoimenov
a3587ea6d1 [HWASAN][NFC] Added implementation for the most of the allocator related functions from the LSAN interface.
Reviewed By: vitalybuka

Differential Revision: https://reviews.llvm.org/D139964
2022-12-13 21:38:13 +00:00
Kirill Stoimenov
1b0d63c506 [HWASAN] Implemented LsanMetadata in HWASAN.
Please note that that this code is not used. It will be connected at some point when the rest of the code is ready.

Reviewed By: vitalybuka

Differential Revision: https://reviews.llvm.org/D139464
2022-12-13 17:05:15 +00:00
Krasimir Georgiev
78f786d02a Revert "Delete sanitizer_common-based ('old') scudo: o7"
This reverts commit 512a98e718.
We'll need some time to migrate some internal usages off this.
Will sync up with @hctim and @vitalybuka directly.
2022-12-13 16:03:11 +01:00
Rainer Orth
255c3e3dcb Reland "[compiler-rt][test] Heed COMPILER_RT_DEBUG when compiling unittests"
When trying to debug some `compiler-rt` unittests, I initially had a hard
time because

- even in a `Debug` build one needs to set `COMPILER_RT_DEBUG` to get
  debugging info for some of the code and
- even so the unittests used a hardcoded `-O2` which often makes debugging
  impossible.

This patch addresses this by instead using `-O0` if `COMPILER_RT_DEBUG`.

Changes relative to the previous commit:

- Use `string(APPEND)` for `COMPILER_RT_TEST_COMPILER_CFLAGS`.
- Omit `-O3` from `COMPILER_RT_TEST_COMPILER_CFLAGS` in non-debug builds for now.
- Provide `__sanitizer::integral_constant<bool, true>::value` instantiation
  for `sanitizer_type_traits_test.cpp` in debug builds.
- Disable subtests of `tsan/tests/unit/tsan_trace_test.cpp` that deadlock
  in debug builds.
- `XFAIL` `tsan/Linux/check_memcpy.c` in debug builds.

Tested on `sparcv9-sun-solaris2.11`, `amd64-pc-solaris2.11`, and
`x86_64-pc-linux-gnu`.

Differential Revision: https://reviews.llvm.org/D91620
2022-12-13 10:58:58 +01:00
Dominic Chen
119f977d9e [scudo] Optimize scudo test string allocation
When the underlying vector becomes full, it resizes, remaps, and then copies over the old data. To avoid thes excess allocations, allow reservation from the backing vector.

Differential Revision: https://reviews.llvm.org/D135119
2022-12-12 15:50:00 -08:00
Mitch Phillips
512a98e718 Delete sanitizer_common-based ('old') scudo: o7
This has been on life support for a long time. Now that -fsanitize=scudo
is scudo_standalone, this can be removed.

Tests are sticking around for now to be reused for scudo_standalone
later on.

Reviewed By: vitalybuka

Differential Revision: https://reviews.llvm.org/D139884
2022-12-12 14:35:56 -08:00
Mitch Phillips
f529a9f324 [GWP-ASan] Fix sanitizer backtrace util using wrong print.
The sanitizer backtrace is used in tests, and calling StackTrace.Print()
means that it uses the sanitizer's Printf(), rather than GWP-ASan's
Printf(). In the current code, GWP-ASan's Printf() *is* the sanitizer
print, but this isn't guaranteed to be the case, and will change in an
upcoming patch.

Reviewed By: eugenis

Differential Revision: https://reviews.llvm.org/D139748
2022-12-12 13:53:11 -08:00
Kirill Stoimenov
ee56d88b02 [HWASAN][NFC] Renamed [g|s]et_requested_size to [G|S]etRequestedSize.
Reviewed By: kda

Differential Revision: https://reviews.llvm.org/D139727
2022-12-12 19:23:19 +00:00
Lei Huang
58f1534320 Revert "[scudo] Enable more warnings for standalone build"
This reverts commit a2b0673dbe.
Broke ppc sanitizer bot: https://lab.llvm.org/buildbot/#/builders/19/builds/14037
2022-12-12 10:25:58 -05:00
Markus Böck
78c033b541 [sanitizers][windows] Correctly override functions with backward jmps
To reproduce: Download and run the latest Firefox ASAN build (https://firefox-ci-tc.services.mozilla.com/api/index/v1/task/gecko.v2.mozilla-central.latest.firefox.win64-asan-opt/artifacts/public/build/target.zip) on Windows 11 (version 10.0.22621 Build 22621); it will crash on launch. Note that this doesn't seem to crash on another Windows 11 VM I've tried, so I'm not sure how reproducible it is across machines, but it reproduces on my machine every time.

The problem seems to be that when overriding the memset function in OverrideFunctionWithRedirectJump(), the relative_offset is stored as a uptr. Per the Intel x64 instruction set reference (https://www.intel.com/content/dam/www/public/us/en/documents/manuals/64-ia-32-architectures-software-developer-instruction-set-reference-manual-325383.pdf - warning: large PDF), on page 646 the jmp instruction (specifically the near jump flavors that start with E9, which are the ones the OverrideFunctionWithRedirectJump() considers) treats the offset as a signed displacement. This causes an incorrect value to be stored for REAL(memset) which points to uninitialized memory, and a crash the next time that gets called.

The fix is to simply treat that offset as signed. I have also added a test case.

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

Differential Revision: https://reviews.llvm.org/D137788
2022-12-12 11:45:43 +01:00
Andrew Browne
5bb06c7cce [DFSan] Add callback that allows to track which function tainted data reaches.
Authored-by: Christopher Liebchen <liebchen@google.com>
Co-authored-by: Andrew Browne <browneee@google.com>

Reviewed By: browneee

Differential Revision: https://reviews.llvm.org/D139543
2022-12-11 23:10:17 -08:00
Mark de Wever
d40dc41738 [CMake] Warn when the version is older than 3.20.0.
This is a preparation to require CMake 3.20.0 after LLVM 16 has been
released.

This change has been discussed on discourse
https://discourse.llvm.org/t/rfc-upgrading-llvms-minimum-required-cmake-version/66193

Reviewed By: #libc_vendors, MaskRay, ChuanqiXu, to268, thieta, stellaraccident, ldionne, #libc, #libc_abi, phosek

Differential Revision: https://reviews.llvm.org/D137724
2022-12-11 20:19:46 +01:00
Gulfem Savrun Yeniceri
ba5edfd386 Revert "[compiler-rt][hwasan] Let CheckAddressSized eventually call HandleTagMismatch on Fuchsia"
This reverts commit bcc4470bad.
2022-12-10 04:44:26 +00:00
Gulfem Savrun Yeniceri
32cd87471f Revert "[compiler-rt][hwasan] Add unused attribute to GetRegisters"
This reverts commit 3e3ae76de4.
2022-12-10 04:44:10 +00:00
Youling Tang
1f8ea4149c [sanitizer] Fix the internal_clone implementation on loongarch
Fix syscall clone argument passing order, also `call fn(arg)` should
return, change `jr $a5`(jirl $zero, $a5, 0) to `jirl $ra, $a5, 0`.

Reviewed By: SixWeining

Differential Revision: https://reviews.llvm.org/D139619
2022-12-10 11:50:39 +08:00