summaryrefslogtreecommitdiff
path: root/lib/asan/asan_malloc_linux.cc
AgeCommit message (Collapse)Author
2017-12-14[Sanitizers] Basic sanitizer Solaris support (PR 33274)Kamil Rytarowski
Summary: This is the first mostly working version of the Sanitizer port to 32-bit Solaris/x86. It is currently based on Solaris 11.4 Beta. This part was initially developed inside libsanitizer in the GCC tree and should apply to both. Subsequent parts will address changes to clang, the compiler-rt build system and testsuite. I'm not yet sure what the right patch granularity is: if it's profitable to split the patch up, I'd like to get guidance on how to do so. Most of the changes are probably straightforward with a few exceptions: * The Solaris syscall interface isn't stable, undocumented and can change within an OS release. The stable interface is the libc interface, which I'm using here, if possible using the internal _-prefixed names. * While the patch primarily target 32-bit x86, I've left a few sparc changes in. They cannot currently be used with clang due to a backend limitation, but have worked fine inside the gcc tree. * Some functions (e.g. largefile versions of functions like open64) only exist in 32-bit Solaris, so I've introduced a separate SANITIZER_SOLARIS32 to check for that. The patch (with the subsequent ones to be submitted shortly) was tested on i386-pc-solaris2.11. Only a few failures remain, some of them analyzed, some still TBD: AddressSanitizer-i386-sunos :: TestCases/Posix/concurrent_overflow.cc AddressSanitizer-i386-sunos :: TestCases/init-order-atexit.cc AddressSanitizer-i386-sunos :: TestCases/log-path_test.cc AddressSanitizer-i386-sunos :: TestCases/malloc-no-intercept.c AddressSanitizer-i386-sunos-dynamic :: TestCases/Posix/concurrent_overflow.cc AddressSanitizer-i386-sunos-dynamic :: TestCases/Posix/start-deactivated.cc AddressSanitizer-i386-sunos-dynamic :: TestCases/default_options.cc AddressSanitizer-i386-sunos-dynamic :: TestCases/init-order-atexit.cc AddressSanitizer-i386-sunos-dynamic :: TestCases/log-path_test.cc AddressSanitizer-i386-sunos-dynamic :: TestCases/malloc-no-intercept.c SanitizerCommon-Unit :: ./Sanitizer-i386-Test/MemoryMappingLayout.DumpListOfModules SanitizerCommon-Unit :: ./Sanitizer-i386-Test/SanitizerCommon.PthreadDestructorIterations Maybe this is good enough the get the ball rolling. Reviewers: kcc, alekseyshl Reviewed By: alekseyshl Subscribers: srhines, jyknight, kubamracek, krytarowski, fedor.sergeev, llvm-commits, #sanitizers Tags: #sanitizers Differential Revision: https://reviews.llvm.org/D40898 git-svn-id: https://llvm.org/svn/llvm-project/compiler-rt/trunk@320740 91177308-0d34-0410-b5e6-96231b3b80d8
2017-08-08Try to appease compiler and break multiline comment.Kamil Rytarowski
git-svn-id: https://llvm.org/svn/llvm-project/compiler-rt/trunk@310428 91177308-0d34-0410-b5e6-96231b3b80d8
2017-08-08Add NetBSD support in asan_malloc_linux.ccKamil Rytarowski
Summary: Part of the code inspired by the original work on libsanitizer in GCC 5.4 by Christos Zoulas. Sponsored by <The NetBSD Foundation> Reviewers: joerg, kcc, fjricci, vitalybuka, filcab Reviewed By: fjricci Subscribers: llvm-commits, kubamracek, #sanitizers Tags: #sanitizers Differential Revision: https://reviews.llvm.org/D36376 git-svn-id: https://llvm.org/svn/llvm-project/compiler-rt/trunk@310414 91177308-0d34-0410-b5e6-96231b3b80d8
2017-08-08[asan] Restore dead-code-elimination optimization for FuchsiaVitaly Buka
Summary: r310244 fixed a bug introduced by r309914 for non-Fuchsia builds. In doing so it also reversed the intended effect of the change for Fuchsia builds, which was to allow all the AllocateFromLocalPool code and its variables to be optimized away entirely. This change restores that optimization for Fuchsia builds, but doesn't have the original change's bug because the comparison arithmetic now takes into account the size of the elements. Submitted on behalf of Roland McGrath. Reviewers: vitalybuka, alekseyshl Reviewed By: alekseyshl Subscribers: llvm-commits, kubamracek Tags: #sanitizers Differential Revision: https://reviews.llvm.org/D36430 git-svn-id: https://llvm.org/svn/llvm-project/compiler-rt/trunk@310330 91177308-0d34-0410-b5e6-96231b3b80d8
2017-08-07[asan] Return sizeof missed by r309914Vitaly Buka
git-svn-id: https://llvm.org/svn/llvm-project/compiler-rt/trunk@310244 91177308-0d34-0410-b5e6-96231b3b80d8
2017-08-03[asan] Allocator support for FuchsiaVitaly Buka
Submitted on behalf of Roland McGrath. Reviewers: vitalybuka, alekseyshl, kcc Reviewed By: alekseyshl Subscribers: srhines, cryptoad, kubamracek, phosek, filcab, llvm-commits Tags: #sanitizers Differential Revision: https://reviews.llvm.org/D36190 git-svn-id: https://llvm.org/svn/llvm-project/compiler-rt/trunk@309914 91177308-0d34-0410-b5e6-96231b3b80d8
2017-06-09[asan] Fix ASan internal failure in AllocateFromLocalPoolMaxim Ostapenko
This patch addresses PR 33206. There might be a situation when dynamic ASan runtime initializes later than shared library which has malloc in static constructor (rtld doesn't provide an order of shared libs initialization). In this case ASan hasn't yet initialized interceptors, but already intercepts malloc. If malloc is too big to be handled by static local pool, ASan will die with error: Sanitizer CHECK failed: lib/asan/asan_malloc_linux.cc:40 ((allocated_for_dlsym)) < ((kDlsymAllocPoolSize)) (1036, 1024) Patch by Denis Khalikov. Differential Revision: https://reviews.llvm.org/D33784 git-svn-id: https://llvm.org/svn/llvm-project/compiler-rt/trunk@305058 91177308-0d34-0410-b5e6-96231b3b80d8
2017-01-30Recommit: Stop intercepting some malloc-related functions on FreeBSD andDimitry Andric
macOS Summary: In https://bugs.freebsd.org/215125 I was notified that some configure scripts attempt to test for the Linux-specific `mallinfo` and `mallopt` functions by compiling and linking small programs which references the functions, and observing whether that results in errors. FreeBSD and macOS do not have the `mallinfo` and `mallopt` functions, so normally these tests would fail, but when sanitizers are enabled, they incorrectly succeed, because the sanitizers define interceptors for these functions. This also applies to some other malloc-related functions, such as `memalign`, `pvalloc` and `cfree`. Fix this by not intercepting `mallinfo`, `mallopt`, `memalign`, `pvalloc` and `cfree` for FreeBSD and macOS, in all sanitizers. Also delete the non-functional `cfree` wrapper for Windows, to fix the test cases on that platform. Reviewers: emaste, kcc, rnk Subscribers: timurrrr, eugenis, hans, joerg, llvm-commits, kubamracek Differential Revision: https://reviews.llvm.org/D27654 git-svn-id: https://llvm.org/svn/llvm-project/compiler-rt/trunk@293536 91177308-0d34-0410-b5e6-96231b3b80d8
2017-01-27Revert "Stop intercepting some malloc-related functions on FreeBSD and macOS"Evgeniy Stepanov
This reverts r293337, which breaks tests on Windows: malloc-no-intercept-499eb7.o : error LNK2019: unresolved external symbol _mallinfo referenced in function _main git-svn-id: https://llvm.org/svn/llvm-project/compiler-rt/trunk@293346 91177308-0d34-0410-b5e6-96231b3b80d8
2017-01-27Stop intercepting some malloc-related functions on FreeBSD and macOSDimitry Andric
Summary: In https://bugs.freebsd.org/215125 I was notified that some configure scripts attempt to test for the Linux-specific `mallinfo` and `mallopt` functions by compiling and linking small programs which references the functions, and observing whether that results in errors. FreeBSD and macOS do not have the `mallinfo` and `mallopt` functions, so normally these tests would fail, but when sanitizers are enabled, they incorrectly succeed, because the sanitizers define interceptors for these functions. This also applies to some other malloc-related functions, such as `memalign`, `pvalloc` and `cfree`. Fix this by not intercepting `mallinfo`, `mallopt`, `memalign`, `pvalloc` and `cfree` for FreeBSD and macOS, in all sanitizers. Reviewers: emaste, kcc Subscribers: hans, joerg, llvm-commits, kubamracek Differential Revision: https://reviews.llvm.org/D27654 git-svn-id: https://llvm.org/svn/llvm-project/compiler-rt/trunk@293337 91177308-0d34-0410-b5e6-96231b3b80d8
2016-09-26[asan, msan] Fix reallocation logic when IsInDlsymAllocPool(ptr) is true.Maxim Ostapenko
git-svn-id: https://llvm.org/svn/llvm-project/compiler-rt/trunk@282389 91177308-0d34-0410-b5e6-96231b3b80d8
2016-09-23[msan] Prevent initialization failure with newer (2.23+) glibc in use.Maxim Ostapenko
This patch is pretty the same as http://reviews.llvm.org/D20235 that we used for ASan. Using the same hack for MSan fixes its initialization with newer Glibc in use. Differential Revision: https://reviews.llvm.org/D24736 git-svn-id: https://llvm.org/svn/llvm-project/compiler-rt/trunk@282232 91177308-0d34-0410-b5e6-96231b3b80d8
2016-05-16[asan] Fix asan initialization failure with newer (2.23+) glibc in use.Maxim Ostapenko
This patch tries to fix https://llvm.org/bugs/show_bug.cgi?id=27310 by using the same hack for malloc as we use for calloc: allocate corresponding memory from internal buffer when ASan is not initialized. This way we could avoid nasty '==6987==AddressSanitizer CHECK failed: ../../../../libsanitizer/asan/asan_rtl.cc:556 "((!asan_init_is_running && "ASan init calls itself!")) != (0)" (0x0, 0x0)' errors in environments with glibc 2.23+ in use, where _dl_signal_error, called from dlsym for undefined symbols calls malloc in order to get a buffer for error message. Differential Revision: http://reviews.llvm.org/D20235 git-svn-id: https://llvm.org/svn/llvm-project/compiler-rt/trunk@269633 91177308-0d34-0410-b5e6-96231b3b80d8
2016-01-14[Sanitizer] Pass proper values to DTLS_on_libc_memalign.Alexey Samsonov
Fix a surprising typo: the old code used to think that dynamic TLS segments were several times larger than they actually are. git-svn-id: https://llvm.org/svn/llvm-project/compiler-rt/trunk@257722 91177308-0d34-0410-b5e6-96231b3b80d8
2015-12-01[asan] Correctly release memory allocated during early startup.Yury Gribov
Calloc interceptor initially allocates memory from temp buffer (to serve dlsyms called during asan_init). There is a chance that some non-instrumented library (or executable) has allocated memory with calloc before asan_init and got pointer from the same temporary buffer which later caused problems with free. Inspired by https://github.com/google/sanitizers/issues/626 Differential Revision: http://reviews.llvm.org/D14979 git-svn-id: https://llvm.org/svn/llvm-project/compiler-rt/trunk@254395 91177308-0d34-0410-b5e6-96231b3b80d8
2014-07-17[asan] Remove leftover debug printf.Evgeniy Stepanov
git-svn-id: https://llvm.org/svn/llvm-project/compiler-rt/trunk@213264 91177308-0d34-0410-b5e6-96231b3b80d8
2014-07-17[asan] Fix malloc interception on Android L Preview.Evgeniy Stepanov
Format of __libc_malloc_dispatch has changed in Android L. While we are moving towards a solution that does not depend on bionic internals, here is something to support both K* and L releases. git-svn-id: https://llvm.org/svn/llvm-project/compiler-rt/trunk@213263 91177308-0d34-0410-b5e6-96231b3b80d8
2014-07-04[sanitizer] support c11 aligned_alloc, Linux only for nowKostya Serebryany
git-svn-id: https://llvm.org/svn/llvm-project/compiler-rt/trunk@212322 91177308-0d34-0410-b5e6-96231b3b80d8
2014-06-09[asan] Add malloc_usable_size to android malloc dispatch.Evgeniy Stepanov
git-svn-id: https://llvm.org/svn/llvm-project/compiler-rt/trunk@210452 91177308-0d34-0410-b5e6-96231b3b80d8
2014-06-06[asan] Make ReplaceSystemMalloc optional on Android.Evgeniy Stepanov
Don't fail if __libc_malloc_dispatch is missing; continue running with normal linux interceptors instead. git-svn-id: https://llvm.org/svn/llvm-project/compiler-rt/trunk@210322 91177308-0d34-0410-b5e6-96231b3b80d8
2014-05-14[asan] use some LIKELY/UNLIKELYKostya Serebryany
git-svn-id: https://llvm.org/svn/llvm-project/compiler-rt/trunk@208776 91177308-0d34-0410-b5e6-96231b3b80d8
2014-03-04A set of trivial changes to support sanitizers on FreeBSD.Alexey Samsonov
Patch by Viktor Kutuzov! git-svn-id: https://llvm.org/svn/llvm-project/compiler-rt/trunk@202801 91177308-0d34-0410-b5e6-96231b3b80d8
2014-01-29[asan] experimental intercetor for __tls_get_addr. So far it does nothing ↵Kostya Serebryany
interesting, actual usage will come later. See https://groups.google.com/forum/#!topic/address-sanitizer/BfwYD8HMxTM for background git-svn-id: https://llvm.org/svn/llvm-project/compiler-rt/trunk@200384 91177308-0d34-0410-b5e6-96231b3b80d8
2013-11-13[ASan] Do not rely on malloc context in allocator reports.Alexey Samsonov
Invoke a fatal stack trace unwinder when ASan prints allocator-relevant error reports (double-free, alloc-dealloc-mismatch, invalid-free). Thus we'll be able to print complete stack trace even if allocation/free stacks are not stored (malloc_context_size=0). Based on the patch by Yuri Gribov! git-svn-id: https://llvm.org/svn/llvm-project/compiler-rt/trunk@194579 91177308-0d34-0410-b5e6-96231b3b80d8
2013-04-03[ASan] Kill the remainders of platform defines in favor of SANITIZER_ definesAlexey Samsonov
git-svn-id: https://llvm.org/svn/llvm-project/compiler-rt/trunk@178629 91177308-0d34-0410-b5e6-96231b3b80d8
2013-03-21[ASan] Switch ASan to generic ThreadRegistry from sanitizer_common. Delete ↵Alexey Samsonov
ASan-specific AsanThreadRegistry. git-svn-id: https://llvm.org/svn/llvm-project/compiler-rt/trunk@177634 91177308-0d34-0410-b5e6-96231b3b80d8
2013-03-19[sanitizer] Replace more platform checks with SANITIZER_ constants.Evgeniy Stepanov
git-svn-id: https://llvm.org/svn/llvm-project/compiler-rt/trunk@177400 91177308-0d34-0410-b5e6-96231b3b80d8
2013-03-19[sanitizer] Move ASan platform macros to sanitizer_common and rename them ↵Evgeniy Stepanov
appropriately. git-svn-id: https://llvm.org/svn/llvm-project/compiler-rt/trunk@177397 91177308-0d34-0410-b5e6-96231b3b80d8
2013-01-31[ASan] Split ASan interface header into private and public parts. Add a test ↵Alexey Samsonov
that makes sure users can include interface header git-svn-id: https://llvm.org/svn/llvm-project/compiler-rt/trunk@174058 91177308-0d34-0410-b5e6-96231b3b80d8
2012-12-26[asan] asan_allocator2: do not align the requested size to the redzone size ↵Kostya Serebryany
(saves a bit more memory) git-svn-id: https://llvm.org/svn/llvm-project/compiler-rt/trunk@171111 91177308-0d34-0410-b5e6-96231b3b80d8
2012-12-21[asan] add a flag alloc_dealloc_mismatch (off by default for now) which ↵Kostya Serebryany
finds malloc/delete, new/free, new/delete[], etc mismatches git-svn-id: https://llvm.org/svn/llvm-project/compiler-rt/trunk@170869 91177308-0d34-0410-b5e6-96231b3b80d8
2012-12-20[asan] add a flag poison_heap to allow better allocator benchmarking, ↵Kostya Serebryany
implemenet malloc_stats() on Linux git-svn-id: https://llvm.org/svn/llvm-project/compiler-rt/trunk@170685 91177308-0d34-0410-b5e6-96231b3b80d8
2012-12-13[asan] add two asan flags: fast_unwind_on_fatal and fast_unwind_on_malloc to ↵Kostya Serebryany
allow using the slow CFI-based unwinder git-svn-id: https://llvm.org/svn/llvm-project/compiler-rt/trunk@170117 91177308-0d34-0410-b5e6-96231b3b80d8
2012-09-12[ASan] fix interception macro for Android buildAlexey Samsonov
git-svn-id: https://llvm.org/svn/llvm-project/compiler-rt/trunk@163692 91177308-0d34-0410-b5e6-96231b3b80d8
2012-08-27A few tweaks for building ASanRT against Android NDK.Evgeniy Stepanov
git-svn-id: https://llvm.org/svn/llvm-project/compiler-rt/trunk@162666 91177308-0d34-0410-b5e6-96231b3b80d8
2012-08-06[ASan] fix names of malloc/free replacements on AndroidAlexey Samsonov
git-svn-id: https://llvm.org/svn/llvm-project/compiler-rt/trunk@161322 91177308-0d34-0410-b5e6-96231b3b80d8
2012-06-25[asan] get rid of '#include <malloc.h>' in the implementation of malloc ↵Kostya Serebryany
interceptors git-svn-id: https://llvm.org/svn/llvm-project/compiler-rt/trunk@159132 91177308-0d34-0410-b5e6-96231b3b80d8
2012-06-25Lots of trivial changes to remove extraneous semicolons throughout ASan.Chandler Carruth
git-svn-id: https://llvm.org/svn/llvm-project/compiler-rt/trunk@159128 91177308-0d34-0410-b5e6-96231b3b80d8
2012-06-04Remove file-type tags for .cc files in ASan run-time libraryAlexey Samsonov
git-svn-id: https://llvm.org/svn/llvm-project/compiler-rt/trunk@157927 91177308-0d34-0410-b5e6-96231b3b80d8
2012-05-31[asan] more renamingKostya Serebryany
git-svn-id: https://llvm.org/svn/llvm-project/compiler-rt/trunk@157746 91177308-0d34-0410-b5e6-96231b3b80d8
2012-03-21[asan] Support for %z to Printf()Evgeniy Stepanov
At the moment, asan internal Printf() uses %l modifier for printing values of size_t and related types. This works, because we control both the implementation of Printf and all its uses, but can be a little misleading. This change adds support for %z to Printf(). All callers that print sizes and pointers as integers are switched to %zu / %zx. git-svn-id: https://llvm.org/svn/llvm-project/compiler-rt/trunk@153177 91177308-0d34-0410-b5e6-96231b3b80d8
2012-02-08AddressSanitizer: replace all "real_X" calls with "REAL(X)"Alexey Samsonov
git-svn-id: https://llvm.org/svn/llvm-project/compiler-rt/trunk@150073 91177308-0d34-0410-b5e6-96231b3b80d8
2012-02-03AddressSanitizer: Replace __attribute__ with macro (for Win compatibility). ↵Alexey Samsonov
Patch by timurrrr@google.com git-svn-id: https://llvm.org/svn/llvm-project/compiler-rt/trunk@149686 91177308-0d34-0410-b5e6-96231b3b80d8
2012-02-02AddressSanitizer: Add macro for definition/declaration of interceptorsAlexey Samsonov
git-svn-id: https://llvm.org/svn/llvm-project/compiler-rt/trunk@149602 91177308-0d34-0410-b5e6-96231b3b80d8
2012-01-30AddressSanitizer: Enforce default visibility for all libc interceptorsAlexey Samsonov
git-svn-id: https://llvm.org/svn/llvm-project/compiler-rt/trunk@149247 91177308-0d34-0410-b5e6-96231b3b80d8
2012-01-17AddressSanitizer: add support for malloc_usable_size() functionAlexey Samsonov
git-svn-id: https://llvm.org/svn/llvm-project/compiler-rt/trunk@148287 91177308-0d34-0410-b5e6-96231b3b80d8
2011-12-01[asan] flatten the asan-rt build slightlyKostya Serebryany
git-svn-id: https://llvm.org/svn/llvm-project/compiler-rt/trunk@145631 91177308-0d34-0410-b5e6-96231b3b80d8
2011-11-30AddressSanitizer run-time library. Not yet integrated with the compiler-rt ↵Kostya Serebryany
build system, but can be built using the old makefile. See details in README.txt git-svn-id: https://llvm.org/svn/llvm-project/compiler-rt/trunk@145463 91177308-0d34-0410-b5e6-96231b3b80d8