Commit Graph

14162 Commits

Author SHA1 Message Date
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
Vitaly Buka 5992823008 [NFC][sanitizer] Remove unused variable 2021-05-21 16:11:51 -07:00
Jon Roelofs cc9c895d88 [compiler-rt][profile] Explicitly specify PROFILE_SOURCES extensions. NFC 2021-05-21 14:46:08 -07:00
Vitaly Buka f50b87e9ef [NFC][sanitizer] Fix android bot after D102815
https://lab.llvm.org/buildbot/#/builders/77/builds/6519
2021-05-21 14:08:04 -07:00
Vitaly Buka 1c6272a481 [scudo] Try to re-enabled the test on arm
It's probably fixed by D102886.

Builder to watch https://lab.llvm.org/buildbot/#/builders/clang-cmake-armv7-full

Reviewed By: hctim, cryptoad

Differential Revision: https://reviews.llvm.org/D102887
2021-05-21 10:57:49 -07:00
Lang Hames 16b284e99e [ORC-RT] Add missing headers to CMakeLists.txt. 2021-05-21 10:17:47 -07:00
Vitaly Buka 53ec41a49c [scudo][NFC] Split BasicTest further
It's still the slowest test under our emulator.
2021-05-20 23:28:08 -07:00
Vitaly Buka 384a460e59 [scudo] Fix compilation after D102886 2021-05-20 22:10:12 -07:00
George Balatsouras 7c35bf85bf [sanitizer_common] Remove unused var in test
Reviewed By: stephan.yichao.zhao

Differential Revision: https://reviews.llvm.org/D102898
2021-05-20 20:42:30 -07:00
George Balatsouras d10c1ba487 [sanitizer_common] Add StackTrace::PrintTo method
This method is like StackTrace::Print but instead of printing to stderr
it copies its output to a user-provided buffer.

Part of https://reviews.llvm.org/D102451.

Reviewed By: vitalybuka, stephan.yichao.zhao

Differential Revision: https://reviews.llvm.org/D102815
2021-05-20 19:39:38 -07:00
Vitaly Buka 51fe7ddce2 [NFC][scudo] Fix typo in comment 2021-05-20 19:37:33 -07:00
Vitaly Buka 2c212db4ea [NFC][scudo] Let disableMemoryTagChecksTestOnly to fail
If this happend we can't run corresponding test.
2021-05-20 19:25:20 -07:00
Vitaly Buka 96b760607f [scudo] Fix EXPECT_DEATH tests
Put allocate/deallocate next to memory
access inside EXPECT_DEATH block.
This way we reduce probability that memory is not mapped
by unrelated code.

It's still not absolutely guaranty that mmap does not
happen so we repeat it few times to be sure.

Reviewed By: cryptoad

Differential Revision: https://reviews.llvm.org/D102886
2021-05-20 17:08:15 -07:00
Mitch Phillips f4ccbaf310 [scudo] Add supported architectures.
Adds extra supported architectures that were available for vanilla
scudo, in preparation for D102543. Hopefully the dust has settled and
7d0a81ca38 is no longer an issue.

Reviewed By: cryptoad, vitalybuka

Differential Revision: https://reviews.llvm.org/D102648
2021-05-20 11:22:51 -07:00
Reid Kleckner 8f20ac9595 [PGO] Don't reference functions unless value profiling is enabled
This reduces the size of chrome.dll.pdb built with optimizations,
coverage, and line table info from 4,690,210,816 to 2,181,128,192, which
makes it possible to fit under the 4GB limit.

This change can greatly reduce binary size in coverage builds, which do
not need value profiling. IR PGO builds are unaffected. There is a minor
behavior change for frontend PGO.

PGO and coverage both use InstrProfiling to create profile data with
counters. PGO records the address of each function in the __profd_
global. It is used later to map runtime function pointer values back to
source-level function names. Coverage does not appear to use this
information.

Recording the address of every function with code coverage drastically
increases code size. Consider this program:

  void foo();
  void bar();
  inline void inlineMe(int x) {
    if (x > 0)
      foo();
    else
      bar();
  }
  int getVal();
  int main() { inlineMe(getVal()); }

With code coverage, the InstrProfiling pass runs before inlining, and it
captures the address of inlineMe in the __profd_ global. This greatly
increases code size, because now the compiler can no longer delete
trivial code.

One downside to this approach is that users of frontend PGO must apply
the -mllvm -enable-value-profiling flag globally in TUs that enable PGO.
Otherwise, some inline virtual method addresses may not be recorded and
will not be able to be promoted. My assumption is that this mllvm flag
is not popular, and most frontend PGO users don't enable it.

Differential Revision: https://reviews.llvm.org/D102818
2021-05-20 11:09:24 -07:00
Mitch Phillips 577a80bff8 [scudo] Disable secondary cache-unmap tests on arm32.
Looks like secondary pointers don't get unmapped on one of the arm32
bots. In the interests of landing some dependent patches, disable this
test on arm32 so that it can be tested in isolation later.

Reviewed By: cryptoad, vitalybuka

Split from differential patchset (1/2): https://reviews.llvm.org/D102648
2021-05-20 11:07:45 -07:00
Lang Hames d22b27cfde [ORC-RT] Add string_view and span utilities for use by the ORC runtime.
These are substitutes for std::string_view (and llvm::StringRef) and std::span
(and llvm::ArrayRef) for use by the ORC runtime.
2021-05-20 11:02:44 -07:00
Tamar Christina 68d5235cb5 libsanitizer: Remove cyclades inclusion in sanitizer
The Linux kernel has removed the interface to cyclades from
the latest kernel headers[1] due to them being orphaned for the
past 13 years.

libsanitizer uses this header when compiling against glibc, but
glibcs itself doesn't seem to have any references to cyclades.

Further more it seems that the driver is broken in the kernel and
the firmware doesn't seem to be available anymore.

As such since this is breaking the build of libsanitizer (and so the
GCC bootstrap[2]) I propose to remove this.

[1] https://lkml.org/lkml/2021/3/2/153
[2] https://gcc.gnu.org/bugzilla/show_bug.cgi?id=100379

Reviewed By: eugenis

Differential Revision: https://reviews.llvm.org/D102059
2021-05-20 18:55:26 +01:00
Tamar Christina 0d3619864c Revert "libsanitizer: Guard cyclades inclusion in sanitizer"
This reverts commit f7c5351552.

To investigate a test failure.
2021-05-20 14:43:57 +01:00
Tamar Christina f7c5351552 libsanitizer: Guard cyclades inclusion in sanitizer
The Linux kernel has removed the interface to cyclades from
the latest kernel headers[1] due to them being orphaned for the
past 13 years.

libsanitizer uses this header when compiling against glibc, but
glibcs itself doesn't seem to have any references to cyclades.

Further more it seems that the driver is broken in the kernel and
the firmware doesn't seem to be available anymore.

As such since this is breaking the build of libsanitizer (and so the
GCC bootstrap[2]) I propose to remove this.

[1] https://lkml.org/lkml/2021/3/2/153
[2] https://gcc.gnu.org/bugzilla/show_bug.cgi?id=100379

Reviewed By: eugenis

Differential Revision: https://reviews.llvm.org/D102059
2021-05-20 11:06:56 +01:00
Vitaly Buka 5faeefd4fa [tsan] Deflake pthread_atfork_deadlock3
sleep(1) does not guaranty afterfork order.
Also relative child/parent afterfork order is not important for this test so we
can just avoid checking that.

Reviewed By: dvyukov

Differential Revision: https://reviews.llvm.org/D102810
2021-05-19 22:59:37 -07:00
Vitaly Buka 09a8372726 [NFC][tsan] clang-format the test 2021-05-19 14:03:50 -07:00
Lang Hames 1dfa47910a [ORC-RT] Add ORC runtime error and expected types.
These will be used for error propagation and handling in the ORC runtime.

The implementations of these types are cut-down versions of the error
support in llvm/Support/Error.h. Most advice on llvm::Error and llvm::Expected
(e.g. from the LLVM Programmer's manual) applies equally to __orc_rt::Error
and __orc_rt::Expected. The primary difference is the mechanism for testing
and handling error types: The ORC runtime uses a new 'error_cast' operation
to replace the handleErrors family of functions. See error_cast comments in
error.h.
2021-05-19 13:31:25 -07:00
Vedant Kumar 7014a10161 [profile] Skip mmap() if there are no counters
If there are no counters, an mmap() of the counters section would fail
due to the size argument being too small (EINVAL).

rdar://78175925

Differential Revision: https://reviews.llvm.org/D102735
2021-05-19 09:31:40 -07:00
Dmitry Vyukov c1eaa1168a tsan: mark sigwait as blocking
Add a test case reported in:
https://github.com/google/sanitizers/issues/1401
and fix it.
The code assumes sigwait will process other signals.

Reviewed By: vitalybuka

Differential Revision: https://reviews.llvm.org/D102057
2021-05-19 13:03:20 +02:00
Peter Collingbourne 8e93d10633 scudo: Test realloc on increasing size buffers.
While developing a change to the allocator I ended up breaking
realloc on secondary allocations with increasing sizes. That didn't
cause any of the unit tests to fail, which indicated that we're
missing some test coverage here. Add a unit test for that case.

Differential Revision: https://reviews.llvm.org/D102716
2021-05-18 14:59:30 -07:00
Martin Storsjö 9f57675e52 [compiler-rt] [builtins] Provide a SEH specific __gcc_personality_seh0
This matches how __gxx_personality_seh0 is hooked up in libcxxabi.

Differential Revision: https://reviews.llvm.org/D102530
2021-05-18 23:52:33 +03:00
Lang Hames 9e5f3dd9db [ORC-RT] Add apply_tuple utility.
This is a substitute for std::apply, which we can't use until we move to c++17.

apply_tuple will be used in upcoming the upcoming wrapper-function utils code.
2021-05-18 08:44:15 -07:00
Lang Hames bd6c93c004 [ORC-RT] Add compiler abstraction header for the ORC runtime.
This header provides helper macros to insulate the rest of the ORC runtime from
compiler specifics.
2021-05-18 08:44:15 -07:00
Vitaly Buka 2e92f1a9bc [NFC][scudo] Reduce test region size on MIPS32 2021-05-18 00:15:22 -07:00
Dmitry Vyukov 00a1007545 sanitizer_common/symbolizer: fix crashes during exit
Override __cxa_atexit and ignore callbacks.
This prevents crashes in a configuration when the symbolizer
is built into sanitizer runtime and consequently into the test process.
LLVM libraries have some global objects destroyed during exit,
so if the test process triggers any bugs after that, the symbolizer crashes.
An example stack trace of such crash:

For the standalone llvm-symbolizer this does not hurt,
we just don't destroy few global objects on exit.

Reviewed By: kda

Differential Revision: https://reviews.llvm.org/D102470
2021-05-18 08:58:08 +02:00
Vitaly Buka 1eb78a64c4 [NFC][scudo] Clang-format tests 2021-05-17 12:31:09 -07:00
Matt Morehouse d97bab6511 [HWASan] Don't build alias mode on non-x86.
Alias mode is not expected work on non-x86, so don't build it there.
Should fix the aarch64 bot.
2021-05-17 10:32:16 -07:00
Matt Morehouse 5f58322368 [HWASan] Build separate LAM runtime on x86_64.
Since we have both aliasing mode and Intel LAM on x86_64, we need to
choose the mode at either run time or compile time.  This patch
implements the plumbing to build both and choose between them at
compile time.

Reviewed By: vitalybuka, eugenis

Differential Revision: https://reviews.llvm.org/D102286
2021-05-17 09:19:06 -07:00
Nico Weber 452e035729 [gn build] Add build file for msan runtime
Works for the examples on
https://clang.llvm.org/docs/MemorySanitizer.html

Differential Revision: https://reviews.llvm.org/D102554
2021-05-17 06:58:10 -04:00
Florian Hahn 086af17399
Revert "tsan: mark sigwait as blocking"
This reverts commit 5dad3d1ba9.

The added test (signal_block2.cpp) does not terminate on some Darwin
configurations and is causing Green Dragon bots to fail. First
failure of the test started in
    http://green.lab.llvm.org/green/job/clang-stage1-RA/20767/
2021-05-17 10:57:59 +01:00
Florian Hahn 65936b9529
Revert "[NFC][LSAN] Limit the number of concurrent threads is the test"
This reverts commit 2a73b7bd8c.

This appears to be causing the following failures on GreenDragon:
  LeakSanitizer-AddressSanitizer-x86_64 :: TestCases/many_threads_detach.cpp
  LeakSanitizer-Standalone-x86_64 :: TestCases/many_threads_detach.cpp

First failure:
    http://green.lab.llvm.org/green/job/clang-stage1-RA/20754/

Still failing in latest build:
    http://green.lab.llvm.org/green/job/clang-stage1-RA/20928/
2021-05-17 09:29:49 +01:00
Vitaly Buka 029005a2e2 [NFC][sanitizer] Fix 'macro redefined' warning in test 2021-05-16 19:11:07 -07:00
Kai Luo d56729b4a4 [AIX][compiler-rt] Build and install standalone libatomic
On AIX, we have to ship `libatomic.a` for compatibility. First, a new `clang_rt.atomic` is added. Second, use added cmake modules for AIX, we are able to build a compatible libatomic.a for AIX. The second step can't be perfectly implemented with cmake now since AIX's archive approach is kinda unique, i.e., archiving shared libraries into a static archive file.

Reviewed By: jsji

Differential Revision: https://reviews.llvm.org/D102155
2021-05-16 05:04:08 +00:00
Dan Liew b7f60d861a [Compiler-rt] Downgrade another fatal error to warning
https://reviews.llvm.org/D101681 landed a change to check the testing
configuration which relies on using the `-print-runtime-dir` flag of
clang to determine where the runtime testing library is.

The patch treated not being able to find the path reported by clang
as an error. Unfortunately this seems to break the
`llvm-clang-win-x-aarch64` bot. Either the bot is misconfigured or
clang is reporting a bogus path.

To temporarily unbreak the bot downgrade the fatal error to a warning.
While we're here also print information about the command used to
determine the path to aid debugging.
2021-05-15 11:09:34 -07:00
Dan Liew 7085cd2f29 [Compiler-rt] Downgrade fatal error about unsupported test configuration
to a warning.

https://reviews.llvm.org/D101681 introduced a check to make sure the
compiler and compiler-rt were using the same library path when
`COMPILER_RT_TEST_STANDALONE_BUILD_LIBS=ON`, i.e. the developer's
intention is to test the just built libs rather that shipped with the
compiler used for testing.

It seems this broken some bots that are likely misconfigured.

So to unbreak them, for now let's make this a warning so the bot
owners can investigate without breaking their builds.
2021-05-15 10:52:10 -07:00
Vitaly Buka 0a621d3398 [sanitizer] Disable test on Android
readelf needs access to the actual compiled binary, but it's replaced
by a wrapper script.
2021-05-14 22:04:35 -07:00
Dan Liew ad7e12226f [Compiler-rt] Distinguish between testing just built runtime libraries and the libraries shipped with the compiler.
The path to the runtime libraries used by the compiler under test
is normally identical to the path where just built libraries are
created. However, this is not necessarily the case when doing standalone
builds. This is because the external compiler used by tests may choose
to get its runtime libraries from somewhere else.

When doing standalone builds there are two types of testing we could be
doing:

* Test the just built runtime libraries.
* Test the runtime libraries shipped with the compile under test.

Both types of testing are valid but it confusingly turns out compiler-rt
actually did a mixture of these types of testing.

* The `test/builtins/Unit/` test suite always tested the just built runtime
  libraries.
* All other testsuites implicitly use whatever runtime library the
  compiler decides to link.

There is no way for us to infer which type of testing the developer
wants so this patch introduces a new
`COMPILER_RT_TEST_STANDALONE_BUILD_LIBS` CMake
option which explicitly declares which runtime libraries should be
tested. If it is `ON` then the just built libraries should be tested,
otherwise the libraries in the external compiler should be tested.

When testing starts the lit test suite queries the compiler used for
testing to see where it will get its runtime libraries from.  If these
paths are identical no action is taken (the common case). If the paths
are not identical then we check the value of
`COMPILER_RT_TEST_STANDALONE_BUILD_LIBS` (progated into the config as
`test_standalone_build_libs`) and check if the test suite supports testing in the
requested configuration.

* If we want to test just built libs and the test suite supports it
  (currently only `test/builtins/Unit`) then testing proceeds without any changes.
* If we want to test the just built libs and the test suite doesn't
  support it we emit a fatal error to prevent the developer from
  testing the wrong runtime libraries.
* If we are testing the compiler's built libs then we adjust
  `config.compiler_rt_libdir` to point at the compiler's runtime
  directory. This makes the `test/builtins/Unit` tests use the
  compiler's builtin library. No other changes are required because
  all other testsuites implicitly use the compiler's built libs.

To make the above work the
`test_suite_supports_overriding_runtime_lib_path` test suite config
option has been introduced so we can identify what each test suite
supports.

Note all of these checks **have to be performed** when lit runs.
We cannot run the checks at CMake generation time because
multi-configuration build systems prevent us from knowing what the
paths will be.

We could perhaps support `COMPILER_RT_TEST_STANDALONE_BUILD_LIBS` being
`ON` for most test suites (when the runtime library paths differs) in
the future by specifiying a custom compiler resource directory path.
Doing so is out of scope for this patch.

rdar://77182297

Differential Revision: https://reviews.llvm.org/D101681
2021-05-14 18:07:34 -07:00
Benjamin Kramer cb846654c6 [compiler-rt] Fix deprection warnings on INSTANTIATE_TEST_CASE_P 2021-05-15 00:24:02 +02:00
Mitch Phillips 597ecf9fb7 [msan] [NFC] Add newline to EOF in test. 2021-05-14 15:00:00 -07:00
Mitch Phillips 6c913b2f37 [Scudo] Delete unused flag 'rss_limit_mb'.
EOM.

Reviewed By: cryptoad

Differential Revision: https://reviews.llvm.org/D102529
2021-05-14 13:45:43 -07:00
Fangrui Song deb2b20510 [sanitizer] Commit a missing change in BufferedStackTrace::Unwind 2021-05-14 12:41:34 -07:00
Fangrui Song fa27255d16 [sanitizer] Fall back to fast unwinder
`-fno-exceptions -fno-asynchronous-unwind-tables` compiled programs don't
produce .eh_frame on Linux and other ELF platforms, so the slow unwinder cannot
print stack traces. Just fall back to the fast unwinder: this allows
-fno-asynchronous-unwind-tables without requiring the sanitizer option
`fast_unwind_on_fatal=1`

Reviewed By: #sanitizers, vitalybuka

Differential Revision: https://reviews.llvm.org/D102046
2021-05-14 12:27:33 -07:00
Mitch Phillips c17ac8432e [GWP-ASan] Migrate lit tests from old Scudo -> Standalone.
This removes one of the last dependencies on old Scudo, and should allow
us to delete the old Scudo soon.

Reviewed By: vitalybuka, cryptoad

Differential Revision: https://reviews.llvm.org/D102349
2021-05-14 10:41:48 -07:00
Matt Morehouse b7d1ab75cf [HWASan] Add aliasing flag and enable HWASan to use it.
-fsanitize-hwaddress-experimental-aliasing is intended to distinguish
aliasing mode from LAM mode on x86_64.  check-hwasan is configured
to use aliasing mode while check-hwasan-lam is configured to use LAM
mode.

The current patch doesn't actually do anything differently in the two
modes.  A subsequent patch will actually build the separate runtimes
and use them in each mode.

Currently LAM mode tests must be run in an emulator that
has LAM support.  To ensure LAM mode isn't broken by future patches, I
will next set up a QEMU buildbot to run the HWASan tests in LAM.

Reviewed By: vitalybuka

Differential Revision: https://reviews.llvm.org/D102288
2021-05-14 09:47:20 -07:00
Fangrui Song 261d6e05d5 [sanitizer] Simplify __sanitizer::BufferedStackTrace::UnwindImpl implementations
Intended to be NFC. D102046 relies on the refactoring for stack boundaries.
2021-05-13 21:26:31 -07:00
Peter Collingbourne f79929acea scudo: Fix MTE error reporting for zero-sized allocations.
With zero-sized allocations we don't actually end up storing the
address tag to the memory tag space, so store it in the first byte of
the chunk instead so that we can find it later in getInlineErrorInfo().

Differential Revision: https://reviews.llvm.org/D102442
2021-05-13 18:14:03 -07:00
Peter Collingbourne 9567131d03 scudo: Check for UAF in ring buffer before OOB in more distant blocks.
It's more likely that we have a UAF than an OOB in blocks that are
more than 1 block away from the fault address, so the UAF should
appear first in the error report.

Differential Revision: https://reviews.llvm.org/D102379
2021-05-13 18:14:02 -07:00
H.J. Lu 72797dedb7 [sanitizer] Use size_t on g_tls_size to fix build on x32
On x32 size_t == unsigned int, not unsigned long int:

../../../../../src-master/libsanitizer/sanitizer_common/sanitizer_linux_libcdep.cpp: In function ??void __sanitizer::InitTlsSize()??:
../../../../../src-master/libsanitizer/sanitizer_common/sanitizer_linux_libcdep.cpp:209:55: error: invalid conversion from ??__sanitizer::uptr*?? {aka ??long unsigned int*??} to ??size_t*?? {aka ??unsigned int*??} [-fpermissive]
  209 |   ((void (*)(size_t *, size_t *))get_tls_static_info)(&g_tls_size, &tls_align);
      |                                                       ^~~~~~~~~~~
      |                                                       |
      |                                                       __sanitizer::uptr* {aka long unsigned int*}

by using size_t on g_tls_size.  This is to fix:

https://bugs.llvm.org/show_bug.cgi?id=50332

Reviewed By: MaskRay

Differential Revision: https://reviews.llvm.org/D102446
2021-05-13 18:07:11 -07:00
Bruno Cardoso Lopes fd184c062c [TSAN] Honor failure memory orders in AtomicCAS
LLVM has lifted strong requirements for CAS failure memory orders in 431e3138a and 819e0d105e.

Add support for honoring them in `AtomicCAS`.

https://github.com/google/sanitizers/issues/970

Differential Revision: https://reviews.llvm.org/D99434
2021-05-13 01:07:22 -07:00
Peter Collingbourne 6732a5328c scudo: Require fault address to be in bounds for UAF.
The bounds check that we previously had here was suitable for secondary
allocations but not for UAF on primary allocations, where it is likely
to result in false positives. Fix it by using a different bounds check
for UAF that requires the fault address to be in bounds.

Differential Revision: https://reviews.llvm.org/D102376
2021-05-12 18:02:10 -07:00
David Spickett 7d0a81ca38 Revert "[scudo] Enable arm32 arch"
This reverts commit b1a77e465e.

Which has a failing test on our armv7 bots:
https://lab.llvm.org/buildbot/#/builders/59/builds/1812
2021-05-12 13:12:28 +01:00
Dmitry Vyukov 8aa7f28497 scudo: fix CheckFailed-related build breakage
I was running:

$ ninja check-sanitizer check-msan check-asan \
  check-tsan check-lsan check-ubsan check-cfi \
  check-profile check-memprof check-xray check-hwasan

but missed check-scudo...

Differential Revision: https://reviews.llvm.org/D102314
2021-05-12 09:10:34 +02:00
Dmitry Vyukov 1dc838717a tsan: fix syscall test on aarch64
Add missing includes and use SYS_pipe2 instead of SYS_pipe
as it's not present on some arches.

Differential Revision: https://reviews.llvm.org/D102311
2021-05-12 09:00:51 +02:00
Dmitry Vyukov 2721e27c3a sanitizer_common: deduplicate CheckFailed
We have some significant amount of duplication around
CheckFailed functionality. Each sanitizer copy-pasted
a chunk of code. Some got random improvements like
dealing with recursive failures better. These improvements
could benefit all sanitizers, but they don't.

Deduplicate CheckFailed logic across sanitizers and let each
sanitizer only print the current stack trace.
I've tried to dedup stack printing as well,
but this got me into cmake hell. So let's keep this part
duplicated in each sanitizer for now.

Reviewed By: vitalybuka

Differential Revision: https://reviews.llvm.org/D102221
2021-05-12 08:50:53 +02:00
Dmitry Vyukov 23596fece0 sanitizer_common: don't write into .rodata
setlocale interceptor imitates a write into result,
which may be located in .rodata section.
This is the only interceptor that tries to do this and
I think the intention was to initialize the range for msan.
So do that instead. Writing into .rodata shouldn't happen
(without crashing later on the actual write) and this
traps on my local tsan experiments.

Reviewed By: vitalybuka

Differential Revision: https://reviews.llvm.org/D102161
2021-05-12 07:54:06 +02:00
Dmitry Vyukov 53558ed8a0 sanitizer_common: fix SIG_DFL warning
Currently we have:

sanitizer_posix_libcdep.cpp:146:27: warning: cast between incompatible
  function types from ‘__sighandler_t’ {aka ‘void (*)(int)’} to ‘sa_sigaction_t’
  146 |     sigact.sa_sigaction = (sa_sigaction_t)SIG_DFL;

We don't set SA_SIGINFO, so we need to assign to sa_handler.
And SIG_DFL is meant for sa_handler, so this gets rid of both
compiler warning, type cast and potential runtime misbehavior.

Reviewed By: vitalybuka

Differential Revision: https://reviews.llvm.org/D102162
2021-05-12 07:23:20 +02:00
Dmitry Vyukov 8214764f35 tsan: declare annotations in test.h
We already declare subset of annotations in test.h.
But some are duplicated and declared in tests.
Move all annotation declarations to test.h.

Reviewed By: vitalybuka

Differential Revision: https://reviews.llvm.org/D102152
2021-05-12 07:22:39 +02:00
Dmitry Vyukov 5dad3d1ba9 tsan: mark sigwait as blocking
Add a test case reported in:
https://github.com/google/sanitizers/issues/1401
and fix it.
The code assumes sigwait will process other signals.

Reviewed By: vitalybuka

Differential Revision: https://reviews.llvm.org/D102057
2021-05-12 06:56:18 +02:00
Dmitry Vyukov 04b2ada51c tsan: add a simple syscall test
Add a simple test that uses syscall annotations.
Just to ensure at least basic functionality works.
Also factor out annotated syscall wrappers into a separate
header file as they may be useful for future tests.

Reviewed By: vitalybuka

Differential Revision: https://reviews.llvm.org/D102223
2021-05-12 06:42:11 +02:00
Vitaly Buka 7d101e0f6a [NFC][msan] Move setlocale test into sanitizer_common 2021-05-11 19:05:07 -07:00
Evgenii Stepanov a7757f6c22 [hwasan] Stress test for thread creation.
This test has two modes - testing reused threads with multiple loops of
batch create/join, and testing new threads with a single loop of
create/join per fork.

The non-reuse variant catches the problem that was fixed in D101881 with
a high probability.

Differential Revision: https://reviews.llvm.org/D101936
2021-05-11 13:10:53 -07:00
Vitaly Buka 2a73b7bd8c [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-05-11 12:32:53 -07:00
Lang Hames e0b6c99288 Re-apply "[ORC-RT] Add unit test infrastructure, extensible_rtti..."
This reapplies 6d263b6f1c (which was reverted in 1c7c6f2b10) with a fix for a
CMake issue.
2021-05-11 10:28:33 -07:00
Lang Hames 1c7c6f2b10 Revert "[ORC-RT] Add unit test infrastructure, extensible_rtti..."
This reverts commit 6d263b6f1c while I investigate the CMake failures that it
causes in some configurations.
2021-05-11 09:51:12 -07:00
Vitaly Buka c057779d38 [NFC][LSAN] Fix flaky multithreaded test 2021-05-10 17:33:46 -07:00
Lang Hames 6d263b6f1c [ORC-RT] Add unit test infrastructure, extensible_rtti implementation, unit test
Add unit test infrastructure for the ORC runtime, plus a cut-down
extensible_rtti system and extensible_rtti unit test.

Removes the placeholder.cpp source file.

Differential Revision: https://reviews.llvm.org/D102080
2021-05-10 17:15:59 -07:00
Mitch Phillips e78b64df98 [Scudo] Use GWP-ASan's aligned allocations and fixup postalloc hooks.
This patch does a few cleanup things:
 1. The non-standalone scudo has a problem where GWP-ASan allocations
 may not meet alignment requirements where Scudo was requested to have
 alignment >= 16. Use the new GWP-ASan API to fix this.
 2. The standalone variant loses some debugging information inside of
 GWP-ASan because we ask GWP-ASan to allocate an aligned size in the
 frontend. This means reports end up with 'UaF on a 16-byte allocation'
 for a 1-byte allocation with 16-byte alignment. Also use the new API to
 fix this.
 3. Add post-alloc hooks for GWP-ASan intercepted allocations, and add
 stats tracking for GWP-ASan allocations.
 4. Add a small test that checks the alignment of the frontend
 allocator, so that it can be used under GWP-ASan torture mode.
 5. Add GWP-ASan torture mode as a testing configuration to catch these
 regressions.

Depends on D94830, D95889.

Reviewed By: cryptoad

Differential Revision: https://reviews.llvm.org/D95884
2021-05-10 12:56:18 -07:00
Mitch Phillips 8936608e6f [scudo] [GWP-ASan] Add GWP-ASan variant of scudo benchmarks.
GWP-ASan is the "production" variant as compiled by compiler-rt, and it's useful to be able to benchmark changes in GWP-ASan or Scudo's GWP-ASan hooks across versions. GWP-ASan is sampled, and sampled allocations are much slower, but given the amount of allocations that happen under test here - we actually get a reasonable representation of GWP-ASan's negligent performance impact between runs.

Reviewed By: cryptoad

Differential Revision: https://reviews.llvm.org/D101865
2021-05-10 12:14:48 -07:00
David Spickett 831cf15ca6 [compiler-rt] Handle None value when polling addr2line pipe
According to:
https://docs.python.org/3/library/subprocess.html#subprocess.Popen.poll

poll can return None if the process hasn't terminated.

I'm not quite sure how addr2line could end up closing the pipe without
terminating but we did see this happen on one of our bots:
```
<...>scripts/asan_symbolize.py",
line 211, in symbolize
    logging.debug("addr2line exited early (broken pipe), returncode=%d"
% self.pipe.poll())
TypeError: %d format: a number is required, not NoneType
```

Handle None by printing a message that we couldn't get the return
code.

Reviewed By: delcypher

Differential Revision: https://reviews.llvm.org/D101891
2021-05-10 09:46:06 +01:00
Matt Morehouse f09414499c [libFuzzer] Fix stack-overflow-with-asan.test.
Fix function return type and remove check for SUMMARY, since it doesn't
seem to be output in Windows.
2021-05-07 09:18:21 -07:00
Sebastian Poeplau 70cbc6dbef [libFuzzer] Fix stack overflow detection
Address sanitizer can detect stack exhaustion via its SEGV handler, which is
executed on a separate stack using the sigaltstack mechanism. When libFuzzer is
used with address sanitizer, it installs its own signal handlers which defer to
those put in place by the sanitizer before performing additional actions. In the
particular case of a stack overflow, the current setup fails because libFuzzer
doesn't preserve the flag for executing the signal handler on a separate stack:
when we run out of stack space, the operating system can't run the SEGV handler,
so address sanitizer never reports the issue. See the included test for an
example.

This commit fixes the issue by making libFuzzer preserve the SA_ONSTACK flag
when installing its signal handlers; the dedicated signal-handler stack set up
by the sanitizer runtime appears to be large enough to support the additional
frames from the fuzzer.

Reviewed By: morehouse

Differential Revision: https://reviews.llvm.org/D101824
2021-05-07 08:18:28 -07:00
Jianzhou Zhao 87a6325fbe [dfsan] Rename and fix an internal test issue for mmap+calloc
The linker suggests using -Wl,-z,notext.

Replaced assert by exit also fixed this.

After renaming, interceptor.c would be used to test interceptors in general by D101204.

Reviewed By: morehouse

Differential Revision: https://reviews.llvm.org/D101649
2021-05-07 00:57:21 +00:00
Christopher Ferris 6fac34251d [scudo] Add initialization for TSDRegistrySharedT
Fixes compilation on Android which has a TSDSharedRegistry object in the config.

Reviewed By: cryptoad, vitalybuka

Differential Revision: https://reviews.llvm.org/D101951
2021-05-05 19:00:54 -07:00
Jianzhou Zhao f3e3a1d79e [dfsan] extend a test case to measure origin memory usage
This is to support D101204.

Reviewed By: gbalats

Differential Revision: https://reviews.llvm.org/D101877
2021-05-06 00:19:44 +00:00
Vitaly Buka 1d767b13bf [scudo] Align objects with alignas
Operator new must align allocations for types with large alignment.

Before c++17 behavior was implementation defined and both clang and gc++
before 11 ignored alignment. Miss-aligned objects mysteriously crashed
tests on Ubuntu 14.

Alternatives are compile with -std=c++17 or -faligned-new, but they were
discarded as less portable.

Reviewed By: hctim

Differential Revision: https://reviews.llvm.org/D101874
2021-05-05 13:29:21 -07:00
Evgenii Stepanov 18959a6a09 [hwasan] Fix missing synchronization in AllocThread.
The problem was introduced in D100348.

It's really hard to trigger the bug in a stress test - the race is just too
narrow - but the new checks in Thread::Init should at least provide usable
diagnostic if the problem ever returns.

Differential Revision: https://reviews.llvm.org/D101881
2021-05-05 11:57:18 -07:00
Jianzhou Zhao 79debe8d7b [dfsan] Turn off all dfsan test cases on non x86_64 OSs
https://reviews.llvm.org/D101666 enables sanitizer allocator.
This broke all test cases on non x86-64.
2021-05-05 05:30:53 +00:00
Jianzhou Zhao bf4e1cf80a Revert "[sanitizer_common] Recycle StackDepot memory"
This reverts commit 78804e6b20.
2021-05-05 00:57:34 +00:00
Jianzhou Zhao 1fb612d060 [dfsan] Add a DFSan allocator
This is a part of https://reviews.llvm.org/D101204

Reviewed By: morehouse

Differential Revision: https://reviews.llvm.org/D101666
2021-05-05 00:51:45 +00:00
Jianzhou Zhao 78804e6b20 [sanitizer_common] Recycle StackDepot memory
This relates to https://reviews.llvm.org/D95835.

In DFSan origin tracking we use StackDepot to record
stack traces and origin traces (like MSan origin tracking).

For at least two reasons, we wanted to control StackDepot's memory cost
1) We may use DFSan origin tracking to monitor programs that run for
   many days. This may eventually use too much memory for StackDepot.
2) DFSan supports flush shadow memory to reduce overhead. After flush,
   all existing IDs in StackDepot are not valid because no one will
   refer to them.
2021-05-05 00:51:45 +00:00
Jianzhou Zhao 36cec26b38 [dfsan] move dfsan_flags.h to cc files
D101666 needs this change.

Reviewed By: morehouse

Differential Revision: https://reviews.llvm.org/D101857
2021-05-04 22:54:02 +00:00
Matt Morehouse 84bf107d50 [libFuzzer] Disable non-exec-time test again.
It was previously disabled for the past 6+ months.  I tried to re-enable
it after some deflaking, but it still fails occasionally.
2021-05-04 10:51:46 -07:00
Matt Morehouse 632ee38513 [libFuzzer] Further deflake exec-time test.
Increase runs to 200,000 since we currently get a random failure about
once per day on the buildbot.
2021-05-04 10:47:05 -07:00
Fabian Meumertzheim b1048ff682 [libFuzzer] Preserve position hint in auto dictionary
Currently, the position hint of an entry in the persistent auto
dictionary is fixed to 1. As a consequence, with a 50% chance, the entry
is applied right after the first byte of the input. As the position 1
does not appear to have any particular significance, this is likely a
bug that may have been caused by confusing the constructor parameter
with a success count.

This commit resolves the issue by preserving any existing position hint
or disabling the hint if the original entry didn't have one.

Reviewed By: morehouse

Differential Revision: https://reviews.llvm.org/D101686
2021-05-04 09:06:51 -07:00
Nico Weber bfb9c749c0 Fix some typos in d7ec48d71b 2021-05-04 10:44:01 -04:00
Nico Weber d7ec48d71b [clang] accept -fsanitize-ignorelist= in addition to -fsanitize-blacklist=
Use that for internal names (including the default ignorelists of the
sanitizers).

Differential Revision: https://reviews.llvm.org/D101832
2021-05-04 10:24:00 -04:00
Fangrui Song 2fec8860d8 [sanitizer] Set IndentPPDirectives: AfterHash in .clang-format
Code patterns like this are common, `#` at the line beginning
(https://google.github.io/styleguide/cppguide.html#Preprocessor_Directives),
one space indentation for if/elif/else directives.
```
#if SANITIZER_LINUX
# if defined(__aarch64__)
# endif
#endif
```

However, currently clang-format wants to reformat the code to
```
#if SANITIZER_LINUX
#if defined(__aarch64__)
#endif
#endif
```

This significantly harms readability in my review.  Use `IndentPPDirectives:
AfterHash` to defeat the diagnostic. clang-format will now suggest:

```
#if SANITIZER_LINUX
#  if defined(__aarch64__)
#  endif
#endif
```

Unfortunately there is no clang-format option using indent with 1 for
just preprocessor directives. However, this is still one step forward
from the current behavior.

Reviewed By: #sanitizers, vitalybuka

Differential Revision: https://reviews.llvm.org/D100238
2021-05-03 13:49:41 -07:00
Mitch Phillips e8f7241e0b [scudo] Don't track free/use stats for transfer batches.
The Scudo C unit tests are currently non-hermetic. In particular, adding
or removing a transfer batch is a global state of the allocator that
persists between tests. This can cause flakiness in
ScudoWrappersCTest.MallInfo, because the creation or teardown of a batch
causes mallinfo's uordblks or fordblks to move up or down by the size of
a transfer batch on malloc/free.

It's my opinion that uordblks and fordblks should track the statistics
related to the user's malloc() and free() usage, and not the state of
the internal allocator structures. Thus, excluding the transfer batches
from stat collection does the trick and makes these tests pass.

Repro instructions of the bug:
 1. ninja ./projects/compiler-rt/lib/scudo/standalone/tests/ScudoCUnitTest-x86_64-Test
 2. ./projects/compiler-rt/lib/scudo/standalone/tests/ScudoCUnitTest-x86_64-Test --gtest_filter=ScudoWrappersCTest.MallInfo

Reviewed By: cryptoad

Differential Revision: https://reviews.llvm.org/D101653
2021-05-03 11:50:00 -07:00
Matt Morehouse ac512890b4 [libFuzzer] Deflake entropic exec-time test. 2021-05-03 10:37:44 -07:00
Fabian Meumertzheim 62e4dca94e [libFuzzer] Fix off-by-one error in ApplyDictionaryEntry
In the overwrite branch of MutationDispatcher::ApplyDictionaryEntry in
FuzzerMutate.cpp, the index Idx at which W.size() bytes are overwritten
with the word W is chosen uniformly at random in the interval
[0, Size - W.size()). This means that Idx + W.size() will always be
strictly less than Size, i.e., the last byte of the current unit will
never be overwritten.

This is fixed by adding 1 to the exclusive upper bound.

Addresses https://bugs.llvm.org/show_bug.cgi?id=49989.

Reviewed By: morehouse

Differential Revision: https://reviews.llvm.org/D101625
2021-05-03 10:37:44 -07:00
Vitaly Buka 95aa116d0c [scudo][NFC] Fix clang-tidy warnings 2021-05-01 01:55:21 -07:00
Vitaly Buka d56ef8523c [scudo] Use require_constant_initialization
Attribute guaranties safe static initialization of globals.

Reviewed By: hctim

Differential Revision: https://reviews.llvm.org/D101514
2021-05-01 01:46:47 -07:00
Dmitry Vyukov bf61690e92 asan: fix a windows test
Before commit "sanitizer_common: introduce kInvalidTid/kMainTid"
asan invalid/unknown thread id was 0xffffff, so presumably we printed "T16777215".
Now it's -1, so we print T-1. Fix the test.
I think the new format is even better, "T-1" clearly looks like something special
rather than a random large number.

Reviewed By: vitalybuka

Differential Revision: https://reviews.llvm.org/D101634
2021-04-30 13:51:58 -07:00
Vitaly Buka f0c9d1e95f [tsan] Remove special SyncClock::kInvalidTid
Followup for D101428.

Reviewed By: dvyukov

Differential Revision: https://reviews.llvm.org/D101604
2021-04-30 13:39:15 -07:00
Vitaly Buka cbd5aceb62 [NFC][tsan] Fix cast after D101428 2021-04-30 11:53:09 -07:00