17436 Commits

Author SHA1 Message Date
Arseny Kapoulkine
d3440304b1
[Fuzzer] Update build.sh to fix build errors (#65496)
Switch from C++11 to C++14 as fuzzer requires std::chrono and stdlibc++
doesn't provide chrono literals when using -std=c++11.

Also remove 'u' from ar command to fix this warning: ar: `u' modifier
ignored since `D' is the default (see `U')
2023-09-07 16:38:28 -07:00
bipmis
370880cdcc [InstCombine] Fold icmp into phi beyond the same BB.
The icmp is being folded in phi only if they belong in the same BB.
This patch extends the same beyond the BB.
Have seen scenarios where this seems to be beneficial.

Differential Revision: https://reviews.llvm.org/D157740
2023-09-07 16:53:29 +01:00
Ying Yi
61d6154044 [llvm-cov] Fix the test of bnary-id-lookup.c after the commit cd8fe1dbc. 2023-09-06 16:44:19 +01:00
Fabio D'Urso
fdb29f7db5 [scudo] Rename AllocatorRingBuffer into scudo:ring_buffer
To maintain the convention of Scudo names starting with "scudo:",
which is used by some tooling to categorize memory usage.

Reviewed By: Chia-hungDuan

Differential Revision: https://reviews.llvm.org/D157102
2023-09-06 11:23:27 +02:00
Jie Fu
1438544e23 [DFSAN] Silence parameter 'va_labels' set but not used warning (NFC)
/data/llvm-project/compiler-rt/lib/dfsan/dfsan_custom.cpp:2546:37: error: parameter 'va_labels' set but not used [-Werror,-Wunused-but-set-parameter]
                       dfsan_label *va_labels, dfsan_label *ret_label,
                                    ^
1 error generated.
2023-09-06 09:28:43 +08:00
Tomasz Kuchta
8dbcf8eba7 [DFSAN] Add support for sscanf.
Reviewed By: browneee

Differential Revision: https://reviews.llvm.org/D153775
2023-09-06 01:16:31 +00:00
Chia-hung Duan
4c676d5265 [scudo] Clean up decl of RSSLimit funtions (NFC)
Reviewed By: cferris

Differential Revision: https://reviews.llvm.org/D159389
2023-09-05 18:37:15 +00:00
Petr Hosek
360d67730a
[compiler-rt] Link atomic against builtins (#65239)
The atomic shared library needs to be linked against builtins. The
`add_compiler_rt_runtime` call already has `DEP builtins` but that only
ensures that the `builtins` target is built before `clang_rt.atomic` but
doesn't link against `clang_rt.builtins`, to do so we need to use
`LINK_LIBS clang_rt.builtins`.
2023-09-03 22:45:11 -07:00
Jessica Clarke
4bb2416d42 [builtins][AArch64] Implement _sync out-of-line atomics
Whilst Clang does not use these, recent GCC does, and so on systems such
as FreeBSD that wish to use compiler-rt as the system runtime library
but also wish to support building programs with GCC these interfaces are
needed.

This is a light adaptation of the code committed to GCC by Sebastian Pop
<spop@amazon.com>, relicensed with permission for use in compiler-rt.

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

Reviewed By: sebpop, MaskRay

Differential Revision: https://reviews.llvm.org/D158536
2023-09-04 01:46:02 +01:00
Ulrich Weigand
208f9a2afc [msan][s390x] Fix long double interceptors
s390x is one of the architectures where the "long double" type was changed
from a 64-bit IEEE to a 128-bit IEEE type back in the glibc 2.4 days.
This means that glibc still exports two versions of the long double functions
(those that already existed back then), and we have to intercept the correct
version. There is already an existing define SANITIZER_NLDBL_VERSION that
indicates this situation, we simply have to respect it when intercepting
strtold and wcstold.

In addition, on s390x a long double return value is passed in memory via
implicit reference. This means the interceptor for functions returning
long double has to unpoison that memory slot, or else we will get
false-positive uninitialized memory reference warnings when the caller
accesses that return value - similar to what is already done in the
mallinfo interceptor. Create a variant macro INTERCEPTOR_STRTO_SRET and
use it on s390x.

Reviewed By: MaskRay

Differential Revision: https://reviews.llvm.org/D159378
2023-09-02 12:36:53 +02:00
Fangrui Song
678e3ee123 [lldb] Fix duplicate word typos; NFC
Those fixes were taken from https://reviews.llvm.org/D137338
2023-09-01 21:32:24 -07:00
Rainer Orth
d39a9e3b4d [Driver] Support GNU ld on Solaris
This patch supports GNU ld on Solaris in addition to Solaris ld, the
default.

- Linker selection is dynamic: one can switch between Solaris ld and GNU ld
  at runtime, with the default selectable with `-DCLANG_DEFAULT_LINKER`.

- Testcases have been adjusted to test both variants in case there are
  differences.

- The `compiler-rt/cmake/config-ix.cmake` and
  `llvm/cmake/modules/AddLLVM.cmake` changes to restrict the tests to
  Solaris ld are necessary because GNU accepts unknown `-z` options, but
  warns every time they are used, creating a lot of noise.  Since there
  seems to be no way to check for those warnings in
  `llvm_check_compiler_linker_flag` or `llvm_check_compiler_linker_flag`, I
  restrict the cmake tests to Solaris ld in the first place.

- The changes to `clang/test/Driver/hip-link-bundle-archive.hip` and
  `flang/test/Driver/linker-flags.f90` are required when LLVM is built with
  `-DCLANG_DEFAULT_LINKER=gld` on Solaris: `MSVC.cpp`
  `visualstudio::Linker::ConstructJob` ultimately calls
  `GetProgramPath("gld")`, resulting in a search for `gld`, which exists in
  `/usr/bin/gld` on Solaris.  With `-fuse-ld=`, this doesn't happen and the
  expected `link` is returned.

- `compiler-rt/test/asan/TestCases/global-location-nodebug.cpp` needs to
  enforce the Solaris ld, otherwise the test would `XPASS` with GNU ld
  which has the `-S` semantics expected by the test.

Tested on `amd64-pc-solaris2.11` and `sparcv9-sun-solaris2.11` with both
`-DCLANG_DEFAULT_LINKER=gld` and the default, and `x86_64-pc-linux-gnu`.
No regressions in either case.

Differential Revision: https://reviews.llvm.org/D85309
2023-09-01 21:42:05 +02:00
Martin Storsjö
1f9eff100c [compiler-rt] Rename the now lone i386/chkstk2.S to i386/chkstk.S
This step was omitted from the previous commit,
885d7b759b5c166c07c07f4c58c6e0ba110fb0c2, for clarity.
2023-09-01 19:43:56 +03:00
Martin Storsjö
885d7b759b [compiler-rt] [builtins] Remove unused/misnamed x86 chkstk functions
For both MSVC and MinGW targets, the compiler generates calls to
functions for probing the stack, in functions that allocate a larger
amount of stack space.

The exact behaviour of these functions differ per architecture (some
decrement the stack, some actually decrement the stack pointer,
some only probe the stack). In MSVC mode, the compiler always
generates calls to a symbol named "__chkstk". In MinGW mode, the
symbol is named "__alloca" on i386 and "___chkstk_ms" on x86_64,
but the functions behave exactly the same as their MSVC counterparts
despite the differing names.

(On i386, these names are the raw symbol names - if considering
a C level function name with the extra implicit leading underscore,
they would be called "_chkstk" and "_alloca".)

Remove the misleading duplicate and unused functions. These were
added in fbfed869106cc9c9cad7538db5e65bcd24f4d92e /
c27de5b2790b65394c50ba13fab319995dbf5956 (adding "___chkstk_ms"
for both architectures, even if that symbol name only was used
on x86_64) and 40eb83ba56ba9c1d2e6de44deacf889ac0143cf7
(adding "__alloca" and "___chkstk", even if the former only was
used on i386, and the latter seeming like a misspelled form of
the MSVC function, with three underscores instead of two).

The x86_64 "___chkstk" was doubly surprising as that function had
the same behaviour as the function used on i386, while the
"__chkstk" that MSVC emitted calls to should behave exactly like
the preexisting "___chkstk_ms".

Remove the unused functions, and rename the misspelled MSVC-like
symbols to the correct name that MSVC mode actually uses.

Note that these files aren't assembled at all when building
compiler-rt builtins in MSVC mode, as they are expected to be
provided by MSVC libraries when building code in MSVC mode.

Differential Revision: https://reviews.llvm.org/D159139
2023-09-01 19:43:50 +03:00
Vitaly Buka
469c3e77cb [test][fuzzer] Deflake fork_corpus_groups.test 2023-09-01 01:11:58 -07:00
Vitaly Buka
99e5f6066e [test][fuzzer] Deflake fork.test 2023-09-01 00:57:35 -07:00
Artem Dergachev
0a3519d5a2 [LSan] Mark create_thread_leak.cpp as UNSUPPORTED: darwin.
It started to fail in a flaky manner a few days ago on GreenDragon buildbots
(i.e. x86_64-darwin). I didn't track down the root cause but LSan isn't
actually supported on darwin anyway, so UNSUPPORTED seems appropriate.

Prior art: 3ff080b5.
2023-08-31 16:41:35 -07:00
Leonard Chan
7ce67d3310 [scudo][tests] Store the allocator instance in a global rather than posix_memalign it
The combined scudo allocator object is over 4MB in size which gets created via
the posix_memalign on every test run. If the tests are sanitized with asan,
then the asan allocator will need to mmap this large object every single time a
test is run. Depending on where this is mapped, we might not be able to find a
large enough contiguous space for scudo's primary allocator to reserve an arena.
Such a case is more likely to occur on 39-bit vma for RISCV where the arena size
is roughly a quarter of the whole address space and fragmentation can be a big issue.

This helps reduce fragmentation by instead placing the allocator instance in a
global storage rather than doing an anonymous mmap.

Differential Revision: https://reviews.llvm.org/D158767
2023-08-31 22:27:14 +00:00
Karl-Johan Karlsson
831b509d5f [builtins] Fix signed integer overflows in fp_fixint_impl.inc
When compiling the builtins with the undefined behavior sanitizer and running
testcases you end up with the following warning:

UBSan: fp_fixint_impl.inc:39:42: left shift of 8388608 by 40 places cannot be represented in type 'fixint_t' (aka 'long long')
UBSan: fp_fixint_impl.inc:39:17: signed integer overflow: -1 * -9223372036854775808 cannot be represented in type 'fixint_t' (aka 'long long')

This can be avoided by doing the shift and the multiplication in a matching
unsigned variant of the type.

The added test only trigger the intended signed overflow case when the builtins
are built with -D__SOFTFP__.

This was found in an out of tree target.

Reviewed By: MaskRay

Differential Revision: https://reviews.llvm.org/D159069
2023-08-31 10:08:15 +02:00
Leonard Chan
1abcf58402 [lsan][Fuchsia] Fix bounds checking for thread_local allocator cache when scanning TLS regions
When scanning over TLS regions, we attempt to check if one of the regions is
one of the thread_local allocator caches which would be located in one of the
TLS blocks pointer to by the DTV. This is to prevent marking a pointer that was
allocated by the primary allocator (from a thread_local cache) as reachable. The
check is a simple bounds check to see if the allocator cache is within the
bounds of one of the TLS block we're iterating over, but it looks like the check
for the end of the cache is slightly incorrect.

Differential Revision: https://reviews.llvm.org/D156015
2023-08-30 20:49:21 +00:00
Christopher Ferris
c8bf93dba0 [scudo] Remove RSS checking code.
The RSS code is not very useful and can be replicated by using
ulimit. Remove it and remove the options associated with it.

Reviewed By: Chia-hungDuan

Differential Revision: https://reviews.llvm.org/D159155
2023-08-30 12:35:14 -07:00
Ian Anderson
680da4b5d7 [Headers][Modules] Make separate headers for the stdarg.h and stddef.h pieces so that they can be modularized
stdarg.h and stddef.h have to be textual headers in their upcoming modules to support their `__needs_xxx` macros. That means that they won't get precompiled into their modules' pcm, and instead their declarations will go into every other pcm that uses them. For now that's ok since the type merger can handle the declarations in these headers, but it's suboptimal at best. Make separate headers for all of the pieces so that they can be properly modularized.

Reviewed By: aaron.ballman, ChuanqiXu

Differential Revision: https://reviews.llvm.org/D158709
2023-08-30 11:41:12 -07:00
Alex Brachet
445978ee8c [compiler-rt] Use just built libatomic if available
Use libclang_rt.atomic.so instead of the libatomic installed
on the system if it is available.

Differential Revision: https://reviews.llvm.org/D151680
2023-08-29 21:38:56 +00:00
Leonard Chan
21d7287269 Revert "[sanitizer] Do not mmap FlagParser::flags_"
Reverting since this caused Linux/odd_stack_size.cpp to fail on a bunch
of builders.

This reverts commit 34e2f4f2e28a464b127d878979efbc87bc148db5.
2023-08-29 20:00:24 +00:00
Leonard Chan
34e2f4f2e2 [sanitizer] Do not mmap FlagParser::flags_
Instead, make it a static array that's part of the FlagParser. The advantage
this has is helping reduce fragmentation from needing to anonymously mmap
this array via the LowLevelAllocator. This will instead place the array on
the stack. Functionally, the only difference is that the array will not be
zero-initialized, but all used elements are explicitly initialized via the
flag handlers.

Differential Revision: https://reviews.llvm.org/D158780
2023-08-29 19:08:16 +00:00
Shoaib Meenai
cd8bba941f Revert "[compiler-rt] Improve defaults for Android"
This reverts commit cf403c10fba72ddc6a083a0e1603974d0749c6b3.

This is breaking Android sanitizer buildbots (see the discussion on
https://reviews.llvm.org/D158793).
2023-08-29 10:37:49 -07:00
V Donaldson
b291182b3f [compiler-rt][BF16] "bfloat -> float -> bfloat" round-trip conversions
Invoking compiler-rt function __truncsfbf2 to convert a zero 32-bit float
0x00000000 to a 16-bit bfloat value currently generates the denormal value
0x0040, rather than value 0x0000. Negative zero 0x80000000 is converted
to denormal 0x8040 rather than 0x8000.

This behavior is seen in flang code under development (not yet integrated)
that converts bfloat/REAL(KIND=3) argument values to float/REAL(KIND=4)
values and then converts those values back to bfloat/REAL(KIND=3). There
are other instances of the problem. A round-trip type conversion using
__truncsfbf2 of a denormal generates a different denormal, and an sNaN
is converted to a qNaN.

The problem is addressed in generic conversion function fp_trunc_impl.inc
by removing trailing 0 significand bits when the source and destination
type formats are identical except for the significand size. This condition
is met only for float -> bfloat conversions.

Round-trip conversions for at least some other type pairs have the same
problem. A solution in those cases would need to account for exponent
size differences. Those cases are not relevant to flang compilations
and are not addressed here. A broader solution might subsume this fix,
or this fix might remain useful as is.

There are no existing tests of bfloat conversion functionality in the
compiler-rt test directory. Tests for other conversions use a common
infrastructure that does not currently have support for bfloat conversions.
This patch does not attempt to add that infrastructure for this new case.
CodeGen test bfloat.ll checks bfloat adds and other operations that invoke
__truncsfbf2.
2023-08-29 09:59:23 -07:00
Brooks Davis
692344d873 [msan] Fix compilation on non-glibc
SANITIZER_GLIBC is always defined so should be tested with an if not an
ifdef.

Fixes: ad7e2501000d

Reviewed By: MaskRay

Differential Revision: https://reviews.llvm.org/D159041
2023-08-28 21:22:29 -07:00
Shoaib Meenai
dcafbd0c67 [compiler-rt] Remove explicit Android libatomic linking
The comments date back to NDK r10, which is ancient. libatomic isn't
always needed anymore, and even when it is, it's bundled into
compiler-rt in the NDK so we'll get it automatically. Remove the
unnecessary explicit links.

Reviewed By: srhines

Differential Revision: https://reviews.llvm.org/D158793
2023-08-28 17:34:48 -07:00
Shoaib Meenai
cf403c10fb [compiler-rt] Improve defaults for Android
Android has only used libc++ for a long time, and since NDK r23, it
also always uses compiler-rt and LLVM's libunwind (which is linked
statically). Reflect these defaults in compiler-rt's build, instead of
requiring the correct settings to always be externally specified.

Reviewed By: srhines

Differential Revision: https://reviews.llvm.org/D158792
2023-08-28 17:34:47 -07:00
Leonard Chan
afd170bdd9 [sanitizer] Consolidate some LowLevelAllocators to one
This removes and replaces usage of a few LowLevelAllocators with a single one
provided by sanitizer_common. Functionally, there should be no difference
between using different allocators vs the same one. This works really well
with D158783 which controls the size of each allocator mmap to significantly
reduce fragmentation.

This doesn't remove them all, mainly the ones used by asan and the flag parser.

Differential Revision: https://reviews.llvm.org/D158786
2023-08-28 23:12:37 +00:00
Leonard Chan
56006757a0 [sanitizer] Set the min size to allocate for the LowLevelAllocator to
65536 bytes

The LowLevelAllocator is a helper class used by many sanitizer internals
for anonymously mmaping stuff. The allocator (usually) maps one page at
a time, but this can lead to a lot of fragmentation if the allocator is
heavily used. The flag parser is an example of this where it needs to do
lots of string copying that need to exist for a variable length of time.

This adds a macro for specifying the number of pages the LowLevelAllocator
can make at a time, which locally I've found to significantly help reduce
fragmentation and help run the scudo allocator tests in an asan-instrumented
build on riscv Sv39. This is a static macro rather than a value that could
be provided via an env variable because flag parsing is one of the earliest
consumers of the LowLevelAllocator, so this should be set before its ever used.

Note this will mainly help instances of the LowLevelAllocator that are heavily
used, but instances of the LowLevelAllocator that do a small fixed number
of allocations won't benefit as much from this. This can be alleviated though
if we instead consolidate all of them to one single LowLevelAllocator (D158786).

Differential Revision: https://reviews.llvm.org/D158783
2023-08-28 23:05:08 +00:00
Chia-hung Duan
88852964ec [scudo] Add SCUDO_ENABLE_HOOKS to enable hooks at compilation time
Accessing the PLT entries of hooks can lead a certain amount of
performance overhead. This is observed on certain tasks which will do a
bunch of malloc/free and their throughputs are impacted by the null
check of hooks.

Also add SCUDO_ENABLE_HOOKS_TESTS to select if we want to run the hook
tests. On some platforms they may have different ways to run the
wrappers tests (end-to-end tests) and test the hooks along with the
wrappers tests may not be feasible. Provide an option to turn it ON/OFF.

By default, we only verify the hook behavior in the scudo standalone
tests if SCUDO_ENABLE_HOOKS is defined or COMPILER_RT_DEBUG is true.

Reviewed By: cferris, fabio-d

Differential Revision: https://reviews.llvm.org/D158784
2023-08-28 22:11:18 +00:00
Wu, Yingcong
9c0302a772 [fuzzer,CMake] Group fuzzer lit test into one check-fuzzer
For now check-fuzzer is just a cmake target that depends
on different check-fuzzer-xxx lit test targets. This causes
check-fuzzer get seperate lit test results like this:

```
********************
********************
Failed Tests (1):
  libFuzzer :: fuzzer-flags.test

Testing Time: 19.80s
  Unsupported      :   7
  Passed           : 128
  Expectedly Failed:   3
  Failed           :   1
make[3]: *** [projects/compiler-rt/test/fuzzer/CMakeFiles/check-fuzzer-default-x86_64.dir/build.make:71: projects/compiler-rt/test/fuzzer/CMakeFiles/check-fuzzer-default-x86_64] Error 1
make[2]: *** [CMakeFiles/Makefile2:36745: projects/compiler-rt/test/fuzzer/CMakeFiles/check-fuzzer-default-x86_64.dir/all] Error 2
make[2]: *** Waiting for unfinished jobs....
--

********************
********************
Failed Tests (1):
  libFuzzer :: fuzzer-flags.test

Testing Time: 24.33s
  Unsupported:  21
  Passed     : 117
  Failed     :   1
make[3]: *** [projects/compiler-rt/test/fuzzer/CMakeFiles/check-fuzzer-default-i386.dir/build.make:71: projects/compiler-rt/test/fuzzer/CMakeFiles/check-fuzzer-default-i386] Error 1
make[2]: *** [CMakeFiles/Makefile2:36697: projects/compiler-rt/test/fuzzer/CMakeFiles/check-fuzzer-default-i386.dir/all] Error 2
make[1]: *** [CMakeFiles/Makefile2:36608: projects/compiler-rt/test/fuzzer/CMakeFiles/check-fuzzer.dir/rule] Error 2
make: *** [Makefile:10719: check-fuzzer] Error 2
```

This patch replaces check-fuzzer-xxx lit test sub-targets with one big check-fuzzer lit test target, just like sanitizer_common test.

```
********************
********************
Failed Tests (2):
  libFuzzer :: fuzzer-flags.test
  libFuzzer :: fuzzer-flags.test

Testing Time: 25.10s
  Unsupported      :  28
  Passed           : 303
  Expectedly Failed:   3
  Failed           :   2
make[3]: *** [projects/compiler-rt/test/fuzzer/CMakeFiles/check-fuzzer.dir/build.make:71: projects/compiler-rt/test/fuzzer/CMakeFiles/check-fuzzer] Error 1
make[2]: *** [CMakeFiles/Makefile2:36618: projects/compiler-rt/test/fuzzer/CMakeFiles/check-fuzzer.dir/all] Error 2
make[1]: *** [CMakeFiles/Makefile2:36625: projects/compiler-rt/test/fuzzer/CMakeFiles/check-fuzzer.dir/rule] Error 2
make: *** [Makefile:10719: check-fuzzer] Error 2
```

Reviewed By: MaskRay

Differential Revision: https://reviews.llvm.org/D158717
2023-08-28 14:45:01 -07:00
Wu, Yingcong
ed5acb1425 [fuzzer,CMake] Add config name for fuzzer lit test
Add config name for fuzzer lit test, to make it easier to identify failures are with which config.

Before this change, same lit tests with different configs will share the same test name.
```
********************
Failed Tests (2):
  libFuzzer :: fuzzer-flags.test
  libFuzzer :: fuzzer-flags.test
```
Actually this is a failure of two lit tests(two configs of the same test).

With this change, the names will be different.
```
********************
Failed Tests (2):
  libFuzzer-i386-default-Linux ::fuzzer-flags.test
  libFuzzer-x86_64-default-Linux :: fuzzer-flags.test
```

Reviewed By: MaskRay, vitalybuka

Differential Revision: https://reviews.llvm.org/D158696
2023-08-28 14:39:45 -07:00
Martin Storsjö
277fc9475f [compiler-rt] [test] Adjust an XFAIL for strtoll_strict.c for MinGW targets
8033231240f223dc7c718d1d27ece2dbcc8057c6 made this test pass
in MinGW environments, even if it still is failing in MSVC
environments.
2023-08-28 23:40:22 +03:00
Zequan Wu
f52f8e817e [Profile] Allow online merging with debug info correlation.
When using debug info correlation, value profiling needs to be switched off.
So, we are only merging counter sections. In that case the existance of data
section is just used to provide an extra check in case of corrupted profile.

This patch performs counter merging by iterating the counter section by counter
size and add them together.

Reviewed By: ellis, MaskRay

Differential Revision: https://reviews.llvm.org/D157632
2023-08-28 16:35:41 -04:00
Vitaly Buka
cd591e02d4 Revert "Reland "[Profile] Allow online merging with debug info correlation.""
Breaks windows https://lab.llvm.org/buildbot/#/builders/127/builds/54239

This reverts commit d80992032fd0d7da70b2bd1a59066703c3c21fbb.
2023-08-28 13:01:25 -07:00
Vitaly Buka
dd3aa26fc8 Revert "[Fuzzer] SetThreadName implementation for Windows"
Fails with "The procedure entry point SetThreadDescription could not be located in the dynamic link library..."

This reverts commit cf76ddcbeb10be1f3eee5fa86dc41f9ca2435d50.
2023-08-28 12:27:00 -07:00
Vitaly Buka
151e33c768 [NFC][fuzzer] Cleanup SetThreadName after D156317 2023-08-28 10:59:39 -07:00
Vitaly Buka
45eb6026d9 [fuzzer] Try to fix windows build after D156317 2023-08-28 10:55:16 -07:00
Vitaly Buka
e0e8695a60 Revert "[fuzzer] Try to fix windows build after D156317"
Will not work, string::data() returns const char*;

This reverts commit d364597f8a479a4e223bc3194f5584f26b5aa7a5.
2023-08-28 10:50:51 -07:00
Vitaly Buka
d364597f8a [fuzzer] Try to fix windows build after D156317 2023-08-28 10:47:38 -07:00
Zequan Wu
d80992032f Reland "[Profile] Allow online merging with debug info correlation."
Original patch: D157632.

Fixed the issue when data is 0 by relaxing the condition.

Reviewed By: ellis

Differential Revision: https://reviews.llvm.org/D159000
2023-08-28 13:32:55 -04:00
David CARLIER
cf76ddcbeb [Fuzzer] SetThreadName implementation for Windows
Api available since Windows Server 2016/Windows 10 1607

Reviewers: vitalybuka

Reviewed-By: vitalybuka

Differential Revison: https://reviews.llvm.org/D156317
2023-08-28 13:14:47 +01:00
David CARLIER
435d4124f2 [sanitizer] enable getrandom/getentropy on solaris based systems.
Reviewers: vitalybuka

Reviewed-By: vitalybuka

Differential Revision: https://reviews.llvm.org/D156578
2023-08-28 13:12:07 +01:00
David CARLIER
c1ad5bac16 [sanitizer] Fix sanitizer procmap test for FreeBSD
the ParseUnixMemoryProfile makes sense only on platforms which truly support procfs

Reviewers: vitalybuka

Reviewed-By: vitalybuka

Differential Revision: https://reviews.llvm.org/D156628
2023-08-28 13:10:34 +01:00
Fangrui Song
ad7e250100 [sanitizer] Intercept glibc 2.38 __isoc23_* functions
`strtol("0b1", 0, 0)` can be (pre-C23) 0 or (C23) 1.
`sscanf("0b10", "%i", &x)` is similar. glibc 2.38 introduced
`__isoc23_strtol` and `__isoc23_scanf` family functions for binary
compatibility.

When `_ISOC2X_SOURCE` is defined (implied by `_GNU_SOURCE`) or
`__STDC_VERSION__ > 201710L`, `__GLIBC_USE_ISOC2X` is defined to 1 and
these `__isoc23_*` symbols are used.

Add `__isoc23_` versions for the following interceptors:

* sanitizer_common_interceptors.inc implements strtoimax/strtoumax.
  Remove incorrect FIXME about https://github.com/google/sanitizers/issues/321
* asan_interceptors.cpp implements just strtol and strtoll. The default
  `replace_str` mode checks `nptr` is readable and `endptr` is writable.
  atoi reuses the existing strtol interceptor.
* msan_interceptors.cpp implements strtol family functions and their
  `_l` versions. Tested by lib/msan/tests/msan_test.cpp
* sanitizer_common_interceptors.inc implements scanf family functions.

The strtol family functions are spreaded, which is not great, but the
patch (intended for release/17.x) does not attempt to address the issue.

Add symbols to lib/sanitizer_common/symbolizer/scripts/global_symbols.txt to
support both glibc pre-2.38 and 2.38.

When build bots migrate to glibc 2.38+, we will lose test coverage for
non-isoc23 versions since the existing C++ unittests imply `_GNU_SOURCE`.
Add test/sanitizer_common/TestCases/{strtol.c,scanf.c}.
They catch msan false positive in the absence of the interceptors.

Fix https://github.com/llvm/llvm-project/issues/64388
Fix https://github.com/llvm/llvm-project/issues/64946

Link: https://lists.gnu.org/archive/html/info-gnu/2023-07/msg00010.html
("The GNU C Library version 2.38 is now available")

Reviewed By: #sanitizers, vitalybuka, mgorny

Differential Revision: https://reviews.llvm.org/D158943
2023-08-28 00:49:49 -07:00
Enna1
94b0851aad [sanitizer] use uptr to store the result of internal_strlen/internal_strnlen in printf_common
The return type of `internal_strlen()` is 'uptr', but in `printf_common()` we store the result of `internal_strlen()` into an 'int' type variable.
When the result value of `internal_strlen()` is larger than the largest possible value of 'int' type, the implicit conversion from 'uptr' to 'int' will change the result value to a negative value.

Without this change, asan reports a false positive negative-size-param in the added testcase.

Reviewed By: vitalybuka

Differential Revision: https://reviews.llvm.org/D157266
2023-08-28 14:37:35 +08:00
Fangrui Song
beeb37a8f3 [sanitizer] scanf interceptor: fix write size for %mc/%mC/%mS
When the optional assignment-allocation character 'm' (Extension to the
ISO C standard) is present, we currently use internal_strlen(buf)+1 for
all of cCsS[ (D85350). Fix cCS to use the correct size.

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

Reviewed By: #sanitizers, vitalybuka

Differential Revision: https://reviews.llvm.org/D158485
2023-08-27 22:19:31 -07:00