Commit Graph

14162 Commits

Author SHA1 Message Date
Matt Morehouse 0867edfc64 [HWASan] Add basic stack tagging support for LAM.
Adds the basic instrumentation needed for stack tagging.

Currently does not support stack short granules or TLS stack histories,
since a different code path is followed for the callback instrumentation
we use.

We may simply wait to support these two features until we switch to
a custom calling convention.

Patch By: xiangzhangllvm, morehouse

Reviewed By: vitalybuka

Differential Revision: https://reviews.llvm.org/D102901
2021-06-11 08:21:17 -07:00
Stephen Hines 6455418d3d [compiler-rt] [builtins] [AArch64] Add missing AArch64 data synchronization barrier (dsb) to __clear_cache
https://developer.arm.com/documentation/den0024/a/Caches/Cache-maintenance
covers how to properly clear caches on AArch64, and the builtin
implementation was missing a `dsb ish` after clearing the icache for the
selected range.

Reviewed By: kristof.beyls

Differential Revision: https://reviews.llvm.org/D104094
2021-06-11 02:13:48 -07:00
Arthur Eubanks b73742bc8d [Profile] Remove redundant check
This is already checked outside the loop.

Followup to D104050.
2021-06-10 16:24:53 -07:00
Arthur Eubanks 189428c8fc [Profile] Handle invalid profile data
This mostly follows LLVM's InstrProfReader.cpp error handling.
Previously, attempting to merge corrupted profile data would result in
crashes. See https://crbug.com/1216811#c4.

Reviewed By: rnk

Differential Revision: https://reviews.llvm.org/D104050
2021-06-10 16:10:13 -07:00
Kevin Athey ddac31c593 Cleanup for final comment on https://reviews.llvm.org/D103304
Consolidate DEFINE_STACK_MALLOC to simplify.

Reviewed By: vitalybuka

Differential Revision: https://reviews.llvm.org/D103965
2021-06-09 13:47:12 -07:00
David Spickett 11ad9e31eb [compiler-rt] Mark symbolize_stack_fp test unsupported on Arm Thumb
The new test `symbolize_stack_fp.cpp` added in
https://reviews.llvm.org/D102046 assumes that
we can fall back to the fast unwinder.

This is not the case for Thumb and the test is currently
failing on our v7 thumb bot:
https://lab.llvm.org/buildbot/#/builders/26/builds/2096

Skip the test if we're building for a Thumb target.

Reviewed By: MaskRay

Differential Revision: https://reviews.llvm.org/D103512
2021-06-09 08:50:21 +00:00
serge-sans-paille 4144827514 Prevent generation of dependency on _cxa_guard for static initialization
This fixes an issue introduced by https://reviews.llvm.org/D70662

Function-scope static initialization are guarded in C++, so we should probably
not use it because it introduces a dependency on __cxa_guard* symbols.
In the context of clang, libasan is linked statically, and it currently needs to
the odd situation where compiling C code with clang and asan requires -lstdc++

Differential Revision: https://reviews.llvm.org/D102475
2021-06-09 09:38:59 +02:00
David Blaikie 8051a48e65 ORTRT: Add tests for string_view equality and inequality operators 2021-06-08 17:53:59 -07:00
David Blaikie 4d9cc7c244 Add a couple of missing includes 2021-06-08 17:53:58 -07:00
David Blaikie cb09f2b10c Rename compiler-rt/lib/orc/endian.h to endianness.h to avoid conflict with system headers 2021-06-08 17:53:58 -07:00
Kevin Athey af8c59e06d Update and improve compiler-rt tests for -mllvm -asan_use_after_return=(never|[runtime]|always).
In addition:
  - optionally add global flag to capture compile intent for UAR:
    __asan_detect_use_after_return_always.
    The global is a SANITIZER_WEAK_ATTRIBUTE.

for issue: https://github.com/google/sanitizers/issues/1394

Reviewed By: vitalybuka

Differential Revision: https://reviews.llvm.org/D103304
2021-06-08 14:39:06 -07:00
Daniel Michael 2551053e8d [scudo] Add Scudo support for Trusty OS
trusty.cpp and trusty.h define Trusty implementations of map and other
platform-specific functions. In addition to adding Trusty configurations
in allocator_config.h and size_class_map.h, MapSizeIncrement and
PrimaryEnableRandomOffset are added as configurable options in
allocator_config.h.
Background on Trusty: https://source.android.com/security/trusty

Differential Revision: https://reviews.llvm.org/D103578
2021-06-08 14:02:10 -07:00
Leonard Chan a9ea0a6a77 Fix for failing test mentioned in https://reviews.llvm.org/D103564.
This updates the path shown in the stack trace.
2021-06-08 12:38:01 -07:00
Leonard Chan 944b3c53ae [NFC][compiler-rt][hwasan] Move allocation functions into their own file
This removes the `__sanitizer_*` allocation function definitions from
`hwasan_interceptors.cpp` and moves them into their own file. This way
implementations that do not use interceptors at all can just ignore
(almost) everything in `hwasan_interceptors.cpp`.

Also remove some unused headers in `hwasan_interceptors.cpp` after the move.

Differential Revision: https://reviews.llvm.org/D103564
2021-06-08 12:08:23 -07:00
David Blaikie c5d56fec50 NFC: .clang-tidy: Inherit configs from parents to improve maintainability
In the interests of disabling misc-no-recursion across LLVM (this seems
like a stylistic choice that is not consistent with LLVM's
style/development approach) this NFC preliminary change adjusts all the
.clang-tidy files to inherit from their parents as much as possible.

This change specifically preserves all the quirks of the current configs
in order to make it easier to review as NFC.

I validatad the change is NFC as follows:

for X in `cat ../files.txt`;
do
  mkdir -p ../tmp/$(dirname $X)
  touch $(dirname $X)/blaikie.cpp
  clang-tidy -dump-config $(dirname $X)/blaikie.cpp > ../tmp/$(dirname $X)/after
  rm $(dirname $X)/blaikie.cpp
done

(similarly for the "before" state, without this patch applied)

for X in `cat ../files.txt`;
do
  echo $X
  diff \
    ../tmp/$(dirname $X)/before \
    <(cat ../tmp/$(dirname $X)/after \
      | sed -e "s/,readability-identifier-naming\(.*\),-readability-identifier-naming/\1/" \
      | sed -e "s/,-llvm-include-order\(.*\),llvm-include-order/\1/" \
      | sed -e "s/,-misc-no-recursion\(.*\),misc-no-recursion/\1/" \
      | sed -e "s/,-clang-diagnostic-\*\(.*\),clang-diagnostic-\*/\1/")
done

(using sed to strip some add/remove pairs to reduce the diff and make it easier to read)

The resulting report is:
  .clang-tidy
  clang/.clang-tidy
  2c2
  < Checks:          'clang-diagnostic-*,clang-analyzer-*,-*,clang-diagnostic-*,llvm-*,misc-*,-misc-unused-parameters,-misc-non-private-member-variables-in-classes,-readability-identifier-naming,-misc-no-recursion'
  ---
  > Checks:          'clang-diagnostic-*,clang-analyzer-*,-*,clang-diagnostic-*,llvm-*,misc-*,-misc-unused-parameters,-misc-non-private-member-variables-in-classes,-misc-no-recursion'
  compiler-rt/.clang-tidy
  2c2
  < Checks:          'clang-diagnostic-*,clang-analyzer-*,-*,clang-diagnostic-*,llvm-*,-llvm-header-guard,misc-*,-misc-unused-parameters,-misc-non-private-member-variables-in-classes'
  ---
  > Checks:          'clang-diagnostic-*,clang-analyzer-*,-*,clang-diagnostic-*,llvm-*,misc-*,-misc-unused-parameters,-misc-non-private-member-variables-in-classes,-llvm-header-guard'
  flang/.clang-tidy
  2c2
  < Checks:          'clang-diagnostic-*,clang-analyzer-*,-*,llvm-*,-llvm-include-order,misc-*,-misc-no-recursion,-misc-unused-parameters,-misc-non-private-member-variables-in-classes'
  ---
  > Checks:          'clang-diagnostic-*,clang-analyzer-*,-*,llvm-*,misc-*,-misc-unused-parameters,-misc-non-private-member-variables-in-classes,-llvm-include-order,-misc-no-recursion'
  flang/include/flang/Lower/.clang-tidy
  flang/include/flang/Optimizer/.clang-tidy
  flang/lib/Lower/.clang-tidy
  flang/lib/Optimizer/.clang-tidy
  lld/.clang-tidy
  lldb/.clang-tidy
  llvm/tools/split-file/.clang-tidy
  mlir/.clang-tidy

The `clang/.clang-tidy` change is a no-op, disabling an option that was never enabled.
The compiler-rt and flang changes are no-op reorderings of the same flags.

(side note, the .clang-tidy file in parallel-libs is broken and crashes
clang-tidy because it uses "lowerCase" as the style instead of "lower_case" -
so I'll deal with that separately)

Differential Revision: https://reviews.llvm.org/D103842
2021-06-08 08:25:59 -07:00
Vitaly Buka b41b76b303 [NFC][scudo] Print errno of fork failure
This fork fails sometime on sanitizer-x86_64-linux-qemu bot.
2021-06-07 18:59:35 -07:00
Vitaly Buka 11539edf52 [NFC][LSAN] Limit the number of concurrent threads is the test
Test still fails with D88184 reverted.

The test was flaky on https://bugs.chromium.org/p/chromium/issues/detail?id=1206745 and
https://lab.llvm.org/buildbot/#/builders/sanitizer-x86_64-linux

Reviewed By: morehouse

Differential Revision: https://reviews.llvm.org/D102218
2021-06-07 17:38:12 -07:00
George Balatsouras 5b4dda550e [dfsan] Add full fast8 support
Complete support for fast8:
- amend shadow size and mapping in runtime
- remove fast16 mode and -dfsan-fast-16-labels flag
- remove legacy mode and make fast8 mode the default
- remove dfsan-fast-8-labels flag
- remove functions in dfsan interface only applicable to legacy
- remove legacy-related instrumentation code and tests
- update documentation.

Reviewed By: stephan.yichao.zhao, browneee

Differential Revision: https://reviews.llvm.org/D103745
2021-06-07 17:20:54 -07:00
Jianzhou Zhao a82747fafe [dfsan] Fix internal build errors because of more strict warning checks 2021-06-07 16:55:56 +00:00
Jianzhou Zhao 2c82588dac [dfsan] Use the sanitizer allocator to reduce memory cost
dfsan does not use sanitizer allocator as others. In practice,
we let it use glibc's allocator since tcmalloc needs more work
to be working with dfsan well. With glibc, we observe large
memory leakage. This could relate to two things:

1) glibc allocator has limitation: for example, tcmalloc can reduce memory footprint 2x easily

2) glibc may call unmmap directly as an internal system call by using system call number. so DFSan has no way to release shadow spaces for those unmmap.

Using sanitizer allocator addresses the above issues
1) its memory management is close to tcmalloc

2) we can register callback when sanitizer allocator calls unmmap, so dfsan can release shadow spaces correctly.

Our experiment with internal server-based application proved that with the change, in a-few-day run, memory usage leakage is close to what tcmalloc does w/o dfsan.

This change mainly follows MSan's code.

1) define allocator callbacks at dfsan_allocator.h|cpp

2) mark allocator APIs to be discard

3) intercept allocator APIs

4) make dfsan_set_label consistent with MSan's SetShadow when setting 0 labels, define dfsan_release_meta_memory when unmap is called

5) add flags about whether zeroing memory after malloc/free. dfsan works at byte-level, so bit-level oparations can cause reading undefined shadow. See D96842. zeroing memory after malloc helps this. About zeroing after free, reading after free is definitely UB, but if user code does so, it is hard to debug an overtainting caused by this w/o running MSan. So we add the flag to help debugging.

This change will be split to small changes for review. Before that, a question is
"this code shares a lot of with MSan, for example, dfsan_allocator.* and dfsan_new_delete.*.
Does it make sense to unify the code at sanitizer_common? will that introduce some
maintenance issue?"

Reviewed By: morehouse

Differential Revision: https://reviews.llvm.org/D101204
2021-06-06 22:09:31 +00:00
Vitaly Buka e3258b0894 Revert "Update and improve compiler-rt tests for -mllvm -asan_use_after_return=(never|[runtime]|always)."
Windows is still broken.

This reverts commit 927688a4cd.
2021-06-05 00:39:50 -07:00
Kevin Athey 927688a4cd Update and improve compiler-rt tests for -mllvm -asan_use_after_return=(never|[runtime]|always).
In addition:
  - optionally add global flag to capture compile intent for UAR:
    __asan_detect_use_after_return_always.
    The global is a SANITIZER_WEAK_ATTRIBUTE.

for issue: https://github.com/google/sanitizers/issues/1394

Reviewed By: vitalybuka

Differential Revision: https://reviews.llvm.org/D103304
2021-06-05 00:26:10 -07:00
Vitaly Buka 5b0e50550c [NFC][asan] Split fake_stack() into two funcions 2021-06-04 23:29:04 -07:00
Vitaly Buka 64b1cbca19 [NFC][asan] Fix include order 2021-06-04 23:25:03 -07:00
Vitaly Buka 6f122d96f7 [NFC][memprof] FIx delete[] usage in test 2021-06-04 23:17:23 -07:00
Vitaly Buka 585b9679ad [NFC][asan] format ThreadStackContainsAddress 2021-06-04 23:16:43 -07:00
Vitaly Buka 4a91118793 [NFC][memprof] Compile *.c tests as C 2021-06-04 23:16:42 -07:00
Vitaly Buka d8a4a2cb93 Revert "Update and improve compiler-rt tests for -mllvm -asan_use_after_return=(never|[runtime]|always)."
Reverts commits of D103304, it breaks Darwin.

This reverts commit 60e5243e59.
This reverts commit 26b3ea224e.
This reverts commit 17600ec32a.
2021-06-04 20:20:11 -07:00
Fangrui Song 35fb4b9a7c [lsan] Bump the thread limit from 1<<13 to 1<<22
This matches asan. Some applications need more than 1<<13 threads.

Reviewed By: vitalybuka

Differential Revision: https://reviews.llvm.org/D103731
2021-06-04 20:15:56 -07:00
Vitaly Buka 9ff982dbbd [NFC][scudo] Fix sign-compare warning in test 2021-06-04 19:33:42 -07:00
Vitaly Buka 57ba226296 [NFC][scudo] Convert to TYPED more ScudoCombinedTest 2021-06-04 19:26:03 -07:00
Vitaly Buka 70b29213eb [scudo] Remove ScopedString::Length
Differential Revision: https://reviews.llvm.org/D103725
2021-06-04 18:28:51 -07:00
Vitaly Buka df87aeb826 [Scudo] Improve ScopedString constructor
Avoid referencing elements beyond internal vector size.

Reviewed By: cryptoad

Differential Revision: https://reviews.llvm.org/D103718
2021-06-04 18:28:29 -07:00
Vitaly Buka b850798f11 [NFC][scudo] Fix sign-compare warning in test 2021-06-04 18:24:00 -07:00
Kevin Athey 17600ec32a remove windows tests for -asan_use-after-return=always (as this is currently disabled for Windows) 2021-06-04 16:59:24 -07:00
Kevin Athey 26b3ea224e fix SANITIZE_WINDOWS pragma for https://reviews.llvm.org/rG60e5243e593ec7e0feca42783edb735e9ac2c4a7 2021-06-04 16:46:54 -07:00
Kevin Athey 60e5243e59 Update and improve compiler-rt tests for -mllvm -asan_use_after_return=(never|[runtime]|always).
In addition:
  - optionally add global flag to capture compile intent for UAR:
    __asan_detect_use_after_return_always.
    The global is a SANITIZER_WEAK_ATTRIBUTE.

for issue: https://github.com/google/sanitizers/issues/1394

Reviewed By: vitalybuka

Differential Revision: https://reviews.llvm.org/D103304
2021-06-04 16:30:47 -07:00
Kostya Kortchinsky 5019b0a565 [scudo] Fix String DCHECK
This resolves an issue tripping a `DCHECK`, as I was checking for the
capacity and not the size. We don't need to 0-init the Vector as it's
done already, and make sure we only 0-out the string on clear if it's
not empty.

Differential Revision: https://reviews.llvm.org/D103716
2021-06-04 13:41:59 -07:00
Vitaly Buka 1e6d135325 [scudo] Untag pointer in iterateOverChunks
Pointer comparison in Lambda will not work on tagged pointers.

Reviewed By: pcc

Differential Revision: https://reviews.llvm.org/D103496
2021-06-04 12:45:07 -07:00
Vitaly Buka 07c92b2e95 [scudo] Add memtag_test
Differential Revision: https://reviews.llvm.org/D103074
2021-06-04 12:38:29 -07:00
Vitaly Buka 39f928ed01 [scudo] Remove disableMemoryTagChecksTestOnly
And replace with ScopedDisableMemoryTagChecks.

Differential Revision: https://reviews.llvm.org/D103708
2021-06-04 12:38:29 -07:00
Fangrui Song b19c0ac7dd [profile] Add -fprofile-instr-generate tests for weak definition and various linkages 2021-06-04 10:26:55 -07:00
Vitaly Buka ba04c7c128 [scudo] Always exclude Tag 0
prepareTaggedChunk uses Tag 0 for header.

Android already PR_MTE_TAG_MASK to 0xfffe,
but with the patch we will not need to deppend
on the system configuration.

Reviewed By: pcc

Differential Revision: https://reviews.llvm.org/D103134
2021-06-04 10:20:32 -07:00
Nico Weber 50c0aaed47 Temporarily remove another test added in one of the tests added in effb87d
This test reads the test file removed in db3e4faa4d.
2021-06-04 10:42:37 -04:00
Nico Weber db3e4faa4d Temporarily remove one of the tests added in effb87dfa8
It fails on some Linux systems. Remove the test until we've figured
out what's going on. See https://crbug.com/1216005 for details.
2021-06-04 10:03:21 -04:00
Kostya Kortchinsky 868317b3fd [scudo] Rework Vector/String
Some platforms (eg: Trusty) are extremelly memory constrained, which
doesn't necessarily work well with some of Scudo's current assumptions.

`Vector` by default (and as such `String` and `ScopedString`) maps a
page, which is a bit of a waste. This CL changes `Vector` to use a
buffer local to the class first, then potentially map more memory if
needed (`ScopedString` currently are all stack based so it would be
stack data). We also want to allow a platform to prevent any dynamic
resizing, so I added a `CanGrow` templated parameter that for now is
always `true` but would be set to `false` on Trusty.

Differential Revision: https://reviews.llvm.org/D103641
2021-06-03 18:12:24 -07:00
Nico Weber 5c600dc6d4 Revert "Update and improve compiler-rt tests for -mllvm -asan_use_after_return=(never|[runtime]|always)."
This reverts commit 41b3088c3f.
Doesn't build on macOS, see comments on https://reviews.llvm.org/D103304
2021-06-03 21:01:11 -04:00
Leonard Chan d4e4799998 [NFC][compiler-rt][hwasan] Refactor hwasan functions
This moves the implementations for HandleTagMismatch, __hwasan_tag_mismatch4,
and HwasanAtExit from hwasan_linux.cpp to hwasan.cpp and declares them in hwasan.h.
This way, calls to those functions can be shared with the fuchsia implementation
without duplicating code.

Differential Revision: https://reviews.llvm.org/D103562
2021-06-03 14:26:35 -07:00
Kevin Athey 41b3088c3f Update and improve compiler-rt tests for -mllvm -asan_use_after_return=(never|[runtime]|always).
In addition:
  - optionally add global flag to capture compile intent for UAR:
    __asan_detect_use_after_return_always.
    The global is a SANITIZER_WEAK_ATTRIBUTE.

for issue: https://github.com/google/sanitizers/issues/1394

Reviewed By: vitalybuka

Differential Revision: https://reviews.llvm.org/D103304
2021-06-03 13:13:51 -07:00
Vitaly Buka b40908e639 [NFC][scudo] Avoid integer overflow in test
releasePagesToOS may shrink RSS below the value stored on start.
2021-06-03 00:08:41 -07:00
Fangrui Song 87c43f3aa9 [InstrProfiling] Delete linkage/visibility toggling for Windows
The linkage/visibility of `__profn_*` variables are derived
from the profiled functions.

    extern_weak => linkonce
    available_externally => linkonce_odr
    internal => private
    extern => private
    _ => unchanged

The linkage/visibility of `__profc_*`/`__profd_*` variables are derived from
`__profn_*` with linkage/visibility wrestling for Windows.

The changes can be folded to the following without changing semantics.

```
if (TT.isOSBinFormatCOFF() && !NeedComdat) {
  Linkage = GlobalValue::InternalLinkage;
  Visibility = GlobalValue::DefaultVisibility;
}
```

That said, I think we can just delete the code block.

An extern/internal function will now use private `__profc_*`/`__profd_*`
variables, instead of internal ones. This saves some symbol table entries.

A non-comdat {linkonce,weak}_odr function will now use hidden external
`__profc_*`/`__profd_*` variables instead of internal ones.  There is potential
object file size increase because such symbols need `/INCLUDE:` directives.
However such non-comdat functions are rare (note that non-comdat weak
definitions don't prevent duplicate definition error).

The behavior changes match ELF.

Reviewed By: rnk

Differential Revision: https://reviews.llvm.org/D103355
2021-06-02 16:49:54 -07:00
Fangrui Song effb87dfa8 [profile] Add -fprofile-instr-generate tests for weak definition and various linkages 2021-06-02 16:12:08 -07:00
David Spickett 8c363efecc [compiler-rt][lsan] Increase libdl_deadlock test timeout
We have been seeing this test fail intermittently on our
2 stage AArch64 bot.

As far back as https://lab.llvm.org/buildbot/#/builders/53/builds/2694

Likely due to a lack of resources at certain times on the
shared machine. Up the time limit to give us some more room.

(this limit only applies to the watchdog thread, so if the
test passes then it won't take 20s)
2021-06-02 13:37:41 +00:00
David Spickett ba99359796 [compiler-rt][asan] Enable unwind-tables for Arm Linux
Since https://reviews.llvm.org/D102046 some tests have
been falling back to fast unwinding on our Thumb bot.

This fails because fast unwinding does not work on Thumb.
By adding the extra information we ensure this does not happen
during testing, but the built library can still fast unwind
as a last resort.

Since there are some situations it can work in, like if
eveything is built with clang. During testing we've got gcc
built system libs and clang built tests.

The same change was made for sanitizer-common in
https://reviews.llvm.org/D96337.

Reviewed By: zatrazz

Differential Revision: https://reviews.llvm.org/D103463
2021-06-02 12:59:46 +00:00
Vitaly Buka 60c0256ef1 [NFC][msan] Fix assigned-unused warning 2021-06-02 00:09:02 -07:00
Vitaly Buka 2445838f74 Revert "[NFC][msan] Fix warning on sanitizer-ppc64le-linux bot"
This fix breaks the test.

This reverts commit 6a2807bc81.
2021-06-02 00:09:02 -07:00
Vitaly Buka 6a2807bc81 [NFC][msan] Fix warning on sanitizer-ppc64le-linux bot 2021-06-01 21:03:41 -07:00
Vitaly Buka 4124bca309 [scudo] Enabled MTE in tests
Reviewed By: pcc, hctim

Differential Revision: https://reviews.llvm.org/D103305
2021-06-01 19:56:57 -07:00
Lang Hames da59241327 [ORC-RT] Add WrapperFunctionResult, Simple Packed Serialization (SPS) system.
WrapperFunctionResult is a C++ wrapper for __orc_rt_CWrapperFunctionResult
that automatically manages the underlying struct.

The Simple Packed Serialization (SPS) utilities support a simple serialization
scheme for wrapper function argument and result buffers:

Primitive typess (bool, char, int8_t, and uint8_t, int16_t, uint16_t, int32_t,
uint32_t, int64_t, uint64_t) are serialized in little-endian form.

SPSTuples are serialized by serializing each of the tuple members in order
without padding.

SPSSequences are serialized by serializing a sequence length (as a uint64_t)
followed by each of the elements of the sequence in order without padding.

Serialization/deserialization always involves a pair of SPS type tag (a tag
representing the serialized format to use, e.g. uint32_t, or
SPSTuple<bool, SPSString>) and a concrete type to be serialized from or
deserialized to (uint32_t, std::pair<bool, std::string>). Serialization for new
types can be implemented by specializing the SPSSerializationTraits type.
2021-06-01 11:24:19 -07:00
Lang Hames 28c3e9c0d1 [ORC-RT] Rename C-API functions to use __orc_rt_ prefix (instead of OrcRT).
This matches the C++ namespace name, and is consistent with other C linkage
functions (e.g. __orc_rt_jit_dispatch).
2021-06-01 11:24:19 -07:00
Lang Hames d791f0c219 [ORC-RT] Add equality/inequality comparison to string_view. 2021-06-01 11:24:19 -07:00
Evgeny Leviant 7879fa6884 [compiler-rt] Fix compilation when multiple architectures can be targeted
When toolchain can supports all of arm, armhf and armv6m architectures compiler-rt
libraries won't compile because architecture specific flags are appended to single
BUILTIN_CFLAGS variable.

Differential revision: https://reviews.llvm.org/D103363
2021-06-01 15:26:51 +03:00
Lang Hames 1ed29f8784 [ORC-RT] Add common.h -- Logging, casting and remote dispatch utilities. 2021-05-30 11:21:17 -07:00
Lang Hames 442f2d7bc0 [ORC-RT] Add OrcRTCWrapperFunctionResult.
OrcRTCWrapperFunctionResult is a C struct that can be used to return serialized
results from "wrapper functions" -- functions that deserialize an argument
buffer, call through to an actual implementation function, then serialize and
return the result of that function. Wrapper functions allow calls between ORC
and the ORC Runtime to be written using a single signature,
WrapperFunctionResult(const char *ArgData, size_t ArgSize), and without coupling
either side to a particular transport mechanism (in-memory, TCP, IPC, ... the
actual mechanism will be determined by the TargetProcessControl implementation).

OrcRTCWrapperFunctionResult is designed to allow small serialized buffers to
be returned by value, with larger serialized results stored on the heap. They
also provide an error state to report failures in serialization/deserialization.
2021-05-30 11:20:57 -07:00
Vitaly Buka bd04d78d64 [cmake][scudo] Add missing headers 2021-05-28 02:06:14 -07:00
Vitaly Buka a6e5a4b464 [NFC][scudo] Re-enable check in the test
It should pass with patched QEMU.
2021-05-28 01:57:55 -07:00
Vitaly Buka 4458e8c4b4 Revert "[scudo] Check if MADV_DONTNEED zeroes memory"
This reverts commit d423509b80.

We are going to use patched QEMU.
2021-05-28 01:53:42 -07:00
Jianzhou Zhao fc1d39849e [dfsan] Add a flag about whether to propagate offset labels at gep
DFSan has flags to control flows between pointers and objects referred
by pointers. For example,

a = *p;
L(a) = L(*p)        when -dfsan-combine-pointer-labels-on-load = false
L(a) = L(*p) + L(p) when -dfsan-combine-pointer-labels-on-load = true

*p = b;
L(*p) = L(b)        when -dfsan-combine-pointer-labels-on-store = false
L(*p) = L(b) + L(p) when -dfsan-combine-pointer-labels-on-store = true
The question is what to do with p += c.

In practice we found many confusing flows if we propagate labels from c
to p. So a new flag works like this

p += c;
L(p) = L(p)        when -dfsan-propagate-via-pointer-arithmetic = false
L(p) = L(p) + L(c) when -dfsan-propagate-via-pointer-arithmetic = true

Reviewed-by: gbalats

Differential Revision: https://reviews.llvm.org/D103176
2021-05-28 00:06:19 +00:00
Ryan Prichard b834d63094 [sanitizer] Android ELF TLS is supported from Q (API 29)
Reviewed By: oontvoo, MaskRay

Differential Revision: https://reviews.llvm.org/D103214
2021-05-27 14:53:49 -07:00
Vitaly Buka c261edb277 [NFC][scudo] Check zeros on smaller allocations
1Tb counting was the slowest test under the QEMU with MTE.
2021-05-27 11:14:26 -07:00
Vitaly Buka eb69763ad8 [NFC][scudo] Rename internal function 2021-05-27 10:41:07 -07:00
Lang Hames 95ce0def7c [ORC-RT] Add endianness support to the ORC runtime.
endian.h is a cut-down version of llvm/Support/SwapByteOrder.h. It will be used
in upcoming serialization utilities for the ORC runtime.
2021-05-26 17:23:35 -07:00
Mitch Phillips 2dba40561a Revert "[scudo] Build scudo_standalone on Android and Fuchsia."
This reverts commit 2fe987e6ba.

Broke the Android buildbots. Turns out a couple more tweaks are
necessary to turn them back on.
2021-05-26 16:52:13 -07:00
Mitch Phillips 2fe987e6ba [scudo] Build scudo_standalone on Android and Fuchsia.
This should be fine now, and is necessary for D102543.

Reviewed By: cryptoad

Differential Revision: https://reviews.llvm.org/D103200
2021-05-26 15:29:28 -07:00
Matt Morehouse fd0a2f75ff Revert "Refactor mutation strategies into a standalone library"
This reverts commit c4a41cd77c due to
buildbot failure.
2021-05-26 15:16:43 -07:00
Matt Morehouse 1032886a41 [libFuzzer] Add missing FuzzerBuiltinsMsvc.h include.
Should fix the Windows build.
2021-05-26 14:38:27 -07:00
Aaron Green c4a41cd77c Refactor mutation strategies into a standalone library
This change introduces libMutagen/libclang_rt.mutagen.a as a subset of libFuzzer/libclang_rt.fuzzer.a. This library contains only the fuzzing strategies used by libFuzzer to produce new test inputs from provided inputs, dictionaries, and SanitizerCoverage feedback.

Most of this change is simply moving sections of code to one side or the other of the library boundary. The only meaningful new code is:

* The Mutagen.h interface and its implementation in Mutagen.cpp.
* The following methods in MutagenDispatcher.cpp:
  * UseCmp
  * UseMemmem
  * SetCustomMutator
  * SetCustomCrossOver
  * LateInitialize (similar to the MutationDispatcher's original constructor)
  * Mutate_AddWordFromTORC (uses callbacks instead of accessing TPC directly)
  * StartMutationSequence
  * MutationSequence
  * DictionaryEntrySequence
  * RecommendDictionary
  * RecommendDictionaryEntry
* FuzzerMutate.cpp (which now justs sets callbacks and handles printing)
* MutagenUnittest.cpp (which adds tests of Mutagen.h)

A note on performance: This change was tested with a 100 passes of test/fuzzer/LargeTest.cpp with 1000 runs per pass, both with and without the change. The running time distribution was qualitatively similar both with and without the change, and the average difference was within 30 microseconds (2.240 ms/run vs 2.212 ms/run, respectively). Both times were much higher than observed with the fully optimized system clang (~0.38 ms/run), most likely due to the combination of CMake "dev mode" settings (e.g. CMAKE_BUILD_TYPE="Debug", LLVM_ENABLE_LTO=OFF, etc.). The difference between the two versions built similarly seems to be "in the noise" and suggests no meaningful performance degradation.

Reviewed By: morehouse

Differential Revision: https://reviews.llvm.org/D102447
2021-05-26 13:27:49 -07:00
Mitch Phillips f7c5c0d87b Revert "[Scudo] Make -fsanitize=scudo use standalone. Migrate tests."
This reverts commit 6911114d8c.

Broke the QEMU sanitizer bots due to a missing header dependency. This
actually needs to be fixed on the bot-side, but for now reverting this
patch until I can fix up the bot.
2021-05-26 10:50:26 -07:00
Mitch Phillips 6911114d8c [Scudo] Make -fsanitize=scudo use standalone. Migrate tests.
This patch moves -fsanitize=scudo to link the standalone scudo library,
rather than the original compiler-rt based library. This is one of the
major remaining roadblocks to deleting the compiler-rt based scudo,
which should not be used any more. The standalone Scudo is better in
pretty much every way and is much more suitable for production usage.

As well as patching the litmus tests for checking that the
scudo_standalone lib is linked instead of the scudo lib, this patch also
ports all the scudo lit tests to run under scudo standalone.

This patch also adds a feature to scudo standalone that was under test
in the original scudo - that arguments passed to an aligned operator new
were checked that the alignment was a power of two.

Some lit tests could not be migrated, due to the following issues:
 1. Features that aren't supported in scudo standalone, like the rss
 limit.
 2. Different quarantine implementation where the test needs some more
 thought.
 3. Small bugs in scudo standalone that should probably be fixed, like
 the Secondary allocator having a full page on the LHS of an allocation
 that only contains the chunk header, so underflows by <= a page aren't
 caught.
 4. Slight differences in behaviour that's technically correct, like
 'realloc(malloc(1), 0)' returns nullptr in standalone, but a real
 pointer in old scudo.
 5. Some tests that might be migratable, but not easily.

Tests that are obviously not applicable to scudo standalone (like
testing that no sanitizer symbols made it into the DSO) have been
deleted.

After this patch, the remaining work is:
 1. Update the Scudo documentation. The flags have changed, etc.
 2. Delete the old version of scudo.
 3. Patch up the tests in lit-unmigrated, or fix Scudo standalone.

Reviewed By: cryptoad, vitalybuka

Differential Revision: https://reviews.llvm.org/D102543
2021-05-26 10:03:17 -07:00
Kostya Kortchinsky a45877eea8 [scudo] Get rid of initLinkerInitialized
Now that everything is forcibly linker initialized, it feels like a
good time to get rid of the `init`/`initLinkerInitialized` split.

This allows to get rid of various `memset` construct in `init` that
gcc complains about (this fixes a Fuchsia open issue).

I added various `DCHECK`s to ensure that we would get a zero-inited
object when entering `init`, which required ensuring that
`unmapTestOnly` leaves the object in a good state (tests are currently
the only location where an allocator can be "de-initialized").

Running the tests with `--gtest_repeat=` showed no issue.

Differential Revision: https://reviews.llvm.org/D103119
2021-05-26 09:53:40 -07:00
Fangrui Song e67259531d [sanitizer] Let glibc aarch64 use O(1) GetTls
The generic approach can still be used by musl and FreeBSD. Note: on glibc
2.31, TLS_PRE_TCB_SIZE is 0x700, larger than ThreadDescriptorSize() by 16, but
this is benign: as long as the range includes pthread::{specific_1stblock,specific}
pthread_setspecific will not cause false positives.

Note: the state before afec953857 underestimated
the TLS size a lot (nearly ThreadDescriptorSize() = 1776).
That may explain why afec953857 actually made some
tests pass.
2021-05-25 16:28:17 -07:00
Alexandre Ganea dd2be15ff9 [gcov] Silence warning: comparison of integers of different signs
When building with Clang 11 on Windows, silence the following:

[432/5643] Building C object projects\compiler-rt\lib\profile\CMakeFiles\clang_rt.profile-x86_64.dir\GCDAProfiling.c.obj
F:\aganea\llvm-project\compiler-rt\lib\profile\GCDAProfiling.c(464,13): warning: comparison of integers of different signs: 'uint32_t' (aka 'unsigned int') and 'int' [-Wsign-compare]
    if (val != (gcov_version >= 90 ? GCOV_TAG_OBJECT_SUMMARY
        ~~~ ^   ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
1 warning generated.
2021-05-25 18:46:37 -04:00
Vitaly Buka e14696bfd7 [NFC][SCUDO] Fix unittest for -gtest_repeat=10
Reviewed By: cryptoad

Differential Revision: https://reviews.llvm.org/D103122
2021-05-25 15:32:42 -07:00
Fangrui Song 3a678fe3e2 [sanitizer][test] s/A<10>/A<7>/ to fix "WARNING: Symbolizer buffer too small" which is somehow a hard error on s390x
https://reviews.llvm.org/D102046#2766553
2021-05-25 12:41:07 -07:00
Bruno Cardoso Lopes 6c35991ca0 [TSAN][CMake] Add support to run lit on individual tests
Handy when testing specific files, already supported in other components.

Example:
cd build; ./bin/llvm-lit ../compiler-rt/test/tsan/ignore_free.cpp

Differential Revision: https://reviews.llvm.org/D103054
2021-05-25 12:33:02 -07:00
Vitaly Buka d1e5f046cc Revert "[NFC][scudo] Let disableMemoryTagChecksTestOnly to fail"
This reverts commit 2c212db4ea.

It's not needed.
2021-05-25 11:53:42 -07:00
Vitaly Buka 8e30b55c82 [scudo] Fix CHECK implementation
Cast of signed types to u64 breaks comparison.
Also remove double () around operands.

Reviewed By: cryptoad, hctim

Differential Revision: https://reviews.llvm.org/D103060
2021-05-25 10:55:52 -07:00
Vitaly Buka 6a84d374d7 [scudo] Consistent setting of SCUDO_DEBUG
Make sure that if SCUDO_DEBUG=1 in tests
then we had the same in the scudo
library itself.

Reviewed By: cryptoad, hctim

Differential Revision: https://reviews.llvm.org/D103061
2021-05-25 10:49:01 -07:00
Kostya Kortchinsky 1872283457 [scudo] Rework dieOnMapUnmapError
Said function had a few shortfalls:
- didn't set an abort message on Android
- was logged on several lines
- didn't provide extra information like the size requested if OOM'ing

This improves the function to address those points.

Differential Revision: https://reviews.llvm.org/D103034
2021-05-25 08:27:37 -07:00
Vitaly Buka a0169b2ed1 [NFC][scudo] Add paramenters DCHECKs
Reviewed By: hctim

Differential Revision: https://reviews.llvm.org/D103042
2021-05-24 18:06:21 -07:00
Vitaly Buka f5bde3d476 [NFC][scudo] Avoid cast in test 2021-05-24 17:14:38 -07:00
Mitch Phillips 1fb6a03072 [scudo] Add unmapTestOnly() to secondary.
When trying to track down a vaddr-poisoning bug, I found that that the
secondary cache isn't emptied on test teardown. We should probably do
that to make the tests hermetic. Otherwise, repeating the tests lots of
times using --gtest_repeat fails after the mmap vaddr space is
exhausted.

To repro:
$ ninja check-scudo_standalone # build
$ ./projects/compiler-rt/lib/scudo/standalone/tests/ScudoUnitTest-x86_64-Test \
--gtest_filter=ScudoSecondaryTest.*:-ScudoSecondaryTest.SecondaryCombinations \
--gtest_repeat=10000

Reviewed By: cryptoad

Differential Revision: https://reviews.llvm.org/D102874
2021-05-24 16:09:02 -07:00
Jinsong Ji bec6b02252 [compiler-rt][scudo] Fix sign-compare warnings
Fix buildbot failure
https://lab.llvm.org/buildbot/#/builders/57/builds/6542/steps/6/logs/stdio

/llvm-project/llvm/utils/unittest/googletest/include/gtest/gtest.h:1629:28:
error: comparison of integers of different signs: 'const unsigned long'
and 'const int' [-Werror,-Wsign-compare]
GTEST_IMPL_CMP_HELPER_(GT, >);
~~~~~~~~~~~~~~~~~~~~~~~~~~^~
/llvm-project/llvm/utils/unittest/googletest/include/gtest/gtest.h:1609:12:
note: expanded from macro 'GTEST_IMPL_CMP_HELPER_'
  if (val1 op val2) {\
      ~~~~ ^  ~~~~
/llvm-project/compiler-rt/lib/scudo/standalone/tests/common_test.cpp:30:3:
note: in instantiation of function template specialization
'testing::internal::CmpHelperGT<unsigned long, int>' requested here
  EXPECT_GT(OnStart, 0);
  ^

Reviewed By: vitalybuka

Differential Revision: https://reviews.llvm.org/D103029
2021-05-24 21:33:02 +00:00
George Balatsouras a11cb10a36 [dfsan] Add function that prints origin stack trace to buffer
Reviewed By: stephan.yichao.zhao

Differential Revision: https://reviews.llvm.org/D102451
2021-05-24 11:09:03 -07:00
Vitaly Buka 6435ca4e2b [NFC][scudo] Small test cleanup
Fixing issues raised on D102979 review.

Reviewed By: cryptoad

Differential Revision: https://reviews.llvm.org/D102994
2021-05-24 10:16:44 -07:00
Kostya Kortchinsky 20c1f94220 [scudo] Separate Fuchsia & Default SizeClassMap
The Fuchsia allocator config was using the default size class map.

This CL gives Fuchsia its own size class map and changes a couple of
things in the default one:
- make `SizeDelta` configurable in `Config` for a fixed size class map
  as it currently is for a table size class map;
- switch `SizeDelta` to 0 for the default config, it allows for size
  classes that allow for power of 2s, and overall better wrt pages
  filling;
- increase the max number of caches pointers to 14 in the default,
  this makes the transfer batch 64/128 bytes on 32/64-bit platforms,
  which is cache-line friendly (previous size was 48/96 bytes).

The Fuchsia size class map remains untouched for now, this doesn't
impact Android which uses the table size class map.

Differential Revision: https://reviews.llvm.org/D102783
2021-05-24 08:54:08 -07:00
Vitaly Buka 93d1e5822e [NFC][scudo] Enforce header size alignment
As-is it should not change struct size, but it will
help to keep correct size if more fields added.
2021-05-23 14:21:35 -07:00
Vitaly Buka 887dda5dcd [NFC][scudo] Replace size_t with uptr 2021-05-22 22:55:53 -07:00
Vitaly Buka 0bccdf82f7 [NFC][scudo] Add releasePagesToOS test 2021-05-22 22:42:59 -07:00
Vitaly Buka 6994bf7dad [NFC][scudo] Move SKIP_ON_FUCHSIA to common header 2021-05-22 22:42:59 -07:00