Commit Graph

1131 Commits

Author SHA1 Message Date
Evgeniy Stepanov 56050e8f69 [sanitizer] Fix __sanitizer_unaligned_* to work with unaligned data types.
llvm-svn: 183224
2013-06-04 13:49:10 +00:00
Alexey Samsonov 8f5138a23f Call __asan_free_hook() before marking the chunk quarantinned
Summary:
With this change, the user may safely call __asan_get_ownership()
from malloc/free hooks and assume it would return "true". If there is a
realloc/free race, free hook might be called twice, but I think it's acceptable,
as it's a data race and would later be reported anyway.

This change also fixes a bug when failing realloc incorrectly marked the
original memory as "quarantinned".

Reviewers: timurrrr, kcc, samsonov

Reviewed By: samsonov

CC: llvm-commits

Differential Revision: http://llvm-reviews.chandlerc.com/D913

llvm-svn: 183220
2013-06-04 12:19:31 +00:00
Sergey Matveev b256ac7584 [asan] Fix invalid thread registry access when checking if LSan is disabled.
llvm-svn: 183218
2013-06-04 10:39:24 +00:00
Timur Iskhodzhanov baf90ccfac Fix ALIGNED misuse in asan_thread.cc (built on all platforms); also, add a comment to the ALIGNED macro describing the correct usage
llvm-svn: 183214
2013-06-04 08:25:17 +00:00
Kostya Serebryany c1aa0e8f69 [asan] ASan Linux MIPS32 support (compiler-rt part), patch by Jyun-Yan Y
llvm-svn: 183105
2013-06-03 14:49:25 +00:00
Sergey Matveev 17ee1abfa7 [lsan] Add __lsan_disable() and __lsan_enable().
Objects allocated after a call to __lsan_disable() will be treated as
live memory. Also add a ScopedDisabler.

llvm-svn: 183099
2013-06-03 11:21:34 +00:00
Alexander Potapenko 41cd6102e9 [ASan] Do not buffer stdin in asan_symbolize.py
llvm-svn: 183006
2013-05-31 14:55:06 +00:00
Sergey Matveev 69f11803ec [lsan] Use the fast version of GetBlockBegin for leak checking in LSan and ASan.
llvm-svn: 182994
2013-05-31 11:13:45 +00:00
Kostya Serebryany 831a1d7cec [sanitizer] introduce LargeMmapAllocator::GetBlockBeginFastSingleThreaded, required for LeakSanitizer to work faster. Also fix lint.
llvm-svn: 182917
2013-05-30 08:43:30 +00:00
Alexander Potapenko a8b41762e4 [ASan] Minor cleanup: remove a couple of unused variables.
llvm-svn: 182915
2013-05-30 07:30:07 +00:00
Timur Iskhodzhanov 013da5cb37 Replaced 'bool .* = 0;' with '... = false;'
llvm-svn: 182868
2013-05-29 17:26:25 +00:00
Sergey Matveev 6a0c722c23 [asan] Fix r182858.
llvm-svn: 182862
2013-05-29 15:31:52 +00:00
Sergey Matveev 4161813a50 [asan] Fix r182854: run the unpoison_tls test only on Linux.
llvm-svn: 182858
2013-05-29 14:37:04 +00:00
Timur Iskhodzhanov cc61eefd4b Fix MSVC W3 compiler warnings
llvm-svn: 182857
2013-05-29 14:11:44 +00:00
Sergey Matveev 09886cd17a [asan] Make ASan report the correct thread address ranges to LSan.
This CL enables thread support in LSan when used on top of ASan.

llvm-svn: 182854
2013-05-29 13:09:44 +00:00
Evgeniy Stepanov 08f662845d [sanitizer] Share TSan accept & accept4 interceptors with other sanitizers.
llvm-svn: 182835
2013-05-29 09:09:58 +00:00
Sergey Matveev 39e8a6d87e [lsan] Begin converting LSan tests to output tests.
In this CL all old tests are removed and one LIT test is added.

llvm-svn: 182730
2013-05-27 11:41:46 +00:00
Alexey Samsonov 9c2bcf8c15 Improve support for compiler-rt tests in CMake build.
Now compiler-rt tests run correctly if compiler-rt is checked out into
arbitrary directory (not necessarily projects/compiler-rt).
Patch by Greg Fitzgerald!

llvm-svn: 182726
2013-05-27 09:35:24 +00:00
Alexey Samsonov 646ec67e25 Disable init-order checking before destructors are run.
We don't want to report initialization-order bugs when a destructor of a global
variable accesses dynamically initialized global from another
(not necessarily initialized) module. We do this by intercepting __cxa_atexit and
registrering our own callback that unpoisons shadow for all dynamically initialized
global variables.

llvm-svn: 182637
2013-05-24 11:46:56 +00:00
Alexander Potapenko fd7d9f45dd [ASan] Rename __asan_preinit to __local_asan_preinit to avoid warnings from the linker which is trying to export all the __asan_* symbols
llvm-svn: 182567
2013-05-23 09:15:20 +00:00
Kostya Serebryany 6ca6ba2f2c [asan] fix the reported PCs for powerpc64
llvm-svn: 182477
2013-05-22 14:21:34 +00:00
Alexey Samsonov 49eb5700e2 Revert r182465 and add lsan-common library to makefile-based build
llvm-svn: 182470
2013-05-22 13:20:37 +00:00
Alexey Samsonov 155dd46e04 [ASan] Temporary remove leak checking from ASan, while we don't have makefile-based build for LSan
llvm-svn: 182465
2013-05-22 12:44:57 +00:00
Kostya Serebryany 15fd53fa39 [asan] enhance stack-overflow.cc test: check that the location frame is properly symbolized
llvm-svn: 182463
2013-05-22 11:00:56 +00:00
Kostya Serebryany b93ae15205 [asan] attempting to fix the debian bot (on ubuntu the test builds; on debian it complains that _SC_PAGESIZE is unknown)
llvm-svn: 182462
2013-05-22 10:38:51 +00:00
Kostya Serebryany 62debd6d6a [asan] fix dlclose-test to work with non-4K pages. Properly disable interface_symbols_linux on non-x86
llvm-svn: 182461
2013-05-22 10:20:10 +00:00
Kostya Serebryany 8410a867eb [asan] workaround for asan bug 189 (swapcontext followed by throw gets OOM kill). Also, disable swapcontext_test on non-x86. Fix lint
llvm-svn: 182456
2013-05-22 08:54:30 +00:00
Sergey Matveev 20ccf95f80 [lsan] Invoke leak detection with atexit().
Keeps it consistent between ASan and LSan.

llvm-svn: 182399
2013-05-21 17:56:45 +00:00
Sergey Matveev 17f5705d3c [asan] Do not invoke LSan hooks unless CAN_SANITIZE_LEAKS.
llvm-svn: 182389
2013-05-21 15:35:34 +00:00
Sergey Matveev 8c235f40d7 [asan] LSan hooks in asan_rtl.
llvm-svn: 182384
2013-05-21 14:15:35 +00:00
Sergey Matveev 620744556a [lsan] Change CMakeLists to build the common LSan module for ASan.
Also, define CAN_SANITIZE_LEAKS.

llvm-svn: 182383
2013-05-21 14:12:11 +00:00
Alexey Samsonov b99085b0b8 [MSan] Add empty default blacklist for MSan
llvm-svn: 182382
2013-05-21 13:55:56 +00:00
Alexey Samsonov e838135b6c [ASan] create default (empty) ASan blacklist file in resource directory
llvm-svn: 182380
2013-05-21 13:48:27 +00:00
Sergey Matveev 7159b2a382 [asan] LSan hooks in asan_allocator2.cc
llvm-svn: 182379
2013-05-21 13:46:41 +00:00
Sergey Matveev 65dd62abe5 [asan] LSan hooks in asan_thread.cc
llvm-svn: 182378
2013-05-21 13:40:13 +00:00
Alexey Samsonov 3677b18388 [ASan] Mark init-order test as XFAIL on Darwin
llvm-svn: 182365
2013-05-21 10:11:17 +00:00
Alexey Samsonov af456d0c40 [ASan] Don't run fast unwinder tests on 32-bit Linux as fast unwinder may be unexpectedly smart on some hosts
llvm-svn: 182363
2013-05-21 09:35:48 +00:00
Alexey Samsonov 1c26f007ed [ASan] Mark some tests as working only on x86_64 and i386 arches
llvm-svn: 182360
2013-05-21 09:01:13 +00:00
Alexey Samsonov 4ca93997f7 Add lit config feature <target>-supported-target to mark target-specific tests
llvm-svn: 182355
2013-05-21 08:22:03 +00:00
Evgeniy Stepanov 970be35808 [sanitizer] Intercept pthread_getschedparam.
llvm-svn: 182353
2013-05-21 08:12:08 +00:00
Timur Iskhodzhanov 67c918a424 Fix realloc'ing freed/invalid pointers
See https://code.google.com/p/address-sanitizer/issues/detail?id=187 for the details

llvm-svn: 182255
2013-05-20 13:05:58 +00:00
Sergey Matveev 6a6c5b6dee [asan] Modify ASan metadata atomically.
We need this to avoid races when ASan and LSan are used together.

llvm-svn: 182252
2013-05-20 11:25:18 +00:00
Timur Iskhodzhanov 667cae7b69 [ASan] Remove an unused ChunkBase field
Also fix wrong alignment maths and an outdated comment

llvm-svn: 182238
2013-05-20 08:20:17 +00:00
Kostya Serebryany 3469375e4f [sanitizer] factor out ByteMap from SizeClassAllocator32 so that it can be later replaced with a more memory-efficient implementation on 64-bit.
llvm-svn: 182234
2013-05-20 07:29:21 +00:00
Timur Iskhodzhanov 836a4f3643 Replace CHECK(a == b); with CHECK_EQ(a, b); throughout asan_allocator2.cc
llvm-svn: 182198
2013-05-18 18:27:33 +00:00
Peter Collingbourne ffaf2eac4d [nolibc] Move all platforms to internal_getpid.
Before, we had an unused internal_getpid function for Linux, and a
platform-independent GetPid function.  To make the naming conventions
consistent for syscall-like functions, the GetPid syscall wrapper
in sanitizer_posix.cc is moved to sanitizer_mac.cc, and GetPid is
renamed to internal_getpid, bringing the Linux variant into use.

llvm-svn: 182132
2013-05-17 16:56:53 +00:00
Peter Collingbourne 6d4a7d3723 [nolibc] Begin moving sanitizer_common's libc-dependent code to a separate library
Introduce a new object library, RTSanitizerCommonLibc, which will contain
the subset of sanitizer_common with libc dependencies. RTSanitizerCommon
contains the remainder of sanitizer_common, and is intended to have no
libc dependencies. Begin moving code to RTSanitizerCommonLibc, starting
with sanitizer_common.cc, whose libc-dependent portion is moved to
sanitizer_common_libcdep.cc, the first member of the new library.

This split affects the CMake build only.  The makefile build continues
to produce the full sanitizer_common library.

llvm-svn: 182118
2013-05-17 16:17:19 +00:00
Alexander Potapenko dd3c583211 [ASan] Make the regression test for time(NULL) Linux-specific, as it crashes on Darwin (and the problem used to occur on Linux).
Do not use zero-based shadow for the time() test.

llvm-svn: 182107
2013-05-17 15:11:26 +00:00
Alexander Potapenko 00b44ba778 [ASan] Fix allow_user_segv.cc on Darwin (32-bit build required a SIGBUS handler instead of the SIGSEGV one)
llvm-svn: 182080
2013-05-17 08:08:50 +00:00
Alexander Potapenko 12d09f3a3d [ASan] Fix init-order-dlopen.cc to pass under Mac OS.
llvm-svn: 182010
2013-05-16 14:51:01 +00:00
Alexander Potapenko 3917fe0d94 [ASan] Fix interface_symbols_darwin to pass a correct flag to nm.
llvm-svn: 182008
2013-05-16 13:49:12 +00:00
Kostya Serebryany aaf7275677 [asan] symbolize when possible, even if ASAN_SYMBOLIZER_PATH is not provided. On Linux this will use dl_iterate_phdr instead of /proc/self/maps, even if the symbolizer is not installed
llvm-svn: 182005
2013-05-16 13:04:29 +00:00
Kostya Serebryany b7ca536888 [asan] fix ShadowGapTest on PowerPC64
llvm-svn: 181991
2013-05-16 07:54:28 +00:00
Kostya Serebryany 2b824f3575 [asan] disable BuiltinLongJmpTest on PowerPC
llvm-svn: 181890
2013-05-15 15:01:14 +00:00
Kostya Serebryany 2b42716213 [asan] fix powerpc build and one test; fix lint
llvm-svn: 181881
2013-05-15 12:36:29 +00:00
Evgeniy Stepanov f1efb256f6 Add sanitizer syscall hooks to the tool's export lists.
llvm-svn: 181790
2013-05-14 13:55:21 +00:00
Sergey Matveev ffe38d267c Quick fix for ASan test build on Android.
llvm-svn: 181429
2013-05-08 14:11:12 +00:00
Sergey Matveev af179b8d63 [sanitizer] Move GetStackTrace from ASan to sanitizer_common.
llvm-svn: 181424
2013-05-08 12:45:55 +00:00
Sergey Matveev 0c8ed9ce44 [asan] Common flags in ASan.
Some flags that are common to ASan/MSan/TSan/LSan have been moved to
sanitizer_common.

llvm-svn: 181193
2013-05-06 11:27:58 +00:00
Alexey Samsonov 5c38383205 [ASan] Add allow_user_segv_handler to let users override SEGV handler installed by ASan
llvm-svn: 180255
2013-04-25 10:52:15 +00:00
Alexey Samsonov bcd32a9525 [ASan] Disable strict-init-order checker once we have more than one thread, as this mode is thread-hostile
llvm-svn: 180106
2013-04-23 13:57:35 +00:00
Alexander Potapenko 262eb01bbf [ASan] Make wait.cc more Darwin-compatible: fix the header name and the CHECK patterns.
llvm-svn: 180097
2013-04-23 12:36:37 +00:00
Alexander Potapenko 15aa1cd1ac [ASan] Disable AddressSanitizer.AllocDeallocMismatch on Darwin.
See https://code.google.com/p/address-sanitizer/issues/detail?id=131.

llvm-svn: 180093
2013-04-23 12:14:55 +00:00
Alexey Samsonov e7ea8cfb49 Fixup for r179843: add missing header
llvm-svn: 179844
2013-04-19 08:49:05 +00:00
Alexey Samsonov dcf0ade114 [ASan] Make init-order checker allow access to already initialized globals.
This change adds ASan runtime option "strict-init-order" (off by default)
that makes init-order checker bark if global initializer accesses any global from different
translation unit (even if the latter is already initialized). strict init-order checking
doesn't play well with, e.g. LLVM registration machineries, and causes issue 
https://code.google.com/p/address-sanitizer/issues/detail?id=178.

llvm-svn: 179843
2013-04-19 08:35:16 +00:00
Sergey Matveev 0136943e03 [asan] Fix spelling in asan_rtl.cc Test commit.
Reviewers: kcc, glider, samsonov

Reviewed By: glider

CC: llvm-commits

Differential Revision: http://llvm-reviews.chandlerc.com/D676

llvm-svn: 179595
2013-04-16 14:58:45 +00:00
Evgeniy Stepanov 755eb32a39 [sanitizer] Add syscall handlers to ASan and TSan runtimes.
ASan checks addressability of syscall arguments. TSan does nothing for now.

llvm-svn: 179380
2013-04-12 14:57:03 +00:00
Kostya Serebryany fd27b83ef2 [asan] inline flags(), up to 1% perf gain on malloc-intensive code
llvm-svn: 179307
2013-04-11 18:36:04 +00:00
Kostya Serebryany bb68f2cd65 [asan] make heavy_uar_test even heavier
llvm-svn: 179306
2013-04-11 18:27:02 +00:00
Alexey Samsonov 9f3938e271 Explicitly list all sanitizer headers in CMake build rules. Make sure sanitizer lit_tests depend on fresh headers.
llvm-svn: 179293
2013-04-11 15:49:52 +00:00
Kostya Serebryany 1c77de3aeb [asan] improve the UAR reporting (try harder to find the correct frame), try to make the test more stable
llvm-svn: 179292
2013-04-11 15:35:40 +00:00
Kostya Serebryany 18f0820552 [asan] make heavy_uar_test a bit more heavy and fix he fake stack to pass this test
llvm-svn: 179286
2013-04-11 14:07:02 +00:00
Alexey Samsonov a672ba6e8f [ASan] test source-based init-order blacklisting added in r179280
llvm-svn: 179281
2013-04-11 13:21:41 +00:00
Kostya Serebryany 3fec2f534a [asan] fix use-after-return functionality (PR15672) and enable the corresponding test. We still don't guarantee anything with regard to use-after-return checking
llvm-svn: 179278
2013-04-11 12:49:38 +00:00
Alexey Samsonov 46cc45a291 [ASan] Symbolize correct address when printint error summary
llvm-svn: 179274
2013-04-11 11:45:04 +00:00
Kostya Serebryany 4e0a33c8be [asan] move fake stack into a separate .h file; actually disable a failing test
llvm-svn: 179273
2013-04-11 11:39:19 +00:00
Kostya Serebryany fd7f924016 [asan] add heavy_uar_test (disabled); fix lint
llvm-svn: 179271
2013-04-11 11:29:07 +00:00
Alexander Potapenko 227e22de5a [ASan] Do not check the shadow of NULL argument in the time() interceptor.
Add a test for time().

llvm-svn: 179177
2013-04-10 15:13:00 +00:00
Kostya Serebryany 92684efb1d [asan] implement callbacks for unaligned loads/stores
Reviewers: samsonov

Reviewed By: samsonov

CC: samsonov, llvm-commits

Differential Revision: http://llvm-reviews.chandlerc.com/D652

llvm-svn: 179175
2013-04-10 13:59:32 +00:00
Alexey Samsonov c0443c5d25 [ASan] fix a typo in legend in error report
llvm-svn: 179161
2013-04-10 07:00:25 +00:00
Evgeniy Stepanov 460067823b [sanitizer] Interceptors for wait*.
llvm-svn: 179096
2013-04-09 14:34:59 +00:00
Evgeniy Stepanov 69967c2835 [msan] Intercept glob() with tests.
llvm-svn: 179091
2013-04-09 11:35:13 +00:00
Kostya Serebryany 9d28efc1ad [asan] relax Linux/zero-base-shadow.cc to make it pass on newer Ubuntu; fix lint
llvm-svn: 179088
2013-04-09 07:08:05 +00:00
Kostya Serebryany 228ecf46ab [asan] make huge_negative_hea_oob more meaningful
llvm-svn: 178876
2013-04-05 15:16:48 +00:00
Kostya Serebryany f5407e8d8f [asan] add a test for huge left oob
llvm-svn: 178874
2013-04-05 15:13:23 +00:00
Kostya Serebryany 5b4267f7e7 [sanitizer] found a bug by code inspection: CHECK(a=b) instead of CHECK(a==b). Was puzzled why lint did not catch it. Turns out this check was disabled for asan source. fix all cases and enable the check
llvm-svn: 178872
2013-04-05 14:40:25 +00:00
Alexey Samsonov 5afe6aa141 [ASan] init-order checker tests: move constexpr test that requires -std=c++11 to a separate test case. Check that structs with no ctor but non-trivial dtor are ignored.
llvm-svn: 178857
2013-04-05 07:51:49 +00:00
Alexey Samsonov 734aab4066 [Sanitizer] Use a common mutex to prevent mixing reports from different sanitizers. This fixes PR15516
llvm-svn: 178853
2013-04-05 07:30:29 +00:00
Kostya Serebryany eef8bd4355 [asan] nuke the old unused allocator code
llvm-svn: 178758
2013-04-04 11:32:49 +00:00
Kostya Serebryany 13b07733b1 [asan] fill first 4K of malloc-ed memory with garbage, implement flags max_malloc_fill_size and malloc_fill_byte
llvm-svn: 178757
2013-04-04 11:17:14 +00:00
Alexey Samsonov 21cb74318c [ASan] Kill the remainders of platform defines in favor of SANITIZER_ defines
llvm-svn: 178629
2013-04-03 07:29:53 +00:00
Alexey Samsonov e624795558 [ASan] More careful reports for globals that are ASCII strings
llvm-svn: 178458
2013-04-01 08:57:38 +00:00
Timur Iskhodzhanov 07d06d7cf5 Remove all 'static' before ALWAYS_INLINE
llvm-svn: 178290
2013-03-28 21:16:09 +00:00
Timur Iskhodzhanov a6788325cf Make all the ALWAYS_INLINE users Windows-friendly; also, avoid ALWAYS_INLINE INLINE combinations
llvm-svn: 178266
2013-03-28 18:52:40 +00:00
Alexey Samsonov a88c60b085 [ASan] Speed-up initialization-order checking: create and use fast versions of PoisonShadow functions, store copies of __asan_global descriptors in a vector instead of list of pointers. This gives 3x speedup on both benchmarks and real binaries with lots of globals.
llvm-svn: 178239
2013-03-28 15:42:43 +00:00
Alexey Samsonov e586170e86 Fix unmatching ASan runtime flag for init-order checking exposed by r178158. Add a test for r178158.
llvm-svn: 178229
2013-03-28 09:11:20 +00:00
Alexey Samsonov 7152debedd [ASan] Demangle global names in error reports.
llvm-svn: 178131
2013-03-27 10:41:22 +00:00
Alexey Samsonov 56a784d2f6 [ASan] Change the ABI of __asan_before_dynamic_init function: now it takes pointer to private string with module name. This string serves as a unique module ID in ASan runtime. compiler-rt part
llvm-svn: 178014
2013-03-26 13:06:12 +00:00
Dmitry Vyukov 6f4b34bcf4 asan/tsan: move strcasecmp() interceptor to sanitizer_common
llvm-svn: 178010
2013-03-26 12:40:23 +00:00
Kostya Serebryany 88b2b45ec8 [asan] print thread number while reporting invalid-free and double-free; add tests; also add a test for use-after-poison
llvm-svn: 177993
2013-03-26 08:01:37 +00:00
Alexey Samsonov 961b636cf1 [ASan] Use dynamic symbol table when checking exported ASan runtime symbols
llvm-svn: 177868
2013-03-25 13:47:53 +00:00
Alexey Samsonov 9328ba400a [ASan] mark local function as static
llvm-svn: 177862
2013-03-25 11:38:42 +00:00
Richard Smith c91e327cba Build and install .syms files alongside sanitizer runtimes. These are used to
specify which symbols are exported to DSOs when the sanitizer is statically
linked into a binary.

llvm-svn: 177784
2013-03-23 00:31:07 +00:00
Timur Iskhodzhanov fb74020cea Revert 177745 as it was incorrect
llvm-svn: 177746
2013-03-22 18:16:57 +00:00
Timur Iskhodzhanov e117eef77f Band-aid fix for the Windows build caused by r177710. Long-term, atomic_compare_exchange_strong should be a template on Windows too...
llvm-svn: 177745
2013-03-22 18:05:28 +00:00
Kostya Serebryany 667a34a120 [asan] Change the way we report the alloca frame on stack-buff-overflow.
Before: the function name was stored by the compiler as a constant string
and the run-time was printing it.
Now: the PC is stored instead and the run-time prints the full symbolized frame.
This adds a couple of instructions into every function with non-empty stack frame,
but also reduces the binary size because we store less strings (I saw 2% size reduction).
This change bumps the asan ABI version to v3.

compiler-rt part, llvm part will follow.

Example of report (now):
==31711==ERROR: AddressSanitizer: stack-buffer-overflow on address 0x7fffa77cf1c5 at pc 0x41feb0 bp 0x7fffa77cefb0 sp 0x7fffa77cefa8
READ of size 1 at 0x7fffa77cf1c5 thread T0
    #0 0x41feaf in Frame0(int, char*, char*, char*) stack-oob-frames.cc:20
    #1 0x41f7ff in Frame1(int, char*, char*) stack-oob-frames.cc:24
    #2 0x41f477 in Frame2(int, char*) stack-oob-frames.cc:28
    #3 0x41f194 in Frame3(int) stack-oob-frames.cc:32
    #4 0x41eee0 in main stack-oob-frames.cc:38
    #5 0x7f0c5566f76c (/lib/x86_64-linux-gnu/libc.so.6+0x2176c)
    #6 0x41eb1c (/usr/local/google/kcc/llvm_cmake/a.out+0x41eb1c)
Address 0x7fffa77cf1c5 is located in stack of thread T0 at offset 293 in frame
    #0 0x41f87f in Frame0(int, char*, char*, char*) stack-oob-frames.cc:12  <<<<<<<<<<<<<< this is new
  This frame has 6 object(s):
    [32, 36) 'frame.addr'
    [96, 104) 'a.addr'
    [160, 168) 'b.addr'
    [224, 232) 'c.addr'
    [288, 292) 's'
    [352, 360) 'd'

llvm-svn: 177723
2013-03-22 10:36:24 +00:00
Alexey Samsonov f1311dfce1 [ASan] fix-up for r177634 on Windows.
llvm-svn: 177711
2013-03-22 07:48:23 +00:00
Alexey Samsonov a5eb3cb721 [ASan] Fix an error on invalid deallocation in ASan allocator. When ASan checks if memory freed by user was indeed previously allocated, it first does an atomic write to presumed location of chunk header. This is wrong, as if the free is invalid, we may overwrite some valuable data (like other fields of the chunk header). Fix this by using atomic_compare_exchange instead.
llvm-svn: 177710
2013-03-22 07:40:34 +00:00
Dmitry Vyukov a7e42b5be5 asan: fix lint warning about line length
llvm-svn: 177709
2013-03-22 07:29:59 +00:00
Alexey Samsonov 54afba8b62 [ASan] Switch ASan to generic ThreadRegistry from sanitizer_common. Delete ASan-specific AsanThreadRegistry.
llvm-svn: 177634
2013-03-21 11:23:41 +00:00
Alexey Samsonov 920b3b9a0c [ASan] Move malloc stats collection away from AsanThreadRegistry class.
llvm-svn: 177508
2013-03-20 10:11:24 +00:00
Alexey Samsonov cf025cb2e6 [ASan] Move GetCurrentThread/SetCurrentThread from AsanThreadRegistry class into plain functions: they don't actually use registry
llvm-svn: 177501
2013-03-20 09:23:28 +00:00
Evgeniy Stepanov 9a8f0f55d5 [asan] s/ASAN_POSIX/SANITIZER_POSIX/
llvm-svn: 177407
2013-03-19 15:26:41 +00:00
Evgeniy Stepanov 95eaa21637 [sanitizer] More renamed macros.
llvm-svn: 177401
2013-03-19 14:54:17 +00:00
Evgeniy Stepanov 0af672326a [sanitizer] Replace more platform checks with SANITIZER_ constants.
llvm-svn: 177400
2013-03-19 14:33:38 +00:00
Evgeniy Stepanov d3b56605f1 [sanitizer] Move ASan platform macros to sanitizer_common and rename them appropriately.
llvm-svn: 177397
2013-03-19 13:54:41 +00:00
Kostya Serebryany 9138f75d0a [asan] make the __asan_get_heap_size more robust
llvm-svn: 177270
2013-03-18 10:52:25 +00:00
Evgeniy Stepanov 6488b2b257 [asan] Switch to allocator2 on Android.
llvm-svn: 177263
2013-03-18 09:22:58 +00:00
Kostya Serebryany c4722a65a5 [asan] while generating the description of a global variable, emit the module name in a separate field, thus not duplicating this information if every description. This decreases the binary size (observed up to 3%). https://code.google.com/p/address-sanitizer/issues/detail?id=168 . This changes the asan API version. compiler-rt part, llvm-part will follow
llvm-svn: 177253
2013-03-18 08:04:55 +00:00
Alexey Samsonov 3a6b6b9d55 [Sanitizer] Don't intercept frexpf and frexpl on Windows. Add frexp declaration to asan_intercepted_functions.h
llvm-svn: 177155
2013-03-15 14:02:21 +00:00
Kostya Serebryany d332d42372 [asan] remove one redundant malloc stress test, unify the usage of ASAN_LOW_MEMORY macro in tests, slightly reduce test memory usage (all to make 32-bit runs consume less RAM)
llvm-svn: 177069
2013-03-14 13:16:09 +00:00
Alexey Samsonov 1dc928e1b1 [ASan] remove -fsanitize=init-order from lit tests as now it's implied by -fsanitize=address
llvm-svn: 177064
2013-03-14 12:43:03 +00:00
Alexey Samsonov 963be1ddd8 [ASan] turn off checking initialization order in ASan runtime by default. Instead, it should be turned on by default in the compiler
llvm-svn: 177058
2013-03-14 11:49:40 +00:00
Alexey Samsonov 140cd84155 [ASan] make ASan assume ASAN_OPTIONS=symbolize=1 if ASAN_EXTERNAL_SYMBOLIZER is defined
llvm-svn: 177036
2013-03-14 10:07:40 +00:00
Alexey Samsonov d7ab381f53 [Sanitizer] Build ASan, TSan and MSan runtimes with -fno-rtti.
llvm-svn: 176940
2013-03-13 09:18:30 +00:00
Kostya Serebryany 67b1478914 [asan] use 4Tb of address space for the asan allocator instead of 1Tb. This increases the memory available for a single size class from 16Gb to 64Gb. The total VM footprint becomes 20Tb
llvm-svn: 176857
2013-03-12 09:04:49 +00:00
Evgeniy Stepanov f5d8c90f57 [asan] Revert r176255, r176264.
New allocator has 1.5x memory overhead of the old one.

llvm-svn: 176340
2013-03-01 09:33:05 +00:00
Evgeniy Stepanov 3305b177e6 [asan] Lower memory usage in LargeMallocTest on Android.
llvm-svn: 176264
2013-02-28 15:54:58 +00:00
Alexander Potapenko f1c48eb509 [ASan] Add the memcmp_strict flag (1 by default) that controls the behavior of accessibility checks in memcmp.
1: memcmp(p1, p2, n) always checks n bytes
0: memcmp checks up to n bytes depending on whether the memory contents differ.

llvm-svn: 176256
2013-02-28 14:09:30 +00:00
Evgeniy Stepanov 1cb95a17b8 [asan] Enable allocator2 on Android.
llvm-svn: 176255
2013-02-28 14:07:01 +00:00
Kostya Serebryany abebb57272 [asan] bump kMidMemEnd to 0x4fffffffffULL since in rare cases prelink uses addresses higher than 0x3fffffffff
llvm-svn: 176250
2013-02-28 12:28:37 +00:00
Kostya Serebryany 8ee2a5adc7 [asan] if calloc returns a freshly-mmaped memory, don't clear it with memset. Speeds up calloc-intensive code
llvm-svn: 176185
2013-02-27 13:38:19 +00:00
Kostya Serebryany 459df6f167 [asan] a bit stricter lint for CHECK vs CHECK_XX (these CHECK_XX really help debugging!)
llvm-svn: 176085
2013-02-26 12:59:06 +00:00
Kostya Serebryany 8caf654731 [asan] fix the output for range accesses (memset, etc); improve the tests; more strict checking in memcmp
llvm-svn: 176078
2013-02-26 07:25:18 +00:00
Kostya Serebryany c8ac15a66b [asan] use the new attribute syntax (no_address_safety_analysis => no_sanitize_address)
llvm-svn: 176077
2013-02-26 07:01:06 +00:00
Kostya Serebryany 1d63d13ce2 [asan] move the .preinit_array hack into a separate file (added used attribute)
llvm-svn: 175871
2013-02-22 07:51:26 +00:00
Alexander Potapenko 97781c4dd0 [ASan] temporarily disable alloc_dealloc_mismatch on Mac, since the previous commit caused error reports in gTest.
llvm-svn: 175766
2013-02-21 17:12:21 +00:00
Alexander Potapenko a47c6ee286 [ASan] Make sure operator new/delete and friends are intercepted on OS X.
Because the interceptors will reside in a dylib, not the main executable, we can't just declare them,
but must use the interposition machinery.
Fix the test expectations in large_func_test.cc affected by the change.
This CL should make our Mac buildbots green.

llvm-svn: 175763
2013-02-21 16:54:09 +00:00
Alexander Potapenko 1615f193eb [ASan] Declare CreateThread as extern "C" to fix the Windows build.
llvm-svn: 175760
2013-02-21 15:32:50 +00:00
Alexander Potapenko 8dbcb98c52 [ASan] Revert the incorrect macro on Linux.
llvm-svn: 175745
2013-02-21 15:15:43 +00:00
Alexander Potapenko b8135a8a6b [ASan] Put several function prototypes back under #ifdef _WIN32 to fix the Windows build.
llvm-svn: 175743
2013-02-21 15:10:03 +00:00
Alexander Potapenko e8ba1c851a [ASan] Refactoring: nuke the redundant function declarations in asan_intercepted_functions.h
that had been used on OS X only.
The INTERCEPTOR() macro on OS X is now responsible for declaring the wrapped function, the wrapper and the
pair of pointers to them in __DATA,__interposition section. Thus adding an interceptor requires editing a single file now.

llvm-svn: 175740
2013-02-21 14:41:16 +00:00
Kostya Serebryany ab5be26af5 [asan] speedup by more than 2x handling of the small memset/memcpy/etc calls
llvm-svn: 175728
2013-02-21 07:07:39 +00:00
Alexey Samsonov 7dc2b2f07d [ASan] revert part of r175631 that looks like accidental commit
llvm-svn: 175655
2013-02-20 19:55:47 +00:00
Alexander Potapenko 70b01558f1 [ASan] Delete asan/dynamic dir and temporarily move the interposers declarations to asan_intercepted_functions.h
Now that we have only one dependency on asan_intercepted_functions.h, we can unite that code with the interceptors declarations in asan_interceptors.cc and get rid of asan_intercepted_functions.h

llvm-svn: 175631
2013-02-20 15:46:02 +00:00
Kostya Serebryany 7b989859a8 [asan] move preinit_test to Linux since on Mac __asan_init is called from ld-preload-ed runtime
llvm-svn: 175625
2013-02-20 15:10:22 +00:00
Kostya Serebryany d8c29210e5 [asan] on linux, run __asan_init from .preinit_array (even earlier than before)
llvm-svn: 175623
2013-02-20 14:28:08 +00:00
Alexey Samsonov aadd1f2ad6 [Sanitizer] use raw syscall instead of _exit() function on Linux
llvm-svn: 175622
2013-02-20 13:54:32 +00:00
Kostya Serebryany ac05bc0556 [asan] add a lit test for invoke-with-no-return instrumentation
llvm-svn: 175618
2013-02-20 12:37:22 +00:00
Evgeniy Stepanov ec1d286111 [sanitizer] Fix lint.
llvm-svn: 175615
2013-02-20 11:06:07 +00:00
Kostya Serebryany 8381ef2035 [asan] add test throw_call_test (broken with -static-libstdc++)
llvm-svn: 175614
2013-02-20 10:43:05 +00:00
Kostya Serebryany 96401c9da9 [asan] don't run the long double test if long double is the same as double
llvm-svn: 175514
2013-02-19 13:43:44 +00:00
Alexey Samsonov 0b07c63e07 [ASan] Allow ASan default runtime options be overriden at compile time by providing ASAN_DEFAULT_OPTIONS macro
llvm-svn: 175512
2013-02-19 13:14:48 +00:00
Kostya Serebryany 9f298da9bd [asan] instrument memory accesses with unusual sizes
This patch makes asan instrument memory accesses with unusual sizes (e.g. 5 bytes or 10 bytes), e.g. long double or
packed structures.
Instrumentation is done with two 1-byte checks
(first and last bytes) and if the error is found
__asan_report_load_n(addr, real_size) or
__asan_report_store_n(addr, real_size)
is called.

asan-rt part

Also fix lint.

llvm-svn: 175508
2013-02-19 11:30:25 +00:00
Evgeniy Stepanov ea61d08185 [sanitizer] Add interceptors for localtime and friends.
llvm-svn: 175499
2013-02-19 09:19:16 +00:00
Kostya Serebryany 776f3bba96 [asan] enable asan_prelink_test when gold is the default linker (gold and bfd linker have different flag syntax)
llvm-svn: 175431
2013-02-18 08:37:49 +00:00
Kostya Serebryany 15e9c852c0 [asan] added flag -d|--demangle to asan_symbolize.py, makes addr2line/llvm-symbolizer demangle the functions names
llvm-svn: 175429
2013-02-18 08:02:16 +00:00
Alexey Samsonov 4544d1fa3d [ASan] make variables unsigned to silence warnings - attempt 2
llvm-svn: 175285
2013-02-15 19:22:49 +00:00
Alexey Samsonov f6d7379def [ASan] make variable unsigned to silence the warning
llvm-svn: 175284
2013-02-15 19:02:32 +00:00
Alexander Potapenko 3182c3e441 [ASan] Fix https://code.google.com/p/address-sanitizer/issues/detail?id=159
MaybeReexec() does now a tricky job to manage DYLD_INSERT_LIBRARIES in a safe way.

Because we're using library interposition, it's critical for an instrumented app
to be executed with the runtime library present in DYLD_INSERT_LIBRARIES list.
Therefore if it's initially missing in that list, we append the runtime library name
to the value of DYLD_INSERT_LIBRARIES and then exec() ourselves.

On the other hand, some of the apps exec()ed by our program may not want to have
ASan runtime library preloaded, so we remove the runtime library from the
DYLD_INSERT_LIBRARIES if it's already there.

Users may want to preload other libraries using DYLD_INSERT_LIBRARIES, so we preserve those.

llvm-svn: 175276
2013-02-15 16:10:49 +00:00
Kostya Serebryany fd61b6f0c8 [asan] make asan work with 7fff8000 offset and prelink
When prelink is installed in the system, prelink-ed
libraries map between 0x003000000000 and 0x004000000000 thus occupying the shadow Gap,
so we need so split the address space even further, like this:
|| [0x10007fff8000, 0x7fffffffffff] || HighMem    ||
|| [0x02008fff7000, 0x10007fff7fff] || HighShadow ||
|| [0x004000000000, 0x02008fff6fff] || ShadowGap3 ||
|| [0x003000000000, 0x003fffffffff] || MidMem     ||
|| [0x00087fff8000, 0x002fffffffff] || ShadowGap2 ||
|| [0x00067fff8000, 0x00087fff7fff] || MidShadow  ||
|| [0x00008fff7000, 0x00067fff7fff] || ShadowGap  ||
|| [0x00007fff8000, 0x00008fff6fff] || LowShadow  ||
|| [0x000000000000, 0x00007fff7fff] || LowMem     ||

Do it only if necessary.

Also added a bit of profiling code to make sure that the
mapping code is efficient.

Added a lit test to simulate prelink-ed libraries.
Unfortunately, this test does not work with binutils-gold linker.
If gold is the default linker the test silently passes.

Also replaced
__has_feature(address_sanitizer)
with
__has_feature(address_sanitizer) || defined(__SANITIZE_ADDRESS__)
in two places.

Patch partially by Jakub Jelinek.

llvm-svn: 175263
2013-02-15 12:00:24 +00:00
Alexander Potapenko 594d99588b [ASan] Fixed the wrong placement of #include
llvm-svn: 175157
2013-02-14 12:37:17 +00:00
Alexander Potapenko 6ad3589964 [ASan] Remove the 'alarm' script which isn't present on OS X by default.
The test may hang now if a regression occurs.

llvm-svn: 175155
2013-02-14 12:18:07 +00:00
Kostya Serebryany dd0ab08b6e [asan] use short path for sanitizer_common/tests/sanitizer_test_utils.h, add -I sanitizer_common/tests to asan/tests/CMakeLists.txt
llvm-svn: 175142
2013-02-14 08:12:26 +00:00
Kostya Serebryany aa7f2b5aa6 [tsan] disable a failing test until it gets fixed. fix lint
llvm-svn: 175137
2013-02-14 06:54:51 +00:00
Alexander Potapenko c5ba5ef3c5 [ASan] When re-executing the process on OS X, make sure we update the existing DYLD_INSERT_LIBRARIES correctly.
Previously ASan used to hang in an exec loop, because it failed to overwrite the env var value
(see https://code.google.com/p/address-sanitizer/issues/detail?id=159).

llvm-svn: 175059
2013-02-13 17:52:55 +00:00
Kostya Serebryany 32214a2587 [asan] fix fixed mapping for mac (ASAN_FLEXIBLE_MAPPING_AND_OFFSET=0)
llvm-svn: 175049
2013-02-13 10:15:03 +00:00
Kostya Serebryany 4681fbf002 [tsan] simplify tsan-vs-gvn test since gvn vs tsan is now fixed; fix lint
llvm-svn: 175037
2013-02-13 06:07:50 +00:00
Evgeniy Stepanov a73704c0f8 [asan] Add new __isoc99_*scanf to ASan intercepted functions list.
llvm-svn: 174965
2013-02-12 12:45:29 +00:00
Kostya Serebryany 2659e96e4b [asan] change the default mapping offset on x86_64 to 0x7fff8000. This gives roughly 5% speedup. Since this is an ABI change, bump the asan ABI version by renaming __asan_init to __asan_init_v1. compiler-rt part
llvm-svn: 174958
2013-02-12 11:11:58 +00:00
Evgeniy Stepanov 9f9d79f3ad [sanitizer] Fix line numbers in a sanitizer lit test.
llvm-svn: 174861
2013-02-11 07:19:24 +00:00
Evgeniy Stepanov 0b805cc75c [asan] Fix off-by-one in AddrIsAtRight.
llvm-svn: 174710
2013-02-08 12:59:42 +00:00
Timur Iskhodzhanov 167f9e4395 [ASan] Switch Windows to allocator v2, also fixing some build errors
llvm-svn: 174707
2013-02-08 12:02:00 +00:00
Timur Iskhodzhanov 659bca56a7 [ASan] Move functions using BitScan/clzl to sanitizer_common
llvm-svn: 174706
2013-02-08 11:45:04 +00:00
Alexander Potapenko c192af29f5 [ASan] Remove the replace_cfallocator flag, which is used no more.
See https://code.google.com/p/address-sanitizer/issues/detail?id=10 for the context.

llvm-svn: 174629
2013-02-07 15:59:37 +00:00
Alexander Potapenko dc91edad59 [ASan] Enable alloc_dealloc_mismatch by default on Darwin.
Enable AddressSanitizer.AllocDeallocMismatch tests.

llvm-svn: 174628
2013-02-07 15:55:21 +00:00
Alexander Potapenko 4fb43438d9 [ASan] Enable the new and delete wrappers on Darwin.
Also fix large_func_test.cc, which got broken when we switched to allocator2: the OOB access was too far from the original allocation, so ASan decided to describe the next one.

llvm-svn: 174626
2013-02-07 15:33:56 +00:00
Alexander Potapenko f444a49310 [ASan] Implement asan_mz_size(), asan_mz_force_lock() and asan_mz_force_unlock() for allocator2.
Switch to allocator2 on Darwin.

llvm-svn: 174603
2013-02-07 11:40:03 +00:00
Alexander Potapenko 09aba10499 [ASan] fix the interceptor for siglongjmp. As we're using dylib interposition, we must intercept both siglongjmp and longjmp on Darwin.
llvm-svn: 174510
2013-02-06 15:45:43 +00:00
Kostya Serebryany b4c2c5c8a6 [asan] print a short one-line report summary after the full report. Currently, works only if symbolization happens in-process.
llvm-svn: 174501
2013-02-06 12:36:49 +00:00
Alexander Potapenko 34157fc33f [ASan] Delete the code related to static runtime on OS X.
Nuke lib/interception/mach_override.

llvm-svn: 174383
2013-02-05 15:57:12 +00:00
Evgeniy Stepanov 36017454ac [asan] Fix Win/Mac build.
llvm-svn: 174376
2013-02-05 15:02:12 +00:00
Evgeniy Stepanov 1bc7298c44 [asan] Fix nonsensical reports of partial right OOB.
In case of partial right OOB, ASan was reporting
  X is located 0 bytes to the right of [A, B)
where X was actually inside [A, B).

With this change, ASan will report B as the error address in such case.

llvm-svn: 174373
2013-02-05 14:32:03 +00:00
Alexey Samsonov 2e50809961 [ASan] remove debug output from the test
llvm-svn: 174188
2013-02-01 16:06:25 +00:00
Kostya Serebryany bda64b4d40 [sanitizer] make the error messages from sanitizer_common contain the actual tool name
llvm-svn: 174059
2013-01-31 14:11:21 +00:00
Alexey Samsonov a0c0da8f51 [ASan] Split ASan interface header into private and public parts. Add a test that makes sure users can include interface header
llvm-svn: 174058
2013-01-31 13:46:14 +00:00
Evgeniy Stepanov 358698279d [sanitizer] Further split private and public sanitizer headers.
And make msan_interface.h C-compatible.

llvm-svn: 173928
2013-01-30 13:12:08 +00:00
Alexey Samsonov 0d92533b29 Use LLVM_BUILD_TYPE instead of CMAKE_BUILD_TYPE in compiler-rt unit tests to match the behavior of llvm unittests
llvm-svn: 173926
2013-01-30 12:18:49 +00:00
Alexey Samsonov 49a32c1d08 [Sanitizer] update style checker script and fix namespace style warnings
llvm-svn: 173910
2013-01-30 07:45:58 +00:00
Alexey Samsonov 322d7fbd9d ASan: fix lint
llvm-svn: 173795
2013-01-29 12:08:12 +00:00
Dmitry Vyukov 73b12d7132 asan: fix the test
llvm-svn: 173786
2013-01-29 09:59:53 +00:00
Alexey Samsonov 9aa2e4f5c4 [ASan] fix deallocation hook in allocator2: according to specification, dealloc hook should be called before deallocating memory
llvm-svn: 173778
2013-01-29 08:19:11 +00:00
Alexey Samsonov 615b86cf0a [ASan] Do allocate memory even for zero-size allocation requests. Explain why we have to do this in comments.
llvm-svn: 173776
2013-01-29 07:51:34 +00:00
Alexey Samsonov 7eda134fa7 [ASan] fix a bug in allocator-v2 which could lead to SEGV on realloc(malloc(0), 4)
llvm-svn: 173681
2013-01-28 11:24:13 +00:00
Kostya Serebryany 61761f182b [asan] fix a crash in asan stats printing (initialize the allocator in __asan_init)
llvm-svn: 173676
2013-01-28 08:05:47 +00:00
Kostya Serebryany 6c17547ef1 [asan] two more internal flags for asan-rt: print_stats (0) and print_legend (1)
llvm-svn: 173671
2013-01-28 07:34:22 +00:00
Alexey Samsonov 5311754b62 [CMake] Fix compiler-rt tests after r173617
llvm-svn: 173668
2013-01-28 07:16:22 +00:00
Kostya Serebryany c1056f90ae [sanitizer] improve the calloc overflow check (spotted by samsonov@)
llvm-svn: 173443
2013-01-25 12:22:21 +00:00
Kostya Serebryany fa79cd65e2 [sanitizer] fix calloc overflow in asan/tsan/msan
llvm-svn: 173441
2013-01-25 11:46:22 +00:00
Kostya Serebryany 35fb1167b0 [asan] run-time tests for adaptive redzones
llvm-svn: 173336
2013-01-24 10:36:11 +00:00