16349 Commits

Author SHA1 Message Date
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
Roy Sundahl
f9450807dd
[ubsan][test] Fix typo in D139230
Fix "runtime runtime error" -> "runtime error"

Reviewed By: MaskRay

Differential Revision: https://reviews.llvm.org/D140321
2023-01-06 14:28:07 -08: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
Florian Hahn
93a0ff2328
[profile] Update test to make condition non-redundant.
The tests contain a redundant condition in the else if branch that can
be simplified with fb13dcf3431c.

Update the condition used to prevent it from getting removed.

Alive2 proof for check removal:
https://alive2.llvm.org/ce/z/iFBnsy
2023-01-05 19:07:04 +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
3ffda42e50 [test] Fix #if 2023-01-03 13:18:46 -08: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
Muhammad Omair Javaid
aa36207c78 [compiler-rt] XFAIL builtins unit tests on WoA
Following tests are marked XFAIl because they are dependent on native
C complex numbers but they are not a native type for Microsoft ABI [1].

Builtins-aarch64-windows :: divmodti4_test.c
Builtins-aarch64-windows :: fixunstfdi_test.c
Builtins-aarch64-windows :: multc3_test.c

Also trampoline_setup_test.c as it runs with only non-clang compiler while
WoA LLVM buildbots use clang.

[1] https://learn.microsoft.com/en-us/cpp/c-runtime-library/complex-math-support?view=msvc-170
2023-01-03 15:22:45 +04: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
7f7a56b9a1 [CMake] Remove unused ALL_SCUDO_SUPPORTED_ARCH after D138157 2022-12-30 18:23:55 -08:00
Gulfem Savrun Yeniceri
1ae7d83803 [profile] Add binary ids into indexed profiles
This patch adds support for including binary ids in an indexed profile.
It adds a new field into the header that points to the offset of the
binary id section. The binary id section consists of a size of the
section, and a list of binary ids (if they are present) that consist
of two parts: length and data.

This patch guarantees that indexed profile is backwards compatible
after adding binary ids.

Differential Revision: https://reviews.llvm.org/D135929
2022-12-29 18:46:56 +00:00
Fangrui Song
df9400c579 [test] Fix dfsan/stack_trace.c 2022-12-29 10:30:41 -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
Fangrui Song
975327a609 [dfsan][test] Replace REQUIRES: x86_64-target-arch with lit.cfg.py check
Make it easier to support a new architecture.

Reviewed By: #sanitizers, vitalybuka

Differential Revision: https://reviews.llvm.org/D140744
2022-12-28 15:35:09 -08:00
Pavel Iliin
fe5cf480ee Reland "[AArch64] FMV support and necessary target features dependencies."
This relands commits e43924a75145d2f9e722f74b673145c3e62bfd07,
a43f36142c501e2d3f4797ef938db4e0c5e0eeec,
bf94eac6a3f7c5cd8941956d44c15524fa3751bd 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
Hans Wennborg
fd0ca2c4e9 Revert "Reland "[pgo] Avoid introducing relocations by using private alias""
This caused lld on mac to assert when building instrumented clang (or
instrumented code in general). See comment on the code review for
reproducer.

> 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.
>
> New compiler-rt tests are Linux only for now.
>
> 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.
>
> Reviewed By: phosek
>
> Differential Revision: https://reviews.llvm.org/D137982

This reverts commit c42e50fede53bbcce79095e7c8115f26826c81ae.
2022-12-21 15:29:00 +01:00
Paul Robinson
566e34829f [lit] Document the 'target=<triple>' feature
Differential Revision: https://reviews.llvm.org/D139869
2022-12-21 06:10:48 -08:00
Paul Robinson
17f804ef4b [hwasan] Convert tests to check 'target=...'
Part of the project to eliminate special handling for triples in lit
expressions.
2022-12-21 05:41:41 -08:00
Paul Robinson
8e60061290 [compiler-rt] Simplify lit test thumb checks 2022-12-21 05:33:32 -08:00
Mitch Phillips
744486ec21 Revert "[AArch64] FMV support and necessary target features dependencies."
This reverts commit e43924a75145d2f9e722f74b673145c3e62bfd07.

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 a43f36142c501e2d3f4797ef938db4e0c5e0eeec.

Reason: Depends on reverted change https://reviews.llvm.org/D127812
2022-12-20 17:15:38 -08:00
Louis Dionne
52aab0e4b4 [clang] Re-apply change to avoid passing -stdlib=libc++ spuriously to CC1 on Darwin
Previously, we would be passing down -stdlib=libc++ from the Driver
to CC1 whenever the default standard library on the platform was libc++,
even if -stdlib= had not been passed to the Driver. This meant that we
would pass -stdlib=libc++ in nonsensical circumstances, such as when
compiling C code.

This logic had been added in b534ce46bd40 to make sure that header
search paths were set up properly. However, since libc++ is now the
default Standard Library on Darwin, passing this explicitly is not
required anymore. Indeed, if no -stdlib= is specified, CC1 will end
up using libc++ if it queries which standard library to use, without
having to be told.

Not passing -stdlib= at all to CC1 on Darwin should become possible
once CC1 stops relying on it to set up framework search paths.

Furthermore, this commit also removes a diagnostic checking whether the
deployment target is too old to support libc++. Nowadays, all supported
deployment targets use libc++ and compiling with libstdc++ is not
supported anymore. The Driver was the wrong place to issue this
diagnostic since it doesn't know whether libc++ will actually be linked
against (e.g. C vs C++), which would lead to spurious diagnostics.
Given that these targets are not supported anymore, we simply drop
the diagnostic instead of trying to refactor it into CC1.

This is a re-application of 6540f32db09c which had been reverted in
49dd02bd0819 because it broke a compiler-rt test. The test had broken
because we were compiling C code and passing -stdlib=libc++, which Clang
will now warn about.

rdar://103198514

Differential Revision: https://reviews.llvm.org/D139938
2022-12-20 19:56:28 -05:00
Pavel Iliin
a43f36142c [AArch64][compiler-rt] Fix HWCAP_CPUID not defined in some cases.
Define HWCAP_CPUID to fix commit e43924a75145d2f9e722f74b673145c3e62bfd07.
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
Paul Robinson
015f8cd78e [xray] Convert tests to check 'target=...'
Part of the project to eliminate special handling for triples in lit
expressions.
2022-12-20 07:36:08 -08: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
Paul Robinson
e6e4362901 [ubsan] Convert tests to check 'target=...'
Part of the project to eliminate special handling for triples in lit
expressions.
2022-12-19 12:04:08 -08:00
Paul Robinson
fbe3f89bcf [tsan] Convert tests to check 'target=...'
Part of the project to eliminate special handling for triples in lit
expressions.
2022-12-19 11:32:38 -08:00
Paul Robinson
975fa72506 [sanitizer-common] Convert tests to check 'target=...'
Part of the project to eliminate special handling for triples in lit
expressions.
2022-12-19 11:01:09 -08:00
Paul Kirth
c42e50fede 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.

New compiler-rt tests are Linux only for now.

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.

Reviewed By: phosek

Differential Revision: https://reviews.llvm.org/D137982
2022-12-19 18:45:58 +00:00
Paul Robinson
2f6439bcf9 [profile] Convert tests to check 'target=...'
Part of the project to eliminate special handling for triples in lit
expressions.
2022-12-19 09:44:49 -08:00
Paul Robinson
02012a78b8 [msan] Convert tests to check 'target=...'
Part of the project to eliminate special handling for triples in lit
expressions.
2022-12-19 06:44:42 -08:00
Paul Robinson
0773a5cbe8 [lsan] Convert tests to check 'target=...'
Part of the project to eliminate special handling for triples in lit
expressions.
2022-12-19 06:26:15 -08: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
Paul Robinson
5bdb9254d9 [fuzzer] Fix UNSUPPORTED criteria for two tests
Fuzzer might decide on a target arch different from the triple.
2022-12-16 12:48:16 -08:00