Commit Graph

649 Commits

Author SHA1 Message Date
pkubaj
fba6ce0e7a Fix build on FreeBSD
On FreeBSD the following syntax is used:
mr REGA,REGB
2019-04-07 14:25:40 -07:00
Jakub Wilk
98ac4ee9bc Fix typos 2019-04-07 13:32:47 -07:00
Aliaksey Kandratsenka
9e5b162873 don't try to mark rsp as clobbered in linux syscall support
rsp is not actually clobbered by that code and later gccs actually (correctly) bark
at it.

Fixed issue #1076.
2019-02-10 12:46:22 -08:00
Romain Geissler
1e36ed7055 Use initial exec TLS model for all thread local variables from thread_cache.cc
This avoids a deadlock when a library which is being dlopen'ed creates
as part of its static constructors a thread which quickly need to call
malloc. We are still in the dlopen call (so with some internal glibc
mutex taken) when the thread executes code and later needs to call
malloc which in term calls tls_get_addr_tail, which wait for the dlopen
mutex to be unlocked. If later the dlopen'ing thread also calls malloc
as part of its constructors, we are in a deadlock.

Fix is similar to
7852eeb75b

Stack of the dlopening thread:
    #0  0x00007fd5406ca93c in __lll_lock_wait () from /data3/mwrep/rgeissler/core.tls/opt/1A/toolchain/x86_64-2.6.32-v2/lib64/libpthread.so.0
    #1  0x00007fd5406c45a5 in pthread_mutex_lock () from /data3/mwrep/rgeissler/core.tls/opt/1A/toolchain/x86_64-2.6.32-v2/lib64/libpthread.so.0
    ... proprietary code in the stack
    #9  0x00007fd5074f0367 in __static_initialization_and_destruction_0 (__initialize_p=1, __priority=65535) at src/ClientImpl.cpp:15
    #10 0x00007fd5074f06d7 in _GLOBAL__sub_I_ClientImpl.cpp(void) () at src/ClientImpl.cpp:85
    #11 0x00007fd50757aa46 in __do_global_ctors_aux ()
    #12 0x00007fd5073e985f in _init () from ...
    #13 0x00007fd53bf9dec8 in ?? () from ...
    #14 0x00007fd54d637a5d in call_init.part () from /data3/mwrep/rgeissler/core.tls/opt/1A/toolchain/x86_64-2.6.32-v2/lib64/ld-linux-x86-64.so.2
    #15 0x00007fd54d637bab in _dl_init () from /data3/mwrep/rgeissler/core.tls/opt/1A/toolchain/x86_64-2.6.32-v2/lib64/ld-linux-x86-64.so.2
    #16 0x00007fd54d63c160 in dl_open_worker () from /data3/mwrep/rgeissler/core.tls/opt/1A/toolchain/x86_64-2.6.32-v2/lib64/ld-linux-x86-64.so.2
    #17 0x00007fd54d637944 in _dl_catch_error () from /data3/mwrep/rgeissler/core.tls/opt/1A/toolchain/x86_64-2.6.32-v2/lib64/ld-linux-x86-64.so.2
    #18 0x00007fd54d63b7d9 in _dl_open () from /data3/mwrep/rgeissler/core.tls/opt/1A/toolchain/x86_64-2.6.32-v2/lib64/ld-linux-x86-64.so.2
    #19 0x00007fd54d61f2b9 in dlopen_doit () from /data3/mwrep/rgeissler/core.tls/opt/1A/toolchain/x86_64-2.6.32-v2/lib64/libdl.so.2
    #20 0x00007fd54d637944 in _dl_catch_error () from /data3/mwrep/rgeissler/core.tls/opt/1A/toolchain/x86_64-2.6.32-v2/lib64/ld-linux-x86-64.so.2
    #21 0x00007fd54d61f889 in _dlerror_run () from /data3/mwrep/rgeissler/core.tls/opt/1A/toolchain/x86_64-2.6.32-v2/lib64/libdl.so.2
    #22 0x00007fd54d61f351 in dlopen@@GLIBC_2.2.5 () from /data3/mwrep/rgeissler/core.tls/opt/1A/toolchain/x86_64-2.6.32-v2/lib64/libdl.so.2

Stack of the newly created thread calling tls_get_addr_tail:
    #0  0x00007fd5406ca93c in __lll_lock_wait () from /data3/mwrep/rgeissler/core.tls/opt/1A/toolchain/x86_64-2.6.32-v2/lib64/libpthread.so.0
    #1  0x00007fd5406c4622 in pthread_mutex_lock () from /data3/mwrep/rgeissler/core.tls/opt/1A/toolchain/x86_64-2.6.32-v2/lib64/libpthread.so.0
    #2  0x00007fd54d63a2ed in tls_get_addr_tail () from /data3/mwrep/rgeissler/core.tls/opt/1A/toolchain/x86_64-2.6.32-v2/lib64/ld-linux-x86-64.so.2
    #3  0x00007fd53fee877d in tcmalloc::ThreadCache::CreateCacheIfNecessary () at src/thread_cache.cc:344
    #4  0x00007fd53fecb4ab in tcmalloc::ThreadCache::GetCache () at src/thread_cache.h:437
    #5  0x00007fd53fefeccb in (anonymous namespace)::do_malloc (size=56) at src/tcmalloc.cc:1354
    #6  tcmalloc::do_allocate_full<tcmalloc::cpp_throw_oom> (size=56) at src/tcmalloc.cc:1762
    #7  tcmalloc::allocate_full_cpp_throw_oom (size=56) at src/tcmalloc.cc:1776
    #8  0x00007fd53ff01b80 in tcmalloc::dispatch_allocate_full<tcmalloc::cpp_throw_oom> (size=56) at src/tcmalloc.cc:1785
    #9  malloc_fast_path<tcmalloc::cpp_throw_oom> (size=56) at src/tcmalloc.cc:1845
    #10 tc_new (size=56) at src/tcmalloc.cc:1980
    ... proprietary code in the stack
    #26 0x00007fd5406c1ef4 in start_thread () from /data3/mwrep/rgeissler/core.tls/opt/1A/toolchain/x86_64-2.6.32-v2/lib64/libpthread.so.0
    #27 0x00007fd5403ba01d in clone () from /data3/mwrep/rgeissler/core.tls/opt/1A/toolchain/x86_64-2.6.32-v2/lib64/libc.so.6
2019-02-10 11:57:18 -08:00
pkubaj
8f9a873fce Fix accessing PC on FreeBSD/powerpc and powerpc64 2019-02-10 11:47:03 -08:00
Tulio Magno Quites Machado Filho
fc00474ddc Include asm/ptrace.h when accessing ucontext_t
In some architectures (e.g. powerpc, powerpc64 and powerpc64le), the
macro that specifies the position of the program counter is defined in
header asm/ptrace.h.

When glibc bug 21457 got fixed in version 2.27, header sys/ucontext.h
stopped including signal.h, which indirectly removed asm/ptrace.h too.

Signed-off-by: Tulio Magno Quites Machado Filho <tuliom@linux.ibm.com>
2019-02-10 11:16:56 -08:00
Laurent Stacul
5574c87e39 Compile time aggressive decommit option
[alkondratenko@gmail.com: performed s/agressive/aggressive/g]
Signed-off-by: Aliaksey Kandratsenka <alkondratenko@gmail.com>
2019-02-10 11:14:23 -08:00
Fabrice Fontaine
e9ab4c5304 undef mmap64 function
mmap64 can already been defined and as a result the following error is
raised:

In file included from src/malloc_hook.cc:686:0:
src/malloc_hook_mmap_linux.h: In function ‘void* mmap(void*, size_t, int, int, int, off_t)’:
src/malloc_hook_mmap_linux.h:173:18: error: redefinition of ‘void* mmap(void*, size_t, int, int, int, off_t)’
 extern "C" void* mmap(void *start, size_t length, int prot, int flags,
                  ^~~~
In file included from src/malloc_hook.cc:41:0:
src/malloc_hook_mmap_linux.h:159:18: note: ‘void* mmap(void*, size_t, int, int, int, off_t)’ previously defined here
 extern "C" void* mmap64(void *start, size_t length, int prot, int flags,
                  ^
Makefile:4874: recipe for target 'src/libtcmalloc_minimal_internal_la-malloc_hook.lo' failed

Signed-off-by: Fabrice Fontaine <fontaine.fabrice@gmail.com>
2018-10-07 11:22:59 -07:00
Aliaksey Kandratsenka
5eec9d0ae3 Drop not very portable and not very useful unwind benchmark. 2018-10-07 08:17:04 -07:00
Fabrice Fontaine
1561f0946f check for __sbrk
__sbrk is not defined in musl so add a check for it in configure.ac and
replace the check on ifndef __UCLIBC__ by a check on ifdef HAVE__SBRK
in src/malloc_hook_mmap_linux.h

Signed-off-by: Fabrice Fontaine <fontaine.fabrice@gmail.com>
2018-10-06 16:58:55 -07:00
Gabriel Marin
1de76671d4 Fix mmap region iteration while no regions are recorded.
If no mmap regions are recorded, iteration failed since the RegionSet
(std::set) object is not initialized.

Original CL https://codereview.chromium.org/14769008

Reviewed-on: https://chromium-review.googlesource.com/c/1130807
2018-10-06 11:39:39 -07:00
Fabrice Fontaine
acdcacc28f Use off64_t instead of __off64_t
__off64_t is a kernel internal symbol, which happens to be user-visible
with glibc, but not necessarily with other C libraries such as musl.

Switching from __off64_t to off64_t allows the code to build properly
with musl.

Signed-off-by: Fabrice Fontaine <fontaine.fabrice@gmail.com>
2018-10-06 11:28:27 -07:00
Gabriel Marin
0177a2420a Return early in WriteProfile to reduce indentation
Small code refactoring to reduce indentation. This change was originally
part of https://codereview.chromium.org/9963095.

Reviewed-on: https://chromium-review.googlesource.com/c/1130804
2018-10-06 11:24:01 -07:00
Gabriel Marin
b85652bf26 Add generic.total_physical_bytes property to MallocExtension
Original CL:

- https://codereview.chromium.org/1410353005

  Add generic.total_physical_bytes property to MallocExtension

  The actual physical memory usage of tcmalloc cannot be obtained by
  GetNumericProperty. This accounts for the current_allocated_bytes,
  fragmentation and malloc metadata, and excludes the unmapped memory
  regions. This helps the user to understand how much memory is actually
  being used for the allocations that were made.

Reviewed-on: https://chromium-review.googlesource.com/1130803
2018-10-06 11:07:59 -07:00
Gabriel Marin
90df23c81f Make some tcmalloc constants truly const
Reviewed-on: https://chromium-review.googlesource.com/c/1130809
2018-10-05 17:17:55 -07:00
Aliaksey Kandratsenka
49dbe4362b Add comment about gperftools 2.8 not deduplicating heapz samples. 2018-09-03 16:44:52 -07:00
Aliaksey Kandratsenka
63a12a5ed3 Drop de-duplication of heap sample (aka heapz) entries.
pprof can aggregate them, and it can do it way better than we can. With
proper unsampling etc.
2018-08-27 20:10:09 -07:00
Aliaksey Kandratsenka
954f9dc0e3 Add flag to disable installing unmaintained & deprecated pprof.
Everyone should be using golang pprof from github.com/google/pprof, but
distros still ship our perl version and not everyone is aware of
better pprof yet.

This is another step in completely dropping perl pprof. We still
default to installing it, but hopefully we'll be able to convince
distros to disable this soon.

We still install pprof under pprof-symbolize name because
stack traces symbolization depends on it, and because golang pprof
won't support this feature.

This is related to issue #1038.
2018-08-26 11:37:59 -07:00
Aliaksey Kandratsenka
893bff51bc Avoid static initialization of pprof path for symbolization.
This is one of the things that chrome's fork fixes, but with c++11 we
can do it even nicer. Proposed fix is to use c++11 local static
variable to ensure that pprof path is initialized once on as-needed
basis.
2018-08-26 11:35:44 -07:00
Holy Wu
69867c523b Clean up MSVC projects
1.Remove superfluous per file settings for include directory and runtime library.
2.Remove unnecessary project tcmalloc_minimal_unittest-static. We can simply build libtcmalloc_minimal as a static library and then link against the single .lib file.
3.Add separate configurations of patching and overriding facility for release mode.
2018-08-14 22:34:00 -07:00
Brian Silverman
f2bca77aed Fix page_heap_test flakiness
After 71fa9f87 (use 2-level page map for 48-bit addresses), there is a
potential for allocs of additional leaves in the middle of the test.
With ASLR enabled on amd64 (without TCMALLOC_SMALL_BUT_SLOW), this
results in the test failing sometimes (< 1% of the time). Instead, make
sure all those leaves are allocated before deciding on the baseline heap
usage in the test.
2018-08-13 18:44:49 -07:00
Aliaksey Kandratsenka
c41688bf20 Use standard-conforming alignof in debugallocation.cc
Clang was giving warning that alignof(<variable>) is extension. So
we're now doing alignof of decltype.
2018-08-05 20:44:04 -07:00
Aliaksey Kandratsenka
71c8cedaca Fix incompatible aliasing warnings
We aliased functions with different signatures and gcc now correctly
gives warning for that. Originally gcc 5 same code merging feature
caused us to alias more than necessary, but I am not able to reproduce
this problem anymore. So we're now aliasing only compatible functions.
2018-08-05 20:43:53 -07:00
Aliaksey Kandratsenka
8dd3040358 Format and fix out of bound access in CpuProfilerSwitch
GCC was giving warning on snprintf and it hinted at base_profile_name
and full_profile_name not being long enough.

Fix is to ensure base_profile_name is long enough for PATH_MAX and
that full_profile_name is enough longer to fit extra chars.
2018-08-05 20:43:17 -07:00
Aliaksey Kandratsenka
467502e70a provide constexpr constructor for Sampler
Constexpr constructor lets us use Sampler in TLS variable in cleaner
way.
2018-08-05 20:25:25 -07:00
HolyWu
1fb543cc70 Patch _free_dbg to make Debug mode in MSVC works
Like _free_base, _free_dbg is called by CRT internal functions or
operator delete in Debug mode.

This closes #719 and closes #894.

[alkondratenko@gmail.com: trivial formatting fixes]
[alkondratenko@gmail.com: build free_dbg even in release builds]
2018-08-05 16:30:08 -07:00
Gabriel Marin
267f431d80 Use indirect system calls in the linux spinlock implementation 2018-08-05 16:21:12 -07:00
Gabriel Marin
73ee9b1544 Use indirect system calls in the mmap malloc hooks.
sys_{mmap|munmap|mremap}(...) calls are replaced with
syscall(SYS_{mmap|munmap|mremap}, ...).
2018-08-05 16:21:12 -07:00
Gabriel Marin
3af509d4f9 benchmark: use angle brackets to include ucontext.h
Using quotes for a system header file fails a presubmit check in Chromium.
2018-08-05 16:15:12 -07:00
Gabriel Marin
0cdda6d7cc use utf-8 for special symbols
A few files in the windows port that haven't been touched in a long time,
use non-utf8 codes for special symbols, breaking a presubmit checker in
Chromium.
2018-08-05 16:15:12 -07:00
etienneb
c7a0cfda88 Fix potential missing nul character on resolved symbol names
The symbol name returned by SymFromName may not contains a NUL character
when the symbol name is exactly the size of the buffer. It believe this
may also happen when the symbol name is too long and truncated.

The original code is based on:
  https://msdn.microsoft.com/en-us/library/windows/desktop/ms680580(v=vs.85).aspx

A right implementation can be found here:
  https://cs.chromium.org/chromium/src/base/debug/stack_trace_win.cc?l=145&rcl=f4ecb9e37e9e2d59e32b8b96f23ac4a1e33b9552

As described here:
  https://msdn.microsoft.com/en-us/library/windows/desktop/ms680686(v=vs.85).aspx

  NameLen
    The length of the name, in characters, not including the null-terminating character.
  MaxNameLen
    The size of the Name buffer, in characters. If this member is 0, the Name member is not used.

This issue was causing the catapult symbolisation script to encode incorrect (random) characters into the symbol names.
See the example in the bug.

Original BUG=713741

Review-Url: https://codereview.chromium.org/2832643004
Cr-Commit-Position: refs/heads/master@{#466098}

BUG=724399,b:70905156

Change-Id: Ia6de4ddbd5c66a966b74ecec3fda5e853f36073b
2018-08-05 16:11:14 -07:00
Gabriel Marin
e42bfc8c06 tcmalloc: use relative addresses with the windows addr2line wrapper
Modifies the Windows addr2line wrapper to expect addresses relative to
DllBase to better simulate how addr2line works with modules in Linux.

Windows DLLs have a concept of "default load address" which hints to the OS
where to load the binary image after relocation. The dbghelp.dll
symbolization library will load the module at this location in the virtual
address space meaning the caller of these functions would need to be aware
of the base address. This makes things unnecessarily complex in the face of
ASLR and also diverges from the behavior of addr2line when used with linux-
style DSOs. This CL simply adds the module base address to the incoming
addresses, thereby making the input relative addresses for the module which
both is easier to use and lines up better with linux's addr2line behavior.

These changes were made originally as part of CL
https://codereview.chromium.org/2730473002.

BUG=724399,b:70905156

Change-Id: I0abe9e0c380e7e60ae29a11021bb805b31718d08
2018-08-05 16:11:14 -07:00
Gabriel Marin
d8f8d1cced tcmalloc: add long form flag '--exe' to specify the binary
This change was originally made as part of CL
https://codereview.chromium.org/2730473002

BUG=724399,b:70905156

Change-Id: I33ee28eac4dab6077cf162358cf4c10b41c0f6a2
2018-08-05 16:11:14 -07:00
Gabriel Marin
25c53aca12 tcmalloc: fixes for the windows addr2line wrapper
Fixes a few small format string bugs and makes the windows library
configuration #defines more friendly for chromium builds.

Based on original CL: https://codereview.chromium.org/2730473002

BUG=724399,b:70905156

Change-Id: If54c6cfc5c508744d2ee18f251677b2456acda72
2018-08-05 16:11:14 -07:00
Gabriel Marin
f02e28f348 Replace builtin_expect configure test with a direct GCC compiler check 2018-08-05 16:07:51 -07:00
obones
62c4eca6e7 Under x64, the PE loader looks for callbacks in constant sections
[alkondratenko@gmail.com: deleted some trailing whitespace]
2018-08-05 16:04:31 -07:00
Brian Silverman
0b588e7490 Fix uninitialized memory use in sampler_test
Sampler's documentation states the following:
  C++03 requires that types stored in TLS be POD.  As a result, you must
  initialize these members to {0, 0, false} before using this class!

However, the test code wasn't doing that. MemorySanitizer and
UndefinedBehaviorSanitizer both failed because of it.
2018-08-05 15:54:00 -07:00
Aliaksei Kandratsenka
51a5613f21 Upgrade MSVC projects to MSVC2015 2018-08-05 15:54:00 -07:00
Aliaksey Kandratsenka
44da4ce539 build with c++11 or later 2018-08-05 15:15:10 -07:00
HolyWu
f47a52ce85 Make _recalloc adhere to MS's definition 2018-05-21 16:08:27 +08:00
Junhao Li
fe87ffb7ea Disable large allocation report by default
Fixes issue #360.

[alkondratenko@gmail.com: adjusted commit message a bit]
[alkondratenko@gmail.com: adjusted configure help message]
Signed-off-by: Aliaksey Kandratsenka <alkondratenko@gmail.com>
2018-05-20 21:13:05 -07:00
Aliaksey Kandratsenka
9608fa3bcf bumped version to 2.7 2018-04-29 23:00:34 -07:00
HolyWu
db890ccfad Clean up src/windows/config.h 2018-04-29 22:59:43 -07:00
HolyWu
497ea33165 Fix WIN32_OVERRIDE_ALLOCATORS for VS2017
At first I try to add some functions as what Chrome does at their
https://chromium.googlesource.com/chromium/src/+/master/base/allocator/allocator_shim_override_ucrt_symbols_win.h,
but it still fails. So I decide to remove all heap-related objects
from libucrt.lib to see what happens. At the end I find that a lot of
functions in the CRT directly invoke _malloc_base instead of
malloc (and the others alike), hence we need to override them as well.

This should close issue #716.

[alkondratenko@gmail.com: added reference to ticket]
Signed-off-by: Aliaksey Kandratsenka <alkondratenko@gmail.com>
2018-04-29 22:59:01 -07:00
HolyWu
ebc85cca90 Enable aligned new/delete declarations on Windows when applicable 2018-04-29 21:51:42 -07:00
Aliaksey Kandratsenka
a3badd6d21 Really fix CheckAddressBits compilation warning
It looks like previous fix introduced another warning on gcc for
i386. Somehow it barked on kAddressBits shift even that shift was dead
code.

Anyways, we now avoid possibility of undefined shift even
stronger. And it actually removes compile warning on all compilers I
tested.
2018-04-29 16:40:22 -07:00
HolyWu
7c718fe176 Add tests for sized deallocation 2018-04-29 14:42:44 -07:00
Fabrice Fontaine
30e5e614a8 Fix build without static libraries
Only add -static to malloc_bench_LDFLAGS and binary_trees_LDFLAGS if
ENABLE_STATC is set otherwise build with some compilers will fail if
user has decided to build only the shared version of gperftools
libraries

Signed-off-by: Fabrice Fontaine <fontaine.fabrice@gmail.com>
2018-04-29 14:29:16 -07:00
Ben Dang
836c4f29a5
Update documentation for heap_checker.html
Make it clear that the static methods used require the "namespace", `HeapLeakChecker::`.
2018-04-13 10:54:05 -07:00
Tulio Magno Quites Machado Filho
e47d0d1c51 powerpc: Re-enable VDSO support
Powerpc requires VDSO support in order to produce a stack trace.
Without this, it isn't possible to complete a build.
Tested on powerpc, powerpc64 and powerpc64le.
2018-04-11 20:19:55 -07:00