Commit Graph

8930 Commits

Author SHA1 Message Date
Evgeniy Stepanov 8cee2e8539 [sanitizer] Intercept bzero.
Summary:
Intercept bzero and enable existing __bzero interceptor in Linux.
bzero is deprecated but still used occasionally.

Reviewers: vitalybuka

Subscribers: srhines, kubamracek, #sanitizers, llvm-commits

Tags: #sanitizers, #llvm

Differential Revision: https://reviews.llvm.org/D58850

llvm-svn: 355347
2019-03-04 22:58:11 +00:00
Manman Ren 4737abc71c Order File Instrumentation: dump the data in compiler-rt
The profile data will be dumped in a file default_xxx.profraw.order.

Differential Revision: https://reviews.llvm.org/D57530

llvm-svn: 355343
2019-03-04 22:28:38 +00:00
Evgeniy Stepanov 02a913367a Revert "[sanitizer] Fix return type of __bzero and __aeabi_mem* interceptors."
Breaks TSan on Mac, which does
  return REAL(func)(...
in COMMON_INTERCEPTOR_ENTER, which is not OK when REAL(func) has return
type of void.

llvm-svn: 355256
2019-03-02 01:33:52 +00:00
Vlad Tsyrklevich a8af6ca065 Revert "Revert "[sanitizers] Don't use Windows Trace Logging on MinGW""
This reverts my orignal revert in r355250, I misread the buildbot logs.
Volodymyr's commit in r355244 fixed the build.

llvm-svn: 355251
2019-03-02 00:46:54 +00:00
Vlad Tsyrklevich a75077bc73 Revert "[sanitizers] Don't use Windows Trace Logging on MinGW"
This reverts commits r355236 and r355244, they broke the Linux sanitizer
build.

llvm-svn: 355250
2019-03-02 00:39:36 +00:00
Volodymyr Sapsai 738f697a19 [sanitizers] Fix build on macOS with LogFullErrorReport redefinition error.
macOS has implementation of LogFullErrorReport and

    INLINE void LogFullErrorReport(const char *buffer) {}

was causing

> compiler-rt/lib/sanitizer_common/sanitizer_mac.cc:658:6: error: redefinition of 'LogFullErrorReport'

Fixup for r355236.

rdar://problem/48526020

llvm-svn: 355244
2019-03-02 00:05:04 +00:00
Julian Lettner a30b116e6f [NFC][Sanitizer] Replace last uses of old Unwind API
Replace remaining uses of old Unwind API in unit tests.

Allows us to remove the old API and WillUseFastUnwind can be made
private.

Reviewed By: vitalybuka

Differential Revision: https://reviews.llvm.org/D58754

llvm-svn: 355242
2019-03-01 23:50:47 +00:00
Martin Storsjo 05394af3ff [sanitizers] Don't use Windows Trace Logging on MinGW
mingw-w64 currently is lacking the headers for this feature.

Make the include lowercase at the same time. We consistently
use lowercase for windows header includes, as windows itself is
case insensitive, the SDK headers (in general, not necessarily
considering this particular header) aren't consistent among themselves
about what the proper canonical capitalization for headers are,
and MinGW uses all lowercase names for the headers (as it is often
used on case sensitive filesystems).

In case mingw-w64 later gets this header, we can revert this
(but keep the include lowercased).

Differential Revision: https://reviews.llvm.org/D58765

llvm-svn: 355236
2019-03-01 22:30:14 +00:00
Julian Lettner 628472dde2 [NFC][Sanitizer][Windows] Fix refactoring oversight
Fix mistake in previous commit: 9fe3b4906f

llvm-svn: 355234
2019-03-01 22:26:45 +00:00
Julian Lettner 9fe3b4906f [NFC][Sanitizer] Make GetStackTrace a private method of BufferedStackTrace
GetStackTrace is a implementation detail of BufferedStackTrace. Make it
a private method.

Reviewed By: vitalybuka

Differential-Revision: https://reviews.llvm.org/D58753
llvm-svn: 355232
2019-03-01 22:10:49 +00:00
Evgeniy Stepanov ddc4b7c1d6 [sanitizer] Fix return type of __bzero and __aeabi_mem* interceptors.
llvm-svn: 355231
2019-03-01 21:59:18 +00:00
Evgeniy Stepanov 72e83488f3 Revert "[sanitizer] Fix return type of __bzero and __aeabi_mem* interceptors."
This change is incomplete.

llvm-svn: 355230
2019-03-01 21:49:40 +00:00
Evgeniy Stepanov 3bbac856f9 [sanitizer] Fix return type of __bzero and __aeabi_mem* interceptors.
They return void, unlike memset/memcpy/memmove.

llvm-svn: 355225
2019-03-01 20:54:16 +00:00
Evgeniy Stepanov c7b322a3d9 [msan] Add an interceptor for ttyname().
llvm-svn: 355214
2019-03-01 18:22:44 +00:00
Clement Courbet dd885eaf5f Reland "[compiler-rt] Intercept the bcmp() function."
Fix test issues on darwin: The REQUIRES for the test should be the same as the
guard for whether we intercept bcmp.

llvm-svn: 355204
2019-03-01 16:42:08 +00:00
Kostya Kortchinsky 6b79f3b1e2 [scudo][standalone] Fix tests makefile
Summary:
A missing `STATIC` entailed some annoying to debug failures wrt 32 vs 64
binaries. Additionally I noticed I was using the wrong variable (the Scudo
one as opposed to the Scudo Standalone one).

See https://reviews.llvm.org/D58184#1412417 and below for discussion.

Reviewers: vitalybuka, eugenis, brzycki

Reviewed By: vitalybuka, brzycki

Subscribers: mgorny, delcypher, #sanitizers, llvm-commits

Tags: #llvm, #sanitizers

Differential Revision: https://reviews.llvm.org/D58794

llvm-svn: 355203
2019-03-01 15:46:23 +00:00
Martin Storsjo 90641b5581 [sanitizers] Explicitly use GetModuleFileNameW with wchar_t
Alternatively we could define the string as TCHAR.

Differential Revision: https://reviews.llvm.org/D58766

llvm-svn: 355180
2019-03-01 08:08:11 +00:00
Julian Lettner 13c4bc5671 [NFC][Sanitizer] Add new BufferedStackTrace::Unwind API
Retrying without replacing call sites in sanitizer_common (which might
not have a symbol definition).

Add new Unwind API. This is the final envisioned API with the correct
abstraction level. It hides/slow fast unwinder selection from the caller
and doesn't take any arguments that would leak that abstraction (i.e.,
arguments like stack_top/stack_bottom).

GetStackTrace will become an implementation detail (private method) of
the BufferedStackTrace class.

Reviewers: vitalybuka

Differential Revision: https://reviews.llvm.org/D58741

> llvm-svn: 355168

llvm-svn: 355172
2019-03-01 04:03:38 +00:00
Julian Lettner e6ec6bd8e0 Revert "[NFC][Sanitizer] Add new BufferedStackTrace::Unwind API"
This reverts commit 6112f37e75.

llvm-svn: 355171
2019-03-01 03:35:05 +00:00
Julian Lettner 6112f37e75 [NFC][Sanitizer] Add new BufferedStackTrace::Unwind API
Add new Unwind API. This is the final envisioned API with the correct
abstraction level. It hides/slow fast unwinder selection from the caller
and doesn't take any arguments that would leak that abstraction (i.e.,
arguments like stack_top/stack_bottom).

GetStackTrace will become an implementation detail (private method) of
the BufferedStackTrace class.

Reviewers: vitalybuka

Differential Revision: https://reviews.llvm.org/D58741

llvm-svn: 355168
2019-03-01 03:08:34 +00:00
Evgeniy Stepanov dc3870d64d [hwasan] Disable vfork code when building w/o interceptors.
Don't define vfork when OMPILER_RT_HWASAN_WITH_INTERCEPTORS=OFF.

llvm-svn: 355165
2019-03-01 02:06:58 +00:00
Nico Weber 77d972b94c cfi: Rename source file from cc to cpp
See discussion on https://reviews.llvm.org/D58620 for the review.

llvm-svn: 355144
2019-02-28 22:03:41 +00:00
Dan Liew d14f1b26fb [CMake][LibFuzzer] Match symbol visibility setting between LibFuzzer object files and unit tests.
Summary:
This fixes inconsistent symbol visibility. This shows up as a linker
warning if r336238 (43f633564e338a6dde83d49a48e5bfcbfdce292c) is
reverted.

```
ld: warning: direct access in function 'fuzzer::CleanseCrashInput(std::__1::vector<std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> >, fuzzer::fuzzer_allocator<std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> > > > const&, fuzzer::FuzzingOptions const&)' from file '/Volumes/data/dev/llvm/upstream/master/builds/projects/compiler-rt/lib/fuzzer/tests/libRTFuzzerTest.x86_64.a(FuzzerDriver.cpp.o)' to global weak symbol 'fuzzer::Command::ignoreRemainingArgs()::kIgnoreRemaining' from file 'FuzzerTestObjects.FuzzerUnittest.cpp.x86_64.o' means the weak symbol cannot be overridden
 at runtime. This was likely caused by different translation units being compiled with different visibility settings.
```

r336238 just hid the issue rather than fixing the real issue. On macOS
and other platforms we usually compile with `-fvisibility=hidden` but
the unit tests were compiled without this flag.

Reviewers: george.karpenkov, kubamracek, kcc, yln

Subscribers: mgorny, #sanitizers, llvm-commits

Tags: #llvm, #sanitizers

Differential Revision: https://reviews.llvm.org/D58055

llvm-svn: 355143
2019-02-28 21:57:58 +00:00
Evgeniy Stepanov ecb2c1fd5b [hwasan] Fix vfork handling with large stack limit.
Remove the maximum stack cleanup size check. With ulimit -s unlimited
main thread stack can be very large, but we don't really have a choice
other than cleaning all of it. It should be reasonably fast - hwasan
cleans large shadow ranges with a single madvise call.

This change fixes check-hwasan after ulimit -s unlimited.

llvm-svn: 355137
2019-02-28 20:43:24 +00:00
H.J. Lu fadb22f4e2 Revert "Revert "[sanitizers] Restore internal_readlink for x32""
This reverts revision 354601 and disables ReadBinaryNameCached check on
Windows since Windows has no working ReadBinaryName.

Differential Revision: https://reviews.llvm.org/D58788

llvm-svn: 355129
2019-02-28 19:34:01 +00:00
Evgeniy Stepanov 37ce064082 [sanitizer] Fix vfork interceptor on i386 w/ dynamic runtime.
PLT calls on i386 expect GOT base address in %ebx.
This call does not need to go through PLT strictly speaking, but I'd
rather avoid future surprises and implement the most general case.

llvm-svn: 355125
2019-02-28 19:21:25 +00:00
Rong Xu 23452e1c85 [PGO] Update InstrProfData.inc to sync with llvm
llvm-svn: 355119
2019-02-28 19:06:02 +00:00
Julian Lettner ce65261fae [NFC][Sanitizer] Weak linkage is not available on Windows
The concept of weak linkage is not available on Windows. The available
workarounds in LLVM/sanitizer runtimes have their own problems. Define a
separte symbol ubsan_GetStackTrace to work around the issue now. At lest
this way it is painfully obvious that we still have to do more cleanup.

Follow-up to revision: https://reviews.llvm.org/D58651

llvm-svn: 355113
2019-02-28 18:42:14 +00:00
Evgeniy Stepanov d4b4e17d2c [sanitizer] Got rid of text relocations in i386 vfork interceptor.
llvm-svn: 355064
2019-02-28 01:54:55 +00:00
Douglas Yung 83663fd989 Add username to TODO comment in sanitizer to satisfy sanitizer lint check. NFC
llvm-svn: 355062
2019-02-28 01:20:38 +00:00
Julian Lettner 22efccf9ab [NFC][TSan] Don't define GetStackTrace when compiling for Go
rdar://48455255

llvm-svn: 355053
2019-02-28 00:43:43 +00:00
Julian Lettner a7171b2e47 [NFC][Sanitizer] Use correct WEAK annotation to make Windows work
The previous fix didn't work for Windows:
52b751088b

llvm-svn: 355052
2019-02-28 00:43:40 +00:00
Julian Lettner 52b751088b [Sanitizer] Attempt to fix linker error on ARM variants
Previous commit:
a0884da62a

llvm-svn: 355046
2019-02-27 23:47:00 +00:00
Matthew G McGovern 8edffdb4f0 [compiler-rt] Windows Trace Logging for error reports.
Adds option for collecting sanitixer dumps via trace logging.
    - Set log_to_syslog=1 to enable this output.
    - Consult https://aka.ms/windowstracelogging for details on use.

llvm-svn: 355045
2019-02-27 23:43:50 +00:00
Evgeniy Stepanov f6b0a14bff [sanitizer] Fix compilation errors in r355030.
Disable hwasan interceptor on non-linux, non-x86-or-arm platforms.
Add @plt to the asm call that clang intergrated-as infers but gcc does
not.

llvm-svn: 355041
2019-02-27 22:23:51 +00:00
Julian Lettner a0884da62a [NFC][Sanitizer] Pull up GetStackTrace into sanitizer_common
We already independently declare GetStackTrace in all (except TSan)
sanitizer runtime headers. Lets move it to sanitizer_stacktrace.h to
have one canonical way to fill in a BufferedStackFrame. Also enables us
to use it in sanitizer_common itself.

This patch defines GetStackTrace for TSan and moves the function from
ubsan_diag.cc to ubsan_diag_standalone.cc to avoid duplicate symbols
for the UBSan-ASan runtime.

Other than that this patch just moves the code out of headers and into
the correct namespace.

Reviewers: vitalybuka

Differential Revision: https://reviews.llvm.org/D58651

llvm-svn: 355039
2019-02-27 22:16:02 +00:00
James Y Knight f33b1f49b7 Fixup compilation/test failures after r354960 and r355013.
llvm-svn: 355034
2019-02-27 21:47:35 +00:00
Evgeniy Stepanov f46a52b536 [hwasan, asan] Intercept vfork.
Summary:
Intercept vfork on arm, aarch64, i386 and x86_64.

Reviewers: pcc, vitalybuka

Subscribers: kubamracek, mgorny, javed.absar, krytarowski, kristof.beyls, #sanitizers, llvm-commits

Tags: #sanitizers, #llvm

Differential Revision: https://reviews.llvm.org/D58533

llvm-svn: 355030
2019-02-27 21:11:50 +00:00
Julian Lettner 46e1b16e36 [NFC][Sanitizer] Hard-code fast/slow unwinder at call site
Also assert that the caller always gets what it requested.

This purely mechanical change simplifies future refactorings and
eventual removal of BufferedStackTrace::Unwind.

Reviewers: vitalybuka

Differential Revision: https://reviews.llvm.org/D58557

llvm-svn: 355022
2019-02-27 20:01:04 +00:00
Jonathan Metzman 518514e81d [libFuzzer][Windows] Port fork mode to Windows
Summary:
Port libFuzzer's fork mode to Windows.
Implement Windows versions of MkDir, RmDir, and IterateDirRecursive to do this.
Don't print error messages under new normal uses of FileSize (on a non-existent file).
Implement portable way of piping output to /dev/null.
Fix test for Windows and comment fork-sigusr.test on why it won't be ported to Win.

Reviewers: zturner

Reviewed By: zturner

Subscribers: kcc, zturner, jdoerfert, #sanitizers, llvm-commits

Tags: #sanitizers, #llvm

Differential Revision: https://reviews.llvm.org/D58513

llvm-svn: 355019
2019-02-27 19:27:16 +00:00
Alexey Lapshin d89d638055 Attempt to fix buildbot after r354972 [#1]. NFCI.
llvm-svn: 355013
2019-02-27 18:36:46 +00:00
Kostya Kortchinsky b3a924afd6 [scudo][standalone] Add a standalone vector class
Summary:
This CL adds a standalone vector class that will be used by the scoped
strings when they land. We reimplement our own vector class because we
can't use the std library one.

It's mostly borrowed from the current sanitizer_common one, with LLVM
code style changes.

Additionnally a casing change in a function name that slipped through
the previous review (the function isn't used yet).

Reviewers: vitalybuka, eugenis, flowerhack, dmmoore415, mcgrathr, morehouse

Reviewed By: vitalybuka

Subscribers: mgorny, delcypher, #sanitizers, llvm-commits

Tags: #llvm, #sanitizers

Differential Revision: https://reviews.llvm.org/D58689

llvm-svn: 354999
2019-02-27 16:30:05 +00:00
Nico Weber e3b6d11038 hwasan: Rename source files from cc to cpp
As discussed elsewhere: LLVM uses cpp as its C++ source extension; the
sanitizers should too. This updates files in hwasan.

Patch generated by

    for f in lib/hwasan/*.cc ; do svn mv $f ${f%.cc}.cpp; done

followed by

    for f in lib/hwasan/*.cpp ; do sed -i '' -e '1s/\.cc -/.cpp /' $f; done

CMakeLists.txt updated manually.

Differential Revision: https://reviews.llvm.org/D58620

llvm-svn: 354989
2019-02-27 15:44:03 +00:00
Julian Lettner c4eff2111a [NFC][Sanitizer] Add TODO comments
llvm-svn: 354947
2019-02-27 01:38:54 +00:00
Craig Topper 938d3f461b [X86] Add 'znver2' and 'cascadelake' support to __cpu_indicator_init.
For 'cascadelake' this is adding a 'avx512vnni' feature check to the 0x55 skylake-avx512 model check. These CPUs use the same model number and only differ in the stepping number. But the feature flag is simpler than collecting all the stepping numbers.

For 'znver2' this is just syncing with LLVM's Host.cpp.

llvm-svn: 354927
2019-02-26 21:51:05 +00:00
Vitaly Buka 9b6135bf2a [libFuzzer] fix missing close on opened file
Summary:
When running the standalone main on a large corpus, I eventually get a
EMFILE error ("Too many open files").

Patch by Paul Chaignon

Reviewers: kcc, vitalybuka

Reviewed By: vitalybuka

Subscribers: lebedev.ri, #sanitizers, llvm-commits

Tags: #llvm, #sanitizers

Differential Revision: https://reviews.llvm.org/D58622

llvm-svn: 354918
2019-02-26 19:33:00 +00:00
Vlad Tsyrklevich 443e00a51b Revert "[compiler-rt] Intercept the bcmp() function."
This reverts commits r354851, 354852, 354853 and r354888. They were
causing build failures on the android sanitizer bot.

llvm-svn: 354906
2019-02-26 18:28:15 +00:00
Jonathan Metzman 7821f892bf [libFuzzer] Remove extra semicolons
Summary:
Remove extra semicolons so that libFuzzer can compile with
-Werror -Wextra-semi

Reviewers: Dor1s, morehouse, thakis

Reviewed By: Dor1s, morehouse

Subscribers: jdoerfert, #sanitizers, llvm-commits

Tags: #sanitizers, #llvm

Differential Revision: https://reviews.llvm.org/D58674

llvm-svn: 354902
2019-02-26 17:46:13 +00:00
Kostya Kortchinsky 41aba567d9 [scudo][standalone] Introduce platform specific code & mutexes
Summary:
This CL adds the platform specific code for Fuchsia, Linux & Android,
as well as some tests related to those (more tests to come later).
While some of it is pretty much a straight port of the existing scudo &
sanitizer_common code, the memory mapping functions have been reworked
a bit to fit the limited usage scenario that Scudo has for them.

For Fuchsia, I can now track the Vmar/Vmo pair for memory mappings if
there is an intent to grow or decommit some mapping (that will be
useful for the Primary).

Reviewers: eugenis, vitalybuka, mcgrathr, phosek, flowerhack, morehouse, dmmoore415

Reviewed By: vitalybuka, morehouse

Subscribers: kcc, dvyukov, srhines, mgorny, delcypher, jfb, jdoerfert, #sanitizers, llvm-commits

Tags: #llvm, #sanitizers

Differential Revision: https://reviews.llvm.org/D58184

llvm-svn: 354895
2019-02-26 16:47:25 +00:00
Pavel Labath 89ae290b58 [Sanitizer] Add interceptor for pthread_sigmask
Summary:
pthread_sigmask is just like sigprocmask, except that its behavior in
multithreaded programs is explicitly specified. Sanitizers were lacking
a common interceptor for pthread_sigmask (although some specific
sanitizers defined custom version), which lead to false positives
(at least in msan) when using this function.

The interceptor implementation, and its test are based on the equivalent
code for sigprocmask.

Reviewers: eugenis, vitalybuka

Subscribers: kubamracek, delcypher, jfb, jdoerfert, llvm-commits, #sanitizers

Tags: #llvm, #sanitizers

Differential Revision: https://reviews.llvm.org/D58382

llvm-svn: 354874
2019-02-26 13:38:23 +00:00
Clement Courbet 02b9b4e18d [compiler-rt] Intercept the bcmp() function.
Summary:
I have not introduced a separate hook for `bcmp()` as I don't think there
should be any reason for a sanitizer to treat it differently from `memcmp()`.

This is only enabled when building on POSIX with GNU extensions.

Context: this is to avoid losing coverage when emitting `bcmp() == 0` instead
of `memcmp() == 0` in llvm, see https://reviews.llvm.org/D56593.

Reviewers: mgorny, krytarowski, vitalybuka, dvyukov

Subscribers: kubamracek, dberris, delcypher, jdoerfert, #sanitizers, llvm-commits, jyknight

Tags: #llvm, #sanitizers

Differential Revision: https://reviews.llvm.org/D58379

llvm-svn: 354851
2019-02-26 07:43:01 +00:00
Reid Kleckner 8b6af00173 [llvm-cov] Fix llvm-cov on Windows and un-XFAIL test
Summary:
The llvm-cov tool needs to be able to find coverage names in the
executable, so the .lprfn and .lcovmap sections cannot be merged into
.rdata.

Also, the linker merges .lprfn$M into .lprfn, so llvm-cov needs to
handle that when looking up sections. It has to support running on both
relocatable object files and linked PE files.

Lastly, when loading .lprfn from a PE file, llvm-cov needs to skip the
leading zero byte added by the profile runtime.

Reviewers: vsk

Subscribers: hiraditya, #sanitizers, llvm-commits

Tags: #sanitizers, #llvm

Differential Revision: https://reviews.llvm.org/D58661

llvm-svn: 354840
2019-02-26 02:30:00 +00:00
David Major b4e16e6ad1 [winasan] Unpoison stack memory when threads exit (redux)
This is a second attempt at r342652 using a TLS callback instead of an
interceptor.

In long-running builds we've seen some ASan complaints during thread creation
that we suspect are due to leftover poisoning from previous threads whose
stacks occupied that memory. This patch adds a callback that unpoisons the
stack memory when a thread exits.

Differential Revision: https://reviews.llvm.org/D58641

llvm-svn: 354836
2019-02-26 01:35:48 +00:00
Richard Trieu 1bf3a09b3d Remove overly broad assert from r354717.
llvm-svn: 354720
2019-02-23 05:48:50 +00:00
Julian Lettner beb33eb3cf [NFC][Sanitizer] Comment out argument checks
These break clang-ppc64 bots.

llvm-svn: 354718
2019-02-23 03:24:10 +00:00
Julian Lettner 7c99328cf4 [NFC][Sanitizer] Add argument checks to BufferedStackTrace::Unwind* functions
Reviewers: vitalybuka

Differential Revision: https://reviews.llvm.org/D58555

llvm-svn: 354717
2019-02-23 02:36:23 +00:00
Julian Lettner 1e4f073582 [NFC][Sanitizer] Rename BufferedStackTrace::FastUnwindStack
FastUnwindStack -> UnwindFast
SlowUnwindStack -> UnwindSlow
Stack is redundant, verb should come first.

SlowUnwindStackWithContext(uptr pc, void *context, u32 max_depth) ->
SlowUnwindStack
WithContext is redundant, since it is a required parameter.

Reviewers: vitalybuka

Differential Revision: https://reviews.llvm.org/D58551

llvm-svn: 354696
2019-02-22 22:03:09 +00:00
Julian Lettner de7626985f [Sanitizer] Fix uses of stack->Unwind(..., fast)
Apply StackTrace::WillUseFastUnwind(fast) in a few more places missed by
my previous patch (https://reviews.llvm.org/D58156).

Reviewers: vitalybuka

Differential Revision: https://reviews.llvm.org/D58550

llvm-svn: 354695
2019-02-22 22:00:13 +00:00
Evgeniy Stepanov a2062b222d [sanitizer] Common macro for .note.GNU-stack directives (NFC)
llvm-svn: 354632
2019-02-21 22:59:29 +00:00
Evgeniy Stepanov 45eea20d2a Revert "[asan] Fix vfork handling.", +1
Revert r354625, r354627 - multiple build failures.

llvm-svn: 354629
2019-02-21 22:02:24 +00:00
Evgeniy Stepanov b5321d7d0b [asan] Fix vfork handling.
__asan_handle_vfork was unpoisoning the wrong part of the stack.
Adjust the test to catch this reliably (current failure is
non-deterministic).

llvm-svn: 354627
2019-02-21 21:55:06 +00:00
Evgeniy Stepanov df91386806 [hwasan,asan] Intercept vfork.
Summary: AArch64 only for now.

Reviewers: vitalybuka, pcc

Subscribers: srhines, kubamracek, mgorny, javed.absar, krytarowski, kristof.beyls, jdoerfert, #sanitizers, llvm-commits, kcc

Tags: #sanitizers, #llvm

Differential Revision: https://reviews.llvm.org/D58313

llvm-svn: 354625
2019-02-21 21:32:24 +00:00
Matt Morehouse 9b900dc7de Revert "[sanitizers] Restore internal_readlink for x32"
This reverts r354451 since it broke the Windows sanitizer bot.

llvm-svn: 354601
2019-02-21 17:06:23 +00:00
Julian Lettner 65e9f98861 [LSan] Fix `__sanitizer_print_stack_trace` via fast unwinder
Summary: Quick follow-up to: https://reviews.llvm.org/D58156

Reviewers: vitalybuka

Differential Revision: https://reviews.llvm.org/D58358

llvm-svn: 354522
2019-02-20 22:28:11 +00:00
H.J. Lu 6716f4af81 [sanitizers] Restore internal_readlink for x32
r316591 has

@@ -389,13 +383,11 @@ uptr internal_dup2(int oldfd, int newfd) {
 }

 uptr internal_readlink(const char *path, char *buf, uptr bufsize) {
-#if SANITIZER_NETBSD
-  return internal_syscall_ptr(SYSCALL(readlink), path, buf, bufsize);
-#elif SANITIZER_USES_CANONICAL_LINUX_SYSCALLS
+#if SANITIZER_USES_CANONICAL_LINUX_SYSCALLS
   return internal_syscall(SYSCALL(readlinkat), AT_FDCWD,
                           (uptr)path, (uptr)buf, bufsize);
 #else
-  return internal_syscall(SYSCALL(readlink), (uptr)path, (uptr)buf, bufsize);
+  return internal_syscall_ptr(SYSCALL(readlink), path, buf, bufsize);
 #endif
 }

which dropped the (uptr) cast and broke x32.  This patch puts back the
(uptr) cast to restore x32 and fixes:

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

Differential Revision: https://reviews.llvm.org/D58413

llvm-svn: 354451
2019-02-20 11:43:43 +00:00
Kostya Serebryany 64c7b060bc [sanitizers] add a regression test for the bug fixed in r354366
llvm-svn: 354373
2019-02-19 19:28:08 +00:00
Kostya Serebryany 6bde702ac9 [sanitizer] fix a memory safety bug (!!!) in sanitizer suppressions code, discovered by Aaron Jacobs
llvm-svn: 354366
2019-02-19 18:43:24 +00:00
Julian Lettner eb3bcc1c95 [Sanitizer] On Darwin `__sanitizer_print_stack_trace` only prints topmost frame
In compiler-rt we have the notion of a `fast` and a `slow` stack
unwinder. Darwin currently only supports the fast unwinder.

From reading the code, my understanding is that
`BufferedStackTrace::Unwind` can be called with `bp=0, stack_top=0,
stack_bottom=0, request_fast_unwind=false`. If
`request_fast_unwind=true`, then we alos need to supply bp, stack_top,
and stack_bottom.

However, `BufferedStackTrace::Unwind` uses
`StackTrace::WillUseFastUnwind` which will adapt `request_fast_unwind`
if the requested unwinder is not supported. On Darwin, the result is
that we don't pass actual values for bp, stack_top, and stack_bottom,
but end up using the fast unwinder. The tests then fail because we only
print the topmost stack frame.

This patch adds a check to `WillUseFastUnwind` at the point of usage to
avoid the mismatch between `request_fast_unwind` and what `Unwind`
actually does. I am also interested in cleaning up the
`request_fast_unwind` machinery so this patch just the simplest thing
possible so I can enable the tests.

Reviewers: vitalybuka, vsk

Differential Revision: https://reviews.llvm.org/D58156

llvm-svn: 354282
2019-02-18 18:47:49 +00:00
Jonas Hahnfeld 0a9cb239a6 [compiler-rt] Fix broken sanitizer bots (hopefully)
According to the logs and local debugging there were two issues:
1) tsan tests listed libc++.a before the source file. That's usually
   ok for shared libraries, but the linker will not add symbols from
   a static library unless needed at that time. As a result the tests
   that rely upon symbols from the library (and not only include the
   headers) had undefined references.
   To solve this I'm adding a new substitution %link_libcxx_tsan which
   expands to libc++.a if available.
2) The target Fuzzer-x86_64-Test linked in SANITIZER_TEST_CXX_LIBRARIES
   which defaults to -lstdc++. This resulted in error messages like
     hidden symbol '_ZdlPv' is not defined locally
     hidden symbol '_Znwm' is not defined locally
   when using GNU gold (ld.bfd and lld are fine). Removing the linkage
   is fine because we build a custom libc++ for that purpose.

llvm-svn: 354231
2019-02-17 18:47:33 +00:00
Jonas Hahnfeld 66c60d9d71 [compiler-rt] Build custom libcxx with libcxxabi
This changes add_custom_libcxx to also build libcxxabi and merges
the two into a static and hermetic library.
There are multiple advantages:
1) The resulting libFuzzer doesn't expose C++ internals and looks
   like a plain C library.
2) We don't have to manually link in libstdc++ to provide cxxabi.
3) The sanitizer tests cannot interfere with an installed version
   of libc++.so in LD_LIBRARY_PATH.

Differential Revision: https://reviews.llvm.org/D58013

llvm-svn: 354212
2019-02-17 12:16:20 +00:00
Jonas Hahnfeld a05d442391 [compiler-rt] Cleanup usage of C++ ABI library
Add missed value "libcxxabi" and introduce SANITIZER_TEST_CXX for linking
unit tests. This needs to be a full C++ library and cannot be libcxxabi.

Recommit r354132 which I reverted in r354153 because it broke a sanitizer
bot. This was because of the "fixes" for pthread linking, so I've removed
these changes.

Differential Revision: https://reviews.llvm.org/D58012

llvm-svn: 354198
2019-02-16 08:34:26 +00:00
Kostya Serebryany b6ca1e7259 [libFuzzer] make len_control less agressive: set the initial max len to the length of the largest seed. This was the original intent, but... Now, with a test, to ensure it stays this way
llvm-svn: 354191
2019-02-16 01:23:41 +00:00
Kostya Serebryany 312af158b0 [libFuzzer] fork mode: try harder to cleanup after itself
llvm-svn: 354186
2019-02-16 00:14:16 +00:00
Kostya Serebryany 9982ee5472 [libFuzzer] form mode: add -ignore_crashes flag, honor the max_total_time flag, print the number of ooms/timeouts/crashes, fix a typo
llvm-svn: 354175
2019-02-15 21:51:15 +00:00
Richard Smith 1dcff8d17c Fix invalid code that Clang trunk will soon diagnose.
There is an ambiguity between ::SizeClassMap (the typedef declared near
the start of this file) and __sanitizer::SizeClassMap (found by the
'using namespace __sanitizer;' near the start of this file).

Historically a Clang bug has meant that the error was not diagnosed, but
soon Clang will start diagnosing it. Explicitly qualify this use of
SizeClassMap so that it finds __sanitizer::SizeClassMap rather than
being ill-formed due to ambiguity.

llvm-svn: 354174
2019-02-15 21:48:57 +00:00
Evgeniy Stepanov 360163f671 Fix unsymbolized stack history printing.
Summary:
When symbols are unavailable, the current code prints
  sp: ... pc: ... (null) (null)
instead of module name + offset.

Change the output to include module name and offset, and also to match
the regular sanitizer stack trace format so that it is recognized by
symbolize.py out of the box.

Reviewers: kcc, pcc

Subscribers: kubamracek, jdoerfert, llvm-commits

Tags: #llvm

Differential Revision: https://reviews.llvm.org/D58267

llvm-svn: 354157
2019-02-15 18:38:23 +00:00
Evgeniy Stepanov a70d88c7a3 Runtime flags for malloc bisection.
Reviewers: kcc, pcc

Subscribers: kubamracek, mgorny, jdoerfert, llvm-commits

Tags: #llvm

Differential Revision: https://reviews.llvm.org/D58162

llvm-svn: 354156
2019-02-15 18:38:14 +00:00
Evgeniy Stepanov 2c0483f5a6 Fix false positive when tag_in_malloc=0,tag_in_free=1.
Summary:
With tag_in_free=1, malloc() can not assume that the memory is untagged,
and needs to retag is to 0.

Reviewers: pcc, kcc

Subscribers: kubamracek, jfb, jdoerfert, llvm-commits

Tags: #llvm

Differential Revision: https://reviews.llvm.org/D58158

llvm-svn: 354155
2019-02-15 18:38:03 +00:00
Jonas Hahnfeld ea686e2845 Revert "[compiler-rt] Cleanup usage of C++ ABI library"
This reverts r354132 because it breaks sanitizer-x86_64-linux:
http://lab.llvm.org:8011/builders/sanitizer-x86_64-linux/builds/19915

llvm-svn: 354153
2019-02-15 18:25:26 +00:00
Jonas Hahnfeld 3cc63cfaa7 [compiler-rt] Cleanup usage of C++ ABI library
Add missed value "libcxxabi" and introduce SANITIZER_TEST_CXX for linking
unit tests. This needs to be a full C++ library and cannot be libcxxabi.

Differential Revision: https://reviews.llvm.org/D58012

llvm-svn: 354132
2019-02-15 14:30:18 +00:00
Kostya Serebryany 77cbc62544 [libFuzzer] print new functions as they are discovered in the fork mode
llvm-svn: 354092
2019-02-15 01:22:00 +00:00
Kostya Serebryany b96b10d1a3 [libFuzzer] fix the unit tests
llvm-svn: 354088
2019-02-15 00:15:13 +00:00
Kostya Serebryany 8c2791469d [libFuzzer] when doing the merge, keep track of the coveraged edges, not just features
llvm-svn: 354087
2019-02-15 00:08:16 +00:00
Kostya Serebryany 96f81bc679 [libFuzzer] when doing the merge, keep track of the coveraged edges, not just features
llvm-svn: 354076
2019-02-14 23:12:33 +00:00
Ana Pazos bbb8129b2c Set hidden attribute on lprofMergeValueProfData
Summary:
The changes in https://reviews.llvm.org/D44847 cause load time failure
due to lprofMergeValueProfData in Android libs enabled with profile generation:

"dlopen failed: cannot locate symbol "lprofMergeValueProfData" referenced by..."

Marking lprofMergeValueProfData as hidden so the correct in-module definition
 is picked by the linker.

Reviewers: davidxl

Reviewed By: davidxl

Subscribers: efriedma, xur, davidxl, llvm-commits

Differential Revision: https://reviews.llvm.org/D55893

llvm-svn: 354064
2019-02-14 21:38:40 +00:00
Kostya Serebryany 8e918d6ead [libFuzzer] better stats for the fork mode
llvm-svn: 354061
2019-02-14 21:09:32 +00:00
Vitaly Buka 9a370ccca2 [msan] Don't delete MSanAtExitRecord
Summary:
Pre 2.27 libc can run same atexit handler twice
We will keep MSanAtExitRecord and reset fun to mark it as executed.

Fix PR40162

Reviewers: eugenis

Subscribers: jfb, jdoerfert, #sanitizers, llvm-commits

Tags: #sanitizers, #llvm

Differential Revision: https://reviews.llvm.org/D58221

llvm-svn: 354005
2019-02-14 02:51:55 +00:00
Kostya Serebryany debf0af71d [libFuzzer] trying to fix the bot (can't reproduce the build failure locally)
llvm-svn: 354000
2019-02-14 01:11:29 +00:00
Kostya Serebryany 60c5ded269 [libFuzzer] add threads to the fork mode: now you can pass -fork=N to run N concurrent workers. Fork mode is still work-in-progress.
llvm-svn: 353997
2019-02-14 00:25:43 +00:00
Dmitry Vyukov 76e961207b tsan: add fiber support
This patch adds functions for managing fibers:

__tsan_get_current_fiber()
__tsan_create_fiber()
__tsan_destroy_fiber()
__tsan_switch_to_fiber()
__tsan_set_fiber_name()

See the added tests for use examples.

Author: yuri (Yuri Per)
Reviewed in: https://reviews.llvm.org/D54889

[The previous commit of this change was reverted,
this is a resubmit with a squashed fix for check_analyze.sh
and COMMON_INTERCEPTOR_NOTHING_IS_INITIALIZED]

llvm-svn: 353947
2019-02-13 13:21:24 +00:00
Diana Picus d3f13f1608 Revert "tsan: update check_analyze.sh"
This reverts commit r353820, to go with the revert of r353817.

llvm-svn: 353942
2019-02-13 12:06:13 +00:00
Diana Picus 4152a09e55 Revert "tsan: add fiber support"
This reverts commit r353817 because we think it broke AARch64 and
PowerPC buildbots.

llvm-svn: 353939
2019-02-13 11:32:56 +00:00
Martin Storsjo 7eb4ec2879 [profile] Provide lprofGetHostName for all windows environments
This function doesn't use anything MSVC specific but works fine
for any _WIN32 target.

Differential Revision: https://reviews.llvm.org/D58106

llvm-svn: 353918
2019-02-13 07:27:05 +00:00
Kostya Serebryany d085748484 [libFuzzer] a bit of refactoring of the fork mode
llvm-svn: 353910
2019-02-13 04:04:45 +00:00
Hubert Tong a9f91c810c [xray][tests][RHDTS] Add -lstdc++ after LLVM libs, resolving link error with RHDTS
Summary:
A link error was encountered when using the Red Hat Developer Toolset.
In the RHDTS, `libstdc++.so` is a linker script that may resolve symbols
to a static library. This patch places `-lstdc++` later in the ordering.

Reviewers: sfertile, nemanjai, tstellar, dberris

Reviewed By: dberris

Subscribers: dberris, mgorny, delcypher, jdoerfert, #sanitizers, llvm-commits

Tags: #llvm, #sanitizers

Differential Revision: https://reviews.llvm.org/D58144

llvm-svn: 353905
2019-02-13 00:55:30 +00:00
Evgeniy Stepanov 8bb5d7e76a [tsan] #undef one-letter macros
buildgo.sh puts most of sanitizer_common together in a single source
file. These single-letter macros end up affecting a lot of unrelated
code; #undef them as early as possible.

llvm-svn: 353902
2019-02-12 23:49:02 +00:00
Kostya Serebryany 5c08e811de [libFuzzer] move the implementation of the fork mode into a separate file
llvm-svn: 353891
2019-02-12 22:48:55 +00:00
Dmitry Vyukov 19e41fb0ca tsan: update check_analyze.sh
Update numbers after 353817.
This was extensively benchmarked in https://reviews.llvm.org/D54889

llvm-svn: 353820
2019-02-12 10:18:27 +00:00
Dmitry Vyukov 6e7089ad40 tsan: add fiber support
This patch adds functions for managing fibers:

__tsan_get_current_fiber()
__tsan_create_fiber()
__tsan_destroy_fiber()
__tsan_switch_to_fiber()
__tsan_set_fiber_name()

See the added tests for use examples.

Author: yuri (Yuri Per)
Reviewed in: https://reviews.llvm.org/D54889

llvm-svn: 353817
2019-02-12 10:11:58 +00:00
Dmitry Vyukov ca524b19c1 tsan: Introduce in_symbolizer() function for Thread sanitizer
This change is preparation for fiber support.

Author: yuri (Yuri Per)
Reviewed in: https://reviews.llvm.org/D58104

llvm-svn: 353805
2019-02-12 08:11:07 +00:00
Kostya Serebryany 2b9a8f37a4 [libFuzzer] make the fork mode less verbose
llvm-svn: 353794
2019-02-12 03:12:40 +00:00
Kostya Serebryany cdbb9dc962 [libFuzzer] teach the fork mode to ignore OOMs and timeouts
llvm-svn: 353792
2019-02-12 02:18:53 +00:00
Petr Hosek 26eec703f7 [sanitizer] Don't compile GetPathAssumingFileIsRelativeToExec on Fuchsia
This avoids the unused function warning during compilation.

Differential Revision: https://reviews.llvm.org/D58082

llvm-svn: 353787
2019-02-12 01:36:08 +00:00
Kostya Serebryany 73bf6d5b35 [libFuzzer] replace slow std::mt19937 with a much faster std::minstd_rand; second attempt after failed r352732, this time with a fix for cmake
llvm-svn: 353782
2019-02-12 01:00:08 +00:00
Kostya Serebryany 56b2d57cbf [libFuzzer] simplify the code for print_coverage=1 so that it doesn't fail on broken debug info
llvm-svn: 353781
2019-02-12 00:52:11 +00:00
Kostya Serebryany 63f48717b5 [libFuzzer] extend the -fork=1 functionality. Still not fully usable, but good enough for the first unit test
llvm-svn: 353775
2019-02-12 00:12:33 +00:00
Vitaly Buka 86a8d50965 tsan: Implement pthread_exit() interceptor for Thread sanitizer
This change is preparation for fiber support.

Author: yuri (Yuri Per)
Reviewed in: https://reviews.llvm.org/D57876
Context: https://reviews.llvm.org/D54889

> llvm-svn: 353385

llvm-svn: 353627
2019-02-09 22:08:31 +00:00
Vitaly Buka 2abcb30f8c [tsan] Remove pthread_exit interceptor
Crashes PPC bot

llvm-svn: 353604
2019-02-09 09:58:57 +00:00
David L. Jones 6218b8e783 [Fuzzer] Fix function prototype in fuzzer::ExternalFunctions. [NFC]
The __sanitizer_acquire_crash_state function has int return type, but the
fuzzer's external function definitions give it bool.

Places where __sanitizer_acquire_crash_state is declared:

  include/sanitizer_common/sanitizer_interface_defs.h
  lib/sanitizer_common/sanitizer_interface_internal.h
  lib/sanitizer_common/sanitizer_common.cc
  lib/fuzzer/FuzzerExtFunctions.def (this is the only bool)

llvm-svn: 353596
2019-02-09 01:45:29 +00:00
Kostya Serebryany 0fda9dcbe9 [libFuzzer] more refactoring; change some of the exit codes (timeout, OOM, interrupt) so that the parent process can distinguish those
llvm-svn: 353584
2019-02-09 00:16:21 +00:00
Kostya Serebryany 114cfafe05 [libFuzzer] refactor the merging code, NFC
llvm-svn: 353576
2019-02-08 22:59:03 +00:00
Kostya Serebryany b1e8b8149b [libFuzzer] remove two unused experimental flags
llvm-svn: 353573
2019-02-08 22:02:37 +00:00
Kostya Serebryany f762a11544 [libFuzzer] introduce an experimental mode -fork=1, where fuzzing happens in a subprocess (still running multiple inputs per process), thus making the fuzzing more resilient to timeouts and OOMs. This is just a skeleton of the code, and some associated refactoring, not a fully working feature yet.
llvm-svn: 353570
2019-02-08 21:27:23 +00:00
Vitaly Buka f333118ee0 Fix Die() after pthread_exit call on macOS
Summary:
Scoped interceptor should not be used when calling real pthread_exit().
On macOS C++ destructors are not called by pthread_exit(), and later check for empty thread ignore set fails.

Patch by Yuri Per.

Reviewers: dvyukov, vitalybuka

Reviewed By: vitalybuka

Subscribers: vitalybuka, thegameg, kubamracek, jfb, llvm-commits, #sanitizers

Tags: #sanitizers, #llvm

Differential Revision: https://reviews.llvm.org/D57963

llvm-svn: 353561
2019-02-08 20:43:26 +00:00
Francis Visoiu Mistrih c716bee053 [InstrProf] Fix darwin errors after r353547
The macros were changed but not updated in the Darwin version.

Fail here: http://green.lab.llvm.org/green/job/clang-stage1-configure-RA/53739/

rdar://47925820

llvm-svn: 353560
2019-02-08 20:37:40 +00:00
Vitaly Buka a1cec5b264 [tsan] Remove SCOPED_TSAN_INTERCEPTOR to try to fix ppc bot
llvm-svn: 353552
2019-02-08 19:37:32 +00:00
Reid Kleckner 987d331fab [InstrProf] Implement static profdata registration
Summary:
The motivating use case is eliminating duplicate profile data registered
for the same inline function in two object files. Before this change,
users would observe multiple symbol definition errors with VC link, but
links with LLD would succeed.

Users (Mozilla) have reported that PGO works well with clang-cl and LLD,
but when using LLD without this static registration, we would get into a
"relocation against a discarded section" situation. I'm not sure what
happens in that situation, but I suspect that duplicate, unused profile
information was retained. If so, this change will reduce the size of
such binaries with LLD.

Now, Windows uses static registration and is in line with all the other
platforms.

Reviewers: davidxl, wmi, inglorion, void, calixte

Subscribers: mgorny, krytarowski, eraman, fedor.sergeev, hiraditya, #sanitizers, dmajor, llvm-commits

Tags: #sanitizers, #llvm

Differential Revision: https://reviews.llvm.org/D57929

llvm-svn: 353547
2019-02-08 19:03:50 +00:00
Kostya Serebryany 0719b3527f [libFuzzer] refactor the way we choose the element to cross-over with, NFC (expected1); add a flag -seed_inputs= to pass extra seed inputs as file paths, not dirs
llvm-svn: 353494
2019-02-08 01:20:54 +00:00
Reid Kleckner c20ff80845 Silence -Wformat warnings about GetLastError returning ULONG
llvm-svn: 353485
2019-02-07 23:58:48 +00:00
Reid Kleckner c795e62ece Commit macro intended to be included in r353483.
llvm-svn: 353484
2019-02-07 23:57:21 +00:00
Reid Kleckner 2428224ffe [compiler rt] Win64 GetInstructionSize additional register MOV + stack alignment AND
Current interception code does not cover all of the required registers
on Windows for a specific flavor of MOV, so this patch adds cases to
identify the following 5-byte instructions on 64-bit Windows:

mov QWORD PTR [rsp + XX], rdx  <- second integer argument
mov QWORD PTR [rsp + XX], r9    <- third integer argument
mov QWORD PTR [rsp + XX], r8    <- fourth integer argument

The instruction for MOV [...] RCX is already covered in the previous
version.

Patch by Matthew McGovern!

Reviewers: rnk

Differential Revision: https://reviews.llvm.org/D57339

llvm-svn: 353483
2019-02-07 23:56:37 +00:00
Vitaly Buka 871b2bd980 [safestack] Explain why tinfo at the end of the buffer
Reviewers: pcc, eugenis, vlad.tsyrklevich

Reviewed By: vlad.tsyrklevich

Subscribers: llvm-commits, jfb, #sanitizers

Tags: #sanitizers, #llvm

Differential Revision: https://reviews.llvm.org/D57863

llvm-svn: 353482
2019-02-07 23:20:47 +00:00
Vitaly Buka 539e6aa421 [safestack] Remove pageSize
Summary:
3rd party sysconf interceptor may crash if it's called before unsafe_stack_setup

However pageSize is not useful here. mmap should round up on it's own, SFS_CHECK can be removed.

Reviewers: eugenis, vlad.tsyrklevich

Subscribers: #sanitizers, llvm-commits

Tags: #sanitizers, #llvm

Differential Revision: https://reviews.llvm.org/D57924

llvm-svn: 353481
2019-02-07 23:20:39 +00:00
Vitaly Buka 6569120b81 [safestack] Don't crash if stack size is not aligned as expected
Summary:
From runtime side looks it's OK to RoundUpTo to needed alignment as buffer is
going to be RoundUpTo to page size anyway.

Reviewers: eugenis, pcc

Subscribers: #sanitizers

Tags: #sanitizers

Differential Revision: https://reviews.llvm.org/D57866

llvm-svn: 353475
2019-02-07 22:26:04 +00:00
Kostya Kortchinsky 7547170ca4 [scudo][standalone] Do not error out on spurious C(XX) flags
Summary:
The standalone Scudo version is being built with `-Werror` which can be
tripped by extraneous command line arguments. We have little control over
those as they can be passed down to us by `CMAKE_C(XX)_FLAGS`, the reported
scenario involving `-stdlib=libc++` (see https://reviews.llvm.org/D57412#1384504).

To work around this, disable `-Wunused-command-line-argument`.

Reviewers: eugenis, vitalybuka, Eugene.Zelenko

Reviewed By: eugenis

Subscribers: mgorny, delcypher, #sanitizers, llvm-commits

Tags: #llvm, #sanitizers

Differential Revision: https://reviews.llvm.org/D57757

llvm-svn: 353418
2019-02-07 15:44:36 +00:00
Dmitry Vyukov bdfba86047 tsan: add more benchmarks
func_entry_exit.cc is for __tsan_func_entry/exit (spends ~75% there),
we don't yet have any.
mop.cc is for memory access functions, as compared to mini_bench_local/shared.cc
this benchmark passes through deduplication logic (ContainsSameAccess).

llvm-svn: 353407
2019-02-07 14:04:04 +00:00
Dmitry Vyukov fddaf1f369 tsan: Optimize performance of Thread sanitizer memory access functions
- Manually unwind code in MemoryAccessImpl1() because clang do not optimize it
- Check for .rodata section only in read operations
- Place LIKELY/UNLIKELY on fast paths

This speeds up synthetic memory access benchmarks by 10-20%.

[dvyukov: fixed up consts in check_analyze.sh]

Author: yuri (Yuri Per)
Reviewed in: https://reviews.llvm.org/D57882
Context: https://reviews.llvm.org/D54889

llvm-svn: 353401
2019-02-07 12:43:09 +00:00
Dmitry Vyukov baf2f35ec4 sanitizers: Introduce ThreadType enum
Replace bool workerthread flag with ThreadType enum.
This change is preparation for fiber support.

[dvyukov: fixed build of sanitizer_thread_registry_test.cc]

Author: yuri (Yuri Per)
Reviewed in: https://reviews.llvm.org/D57839
Context: https://reviews.llvm.org/D54889

llvm-svn: 353390
2019-02-07 11:01:22 +00:00
Dmitry Vyukov 17132b62e0 tsan: Implement pthread_exit() interceptor for Thread sanitizer
This change is preparation for fiber support.

Author: yuri (Yuri Per)
Reviewed in: https://reviews.llvm.org/D57876
Context: https://reviews.llvm.org/D54889

llvm-svn: 353385
2019-02-07 10:46:02 +00:00
Vitaly Buka 1665ea19e9 [sanitizer] Remove unneeded pointer check
Summary: unpoison_passwd and unpoison_group support nullptrs

Reviewers: eugenis

Subscribers: kubamracek, #sanitizers

Tags: #sanitizers

Differential Revision: https://reviews.llvm.org/D57784

llvm-svn: 353365
2019-02-07 01:54:59 +00:00
Vitaly Buka eb7031ecf6 [sanitizer] Don't unpoison buffer in getpw/getgr functions
Summary:
Buffer should be referenced by results so used parts will be unpoisoned with unpoison_group and unpoison_passwd.

This fixes TSAN performance issue made us to disable this interceptors.

Reviewers: eugenis, dvyukov

Subscribers: srhines, kubamracek, krytarowski, #sanitizers

Tags: #sanitizers

Differential Revision: https://reviews.llvm.org/D57731

llvm-svn: 353351
2019-02-07 00:08:14 +00:00
Evgeniy Stepanov 54c82886cb [sanitizer] Fix fuchsia and windows build.
llvm-svn: 353261
2019-02-06 01:58:23 +00:00
Evgeniy Stepanov 443c034391 [sanitizer] Decorate /proc/self/maps better.
Summary:
Refactor the way /proc/self/maps entries are annotated to support most
(all?) posix platforms, with a special implementation for Android.
Extend the set of decorated Mmap* calls.

Replace shm_open with internal_open("/dev/shm/%s"). Shm_open is
problematic because it calls libc open() which may be intercepted.

Generic implementation has limits (max number of files under /dev/shm is
64K on my machine), which can be conceivably reached when sanitizing
multiple programs at once. Android implemenation is essentially free, and
enabled by default.

The test in sanitizer_common is copied to hwasan and not reused directly
because hwasan fails way too many common tests at the moment.

Reviewers: pcc, vitalybuka

Subscribers: srhines, kubamracek, jfb, llvm-commits, kcc

Differential Revision: https://reviews.llvm.org/D57720

llvm-svn: 353255
2019-02-06 01:14:50 +00:00
Kamil Rytarowski 3349bd662a Update the ioctl(2) list in sanitizers with NetBSD 8.99.34
llvm-svn: 353224
2019-02-05 22:20:25 +00:00
Reid Kleckner 0a142346b3 [InstrProf] Merge COFF .lprof* and .lcovmap sections into .data/.rdata
There is no reason for these sections to remain separate in the final
DLL or EXE.

I have not yet added a InstrProfilingPlatformWindows.c for these, since
avoiding dynamic profile data registration is a larger project for
later.

llvm-svn: 353221
2019-02-05 21:26:31 +00:00
Vitaly Buka 0ca702f8d5 [sanitizer] Fix unused function 'unpoison_passwd'
llvm-svn: 353205
2019-02-05 19:46:44 +00:00
Vitaly Buka d2a42c3815 [tsan] Disable fgetpwent_r to work around performance issues
This was missed from D54041 when SANITIZER_INTERCEPT_FGETPWENT_R was branched from SANITIZER_INTERCEPT_GETPWENT_R

llvm-svn: 353110
2019-02-04 23:25:55 +00:00
Jonathan Metzman 7c907bac6f [libFuzzer][Windows] Clean up RawPrint
Summary:
Use `_write` instead of the deprecated alias `write` on Windows.
Also, remove comment saying RawPrint is untested on Windows.

Reviewers: vitalybuka

Reviewed By: vitalybuka

Subscribers: vitalybuka

Differential Revision: https://reviews.llvm.org/D57589

llvm-svn: 353108
2019-02-04 23:01:06 +00:00
Kostya Kortchinsky 47f0d136f1 [scudo] Initial standalone skeleton check-in
Summary:
This is the initial check-in for the Standalone version of Scudo.

The project is initially going to live in scudo/standalone then will
replace scudo. See http://lists.llvm.org/pipermail/llvm-dev/2019-January/129113.html
for details.

This initial CL is meant to lay out the project structure, of both
code & tests, providing a minimal amount of functionalities, namely
various definitions, some atomic helpers and an intrusive list.
(empty.cc is just here to have a compilation unit, but will go away
in the upcoming CLs).

Initial support is restricted to Linux i386 & x86_64 in make files
and will be extended once things land & work.

We will grow organically from here, adding functionalities in limited
amounts.

Reviewers: morehouse, eugenis, vitalybuka, kcc, mcgrathr, flowerhack

Reviewed By: morehouse, vitalybuka

Subscribers: srhines, mgorny, krytarowski, delcypher, jfb, #sanitizers, llvm-commits

Tags: #llvm, #sanitizers

Differential Revision: https://reviews.llvm.org/D57412

llvm-svn: 353055
2019-02-04 16:25:40 +00:00
Reid Kleckner 33706e3cbf [ubsan] Make suppressions.cpp test pass for me on Windows
The test seems to be failing because the module suppression file
contains a colon. I found that it was sufficient to just use the
basename of the suppression file.

While I was here, I noticed that we don't implement IsAbsolutePath for
Windows, so I added it.

llvm-svn: 352921
2019-02-01 21:35:17 +00:00
Peter Collingbourne 6fa43f8b9c Mark __rela_iplt_{start,end} as weak.
Should fix non-lld links.

llvm-svn: 352823
2019-02-01 00:43:31 +00:00
Peter Collingbourne 886b7cc107 hwasan: Add __hwasan_init_static() function.
This function initializes enough of the runtime to be able to run
instrumented code in a statically linked executable. It replaces
__hwasan_shadow_init() which wasn't doing enough initialization for
instrumented code that uses either TLS or IFUNC to work.

Differential Revision: https://reviews.llvm.org/D57490

llvm-svn: 352816
2019-01-31 23:37:12 +00:00
Jonathan Metzman fc7faecb40 [fuzzer] Use RawPrint instead of Printf for instrumentation warning
Summary:
Use RawPrint instead of Printf for instrumentation warning because
Printf doesn't work on Win when instrumentation is being
initialized (since OutputFile is not yet initialized).

Reviewers: kcc

Reviewed By: kcc

Differential Revision: https://reviews.llvm.org/D57531

llvm-svn: 352789
2019-01-31 20:32:20 +00:00
Jeremy Morse d778d4fded Revert r352732: [libFuzzer] replace slow std::mt19937 with a much faster std::minstd_rand
This causes a failure on the following bot as well as our internal ones:

http://lab.llvm.org:8011/builders/sanitizer-x86_64-linux-fuzzer/builds/23103

llvm-svn: 352747
2019-01-31 12:44:14 +00:00
Kostya Serebryany 046cac61c1 [libFuzzer] replace slow std::mt19937 with a much faster std::minstd_rand
llvm-svn: 352732
2019-01-31 06:52:55 +00:00
Kostya Serebryany 23482e1d07 [libFuzzer] set libFuzzer's own SEGV handler even one is already present, but call that handler from ours (unless we are unprotecting lazy counters). Call ProtectLazyCounters later, so that it runs after the initialization code in the target.
llvm-svn: 352713
2019-01-31 01:40:14 +00:00
Julian Lettner 15df273eb4 [libFuzzer] Set default sanitizer options in fuzzer tests
Summary:
Set default `ASAN_OPTIONS` when running libFuzzer tests. This allows us
to remove special casing in code for Darwin where we usually pass
`abort_on_error=0` to override platform defaults for tests.

A previous commit changed the code to make the tests pass:
7764a04af0

Adapted a few tests to use `%env_asan_opts=` instead of directly setting
the environment variable.

rdar://problem/47515276

Reviewers: kcc, george.karpenkov

Differential Revision: https://reviews.llvm.org/D57465

llvm-svn: 352711
2019-01-31 01:24:01 +00:00
Kostya Serebryany 8da9479e40 [libFuzzer] experimental performance optimization -lazy_counters, off by default. Posix-only for now, tested on Linux
llvm-svn: 352700
2019-01-31 00:09:43 +00:00
Kostya Serebryany 5c0751ec3e [libFuzzer] remove stale code, NFC
llvm-svn: 352604
2019-01-30 06:21:20 +00:00
Kostya Serebryany 6fd4d8ab9c [libFuzzer] refactor the handling of instrumentation counters so that they are grouped in regions one full page each. Needed for future optimization. NFC
llvm-svn: 352603
2019-01-30 06:15:52 +00:00
Kostya Serebryany 2891b257c2 [libFuzzer] remove stale code
llvm-svn: 352571
2019-01-29 23:53:28 +00:00
Kostya Serebryany 035c08f73d [libFuzzer] revert an accidental commit
llvm-svn: 352567
2019-01-29 23:41:50 +00:00
Kostya Serebryany 62d7270610 [libFuzzer] remove deprecated support for -fsanitize-coverage=trace-pc[-guard]
llvm-svn: 352566
2019-01-29 23:40:05 +00:00
Kostya Serebryany 50a1c69712 [libFuzzer] remove deprecated support for -fsanitize-coverage=trace-pc[-guard]
llvm-svn: 352564
2019-01-29 23:37:20 +00:00
James Y Knight 5d71fc5d7b Adjust documentation for git migration.
This fixes most references to the paths:
 llvm.org/svn/
 llvm.org/git/
 llvm.org/viewvc/
 github.com/llvm-mirror/
 github.com/llvm-project/
 reviews.llvm.org/diffusion/

to instead point to https://github.com/llvm/llvm-project.

This is *not* a trivial substitution, because additionally, all the
checkout instructions had to be migrated to instruct users on how to
use the monorepo layout, setting LLVM_ENABLE_PROJECTS instead of
checking out various projects into various subdirectories.

I've attempted to not change any scripts here, only documentation. The
scripts will have to be addressed separately.

Additionally, I've deleted one document which appeared to be outdated
and unneeded:
  lldb/docs/building-with-debug-llvm.txt

Differential Revision: https://reviews.llvm.org/D57330

llvm-svn: 352514
2019-01-29 16:37:27 +00:00
Igor Kudrin 0f13000958 [compiler-rt] Fix reporting unrecognized flags in unit tests.
Previously, the warning messages might be issued within a wrong test case.

Differential Revision: https://reviews.llvm.org/D57318

llvm-svn: 352447
2019-01-29 02:31:57 +00:00
Jonathan Metzman 8f7fc95ab7 [libFuzzer][Windows] Use dllexport for all declarations in FuzzerInterface.h
Summary:
Use dllexport for all declarations in FuzzerInterface.h Use it for clang
even though clang supports default visibility attribute to prevent a
warning from being thrown when LLVMFuzzerMutate is defined with dllexport.
This makes `FUZZER_INTERFACE_VISIBILITY` (FuzzerInterface.h) consistent with
`ATTRIBUTE_INTERFACE` (FuzzerDefs.h) when using clang on Windows.

Reviewers: vitalybuka, morehouse

Reviewed By: morehouse

Differential Revision: https://reviews.llvm.org/D57305

llvm-svn: 352395
2019-01-28 17:51:13 +00:00
Jonathan Metzman 3720e2b39e [fuzzer][afl] Remove AFL_DRIVER_EXTRA_STATS_FILENAME
Summary:
Remove this feature as it is unused, buggy, and not worth correcting
since the forkserver makes it difficult.

Reviewers: morehouse, jfb

Reviewed By: morehouse

Differential Revision: https://reviews.llvm.org/D57308

llvm-svn: 352392
2019-01-28 17:15:49 +00:00
Dan Liew 225eb75a10 Make more allocator methods work correctly with in an out-of-process mode.
Summary:
This makes `GetBlockBegin()` and `GetBlockBeginFastLocked()` work correctly with `RemoteAddressSpaceView`.

This has a knock on effect of also making the `PointerIsMine()` and
`GetMetaData()` methods behave correctly when `RemoteAddressSpaceView`
is used to instantiate the allocators.

This will be used by future out-of-process allocator enumeration
patches.

rdar://problem/45284065

Reviewers: kcc, vitalybuka, dvyukov, cryptoad, eugenis, george.karpenkov, yln

Subscribers: #sanitizers, llvm-commits, kubamracek

Differential Revision: https://reviews.llvm.org/D56964

llvm-svn: 352335
2019-01-27 22:45:11 +00:00
Kostya Serebryany bb01a098b1 [libFuzzer] print uncovered functions when doing -print_coverage=1
llvm-svn: 352263
2019-01-26 01:33:09 +00:00
Dimitry Andric d849f8fd8f Fix XRayTest link on FreeBSD (and likely NetBSD too)
Summary:
As reported on llvm-testers, during 8.0.0-rc1 testing I got errors while
building of `XRayTest`, during `check-all`:

```
[100%] Generating XRayTest-x86_64-Test
/home/dim/llvm/8.0.0/rc1/Phase3/Release/llvmCore-8.0.0-rc1.obj/./lib/libLLVMSupport.a(Signals.cpp.o): In function `llvm::sys::PrintStackTrace(llvm::raw_ostream&)':
Signals.cpp:(.text._ZN4llvm3sys15PrintStackTraceERNS_11raw_ostreamE+0x24): undefined reference to `backtrace'
Signals.cpp:(.text._ZN4llvm3sys15PrintStackTraceERNS_11raw_ostreamE+0x254): undefined reference to `llvm::itaniumDemangle(char const*, char*, unsigned long*, int*)'
clang-8: error: linker command failed with exit code 1 (use -v to see invocation)
gmake[3]: *** [projects/compiler-rt/lib/xray/tests/unit/CMakeFiles/TXRayTest-x86_64-Test.dir/build.make:73: projects/compiler-rt/lib/xray/tests/unit/XRayTest-x86_64-Test] Error 1
gmake[3]: Target 'projects/compiler-rt/lib/xray/tests/unit/CMakeFiles/TXRayTest-x86_64-Test.dir/build' not remade because of errors.
gmake[2]: *** [CMakeFiles/Makefile2:33513: projects/compiler-rt/lib/xray/tests/unit/CMakeFiles/TXRayTest-x86_64-Test.dir/all] Error 2
gmake[2]: Target 'CMakeFiles/check-all.dir/all' not remade because of errors.
gmake[1]: *** [CMakeFiles/Makefile2:737: CMakeFiles/check-all.dir/rule] Error 2
gmake[1]: Target 'check-all' not remade because of errors.
gmake: *** [Makefile:277: check-all] Error 2
[Release Phase3] check-all failed
```

This is because the `backtrace` function requires `-lexecinfo` on BSD
platforms.  To fix this, detect the `execinfo` library in
`cmake/config-ix.cmake`, and add it to the unit test link flags.

Additionally, since the code in `sys::PrintStackTrace` makes use of
`itaniumDemangle`, also add `-lLLVMDemangle`.  (Note that this is more
of a general problem with libLLVMSupport, but I'm looking for a quick
fix now so it can be merged to the 8.0 branch.)

Reviewers: dberris, hans, mgorny, samsonov

Reviewed By: dberris

Subscribers: krytarowski, delcypher, erik.pilkington, #sanitizers, emaste, llvm-commits

Differential Revision: https://reviews.llvm.org/D57181

llvm-svn: 352234
2019-01-25 19:36:47 +00:00
Kamil Rytarowski 63bd043a12 Enhance support for NetBSD in SafeStack
Summary:
Always try to detect and call internal or real libc symbols instead of
locally installed interceptors.

This covers:
 - GetTid()
 - TgKill()
 - Mmap()
 - Munmap()
 - Mprotect()

This cherry-picks code from sanitizer_common/sanitizer_netbsd.cc.

Reviewers: vitalybuka

Reviewed By: vitalybuka

Subscribers: llvm-commits, mgorny, #sanitizers

Tags: #sanitizers

Differential Revision: https://reviews.llvm.org/D57179

llvm-svn: 352154
2019-01-25 02:18:01 +00:00
Evgeniy Stepanov f4e7051c67 [hwasan] Madvise away thread aux data
Summary:
Release memory pages for thread data (allocator cache, stack allocations
ring buffer, etc) when a thread exits. We can not simply munmap them
because this memory is custom allocated within a limited address range,
and it needs to stay "reserved".

This change alters thread storage layout by putting the ring buffer
before Thread instead of after it. This makes it possible to find the
start of the thread aux allocation given only the Thread pointer.

Reviewers: kcc, pcc

Subscribers: kubamracek, llvm-commits

Differential Revision: https://reviews.llvm.org/D56621

llvm-svn: 352151
2019-01-25 02:05:48 +00:00
Evgeniy Stepanov 9ea001401c [hwasan] Implement print_module_map flag.
Reviewers: kcc, pcc

Subscribers: kubamracek, llvm-commits

Differential Revision: https://reviews.llvm.org/D57130

llvm-svn: 352150
2019-01-25 02:05:25 +00:00
Jonathan Metzman 62f1871060 [libFuzzer][MSVC] Disable exceptions in MSVC headers
Summary:
Disable exceptions in MSVC headers using -D_HAS_EXCEPTIONS=0
to silence compiler warning instead of using /Ehsc.

Reviewers: rnk, morehouse, metzman

Reviewed By: rnk, morehouse, metzman

Subscribers: rnk, morehouse, mgorny

Differential Revision: https://reviews.llvm.org/D57119

llvm-svn: 352144
2019-01-25 01:10:57 +00:00
Kostya Serebryany 360bf5ff58 [libFuzzer] more agressive value profiling and CMP tracing for switch statements
llvm-svn: 352107
2019-01-24 21:08:54 +00:00
Kostya Kortchinsky f0fbeaf44a [scudo] Tuning changes based on feedback from current use
Summary:
This tunes several of the default parameters used within the allocator:
- disable the deallocation type mismatch on Android by default; this
  was causing too many issues with third party libraries;
- change the default `SizeClassMap` to `Dense`, it caches less entries
  and is way more memory efficient overall;
- relax the timing of the RSS checks, 10 times per second was too much,
  lower it to 4 times (every 250ms), and update the test so that it
  passes with the new default.

Reviewers: eugenis

Reviewed By: eugenis

Subscribers: srhines, delcypher, #sanitizers, llvm-commits

Differential Revision: https://reviews.llvm.org/D57116

llvm-svn: 352057
2019-01-24 15:56:54 +00:00
Martin Liska acc348aad0 Revert https://reviews.llvm.org/D56485.
llvm-svn: 352033
2019-01-24 08:46:06 +00:00
Martin Liska dc5c81330b Always compare C++ typeinfo (based on libstdc++ implementation).
Differential Revision: https://reviews.llvm.org/D56485.

llvm-svn: 352032
2019-01-24 08:25:36 +00:00
Martin Storsjo b5a5055704 Fix building sanitizers for MinGW
The /EHsc flag is MSVC specific, not generic to the windows target.

llvm-svn: 351927
2019-01-23 07:23:16 +00:00
Peter Collingbourne 73078ecd38 hwasan: Move memory access checks into small outlined functions on aarch64.
Each hwasan check requires emitting a small piece of code like this:
https://clang.llvm.org/docs/HardwareAssistedAddressSanitizerDesign.html#memory-accesses

The problem with this is that these code blocks typically bloat code
size significantly.

An obvious solution is to outline these blocks of code. In fact, this
has already been implemented under the -hwasan-instrument-with-calls
flag. However, as currently implemented this has a number of problems:
- The functions use the same calling convention as regular C functions.
  This means that the backend must spill all temporary registers as
  required by the platform's C calling convention, even though the
  check only needs two registers on the hot path.
- The functions take the address to be checked in a fixed register,
  which increases register pressure.
Both of these factors can diminish the code size effect and increase
the performance hit of -hwasan-instrument-with-calls.

The solution that this patch implements is to involve the aarch64
backend in outlining the checks. An intrinsic and pseudo-instruction
are created to represent a hwasan check. The pseudo-instruction
is register allocated like any other instruction, and we allow the
register allocator to select almost any register for the address to
check. A particular combination of (register selection, type of check)
triggers the creation in the backend of a function to handle the check
for specifically that pair. The resulting functions are deduplicated by
the linker. The pseudo-instruction (really the function) is specified
to preserve all registers except for the registers that the AAPCS
specifies may be clobbered by a call.

To measure the code size and performance effect of this change, I
took a number of measurements using Chromium for Android on aarch64,
comparing a browser with inlined checks (the baseline) against a
browser with outlined checks.

Code size: Size of .text decreases from 243897420 to 171619972 bytes,
or a 30% decrease.

Performance: Using Chromium's blink_perf.layout microbenchmarks I
measured a median performance regression of 6.24%.

The fact that a perf/size tradeoff is evident here suggests that
we might want to make the new behaviour conditional on -Os/-Oz.
But for now I've enabled it unconditionally, my reasoning being that
hwasan users typically expect a relatively large perf hit, and ~6%
isn't really adding much. We may want to revisit this decision in
the future, though.

I also tried experimenting with varying the number of registers
selectable by the hwasan check pseudo-instruction (which would result
in fewer variants being created), on the hypothesis that creating
fewer variants of the function would expose another perf/size tradeoff
by reducing icache pressure from the check functions at the cost of
register pressure. Although I did observe a code size increase with
fewer registers, I did not observe a strong correlation between the
number of registers and the performance of the resulting browser on the
microbenchmarks, so I conclude that we might as well use ~all registers
to get the maximum code size improvement. My results are below:

Regs | .text size | Perf hit
-----+------------+---------
~all | 171619972  | 6.24%
  16 | 171765192  | 7.03%
   8 | 172917788  | 5.82%
   4 | 177054016  | 6.89%

Differential Revision: https://reviews.llvm.org/D56954

llvm-svn: 351920
2019-01-23 02:20:10 +00:00
Yi Kong 02d85149a0 [builtins] Do not set hidden attribute on Android
Bionic libc relies on an old libgcc behaviour which does not set hidden
visibility attribute. Keep exporting these symbols on Android for 
compatibility.

Differential Revision: https://reviews.llvm.org/D56977

llvm-svn: 351915
2019-01-23 01:59:35 +00:00
Jonathan Metzman 3c535a60dd [libFuzzer][MSVC] Enable building libFuzzer with MSVC
Summary:
Enable building libFuzzer with MSVC.

* Don't try to include <endian.h> in FuzzerSHA1.cpp. MSVC
  doesn't have this header, and WINDOWS is always little
  endian (even on ARM)

Subscribers: srhines, mgorny, javed.absar, kristof.beyls

Differential Revision: https://reviews.llvm.org/D56510

llvm-svn: 351855
2019-01-22 18:59:25 +00:00
Vitaly Buka 096ee9159f [safestack] Return syscalls for mmap, munmap and mprotect
This function can be already intercepted by instrumented code.

llvm-svn: 351783
2019-01-22 05:23:48 +00:00
Vitaly Buka b793d25443 [safestack] Fix NetBSD build
llvm-svn: 351771
2019-01-22 00:39:59 +00:00
Eugene Leviant 0d7952ce78 [HWASAN] Improve tag mismatch diagnostics
Reports correct size and tags when either size is not power of two
or offset to bad granule is not zero.

Differential revision: https://reviews.llvm.org/D56603

llvm-svn: 351730
2019-01-21 09:51:10 +00:00
Vitaly Buka 2b3d8b3286 [safestack] Remove unsupported platforms
llvm-svn: 351716
2019-01-21 02:21:59 +00:00
Vitaly Buka 7ef159dda5 [safestack] Fix FreeBSD runtime build
llvm-svn: 351715
2019-01-21 02:21:51 +00:00
Jonathan Metzman dd467f4f43 [libFuzzer][MSVC] Make Sanitizer Coverage MSVC-compatible
Summary:
Make Sanitizer Coverage work when compiled work when compiler-rt
is compiled with MSVC.

The previous solution did not work for MSVC because MSVC tried to
align the .SCOV$CZ section even though we used
__declspec(align(1)) on its only symbol:
__stop___sancov_cntrs.
Because the counter array is composed
of 1 byte elements, it does not always end on an 8 or 4 byte
boundary. This means that padding was sometimes added to
added to align the next section, .SCOV$CZ.
Use a different strategy now: instead of only instructing
the compiler not to align the symbol, make the section
one byte long by making its only symbol a uint8_t, so that
the linker won't try to align it.

Reviewers: morehouse, rnk

Reviewed By: rnk

Subscribers: kubamracek

Differential Revision: https://reviews.llvm.org/D56866

llvm-svn: 351714
2019-01-21 02:15:29 +00:00
Dan Liew a35df433bf [ASan] On Darwin record global allocator pointer and size in introspection struct.
This implements `mi_extra_init(...)` for the ASan allocator on
Darwin and uses the `__lsan::GetAllocatorGlobalRange(...)` function
to retrieve the allocator pointer and size.

rdar://problem/45284065

llvm-svn: 351713
2019-01-21 01:41:12 +00:00
Dan Liew 5a3857c9b2 On Darwin add allocator address and size fields to
`sanitizer_malloc_introspection_t` and initialize them to zero.

We allow sanitizer implementations to perform different initialization
by defining `COMMON_MALLOC_HAS_EXTRA_INTROSPECTION_INIT` to be `1`
and providing an implementation of `mi_extra_init(...)`.

We use these changes in future patches to implement malloc zone enumeration.

rdar://problem/45284065

llvm-svn: 351712
2019-01-21 01:41:08 +00:00
Dan Liew 4dd0bf9487 On Darwin allow for sanitizer malloc implementations to provide a zone
enumerator.

This is done by defining `COMMON_MALLOC_HAS_ZONE_ENUMERATOR` to `1` and
then by providing an implementation of the `mi_enumerator(...)` function.
If a custom implementation isn't desired the macro is set to `0` which
causes a stub version (that fails) to be used.

Currently all Darwin sanitizers that have malloc implementations define
this to be `0` so there is no functionality change.

rdar://problem/45284065

llvm-svn: 351711
2019-01-21 01:41:01 +00:00
Dan Liew 0e83f5dff1 Fix bug in `AsanAllocatorASVT` (ASan) and `AllocatorASVT` (LSan) templated alias.
We forgot to pass `AddressSpaceView` to the `CombinedAllocator`
which meant we would always use `LocalAddressSpaceView` for the
`CombinedAllocator` leading to a static_assert failing when we
tried to do `AsanAllocatorASVT<RemoteAddressSpaceView>` or
`AllocatorASVT<RemoteAddressSpaceView>`.

rdar://problem/45284065

llvm-svn: 351689
2019-01-20 16:57:24 +00:00
Chandler Carruth 57b08b0944 Update more file headers across all of the LLVM projects in the monorepo
to reflect the new license. These used slightly different spellings that
defeated my regular expressions.

We understand that people may be surprised that we're moving the header
entirely to discuss the new license. We checked this carefully with the
Foundation's lawyer and we believe this is the correct approach.

Essentially, all code in the project is now made available by the LLVM
project under our new license, so you will see that the license headers
include that license only. Some of our contributors have contributed
code under our old license, and accordingly, we have retained a copy of
our old license notice in the top-level files in each project and
repository.

llvm-svn: 351648
2019-01-19 10:56:40 +00:00
Chandler Carruth 2946cd7010 Update the file headers across all of the LLVM projects in the monorepo
to reflect the new license.

We understand that people may be surprised that we're moving the header
entirely to discuss the new license. We checked this carefully with the
Foundation's lawyer and we believe this is the correct approach.

Essentially, all code in the project is now made available by the LLVM
project under our new license, so you will see that the license headers
include that license only. Some of our contributors have contributed
code under our old license, and accordingly, we have retained a copy of
our old license notice in the top-level files in each project and
repository.

llvm-svn: 351636
2019-01-19 08:50:56 +00:00
Evgeniy Stepanov c089fbbaf2 [hwasan] Madvise away unused shadow.
Summary:
Whenever a large shadow region is tagged to zero, madvise(DONT_NEED)
as much of it as possible.

This reduces shadow RSS on Android by 45% or so, and total memory use
by 2-4%, probably even more on long running multithreaded programs.
CPU time seems to be in the noise.

Reviewers: kcc, pcc

Subscribers: srhines, kubamracek, llvm-commits

Differential Revision: https://reviews.llvm.org/D56757

llvm-svn: 351620
2019-01-19 01:54:09 +00:00
Vitaly Buka 22039df5d1 [safestack] Add ThreadId type as uint64_t
Reviewers: krytarowski, eugenis

Subscribers: llvm-commits

Differential Revision: https://reviews.llvm.org/D56937

llvm-svn: 351607
2019-01-18 22:32:29 +00:00
Vitaly Buka f5ce42c040 [safestack] Remove dependency of SafeStack on sanitizer_common
Summary:
SafeStack needs just few functions from there, but sanitizer_common
introduces conflicts with other runtimes, e.g. SCUDO.

Reviewers: eugenis, kcc, cryptoad

Subscribers: mgorny, krytarowski, fedor.sergeev, jfb, llvm-commits

Differential Revision: https://reviews.llvm.org/D56886

llvm-svn: 351506
2019-01-18 01:53:37 +00:00
Vitaly Buka dbe4b02eeb [safestack] Replace statics with unnamed namespace
Reviewers: eugenis

Subscribers: jfb, llvm-commits

Differential Revision: https://reviews.llvm.org/D56888

llvm-svn: 351503
2019-01-18 01:36:09 +00:00
Jonathan Metzman b795c31dff [libFuzzer][MSVC] Make attribute-use compatible with MSVC
Summary:
Replace attributes with macros that use equivalent declspecs
for MSVC.

Reviewers: vitalybuka

Reviewed By: vitalybuka

Differential Revision: https://reviews.llvm.org/D56512

llvm-svn: 351456
2019-01-17 16:36:05 +00:00
Nico Weber 07d8b321b3 Make compiler-rt CMakeLists.txt formatting a bit more like LLVM's usual formatting
llvm-svn: 351363
2019-01-16 18:12:45 +00:00
Julian Lettner ac855d3ea9 [TSan] Use switches when dealing with enums
Summary:
Small refactoring: replace some if-else cascades with switches so that the compiler warns us about missing cases.
Maybe found a small bug?

Reviewers: dcoughlin, kubamracek, dvyukov, delcypher, jfb

Reviewed By: dvyukov

Subscribers: llvm-commits, #sanitizers

Tags: #sanitizers

Differential Revision: https://reviews.llvm.org/D56295

llvm-svn: 351288
2019-01-16 01:45:12 +00:00
Jonathan Metzman 9e14cccf6f [libFuzzer] Remove unstable edge handling
Summary:
Remove code for handling unstable edges from libFuzzer since
it has not been found useful.

Differential Revision: https://reviews.llvm.org/D56730

llvm-svn: 351262
2019-01-15 22:12:51 +00:00
Rong Xu 3e9e7fb961 [profile] Sync up InstrProfData.inc with llvm copy /NFC
llvm-svn: 351257
2019-01-15 21:59:17 +00:00
David Carlier bd27e4c156 [Sanitizer] Intercept sl_add api on FreeBSD/NetBSD
Reviewers: krytarowski, vitalybuka

Reviewed By: krytarowski

Differential Revision: https://reviews.llvm.org/D56670

llvm-svn: 351189
2019-01-15 11:21:33 +00:00
Roman Lebedev a06ad18669 [compiler-rt][UBSan] Sanitization for alignment assumptions.
Summary:
This is the compiler-rt part.
The clang part is D54589.

This is a second commit, the original one was r351106,
which was mass-reverted in r351159 because 2 compiler-rt tests were failing.

Now, i have fundamentally changed the testing approach:
i malloc a few bytes, intentionally mis-align the pointer
(increment it by one), and check that. Also, i have decreased
the expected alignment. This hopefully should be enough to pacify
all the bots. If not, i guess i might just drop the two 'bad' tests.

Reviewers: filcab, vsk, #sanitizers, vitalybuka, rsmith, morehouse

Reviewed By: morehouse

Subscribers: rjmccall, krytarowski, rsmith, kcc, srhines, kubamracek, dberris, llvm-commits

Tags: #sanitizers

Differential Revision: https://reviews.llvm.org/D54590

llvm-svn: 351178
2019-01-15 09:44:27 +00:00
Vlad Tsyrklevich 86e68fda3b Revert alignment assumptions changes
Revert r351104-6, r351109, r351110, r351119, r351134, and r351153. These
changes fail on the sanitizer bots.

llvm-svn: 351159
2019-01-15 03:38:02 +00:00
Jonathan Metzman a4d569bc19 [libFuzzer][MSVC] Use alternatename for ext functions
Summary:
Use alternatename for external functions only when using
MSVC since Clang doesn't support it and MSVC doesn't support
Clang's method (weak aliases).

Reviewers: morehouse

Reviewed By: morehouse

Subscribers: rnk, thakis, mgorny

Differential Revision: https://reviews.llvm.org/D56514

llvm-svn: 351152
2019-01-15 02:20:53 +00:00
Roman Lebedev fd10ac3584 [compiler-rt] Update ubsan_interface.inc with alignment assumption handlers
Somehow this escaped my local testing.
A follow-up for r351106.

llvm-svn: 351110
2019-01-14 19:35:12 +00:00
Michal Gorny 965517fdad [test] Disable sunrpc tests when rpc/xdr.h is missing
Disable tests requiring sunrpc when the relevant headers are missing.
In order to accommodate that, move the header check
from sanitizer_common to base-config-ix, and define the check result
as a global variable there.  Use it afterwards both for definition
needed by sanitizer_common, and to control 'sunrpc' test feature.

While at it, remove the append_have_file_definition macro that was used
only once, and no longer fits the split check-definition.

Bug report: https://github.com/google/sanitizers/issues/974

Differential Revision: https://reviews.llvm.org/D47819

llvm-svn: 351109
2019-01-14 19:18:34 +00:00