Commit Graph

13472 Commits

Author SHA1 Message Date
Mitch Phillips 30d292ddbb [sanitizer-common] Pickup llvm-symbolizer from $OUT/bin IFF exists.
Fix-forward for D93352.

Slight rework of the same idea, pickup the external symbolizer from the
binary directory iff it exists.
2020-12-16 11:59:10 -08:00
Mitch Phillips 66ee0d3d84 [sanitizer-common] Force pickup of llvm-symbolizer from new binaries.
It's possible currently that the sanitizer runtimes when testing grab
the path to the symbolizer through *SAN_SYMBOLIZER_PATH=...

This can be polluted by things like Android's setup script. This patch
forces external_symbolizer_path=$new_build_out_dir/llvm-symbolizer when
%env_tool_options is used.

Reviewed By: vitalybuka

Differential Revision: https://reviews.llvm.org/D93352
2020-12-16 06:36:26 -08:00
Stephan Bergmann 75f98f0f8c [PATCH] [compiler-rt] [builtins] Fix name of __aarch64_have_lse_atomics on Darwin
...where the name of that variable defined in
compiler-rt/lib/builtins/cpu_model.c is decorated with a leading underscore

Differential Revision: https://reviews.llvm.org/D93390
2020-12-16 14:42:03 +01:00
Raul Tambre b2851aea80 Revert "[Compiler-rt][AArch64] Workaround for .cfi_startproc assembler parser bug."
039cb03dd0 (D93378) fixed the assembly separator, so the workaround is no longer necessary.

This reverts commit 3000c19df6.

Differential Revision: https://reviews.llvm.org/D93379
2020-12-16 10:22:04 +02:00
Fangrui Song 039cb03dd0 [builtins] Use %% as the separator for aarch64-*-darwin and ; for powerpc{32,64}
`;` is the default comment marker, which is also used by powerpc*-*-elf target triples.
`@` is the comment marker of powerpc*-*-darwin but the Darwin support has been deleted for PowerPC (D72063).
`%%` is the statement separator used by aarch64-*-darwin (see AArch64MCAsmInfoDarwin, it uses `;` as the comment marker, which is different from most other targets)

Reviewed By: tambre

Differential Revision: https://reviews.llvm.org/D93378
2020-12-16 00:13:22 -08:00
Raul Tambre a72d462eb9 Re-apply "[CMake][compiler-rt][AArch64] Avoid preprocessing LSE builtins separately"
aa772fc85e (D92530) has landed fixing relocations on Darwin.
3000c19df6 (D93236) has landed working around an assembly parser bug on Darwin.
Previous quick-fix d9697c2e6b (D93198) included in this commit.

Invoking the preprocessor ourselves is fragile and would require us to replicate CMake's handling of definitions, compiler flags, etc for proper compatibility.
In my toolchain builds this notably resulted in a bunch of warnings from unused flags as my CMAKE_C_FLAGS includes CPU-specific optimization options.
Notably this part was already duplicating the logic for VISIBILITY_HIDDEN define.

Instead, symlink the files and set the proper set of defines on each.
This should also be faster as we avoid invoking the compiler multiple times.

Fixes https://llvm.org/PR48494

Differential Revision: https://reviews.llvm.org/D93278
2020-12-15 08:18:07 +02:00
Raul Tambre 3000c19df6 [Compiler-rt][AArch64] Workaround for .cfi_startproc assembler parser bug.
Put .cfi_startproc on a new line to avoid hitting the assembly parser bug in MasmParser::parseDirectiveCFIStartProc().

Reviewed By: tambre

Differential Revision: https://reviews.llvm.org/D93236
2020-12-15 08:14:42 +02:00
Nemanja Ivanovic eed0b9acdf [PowerPC] Temporarily disable asan longjmp tests
Commit bfdc19e778 seems to have broken
some PPC bots with a couple of asan test cases. Disable those test
cases for now until I can resolve the issue.
2020-12-14 18:22:08 -06:00
Peter Collingbourne f21f3339ba scudo: Remove positional template arguments for secondary cache. NFCI.
Make these arguments named constants in the Config class instead
of being positional arguments to MapAllocatorCache. This makes the
configuration easier to follow.

Eventually we should follow suit with the other classes but this is
a start.

Differential Revision: https://reviews.llvm.org/D93251
2020-12-14 15:40:07 -08:00
Kuba Mracek f276c00898 [sanitizer] Restrict querying VM size on Darwin only to iOS devices
We currently do this for SANITIZER_IOS, which includes devices *and* simulators. This change opts out the check for simulators to unify the behavior with macOS, because VM size is really a property of the host OS, and not the simulator.

<rdar://problem/72129387>

Differential Revision: https://reviews.llvm.org/D93140
2020-12-14 10:48:48 -08:00
Raul Tambre c21df2a79c Revert "Re-apply "[CMake][compiler-rt][AArch64] Avoid preprocessing LSE builtins separately""
This reverts commit 03ebe1937192c247c4a7b8ec19dde2cf9845c914.

It's still breaking bots, e.g. http://green.lab.llvm.org/green/job/clang-stage1-RA/17027/console although it doesn't change any actual code.
The compile errors don't make much sense either. Revert for now.

Differential Revision: https://reviews.llvm.org/D93228
2020-12-14 18:43:55 +02:00
Raul Tambre d0797e62fa Re-apply "[CMake][compiler-rt][AArch64] Avoid preprocessing LSE builtins separately"
aa772fc85e (D92530) has landed fixing Apple builds.
Previous quick-fix d9697c2e6b (D93198) included in this commit.

Invoking the preprocessor ourselves is fragile and would require us to replicate CMake's handling of definitions, compiler flags, etc for proper compatibility.
In my toolchain builds this notably resulted in a bunch of warnings from unused flags as my CMAKE_C_FLAGS includes CPU-specific optimization options.
Notably this part was already duplicating the logic for VISIBILITY_HIDDEN define.

Instead, symlink the files and set the proper set of defines on each.
This should also be faster as we avoid invoking the compiler multiple times.

Fixes https://llvm.org/PR48494

Differential Revision: https://reviews.llvm.org/D93211
2020-12-14 16:45:48 +02:00
Kuba Mracek aa772fc85e [compiler-rt] [builtins] Make lse.S compile on Darwin
Reviewed By: ilinpv

Differential Revision: https://reviews.llvm.org/D92530
2020-12-14 16:38:48 +02:00
Raul Tambre 55f07a3400 [XRay] Remove unnecessary <x86intrin.h> include
It hasn't been necessary since commit 4d4ed0e288 (D43278).

Reviewed By: dberris

Differential Revision: https://reviews.llvm.org/D93196
2020-12-14 12:36:35 +02:00
Raul Tambre 617cd01a4b Revert "[CMake][compiler-rt][AArch64] Avoid preprocessing LSE builtins separately"
Causing issues on Apple buildbots.
http://green.lab.llvm.org/green/job/clang-stage1-RA/17019/console

This reverts commit 33b740f8dc.
This reverts commit d9697c2e6b.

Differential Revision: https://reviews.llvm.org/D93199
2020-12-14 11:42:28 +02:00
Raul Tambre d9697c2e6b [compiler-rt][CMake] Define HAS_ASM_LSE on Apple if available
Should hopefully fix 33b740f8dc (D93178) failing on bots.

Differential Revision: https://reviews.llvm.org/D93198
2020-12-14 11:26:24 +02:00
Raul Tambre 33b740f8dc [CMake][compiler-rt][AArch64] Avoid preprocessing LSE builtins separately
Invoking the preprocessor ourselves is fragile and would require us to replicate CMake's handling of definitions, compiler flags, etc for proper compatibility.
In my toolchain builds this notably resulted in a bunch of warnings from unused flags as my CMAKE_C_FLAGS includes CPU-specific optimization options.
Notably this part was already duplicating the logic for VISIBILITY_HIDDEN define.

Instead, symlink the files and set the proper set of defines on each.
This should also be faster as we avoid invoking the compiler multiple times.

Fixes https://llvm.org/PR48494

Reviewed By: ilinpv

Differential Revision: https://reviews.llvm.org/D93178
2020-12-14 09:20:30 +02:00
Matt Morehouse 7bc7501ac1 [DFSan] Add custom wrapper for recvmmsg.
Uses the recvmsg wrapper logic in a loop.

Reviewed By: stephan.yichao.zhao

Differential Revision: https://reviews.llvm.org/D93059
2020-12-11 06:24:56 -08:00
Fangrui Song f23fae29eb [test] Fix compiler-rt/test/profile/coverage_emptylines.cpp if the build directory is under /tmp
llvm-cov -path-equivalence=/tmp,... is used by some checked-in coverage mapping
files where the original filename is under /tmp. If the test itself produces the
coverage mapping file, there is no need for /tmp.

For coverage_emptylines.cpp: the source filename is under the build directory.
If the build directory is under /tmp, the path mapping will make
llvm-cov fail to find the file.
2020-12-10 16:57:10 -08:00
Xinhao Yuan 97260ab478 [llvm-cov][gcov] Optimize the cycle counting algorithm by skipping zero count cycles
This change is similar to http://gcc.gnu.org/PR90380

This reduces the complexity from exponential to polynomial of the arcs.

Reviewed By: MaskRay

Differential Revision: https://reviews.llvm.org/D93036
2020-12-10 15:22:29 -08:00
Florian Schmaus b1dd1a0997 [msan] Do not use 77 as exit code, instead use 1
MSan uses 77 as exit code since it appeared with c5033786ba ("[msan]
MemorySanitizer runtime."). However, Test runners like the one from
Meson use the GNU standard approach where a exit code of 77 signals
that the test should be skipped [1]. As a result Meson's test runner
reports tests as skipped if MSan is enabled and finds issues:

build $ meson test
ninja: Entering directory `/home/user/code/project/build'
ninja: no work to do.
1/1 PROJECT:all / SimpleTest    SKIP           0.09s

I could not find any rationale why 77 was initially chosen, and I
found no other clang sanitizer that uses this value as exit
code. Hence I believe it is safe to change this to a safe
default. You can restore the old behavior by setting the environment
variable MSAN_OPTIONS to "exitcode=77", e.g.

export MSAN_OPTIONS="exitcode=77"

1: https://mesonbuild.com/Unit-tests.html#skipped-tests-and-hard-errors

Reviewed By: #sanitizers, eugenis

Differential Revision: https://reviews.llvm.org/D92490
2020-12-10 14:23:12 -08:00
Matt Morehouse 5ff35356f1 [DFSan] Appease the custom wrapper lint script. 2020-12-10 14:12:26 -08:00
Matt Morehouse 009931644a [DFSan] Add custom wrapper for pthread_join.
The wrapper clears shadow for retval.

Reviewed By: stephan.yichao.zhao

Differential Revision: https://reviews.llvm.org/D93047
2020-12-10 13:41:24 -08:00
Mitch Phillips 61a038f852 [GWP-ASan] IWYU & clang-format
Run an IWYU pass and clang-format GWP-ASan code.

Reviewed By: eugenis, mcgrathr

Differential Revision: https://reviews.llvm.org/D92688
2020-12-10 12:42:01 -08:00
Matt Morehouse fa4bd4b338 [DFSan] Add custom wrapper for getpeername.
The wrapper clears shadow for addr and addrlen when written to.

Reviewed By: stephan.yichao.zhao

Differential Revision: https://reviews.llvm.org/D93046
2020-12-10 12:26:06 -08:00
Mitch Phillips ebff66be65 [scudo] [standalone] [NFC] clang-format code.
clang-format the scudo standalone codebase.

Reviewed By: cryptoad

Differential Revision: https://reviews.llvm.org/D93056
2020-12-10 12:25:42 -08:00
Matt Morehouse 72fd47b93d [DFSan] Add custom wrapper for _dl_get_tls_static_info.
Implementation is here:
https://code.woboq.org/userspace/glibc/elf/dl-tls.c.html#307

We use weak symbols to avoid linking issues with glibcs older than 2.27.

Reviewed By: stephan.yichao.zhao

Differential Revision: https://reviews.llvm.org/D93053
2020-12-10 11:03:28 -08:00
Kostya Kortchinsky 3f70987b35 [scudo][standalone] Small changes to the fastpath
There are a few things that I wanted to reorganize for a while:
- the loop that incrementally goes through classes on failure looked
  horrible in assembly, mostly because of `LIKELY`/`UNLIKELY` within
  the loop. So remove those, we are already in an unlikely scenario
- hooks are not used by default on Android/Fuchsia/etc so mark the
  tests for the existence of the weak functions as unlikely
- mark of couple of conditions as likely/unlikely
- in `reallocate`, the old size was computed again while we already
  have it in a variable. So just use the one we have.
- remove the bitwise AND trick and use a logical AND, that has one
  less test by using a purposeful underflow when `Size` is 0 (I
  actually looked at the assembly of the previous code to steal that
  trick)
- move the read of the options closer to where they are used, mark them
  as `const`

Overall this makes things a tiny bit faster, but cleaner.

Differential Revision: https://reviews.llvm.org/D92689
2020-12-10 10:25:59 -08:00
Matt Morehouse bdaeb82a5f [DFSan] Add custom wrapper for sigaltstack.
The wrapper clears shadow for old_ss.

Reviewed By: stephan.yichao.zhao

Differential Revision: https://reviews.llvm.org/D93041
2020-12-10 10:16:36 -08:00
Matt Morehouse 8a874a4277 [DFSan] Add custom wrapper for getsockname.
The wrapper clears shadow for any bytes written to addr or addrlen.

Reviewed By: stephan.yichao.zhao

Differential Revision: https://reviews.llvm.org/D92964
2020-12-10 08:13:05 -08:00
Matt Morehouse 4eedc2e3af [DFSan] Add custom wrapper for getsockopt.
The wrapper clears shadow for optval and optlen when written.

Reviewed By: stephan.yichao.zhao, vitalybuka

Differential Revision: https://reviews.llvm.org/D92961
2020-12-09 14:29:38 -08:00
Peter Collingbourne a779050852 scudo: Shrink secondary header and cache entry size by a word on Linux. NFCI.
Normally compilers will allocate space for struct fields even if the
field is an empty struct. Use the [[no_unique_address]] attribute to
suppress that behavior. This attribute that was introduced in C++20,
but compilers that do not support [[no_unique_address]] will ignore
it since it uses C++11 attribute syntax.

Differential Revision: https://reviews.llvm.org/D92966
2020-12-09 14:14:49 -08:00
Matt Morehouse a3eb2fb247 [DFSan] Add custom wrapper for recvmsg.
The wrapper clears shadow for anything written by recvmsg.

Reviewed By: stephan.yichao.zhao

Differential Revision: https://reviews.llvm.org/D92949
2020-12-09 13:07:51 -08:00
Peter Collingbourne e5a28e1261 scudo: Fix quarantine allocation when MTE enabled.
Quarantines have always been broken when MTE is enabled because the
quarantine batch allocator fails to reset tags that may have been
left behind by a user allocation.

This was only noticed when running the Scudo unit tests with Scudo
as the system allocator because quarantines are turned off by
default on Android and the test binary turns them on by defining
__scudo_default_options, which affects the system allocator as well.

Differential Revision: https://reviews.llvm.org/D92881
2020-12-09 11:48:41 -08:00
Peter Collingbourne 9f8aeb0602 scudo: Split setRandomTag in two. NFCI.
Separate the IRG part from the STZG part since we will need to use
the latter on its own for some upcoming changes.

Differential Revision: https://reviews.llvm.org/D92880
2020-12-09 11:48:41 -08:00
Jianzhou Zhao ea981165a4 [dfsan] Track field/index-level shadow values in variables
*************
* The problem
*************
See motivation examples in compiler-rt/test/dfsan/pair.cpp. The current
DFSan always uses a 16bit shadow value for a variable with any type by
combining all shadow values of all bytes of the variable. So it cannot
distinguish two fields of a struct: each field's shadow value equals the
combined shadow value of all fields. This introduces an overtaint issue.

Consider a parsing function

   std::pair<char*, int> get_token(char* p);

where p points to a buffer to parse, the returned pair includes the next
token and the pointer to the position in the buffer after the token.

If the token is tainted, then both the returned pointer and int ar
tainted. If the parser keeps on using get_token for the rest parsing,
all the following outputs are tainted because of the tainted pointer.

The CL is the first change to address the issue.

**************************
* The proposed improvement
**************************
Eventually all fields and indices have their own shadow values in
variables and memory.

For example, variables with type {i1, i3}, [2 x i1], {[2 x i4], i8},
[2 x {i1, i1}] have shadow values with type {i16, i16}, [2 x i16],
{[2 x i16], i16}, [2 x {i16, i16}] correspondingly; variables with
primary type still have shadow values i16.

***************************
* An potential implementation plan
***************************

The idea is to adopt the change incrementially.

1) This CL
Support field-level accuracy at variables/args/ret in TLS mode,
load/store/alloca still use combined shadow values.

After the alloca promotion and SSA construction phases (>=-O1), we
assume alloca and memory operations are reduced. So if struct
variables do not relate to memory, their tracking is accurate at
field level.

2) Support field-level accuracy at alloca
3) Support field-level accuracy at load/store

These two should make O0 and real memory access work.

4) Support vector if necessary.
5) Support Args mode if necessary.
6) Support passing more accurate shadow values via custom functions if
necessary.

***************
* About this CL.
***************
The CL did the following

1) extended TLS arg/ret to work with aggregate types. This is similar
to what MSan does.

2) implemented how to map between an original type/value/zero-const to
its shadow type/value/zero-const.

3) extended (insert|extract)value to use field/index-level progagation.

4) for other instructions, propagation rules are combining inputs by or.
The CL converts between aggragate and primary shadow values at the
cases.

5) Custom function interfaces also need such a conversion because
all existing custom functions use i16. It is unclear whether custome
functions need more accurate shadow propagation yet.

6) Added test cases for aggregate type related cases.

Reviewed-by: morehouse

Differential Revision: https://reviews.llvm.org/D92261
2020-12-09 19:38:35 +00:00
Matt Morehouse 6f13445fb6 [DFSan] Add custom wrapper for epoll_wait.
The wrapper clears shadow for any events written.

Reviewed By: stephan.yichao.zhao

Differential Revision: https://reviews.llvm.org/D92891
2020-12-09 06:05:29 -08:00
Jeroen Dobbelaere 8d33f08844 [compiler-rt sanitizer] Use our own PTRACE_GETREGSET if it does not exist.
On RH66 does not support 'PTRACE_GETREGSET'. This change makes this part of compiler-rt build again on older os-es

Reviewed By: vitalybuka

Differential Revision: https://reviews.llvm.org/D91686
2020-12-09 01:08:14 -08:00
Matt Morehouse 483fb33360 [DFSan] Add pthread and other functions to ABI list.
The non-pthread functions are all clear discard functions.

Some of the pthread ones could clear shadow, but aren't worth writing
custom wrappers for.  I can't think of any reasonable scenario where we
would pass tainted memory to these pthread functions.

Reviewed By: stephan.yichao.zhao

Differential Revision: https://reviews.llvm.org/D92877
2020-12-08 13:55:35 -08:00
Matt Morehouse 3bd2ad5a08 [DFSan] Add several math functions to ABI list.
These are all straightforward functional entries.

Reviewed By: stephan.yichao.zhao

Differential Revision: https://reviews.llvm.org/D92791
2020-12-08 10:51:05 -08:00
Jeroen Dobbelaere d7e71b5db8 [compiler-rt santizer] Use clock_gettime instead of timespec_get
On RH66, timespec_get is not available. Use clock_gettime instead.

This problem was introduced with D87120

Reviewed By: tejohnson

Differential Revision: https://reviews.llvm.org/D91687
2020-12-08 10:10:17 -08:00
Adhemerval Zanella db61b1844e [compiler-rt] [builtins] Support conversion between fp16 and fp128
This patch adds both extendhftf2 and trunctfhf2 to support
conversion between half-precision and quad-precision floating-point
values. They are built iff the compiler supports _Float16.

Some notes on ARM plaforms: while fp16 is supported on all
architectures, _Float16 is supported only for 32-bit ARM, 64-bit ARM,
and SPIR (as indicated by clang/docs/LanguageExtensions.rst). Also,
fp16 is a storage format and 64-bit ARM supports floating-point
convert precision to half as base armv8-a instruction.

This patch does not change the ABI for 32-bit ARM, it will continue
to pass _Float16 as uint16.

This re-enabled revert done by https://reviews.llvm.org/rGb534beabeed3ba1777cd0ff9ce552d077e496726

Differential Revision: https://reviews.llvm.org/D92242
2020-12-08 11:51:55 -03:00
Hafiz Abid Qadeer deec343bfd [compiler-rt] Allow appending to 'target_cflags' value from lit_config.
This patch is similar to D84708. When testing compiler-rt on different
baremetal targets, it helps to have the ability to pass some more parameters
at test time that allows you to build the test executable for a
given target. For an example, you may need a different linker command
file for different targets.

This patch will allows to do things like

$ llvm-lit --param=append_target_cflags="-T simulator.ld"
or
$ llvm-lit --param=append_target_cflags="-T hardware.ld"

In this way, you can run tests on different targets without having to run
cmake again.

Reviewed By: delcypher

Differential Revision: https://reviews.llvm.org/D91783
2020-12-08 11:46:36 +00:00
Mitch Phillips 1d03a54d94 Revert "[test] Fix asan/TestCases/Linux/globals-gc-sections-lld.cpp with -fsanitize-address-globals-dead-stripping"
This reverts commit 140808768d.

Reason: Broke the upstream bots - discussed offline.
2020-12-07 14:30:53 -08:00
Kazushi (Jam) Marukawa 414d3dc62c [VE][compiler-rt] Support VE in clear_cache.c
Support SX Aurora VE by __clear_cache() function.  This modification
allows VE to run written data, e.g. clear_cache_test.c under compiler-rt
test.  We still have code alignment problem in enable_execute_stack_test.c,
though.

Reviewed By: simoll

Differential Revision: https://reviews.llvm.org/D92703
2020-12-07 17:38:23 +09:00
Pavel Iliin 377ba7be93 [compiler-rt][AArch64] Put outline atomic helpers into dedicated dir.
Differential Revision: https://reviews.llvm.org/D92724
2020-12-07 00:28:09 +00:00
Fangrui Song 140808768d [test] Fix asan/TestCases/Linux/globals-gc-sections-lld.cpp with -fsanitize-address-globals-dead-stripping
r302591 dropped -fsanitize-address-globals-dead-stripping for ELF platforms
(to work around a gold<2.27 bug: https://sourceware.org/bugzilla/show_bug.cgi?id=19002)

Upgrade REQUIRES: from lto (COMPILER_RT_TEST_USE_LLD (set by Android, but rarely used elsewhere)) to lto-available.
2020-12-06 11:11:15 -08:00
Fangrui Song dde44f488c [test] Fix asan/TestCases/Posix/lto-constmerge-odr.cpp when 'binutils_lto' is avaiable
If COMPILER_RT_TEST_USE_LLD is not set, config.use_lld will be False.
However, if feature 'binutils_lto' is available, lto_supported can still be True,
but config.target_cflags will not get -fuse-ld=lld from config.lto_flags

As a result, we may use clang -flto with system 'ld' which may not support the bitcode file, e.g.

  ld: error: /tmp/lto-constmerge-odr-44a1ee.o: Unknown attribute kind (70) (Producer: 'LLVM12.0.0git' Reader: 'LLVM 12.0.0git')
  // The system ld+LLVMgold.so do not support ATTR_KIND_MUSTPROGRESS (70).

Just require lld-available and add -fuse-ld=lld.
2020-12-06 10:31:40 -08:00
Fangrui Song b00f345acd [asan][test] Fix odr-vtable.cpp 2020-12-05 19:30:41 -08:00
Benjamin Kramer 2a136a7a9c [X86] Autodetect znver3 2020-12-05 19:08:20 +01:00