19290 Commits

Author SHA1 Message Date
Sander de Smalen
5a0d73b1da
[compiler-rt][AArch64] NFCI: Simplify __arm_get_current_vg. (#119210)
This patch simplifies the code in two different ways:
* When SVE is available, return `cntd` directly to avoid the need for
bitfield insert.
* When SME is available, check the PSTATE.SM bit of `SVCR` directly
rather than calling `__arm_sme_state`.
2024-12-10 16:35:06 +00:00
ChiaHungDuan
aac000a01b
[scudo] Clean the TODO in list.h (#119323)
* Finished the type and size verification
* Remove the TODO for checking if array size can be fit into LinkTy
because if there's a truncation happens, other DCHECK like offset
checking will catch the failure. In addition, it's supposed to be a rare
case.
2024-12-09 20:39:18 -08:00
ChiaHungDuan
2c0b8b10dd
[scudo] Group type traits into a single header (NFC) (#118888) 2024-12-09 20:34:16 -08:00
Aaron Puchert
f5f965058a
Move interceptors for libresolv functions to MSan (#119071)
The functions are not relevant for most sanitizers and only required for
MSan to see which regions have been written to. This eliminates a link
dependency for all other sanitizers and fixes #59007: while `-lresolv`
had been added for the static runtime in 6dce56b2a308, it wasn't added
to the shared runtimes.

Instead of just moving the interceptors, we adapt them to MSan
conventions:
* We don't skip intercepting when `msan_init_is_running` is true, but
directly call ENSURE_MSAN_INITED() like most other interceptors. It
seems unlikely that these functions are called during initialization.
* We don't unpoison `errno`, because none of the functions is specified
to use it.
2024-12-09 22:03:03 +01:00
bernhardu
bf6f1ca236
[win/asan] GetInstructionSize: Make F6 C1 XX a generic entry. (#118144) 2024-12-09 18:15:24 +01:00
bernhardu
213c90d3c1
[win/asan] GetInstructionSize: Fix 41 81 7c ... to return 9. (#117828)
Trying to populate the recently added test for GetInstructionSize I
stumbled over this.
gdb and bddisasm have the opinion this instruction is 9 bytes.
Also lldb shows this:
```
(lldb) disassemble --bytes --start-address 0x0000555555556004 --end-address 0x0000555555556024
    0x555555556004: 41 81 7b 73 74 75 76 77     cmpl   $0x77767574, 0x73(%r11)   ; imm = 0x77767574 
    0x55555555600c: 41 81 7c 73 74 75 76 77 78  cmpl   $0x78777675, 0x74(%r11,%rsi,2) ; imm = 0x78777675 
    0x555555556015: 41 81 7d 73 74 75 76 77     cmpl   $0x77767574, 0x73(%r13)   ; imm = 0x77767574 
    0x55555555601d: 00 00                       addb   %al, (%rax)
```

There is also a handy tool in llvm to directly feed in the byte sequence
- `41 81 7c` also uses 9 bytes here:
```
$ echo -n -e "0x41, 0x81, 0x7b, 0x73, 0x74, 0x75, 0x76, 0x77, 0x90" | ./llvm/build/bin/llvm-mc --disassemble --show-encoding
        .text
        cmpl    $2004252020, 115(%r11)          # encoding: [0x41,0x81,0x7b,0x73,0x74,0x75,0x76,0x77]
                                        # imm = 0x77767574
        nop                                     # encoding: [0x90]
$ echo -n -e "0x41, 0x81, 0x7c, 0x73, 0x74, 0x75, 0x76, 0x77, 0x78, 0x90" | ./llvm/build/bin/llvm-mc --disassemble --show-encoding
        .text
        cmpl    $2021095029, 116(%r11,%rsi,2)   # encoding: [0x41,0x81,0x7c,0x73,0x74,0x75,0x76,0x77,0x78]
                                        # imm = 0x78777675
        nop                                     # encoding: [0x90]
```
2024-12-09 18:14:55 +01:00
Sander de Smalen
bbd99d903e
[compiler-rt][AArch64] NFCI: Remove sme-abi-vg.c (#119193)
Given that FMV support is required for the SME builtins to be built, the
FMV constructor as defined in:

  compiler-rt/lib/builtins/cpu_model/aarch64.c

already initialises the feature bits, so there's no need to create
another one.
2024-12-09 11:25:30 +00:00
Nikita Popov
fbbea8929f
[profile] Perform pointer arithmetic in uintptr_t (#118944)
Based on the feedback from #118782, this switches most of the pointer
arithmetic in __llvm_profile_merge_from_buffer to work on uintptr_t
instead of const char *, only casting back to a pointer when performing
actual accesses.

This ensures that all the arithmetic is performed without any
assumptions about pointer overflow.
2024-12-09 12:16:37 +01:00
David CARLIER
6b93a1ff82
[compiler-rt] fix __sanitizer::struct_sock_fprog_sz availability (#118762) 2024-12-09 06:36:08 +00:00
Lang Hames
f2d18a4d00 Reapply "[ORC] Introduce LazyReexportsManager, ... (#118923)" with fixes.
This re-applies 570ecdcf8b4, which was reverted in 74e8a37ff32 due to bot
failures. This commit renames sysv_resolve.cpp to resolve.cpp, which was the
cause of the config errors.
2024-12-09 03:22:51 +00:00
Lang Hames
f6c51ea84a [ORC-RT] Fix unit tests on Linux.
The unit tests may transiently depend on __orc_rt_log_error, which is usually
provided by an alias when loading the runtime through the JIT. The unit tests
statically link the runtime, so this patch provides a fixed definition.
2024-12-09 13:41:24 +11:00
Lang Hames
74e8a37ff3 Revert "Reapply "[ORC] Introduce LazyReexportsManager, … (#118923)" with fixes"
This reverts commit 41652c6c92958a87b8505b9b1e6f008856e392ac while I investigate
more bot failures.
2024-12-09 12:38:59 +11:00
Lang Hames
41652c6c92 Reapply "[ORC] Introduce LazyReexportsManager, … (#118923)" with fixes
This reapplies 570ecdcf8b4, which was reverted in 6073dd923b8 due to bot
failures.

The test failures on Linux were fixed by:
1. Removing an overly restrictive assertion (query dependence on a symbol no
longer implies a MaterializingInfo for that symbol)
2. Adding reentry and resolver files to the ORC runtime CMakeLists.txt for
Linux.
3. Adding the __orc_rt_reentry -> __orc_rt_sysv_reentry alias to ELFNixPlatform.
2024-12-09 12:08:07 +11:00
David CARLIER
2ab687e205
[compiler-rt][rtsan] fdopen/freopen(64) support. (#119100) 2024-12-08 19:24:18 +00:00
Vitaly Buka
6dec33834d
[sanitizer] Fix few size types in memprof (#119114)
Fix type in a few related Min() calls.

Follow up to #116957.

Co-authored-by: Stefan Schulze Frielinghaus <stefansf@linux.ibm.com>
2024-12-07 21:02:22 -08:00
Stefan Schulze Frielinghaus
ce44640fe2
[sanitizer] Add type __sanitizer::ssize (#116957)
Since the sanitizer merge in commit r15-5164-gfa321004f3f628 of GCC
which entails LLVM commit 61a6439f35b6de28ff4aff4450d6fca970292fd5, GCCs
bootstrap is broken on s390 -m31. This is due to commit
ec68dc1ca4d967b599f1202855917d5ec9cae52f which introduces stricter type
checking which is why GCC bootstrap fails with

```
In file included from /gcc/src/libsanitizer/interception/interception.h:18,
                 from /gcc/src/libsanitizer/interception/interception_type_test.cpp:14:
/gcc/src/libsanitizer/interception/interception_type_test.cpp:30:61: error: static assertion failed
   30 | COMPILER_CHECK((__sanitizer::is_same<::SSIZE_T, ::ssize_t>::value));
      |                ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~^~~~~~
/gcc/src/libsanitizer/sanitizer_common/sanitizer_internal_defs.h:363:44: note: in definition of macro 'COMPILER_CHECK'
  363 | #define COMPILER_CHECK(pred) static_assert(pred, "")
      |                                            ^~~~
make[8]: *** [Makefile:469: interception_type_test.lo] Error 1
```

The culprit seems to be that we don't check for equality of type sizes
anymore but rather whether the types are indeed the same. On s390 -m31
we have that `sizeof(int)==sizeof(long)` holds which is why previously
the checks succeeded. They fail now because

```
size_t      => unsigned long
ssize_t     => long
ptrdiff_t   => int
::SSIZE_T   => __sanitizer::sptr => int
::PTRDIFF_T => __sanitizer::sptr => int
```

This is fixed by mapping `SSIZE_T` to `long` in the end.

```
#if defined(__s390__) && !defined(__s390x__)
typedef long ssize;
#else
typedef sptr ssize;
#endif

#define SSIZE_T __sanitizer::ssize
```
2024-12-07 20:41:53 -08:00
Stefan Schulze Frielinghaus
9a156f6b2b [sanitizer] Replace uptr by usize/SIZE_T in interfaces
For some targets uptr is mapped to unsigned int and size_t to unsigned
long and sizeof(int)==sizeof(long) holds.  Still, these are distinct
types and type checking may fail.  Therefore, replace uptr by
usize/SIZE_T wherever a size_t is expected.

Part of #116957
2024-12-07 20:20:27 -08:00
Chris Apple
4bdac0851f
[rtsan] Warn if instrumented rtsan library opened via dlopen and interceptors are not working (#119029) 2024-12-07 07:02:04 -08:00
Lang Hames
6073dd923b Revert "[ORC] Introduce LazyReexportsManager, JITLinkTrampolines, … (#118923)"
This reverts commit 570ecdcf8b44aec853ce381a5f6b77222b041afa while I investigate
bot failures, e.g. https://lab.llvm.org/buildbot/#/builders/17/builds/4446.
2024-12-07 22:15:27 +11:00
Lang Hames
570ecdcf8b
[ORC] Introduce LazyReexportsManager, JITLinkTrampolines, ORC-RT base… (#118923)
…d reentry.

These utilities provide new, more generic and easier to use support for
lazy compilation in ORC.

LazyReexportsManager is an alternative to LazyCallThroughManager. It
takes requests for lazy re-entry points in the form of an alias map:
lazy-reexports = {
  ( <entry point symbol #1>, <implementation symbol #1> ),
  ( <entry point symbol #2>, <implementation symbol #2> ),
  ...
  ( <entry point symbol #n>, <implementation symbol #n> )
}

LazyReexportsManager then:
1. binds the entry points to the implementation names in an internal
table.
2. creates a JIT re-entry trampoline for each entry point.
3. creates a redirectable symbol for each of the entry point name and
binds redirectable symbol to the corresponding reentry trampoline.

When an entry point symbol is first called at runtime (which may be on
any thread of the JIT'd program) it will re-enter the JIT via the
trampoline and trigger a lookup for the implementation symbol stored in
LazyReexportsManager's internal table. When the lookup completes the
entry point symbol will be updated (via the RedirectableSymbolManager)
to point at the implementation symbol, and execution will proceed to the
implementation symbol.

Actual construction of the re-entry trampolines and redirectable symbols
is delegated to an EmitTrampolines functor and the
RedirectableSymbolsManager respectively.

JITLinkReentryTrampolines.h provides a JITLink-based implementation of
the EmitTrampolines functor. (AArch64 only in this patch, but other
architectures will be added in the near future).

Register state save and reentry functionality is added to the ORC
runtime in the __orc_rt_sysv_resolve and __orc_rt_resolve_implementation
functions (the latter is generic, the former will need custom
implementations for each ABI and architecture to be supported, however
this should be much less effort than the existing OrcABISupport
approach, since the ORC runtime allows this code to be written as native
assembly).

The resulting system:
1. Works equally well for in-process and out-of-process JIT'd code.
2. Requires less boilerplate to set up.

Given an ObjectLinkingLayer and PlatformJD (JITDylib containing the ORC
runtime), setup is just:

```c++
auto RSMgr = JITLinkRedirectableSymbolManager::Create(OLL);
if (!RSMgr)
  return RSMgr.takeError();

auto LRMgr = createJITLinkLazyReexportsManager(OLL, **RSMgr, PlatformJD);
if (!LRMgr)
  return LRMgr.takeError();
```

after which lazy reexports can be introduced with:

```c++
JD.define(lazyReexports(LRMgr, <alias map>));
```

LazyObectLinkingLayer is updated to use this new method, but the LLVM-IR
level CompileOnDemandLayer will continue to use LazyCallThroughManager
and OrcABISupport until the new system supports a wider range of
architectures and ABIs.

The llvm-jitlink utility's -lazy option now uses the new scheme. Since
it depends on the ORC runtime, the lazy-link.ll testcase and associated
helpers are moved to the ORC runtime.
2024-12-07 21:08:39 +11:00
Ellis Hoag
2e33ed9ecc
[memprof] Use -memprof-runtime-default-options to set options during compile time (#118874)
Add the `__memprof_default_options_str` variable, initialized via the
`-memprof-runtime-default-options` LLVM flag, to hold the default options string
for memprof. This allows us to set these options during compile time in
the clang invocation.

Also update the docs to describe the various ways to set these options.
2024-12-06 09:22:16 -08:00
Nikita Popov
3eed8479a8
[profile] Fix bounds checks in profile merging (#118782)
These bounds checks work on the result of the pointer addition -- but
the pointer addition already asserts that no overflow may occur, so the
checks are optimized away after #118472. Avoid this by performing the
addition in a way that permits overflow.
2024-12-06 10:09:30 +01:00
bernhardu
055f1a77f6
[win/asan] Avoid warnings in interception_win.cpp. (#118143)
warning: format specifies type 'void *' but the argument has type 'uptr'
(aka 'unsigned long long') [-Wformat] (observed at x86_64, in
AllocateTrampolineRegion)

warning: format specifies type 'char *' but the argument has type
'RVAPtr<char>' [-Wformat] (observed at x86_64, in
InternalGetProcAddress)
2024-12-06 09:51:57 +01:00
Vitaly Buka
6f21401ae9
Remove fixme about BFD and Android
Follow up to #118858
2024-12-05 13:23:50 -08:00
Vitaly Buka
0550480fe6
Disable test broken by #117624 (#118858)
The test fails after #117624
https://lab.llvm.org/buildbot/#/builders/186/builds/4581
2024-12-05 12:33:50 -08:00
David CARLIER
97fd435eea
[rtsan] intercept accept4 syscall. (#117278) 2024-12-05 07:37:26 -08:00
Chris Apple
af4ae12780
[rtsan] Add fork/execve interceptors (#117198) 2024-12-04 16:38:37 -08:00
ChiaHungDuan
9c5217c4ed
[scudo] Use internal list to manage the LRU cache (#117946) 2024-12-04 11:31:41 -08:00
bernhardu
b8d857efac
[win/asan] Populate test for function GetInstructionSize. (#118204)
This puts the content of GetInstructionSize into a test.
There are 5 cases missing, which I have already or would like to propose
a fix later.
2024-12-04 18:47:13 +01:00
Mészáros Gergely
bba2507c19
[compiler-rt][MSVC][CMake] Wrap Linker flags for ICX (#118496)
RFC:
https://discourse.llvm.org/t/rfc-cmake-linker-flags-need-wl-equivalent-for-intel-c-icx-on-windows/82446

My previous pass missed some flags because I used
`-Werror=unknown-argument`, but `/D`, `/I` and `/O` are accepted by
clang (even when only linking), but mean different things than intended
for `link.exe`.
2024-12-04 10:09:29 +01:00
ronryvchin
ff281f7d37
[PGO] Add option to always instrumenting loop entries (#116789)
This patch extends the PGO infrastructure with an option to prefer the
instrumentation of loop entry blocks.
This option is a generalization of
19fb5b467b,
and helps to cover cases where the loop exit is never executed.
An example where this can occur are event handling loops.

Note that change does NOT change the default behavior.
2024-12-04 07:56:46 +01:00
Phoebe Wang
a63931292b
[X86] Fix typo of gracemont (#118486) 2024-12-03 20:56:52 +08:00
Cyndy Ishida
877b934831
[CompilerRT] Remove sanitizer support for i386 watchsim (#117013)
This patch removes remaining support for i386 simulators, watch was the
only one left though.

resolves: rdar://102741146
2024-12-02 19:34:25 -08:00
Dimitry Andric
867a1d621d
[sanitizer_common] mark __elf_aux_vector as weak on FreeBSD (#118110)
At some point FreeBSD introduced libsys as a wrapper between syscalls
and libc, and then linking sanitized programs started failing with:

```text
  # c++ -fsanitize=address main.cc
  ld: error: undefined symbol: __elf_aux_vector
  >>> referenced by sanitizer_linux_libcdep.cpp:950 (/usr/src/contrib/llvm-project/compiler-rt/lib/sanitizer_common/sanitizer_linux_libcdep.cpp:950)
  >>>               sanitizer_linux_libcdep.o:(__sanitizer::ReExec()) in archive /usr/lib/clang/17/lib/freebsd/libclang_rt.asan-x86_64.a
  c++: error: linker command failed with exit code 1 (use -v to see invocation)
```

Mark `__elf_aux_vector` as weak in the internal sanitizer declaration,
so the linker will accept it at link time. The dynamic linker will then
take care of the symbol at run time.
2024-12-03 00:31:19 +01:00
Brian Cain
c906907d87
[hexagon][cmake] Disable ctx_profile (#117965)
Since #105495, we will build sanitizer_common when
COMPILER_RT_BUILD_CTX_PROFILE is set. But we have outstanding failures
when building sanitizer_common, so for now we'll disable ctx_profile
too.
2024-12-02 15:47:20 -06:00
Alexander Richardson
7545283194
[compiler-rt] Don't detect a versioned clang test compiler as GCC
I was trying to build compiler-rt with /usr/bin/clang-17 and the testsuite
failed due to the code in lit.common.cfg.py:
```
# GCC-ASan uses dynamic runtime by default (since config.bits is not set).
if config.compiler_id == "GNU":
    gcc_dir = os.path.dirname(config.clang)
    libasan_dir = os.path.join(gcc_dir, "..", "lib" + config.bits)
    push_dynamic_library_lookup_path(config, libasan_dir)
```

Fix this in two ways: First, if the test compiler matches the library
compiler, set COMPILER_RT_TEST_COMPILER_ID to CMAKE_C_COMPILER_ID. Second,
relax the regex detecting clang to allow any kind of suffix.

Reviewed By: compnerd

Pull Request: https://github.com/llvm/llvm-project/pull/117812
2024-12-02 11:49:52 -08:00
Alexander Richardson
d33dc14833
[compiler-rt] Allow running extendhfxf2_test without int128 support
We don't need 128-bit integers here, instead rewrite the fp_test.h helpers
to avoid the need for __int128. Also change the high argument for
compareResultF80() and F80FromRep80() to be uint16_t since values greater
than this do not make any sense. This should allow the compiler to detect
accidentally swapping the arguments.

Reviewed By: biabbas, alexander-shaposhnikov

Pull Request: https://github.com/llvm/llvm-project/pull/117818
2024-12-02 10:52:58 -08:00
Paul Osmialowski
fed07a0545
[compiler-rt][tests] Make this test case pass on AArch64 (#117628)
See also D92832 and GCC bug
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=80878
2024-12-02 16:41:53 +00:00
Chris Apple
eae30a240e
[rtsan] Add syscall interceptor (#118250)
This is a complex one - `syscall` is used when people want to bypass
libc and make the call directly

However, this call:
* Has a variable amount of arguments (up to 6, typically)
* Has arguments that can be any type, (think of whatever arguments go in
to the libc call, or see more details here
https://syscalls.mebeim.net/?table=x86/64/x64/latest)


I've tried to put in a couple tests to ensure we aren't mucking with the
underlying functionality and they seem to be working.
2024-12-02 06:29:54 -08:00
Phoebe Wang
3348b4688f
[X86][compiler-rt] Split CPU names even they have the same subtype (#118237)
Fixes: #118205
2024-12-02 18:51:19 +08:00
David Spickett
fec0eb4c3e
[compiler-rt] Move CODE_OWNERS.txt to Maintainers.txt (#118086)
To align with https://llvm.org/docs/DeveloperPolicy.html#maintainers

No format change, I just want each project to have a `Maintainers.*`
file so it is easy to find.
2024-12-02 09:13:28 +00:00
Chris Apple
4a074330c6
[rtsan] Intercept various file system functions (#118183)
Adds interceptors for
* chmod
* fchmod
* mkdir
* rmdir
* umask
2024-12-01 07:40:04 -08:00
Chris Apple
f28e071dc0
[rtsan] NFC: Fix style of some interceptors not using MAYBE (#118145)
There were a few interceptors that weren't using the newer MAYBE style -
fixed them up for uniform style.
2024-11-29 15:50:33 -08:00
bernhardu
a943922c0d
[win/asan] GetInstructionSize: Remove duplicate instruction FF 25 .... (#116894)
It appears already some lines above with this comment:
  "Cannot overwrite control-instruction. Return 0 to indicate failure.".

Replacing just the comment in the first appearance.

Found after creating the test in #113085.
2024-11-29 09:17:37 +01:00
Min-Yih Hsu
96dd39c575
[XRay] Add __xray_default_options to specify build-time defined options (#117921)
Similar to `__asan_default_options`, users can specify default options
upon building the instrumented binaries by providing their own
definition of `__xray_default_options` which returns the option strings.

This is useful in cases where setting the `XRAY_OPTIONS` environment
variable might be difficult. Plus, it's a convenient way to populate
XRay options when you always want the instrumentation to be enabled.
2024-11-28 22:48:57 -08:00
Alexander Richardson
a4c8ef0f40
[compiler-rt] Fix detecting _Float16 support for secondary targets (#117813)
It turns out we were not passing -m32 to the check_c_source_compiles()
invocation since CMAKE_REQUIRE_FLAGS needs to be string separated list
and
we were passing a ;-separated CMake list which appears to be parsed by
CMake as 'ignore all arguments beyond the first'.
Fix this by transforming the list to a command line first.

With this change, Clang 17 no longer claims to support _Float16 for
i386.
2024-11-28 19:42:47 +01:00
Josh Stone
bc1e0c53a2
[profile] Make the binary-id-offset.c test more robust (#117647)
Using a `--section-start` address in the test was causing link errors on
some targets. Now it uses a linker script to move the note after `.bss`,
which should still have the kind of memory offset we're looking for.

This is a follow-up to #114907 to fix buildbot errors.
2024-11-27 00:06:30 -05:00
B I Mohammed Abbas
06d24da131
Fix extendhfxf2 test (#117665)
Fix changes in #113897

Co-authored-by: Alex Richardson <alexrichardson@google.com>
2024-11-26 15:27:53 -08:00
Chris Apple
3a8b28f698
[rtsan] Add ioctl interceptor (#117569) 2024-11-26 15:17:04 -08:00
Vitaly Buka
8ffe63fb55 [nfc][asan] Fix typo in comment 2024-11-26 14:30:26 -08:00