17628 Commits

Author SHA1 Message Date
Ivan Tadeu Ferreira Antunes Filho
400389db7d
Initialize sigset in asan_interceptors (#69502)
When compiling for Darwin, sigset is not initialized. 

When -Werror,-Wuninitialized-const-reference are enabled we see the
error:
asan_interceptors.cpp:260:38: error: variable 'sigset' is uninitialized
when passed as a const reference argument here
[-Werror,-Wuninitialized-const-reference]

This fixes the error
2023-10-18 13:01:36 -07:00
Kazu Hirata
781424c872 [compiler-rt] Fix a warning
This patch fixes:

  compiler-rt/lib/builtins/int_to_fp_impl.inc:36:10: error: expression
  is not an integer constant expression; folding it to a constant is a
  GNU extension [-Werror,-Wgnu-folding-constant]
2023-10-18 12:16:41 -07:00
Thurston Dang
ddf1de20a3
[hwasan] Fix rare false negative (zero tag) in stack-uar.c (#69374)
stack-uar.c is flaky (1 in 256 executions) because the random tag
may be zero (https://github.com/llvm/llvm-project/issues/69221).

This patch works around the issue in the same way as deep-recursion.c

(aa4dfd3736),
by falling back to a neighboring object, which must have a different
(non-zero) tag.

This patch also does a minor cleanup of the aforementioned
deep-recursion.c, for consistency with stack-uar.c.

Co-authored-by: Thurston Dang <thurston@google.com>
2023-10-18 10:43:53 -07:00
Alex Bradbury
69660ccf2a
[builtins] Convert more int to fp functions to use common implementation (#67540)
Builds on #66903, converting the rest of the low-hanging fruit to use
the common implementation.

See https://github.com/llvm/llvm-project/pull/67540#issuecomment-1766499179 for links to Alive2 comparisons of before/after.
2023-10-18 14:13:43 +01:00
Sander de Smalen
975ec8368f
[compiler-rt] Only build SME ABI routines for baremetal or platforms that have sys/auxv.h (#69423)
This avoids link failures on other platorms that don't (yet) have an
implementation of __aarch64_sme_accessible.
2023-10-18 10:39:43 +01:00
PiJoules
bd0fc480df
[sanitizer_common] Use 38-bit mmap range for Fuchsia (#69387)
46cb8d9a325233ac11ed5e90367c43774294d87e unconditionally changed the
mmap range to 2^48 for all riscv sanitizers. This changes the allocator
tunings for the 32-bit allocator for riscv and led to a severe
performance regression for our lsan tests. This effectively revers the
tuning change but only for Fuchsia.

Once we enable the 64-bit allocator for everything riscv, this value
will be irrelevant since it's only relevant for the 32-bit allocator.
2023-10-17 17:02:59 -07:00
Thurston Dang
7b1e6851b6 [hwasan] Exclude bcmp interceptor test from Android
This fixes a buildbot breakage (e.g.,
https://lab.llvm.org/buildbot/#/builders/77/builds/31422/steps/21/logs/stdio)
that was caused by the introduction of this test
(ff1329e297).

Build error from buildbot:
/var/lib/buildbot/sanitizer-buildbot6/sanitizer-x86_64-linux-android/build/llvm-project/compiler-rt/test/hwasan/TestCases/bcmp.cpp:18:10: error: use of undeclared identifier 'bcmp'
   18 |   return bcmp(p, a, size);
2023-10-17 16:03:26 +00:00
David Spickett
e483673246 [compiler-rt][HWASAN] Add missing include in deep-recursion.c test 2023-10-17 08:12:21 +00:00
Thurston Dang
aa4dfd3736
[hwasan] Fix and re-enable deep-recursion.c (#69265)
deep-recursion.c was disabled

(c007e0f66e)
because the test may get unlucky and end up with a zero-tagged variable,
leading to a false negative
(https://github.com/llvm/llvm-project/issues/69221).

This patch re-enables the test and adds a workaround: it checks
if the variable is zero-tagged, and if so, it will instead use the
neighboring variable, which must have a different (hence non-zero)
tag.

Fixing the stack allocation tagging is left as an exercise for the
reader. It is non-trivial because, even if the stackTagBase is
non-zero, tags for subsequent allocations in the stack frame may wrap
around to zero; working around this would require adding multiple
instructions to each alloca.

---------

Co-authored-by: Thurston Dang <thurston@google.com>
2023-10-16 22:46:27 -07:00
Alexander Shaposhnikov
d85f5a6216 [compiler-rt] Fix build of builtins on Windows
Fix Windows build after 910a4bf5b70ae14e
(the breakage was found by the buildbot
https://lab.llvm.org/buildbot/#/builders/127/builds/56796)
2023-10-16 23:49:46 +00:00
Alexander Shaposhnikov
910a4bf5b7
[compiler-rt] Implement __extendxftf2 and __trunctfxf2 for x86_64 (#66918)
This patch implements __extendxftf2 (long double -> f128) and
__trunctfxf2 (f128 -> long double) on x86_64.
This is a preparation to unblock https://reviews.llvm.org/D53608,
We intentionally do not modify compiler-rt/lib/builtins/fp_lib.h in this
PR
(in particular, to limit the scope and avoid exposing other functions on
X86_64 in this PR).
Instead, TODOs were added to use fp_lib.h once it is available.

Test plan:
1. ninja check-compiler-rt (verified on X86_64 and on Aarch64)
In particular, new tests (extendxftf2_test.c and trunctfxf2_test.c) were
added.
2. compared the results of conversions with what other compilers (gcc)
produce.
2023-10-16 16:12:33 -07:00
Kirill Stoimenov
ff1329e297
[HWASAN] Add bcmp interceptor (#69257) 2023-10-16 16:09:44 -07:00
Paul Kirth
c007e0f66e
[hwasan][test] Fix regex so deep-recursion.c is unsupported on aarch64 targets (#69254)
After 144c5b6d58803a2d4a0fe92a0fe331ff0347dc3b, we still see this test
running in CI for aarch64-linux targets. This appears to be related to
the triple being `aarch64-unknown-linux-gnu`, or similar.

The bot link below includes 144c5b6d58803a2d4a0fe92a0fe331ff0347dc3b,
and fails the deep-recursion.c test, which should have been disabled.
https://luci-milo.appspot.com/ui/p/fuchsia/builders/toolchain.ci/clang-linux-arm64/b8767065085790662609/overview
2023-10-16 14:55:57 -07:00
David Spickett
144c5b6d58 [compiler-rt][hwasan] Disable deep-recursion.c test on AArch64 Linux
The test program occasionaly fails to detect the fault as it should.
See https://github.com/llvm/llvm-project/issues/69221.
2023-10-16 15:26:31 +00:00
Alex Bradbury
6dfea561ba
[builtins] Start to refactor int to fp conversion functions to use a common implementation (#66903)
After this patch, the softfp implementations of floatdidf and floatundidf
use a common implementation (int_to_fp.h and int_to_fp_impl.inc). This
roughly follows the pattern used for a wide range of other builtins,
e.g. fp_trunc_impl.inc.

Currently there is substantial copy and paste for the various int to fp
conversion functions, with just a few constants being changed. This is a
barrier to maintainability, and it's also not attractive to copy this
approach as we introduce additional int to fp conversion functions for
bf16 and half (which we currently lack, but need - see
<https://reviews.llvm.org/D157509>).

I've opted to conservatively start by replacing just two functions,
leaving a follow-up patch to replace others that follow the same
pattern. Also, for better or worse I've left the logic in float[un]didf
largely unchanged other than using a similar approach to
fp_trunc_impl.inc to remove the constants that are tied to a specific
output floating point format.
2023-10-15 16:14:55 +01:00
Sander de Smalen
311bc6683d
[AArch64][compiler-rt] Only build SME ABI routines when compiler supports asm. (#68991)
This also adds the .variant_pcs directive to some functions from which
it was previously missing.
2023-10-14 16:35:03 +01:00
Kai Luo
18dc8dcd76
[PowerPC][JITLink] Support R_PPC64_GOT_TLSGD_PCREL34 (#68660)
`R_PPC64_GOT_TLSGD_PCREL34` is generated for pwr10+.
2023-10-14 10:57:03 +08:00
Christopher Ferris
d9ede91a27
[scudo] Fix type mismatch in trusty. (#69024) 2023-10-13 13:36:58 -07:00
Christopher Ferris
99d92d18e3
[scudo] Add specific die functions for linux specific failures. (#68650)
While running into failures on unmap calls, it becomes difficult to
figure out what's wrong. Break the dieOnMapUnmapError into specific
versions for map, unmap, and then one for mprotect.

Also, put these in a common linux space so that all linux derived code
can reuse this code.
2023-10-13 12:19:11 -07:00
Kirill Stoimenov
844c731f2d
[HWASAN] Mark built-ins as not built-ins to prevent optimizations (#68936)
The other 3 sanitizers (ASAN, TSAN and MSAN) all use
maybeMarkSanitizerLibraryCallNoBuiltin to make disable optimizations
which inline functions like memcmp for example. The lack of this
optimization was allowing ExpandMemCmpPass to convert a memcmp call to
inlined assembly and cause a false negative in HWASAN.
2023-10-13 11:43:29 -07:00
nicole mazzuca
160e8eb449
[ASan] Recognize lea r10, [rip + XX] (#68910)
This instruction is present in memcpy in the latest vcruntime

This PR has been opened for @AndrewDeanMS (a teammate inside Microsoft)
who made the PR to our internal branch.

Co-authored-by: Andrew Dean <Andrew.Dean@microsoft.com>
2023-10-13 08:47:23 -07:00
AdityaK
46cb8d9a32
[TSAN] add support for riscv64 (#68735)
Implements for sv39 and sv48 VMA layout.

Userspace only has access to the bottom half of vma range. The top half
is used by kernel. There is no dedicated vsyscall or heap segment.
PIE program is allocated to start at TASK_SIZE/3*2. Maximum ASLR is
ARCH_MMAP_RND_BITS_MAX+PAGE_SHIFT=24+12=36 Loader, vdso and other
libraries are allocated below stack from the top.

Also change RestoreAddr to use 4 bits to accommodate MappingRiscv64_48

Reviewed by: MaskRay, dvyukov, asb, StephenFan, luismarques, jrtc27,
hiraditya, vitalybuka

Differential Revision: https://reviews.llvm.org/D145214

D145214 was reverted because one file was missing in the latest commit.
Luckily the file was there in the previous commit, probably the author
missed uploading that file with latest commit.

Co-authored-by: Alex Fan <alex.fan.q@gmail.com>
2023-10-12 16:03:07 -07:00
Sander de Smalen
f445be9790 Reland "[compiler-rt][aarch64] Add SME ABI support routines." (#68875)
Resolved issue with green dragon build by fixing relocations for
MachO/Darwin which doesn't compile without @page/@pageoff directives.

Also silenced a warning about constructor(90) priority being < 101,
which is reserved for the implementation. In this case, we're compiling
the implementation so we should be able to use 90.

This reverts commit 072713add4408199d4bce7b3b02cc74a4a382ee0.
2023-10-12 13:56:58 +00:00
Henrik G. Olsson
072713add4
Revert "[compiler-rt][aarch64] Add SME ABI support routines." (#68875)
This reverts commit 2b05fa8f0be7e38f4b4364ea855a3d200ded7480. It caused build errors in compiler-rt.
2023-10-12 13:11:25 +02:00
Sander de Smalen
2b05fa8f0b [compiler-rt][aarch64] Add SME ABI support routines.
When compiling for SME and using the attributes to use PSTATE.ZA,
Clang will emit calls to SME ABI support routines to save and
restore ZA state.

Reviewed By: paulwalker-arm

Differential Revision: https://reviews.llvm.org/D154045
2023-10-12 07:47:16 +00:00
Aaron Ballman
ac2722873b Revert "Diagnose problematic uses of constructor/destructor attribute (#67673)"
This reverts commit 27ecb63c260400dd20b8c5dc16d0dfd2d0e7122e.

Still fails compiler-rt:
https://lab.llvm.org/buildbot/#/builders/109/builds/75364
2023-10-11 09:02:24 -04:00
Aaron Ballman
27ecb63c26 Diagnose problematic uses of constructor/destructor attribute (#67673)
Functions with these attributes will be automatically called before
main() or after main() exits gracefully. In glibc environments, the
constructor function is passed the same arguments as main(), so that
signature is allowed. In all other environments, we require the function
to accept no arguments and either return `void` or `int`. The functions
must use the C calling convention. In C++ language modes, the functions
cannot be a nonstatic member function, or a consteval function.

Additionally, these reuse the same priority logic as the init_priority
attribute which explicitly reserved priorty values <= 100 or > 65535. So
we now diagnose use of reserved priorities the same as we do for the
init_priority attribute, but we downgrade the error to be a warning
which defaults to an error to ease use for implementers like compiler-rt
or libc.

This relands a633a3761fcbd0799426cbf5fbd7794961080e43 with fixes.
2023-10-11 08:55:33 -04:00
Aaron Ballman
0cb6c413b1 Revert "Diagnose problematic uses of constructor/destructor attribute (#67673)"
This reverts commit a633a3761fcbd0799426cbf5fbd7794961080e43.

Still breaking compiler-rt bots:
https://lab.llvm.org/buildbot/#/builders/109/builds/75360
2023-10-11 08:31:13 -04:00
Aaron Ballman
a633a3761f
Diagnose problematic uses of constructor/destructor attribute (#67673)
Functions with these attributes will be automatically called before
main() or after main() exits gracefully. In glibc environments, the
constructor function is passed the same arguments as main(), so that
signature is allowed. In all other environments, we require the function
to accept no arguments and either return `void` or `int`. The functions
must use the C calling convention. In C++ language modes, the functions
cannot be a nonstatic member function, or a consteval function.

Additionally, these reuse the same priority logic as the init_priority
attribute which explicitly reserved priorty values <= 100 or > 65535. So
we now diagnose use of reserved priorities the same as we do for the
init_priority attribute, but we downgrade the error to be a warning
which defaults to an error to ease use for implementers like compiler-rt
or libc.

This relands b4435104ca3904529723b0673cc0f624cf8c54e6 with fixes.
2023-10-11 08:14:45 -04:00
serge-sans-paille
97b989b274
[compiler-rt] During profile flushing, setup SIGKILL mask earlier (#68622)
In multi threaded application, it is possible for one thread to
terminate the program while another is flushing profile information. We
setup a signal mask to delay SIGKILL so that we can safely flush the
profile.

This patch setups the mask earlier: it reduces the window during which a
SIGKILL can end the computation prematurely.

This fixes https://bugzilla.mozilla.org/show_bug.cgi?id=1850940, where a
profiled firefox was encountering several:

LLVM Profile Error: Failed to write file "default_*.profraw": Broken
pipe

Co-authored-by: serge-sans-paille <sguelton@mozilla.com>
2023-10-10 19:19:23 +00:00
Fangrui Song
792674400f -fsanitize=alignment: check memcpy/memmove arguments (#67766)
The -fsanitize=alignment implementation follows the model that we allow
forming unaligned pointers but disallow accessing unaligned pointers.
See [RFC: Enforcing pointer type alignment in Clang](https://lists.llvm.org/pipermail/llvm-dev/2016-January/094012.html)
for detail.

memcpy is a memory access and we require an `int *` argument to be aligned.
Similar to https://reviews.llvm.org/D9673 , emit -fsanitize=alignment check for
arguments of builtin memcpy and memmove functions to catch misaligned load like:
```
// Check the alignment of a but ignore the alignment of b
void unaligned_load(int *a, void *b) { memcpy(a, b, sizeof(*a)); }
```

For a reference parameter, we emit a -fsanitize=alignment check as well, which
can be optimized out by InstCombinePass. We rely on the call site
`TCK_ReferenceBinding` check instead.
```
// The alignment check of a will be optimized out.
void unaligned_load(int &a, void *b) { memcpy(&a, b, sizeof(a)); }
```

The diagnostic message looks like
```
runtime error: store to misaligned address [[PTR:0x[0-9a-f]*]] for type 'int *'
```

We could use a better message for memcpy, but we don't do it for now as it would
require a new check name like misaligned-pointer-use, which is probably not
necessary. *RFC: Enforcing pointer type alignment in Clang* is not well documented,
but this patch does not intend to change the that.

Technically builtin memset functions can be checked for -fsanitize=alignment as
well, but it does not seem too useful.
2023-10-09 23:02:07 -07:00
ChiaHungDuan
24b0c43c99
Reapply "[scudo] Make local cache be agnostic to the type of node in … (#68633)
…f… (#68626)

This reverts commit 8dd9615dfbd148993964ea6f2de6c6a94f49660c.

1. Fixed the ambiguous aliasing
2. Fixed the type conversion warning
2023-10-09 15:17:42 -07:00
nicole mazzuca
bc34a83380
[ASan][Windows] Fix rip-relative instruction replacement (#68432)
The old code incorrectly checked what relative offsets were allowed.

The correct check is that the offset from the target to the instruction
pointer should be within $[-2^{31}, 2^{31})$; however, the check that
was originally written was that the offset was within $[0, 2^{31})$.
Negative offsets are certainly allowable (as long as they fit in 32
bits), and this change fixes that.
2023-10-09 14:53:07 -07:00
Roy Sundahl
07d2e90f28
Remove LLDB introspection entrypoints from the shim (#68450)
Rather than forwarding the LLDB entrypoints into asan_abi stable ABI,
leave them unimplemented for now. Doing so allows the shim and asan_abi
to be solely constrained to the entrypoints expected by the
instrumentation. We will take up a model for other stable ABIs (tsan,
ubsan, common, etc.) at a later date after choosing an inter-sanitizer
stable abi pattern after discussion and RFC. This commit modifies
https://reviews.llvm.org/D159545 by simply eliminating them from the
shim entirely.

rdar://115974403
2023-10-09 14:32:29 -07:00
ChiaHungDuan
8dd9615dfb
Revert "[scudo] Make local cache be agnostic to the type of node in f… (#68626)
…reelist (#67379)"

This reverts commit b9c6737ba7307308ecb6ec4cecc4c07e48e7c141.
2023-10-09 13:54:27 -07:00
Leonard Chan
37432c154f Revert "[compiler-rt] Allow Fuchsia to use 64-bit allocator for RISCV (#68343)"
This reverts commit a4d51e5bf0513eef77ec4c00aaae329ab9c20dd4.

Reverting since this breaks the lsan-test on fuchsia riscv builders. I
had adjusted settings for the 64-bit allocator for asan, but forgot
about standalone lsan and need to do that also.
2023-10-09 20:21:05 +00:00
ChiaHungDuan
b9c6737ba7
[scudo] Make local cache be agnostic to the type of node in freelist (#67379)
This change moves the `TransferBatch` and `BatchGroup` out of
SizeClassAllocatorLocalCache. It allows us that the node in freelist can
store more blocks instead of depending on the number of blocks cached.

That means we will be able to store more blocks in each node of freelist
and therefore reduce the memory used by BatchClass (with little
performance overhead). Note that we haven't enabled that in this patch.
This is the first step of this transition.
2023-10-09 13:11:55 -07:00
Haowei Wu
531233d4b0 Revert "add support for riscv64"
This reverts commit cd0a8245b0feb951569eb3d396a1ff629daeb55c, which
breaks the build of compiler-rt for riscv64.
2023-10-06 14:56:16 -07:00
ChiaHungDuan
b53ff43d36
[scudo] Improve the message of region exhaustion (#68444)
In this CL, we move the printing of allocator stats from primary.h to
combined.h. This will also dump the secondary stats and reduce the log
spam when an OOM happens

Also change the symbol `F` to `E` to indicate region pages exhausted. It
means the region can't map more pages for blocks but it may still have
free blocks to allocate. `F` may hint the failure of fatel error in the
region. Also update the related comments.
2023-10-07 05:31:33 +08:00
AdityaK
ce8ed00087 Revert Wframe-larger-than to 530
I missed reverting this change committed in cd0a8245b0feb951569eb3d396a1ff629daeb55c.
2023-10-06 13:51:51 -07:00
Alex Fan
cd0a8245b0 add support for riscv64
Implements for sv39 and sv48 VMA layout.

Userspace only has access to the bottom half of vma range. The top half is used by kernel.
There is no dedicated vsyscall or heap segment.
PIE program is allocated to start at TASK_SIZE/3*2. Maximum ASLR is ARCH_MMAP_RND_BITS_MAX+PAGE_SHIFT=24+12=36
Loader, vdso and other libraries are allocated below stack from the top.

Also change RestoreAddr to use 4 bits to accommodate MappingRiscv64_48

Reviewed by: MaskRay, dvyukov, asb, StephenFan, luismarques, jrtc27, hiraditya, vitalybuka

Differential Revision: https://reviews.llvm.org/D145214
2023-10-06 13:48:48 -07:00
PiJoules
a4d51e5bf0
[compiler-rt] Allow Fuchsia to use 64-bit allocator for RISCV (#68343)
The allocator should be tuned well enough for Fuchsia+RISCV.
2023-10-06 11:36:22 -07:00
MarcoFalke
fad0919c50
[NFC][compiler-rt] Fix typo in FuzzedDataProvider.h doc 2023-10-06 10:02:45 +02:00
ChiaHungDuan
ea2036e1e5
[scudo] Fix the use of ASSERT_CAPABILITY in TSD (#68273)
In getCache()/getQuarantineCache(), they return a reference to variable
guarded by a mutex. After #67776, thread-safey analysis checks if a
variable return by reference has the lock held. The ASSERT_CAPABILITY
only claims after calling that function, the lock will be held. But not
asserting that the lock is held *before* calling that function.

In the patch, we switch to use REQUIRES() and assertLocked() to mark the
code paths. Also remove the misused ASSERT_CAPABILITY.

Fixes #67795, #67796
2023-10-05 11:35:41 -07:00
Martin Storsjö
7c5e4e5fa3
Reapply [compiler-rt] Check for and use -lunwind when linking with -nodefaultlibs (#66584)
If libc++ is available and should be used as the ubsan C++ ABI library,
the check for libc++ might fail if libc++ is a static library, as the
-nodefaultlibs flag inhibits a potential compiler default -lunwind.

Just like the -nodefaultlibs configuration tests for and manually adds a
bunch of compiler default libraries, look for -lunwind too.

This is a reland of #65912.
2023-10-05 11:41:11 +03:00
Xi Ruoyao
0cf0bc7b45
[compiler-rt] Don't redefine LLVM_COMMON_CMAKE_UTILS if it's defined (#66761)
If we are building compiler-rt inside llvm-x.y.z.src directory, we
should not redefine LLVM_COMMON_CMAKE_UTILS.
2023-10-04 14:05:48 +02:00
Pavel Iliin
b04fe222d2
[AArch64][FMV] Add rcpc3 support, introduce bits for features extensi… (#68104)
…on and initialization.

The patch implements FEAT_LRCPC3 support (Load-Acquire RCpc instructions
version 3) in Function Multi Versioning. To maintain compatibility while
features list grows extension bit FEAT_EXT and initialization bit
FEAT_INIT are reserved.
2023-10-03 22:52:01 +01:00
Zequan Wu
3c34245c47
[Profile] Use upper 32 bits of profile version for profile variants. (#67695)
Currently all upper 8 bits are reserved for different profile variants.
We need more bits for new mods in the future.
Context:
https://discourse.llvm.org/t/how-to-add-a-new-mode-to-llvm-raw-profile-version/73688
2023-10-03 10:15:22 -04:00
ChiaHungDuan
ce00dde80e
[scudo] Mark page status in getStats in secondary (#67588)
Cache entry marked with [R] indicates that the pages have been released
by releaseToOS().
2023-10-03 06:13:32 +08:00
Alexandre Ganea
d58fb40670 [compiler-rt][asan] Silence warning
This would silence:
```
[2003/2029] Generating ASAN_NOINST_TEST_OBJECTS.asan_noinst_test.cpp.x86_64-inline.o
In file included from C:/git/llvm-project/compiler-rt/lib/asan/tests/asan_noinst_test.cpp:24:
In file included from C:/git/llvm-project/compiler-rt/lib/asan\asan_allocator.h:20:
In file included from C:/git/llvm-project/compiler-rt/lib\sanitizer_common/sanitizer_allocator.h:74:
C:/git/llvm-project/compiler-rt/lib\sanitizer_common\sanitizer_allocator_primary64.h:639:54: warning: 'static_assert' with no message is a C++17 extension [-Wc++17-extensions]
  639 |   static_assert(kRegionSize >= SizeClassMap::kMaxSize);
      |                                                      ^
      |                                                      , ""
1 warning generated.
```
2023-10-02 12:29:29 -04:00