Commit Graph

772 Commits

Author SHA1 Message Date
Aliaksey Kandratsenka
e78238d94d reworked heap leak checker for more portability
In most practical terms, this expands "official" heap leak checker
support to Linux/arm64 and Linux/riscv (mips-en and legacy arm are
likely to work & pass tests too now).

The code is now explicitly Linux-only, without trying to pretend
otherwise. Main goal of this change is to finally amputate
linux_syscall_support.h, which we historically had trouble maintaining
well. Biggest challenge was around thread listing facility which uses
clone (ptrace explicitly fails between threads) and that causes
difficulties around parent and child tasks sharing
errno. linux_syscall_support stuff had special feature to "redirect"
errno accesses. But it caused us for more trouble. We switched to
regular syscalls, and errno stamping avoidance is now simply via
careful programming.

A number of other cleanups is made (such us thread finding codes in
procfs which clearly was built for some ages old and odd kernels).

sem_post/sem_wait synchronization was previously potentially prone to
deadlock (if parent died at bad time). We now use pipe pair for this
synchronization and it is fully robust.
2023-07-02 22:30:00 -04:00
Aliaksey Kandratsenka
2186967987 fix heap checker unittest
We had shell wrapper for heap checker unittest, but it failed to deal
with heap-checker-debug variant. So we now posix_spawn from .cc test
instead.
2023-07-02 22:30:00 -04:00
Aliaksey Kandratsenka
1c3f0dda1b ensure that heap checker initialization actually calls malloc
I.e. all recent compilers (both gcc and clang) optimize out delete(new
int) sequence to nothing. We call to tc_new and tc_delete directly to
suppress this optimization.
2023-07-02 22:30:00 -04:00
Aliaksey Kandratsenka
b96dc99dbf one trivial config cleanup 2023-07-02 22:30:00 -04:00
Aliaksey Kandratsenka
b7e47a77c0 simplify heap checker building default to be Linux-only
This also fixes cmake and freebsd where previously check for freebsd
wasn't working.
2023-07-02 22:30:00 -04:00
Aliaksey Kandratsenka
b58cbd2e23 make preamble patcher build and run (win64 only)
First, ml64 (amd64 version of masm) doesn't support /coff. Second, it
also doesn't support (nor use) .model directive.

Sadly, asm is inherently amd64-only, so this entire test won't build
in i386 configuration.
2023-07-02 22:30:00 -04:00
Aliaksey Kandratsenka
54605b8a58 amputate old atomic ops implementation 2023-07-02 22:30:00 -04:00
Aliaksey Kandratsenka
ea0988b020 port spinlocks atomic ops usage to std::atomic 2023-07-02 21:28:30 -04:00
Aliaksey Kandratsenka
3494eb29d6 switch malloc hooks to std::atomic
This makes our code one step closer to killing unportable custom
atomics implementation. I did manually inspect generated code that
fast-path is identical and slow path's changes of generated code are
cosmetic.
2023-07-02 21:28:30 -04:00
Aliaksey Kandratsenka
0e21f36843 unbreak frame skipping in generic-fp backtrace method 2023-07-02 21:28:30 -04:00
Aliaksey Kandratsenka
6f3cacf698 stacktrace_unittest: test backtracing from signals more reliably
Somehow I originally choose to segfault to test this, and it caused us
to deal with 'skipping over' null pointer access. Which ended up not
so easy to do semi-portably. But easier way is to do same
itimer/sigprof thing that we do in actual profiler.

We're still somewhat at the mercy of compiler placing code "normally",
but this implementation seems more robust anyways.
2023-07-02 21:28:30 -04:00
Aliaksey Kandratsenka
68b442714a stop working around obsolete compilation bug
This was targeting (some obsure and perhaps even Google-internal
version) of now-ancient compiler. No need to keep this anymore.
2023-07-02 21:28:30 -04:00
Aliaksey Kandratsenka
16889f6ddb fix minor clang warning 2023-07-02 21:28:30 -04:00
Aliaksey Kandratsenka
246782e1d6 use more noopt in various unit tests
Many our unit tests require specific stack traces or that
allocation/deallocation is not elimininated. As compilation gets more
aggressive (such as when cross-object optimization is enabled during
LTO), we break more of those cases.

This commit extends noopt usage that disables inlining optimization in
specific cases. This fixes github issue #1358.
2023-07-02 21:28:30 -04:00
Aliaksey Kandratsenka
6bdeec0ecb mark stacktrace capturing functions as noinline
It is required for LTO builds, specifically it fixes
stacktrace_unittest. This is because API of stacktrace capturing
functions implicitly assumes that those are not inlined.

Refers to github issue #1358.
2023-07-02 21:28:30 -04:00
Aliaksey Kandratsenka
777182fbdf enable ATTRIBUTE_NOINLINE for MSVC 2023-07-02 21:28:30 -04:00
Aliaksey Kandratsenka
9bde8d837b unbreak building with visual studio clang platform toolset 2023-07-02 21:28:30 -04:00
Aliaksey Kandratsenka
0451d21e83 use libunwind when it actually works
Previously we blindly tried to use libunwind whenever header is
detected. Even if actually working libunwind library is missing. This
is now fixed, so we attempt to use libunwind when it actually works.

Somehow recent freebsd ships libunwind.h (which seems to belong to
llvm's implementation), but apparently without matching .so. So then building
and linking failed.
2023-07-02 21:28:30 -04:00
Aliaksey Kandratsenka
90eff0637b upgrade malloc bench away from std::random_shuffle
C++17 dropped it, so we use C++11 and later std::shuffle
instead. Fixes github issue #1378
2023-07-02 21:28:30 -04:00
Aliaksey Kandratsenka
b501806f2a fix malloc_bench on clang
We got bitten again by compiler optimizing out free(malloc(sz))
combination. We replace calls to malloc/free with calls to global
function operator new/delete. Those are apparently forbidden by
standard to be optimized out.
2023-07-02 21:28:30 -04:00
Aliaksey Kandratsenka
ff68bcab60 [benchmark] detect iterations overflow
If for some reason benchmark function is too fast (like when it got
optimized out to nothing), we'd previously hang in infinite loop. Now
we'll catch this condition due to iterations count overflowing.
2023-07-02 21:28:30 -04:00
Aliaksey Kandratsenka
e003e91b74 drop dependency on PTHREAD_CREATE_JOINABLE 2023-07-02 21:28:30 -04:00
Aliaksey Kandratsenka
8fc84c29a3 mix thread stack address into sampler
This fixes test failures on freebsd (assert that sampler is seeded
with non-0 value).
2023-07-02 21:28:30 -04:00
Aliaksey Kandratsenka
d9b14b9da1 actually test malloc/free from InitLateMaybeRecursive
This days compilers ~always optimize out free(malloc(N)) to nothing.
2023-07-02 21:28:30 -04:00
Aliaksey Kandratsenka
a80ce7b0e1 slow down profiler_unittest some more
On modern machines xoring volatile int is fast enough to occasionally
make specific test case's profiling results not stable enough. So we
now force atomics into the picture which is slightly slower (could be
lots on some platforms and/or optimizer flags).
2023-07-02 21:28:30 -04:00
Aliaksey Kandratsenka
c37f6c4c7c fix deprecated autoconf bits
As part of that we also upgrade required autoconf version to 2.69
which is what I see in rhel/centos 7 and ubuntu 14.04. Both are old
enough. And, of course, .tar.gz releases still ship "packaged" configure,
so will work on older distros.

This fixes issue #1335.
2023-07-02 21:28:30 -04:00
Aliaksey Kandratsenka
f06052d736 synchronize ucontext-from-pc tests autoconf -> cmake
Refers to github issue #1398.
2023-06-21 10:25:14 -04:00
Henrik Reinstädtler
5e923877aa Fix uc_mcontext for apple silicon 2023-06-19 18:11:10 +02:00
Aliaksey Kandratsenka
bf8b714bf5 bump version to 2.10 2022-05-30 21:21:21 -07:00
Aliaksey Kandratsenka
9d44463380 Remove basic support for Elbrus 2000 (e2k)
This reverts commit 3b1c60cc4e.
2022-05-30 20:33:18 -07:00
Aliaksey Kandratsenka
6c99def347 avoid casting NULL to uinptr_t
Which somehow fails to compile on musl. Fixes issue #1338.
2022-05-30 19:58:15 -07:00
Jingyun Hua
fe85bbdf4c Add support for LoongArch.
Only 64-bit is supported at the moment.

Signed-off-by: Jingyun Hua <huajingyun@loongson.cn>
2022-02-08 20:47:10 +08:00
Aliaksey Kandratsenka
e80652b627 ship cmake bits with tar.gz distribution
Fixes issue #1321.
2022-01-14 23:08:57 -08:00
Volodymyr Nikolaichuk
003775aa81 free memory with mmap(PROT_NONE, MAP_FIXED) 2021-12-12 22:29:36 -08:00
Natale Patriciello
852fb6df03 Implement free_definite_size
In Monterey, it seems that free_definite_size is required (despite
the documentation saying that is optional). The implementation
just forward the call to free.

Signed-off-by: Natale Patriciello <natale.patriciello@gmail.com>
2021-12-12 22:28:06 -08:00
stdpain
c25941200e fix cmake gperftools_enable_libunwind invalid 2021-06-20 10:07:42 -07:00
Robert Scott
43504ab709 tcmalloc page fences: add TCMALLOC_PAGE_FENCE_READABLE option 2021-06-20 10:02:06 -07:00
Matt T. Proud
d57a9ea8bc README: replace "golang" moniker with "Go"
This commit replaces the "golang" moniker in the README file with the
appropriate name of "Go" per https://golang.org/doc/faq#go_or_golang.

In this context, no disambiguation is required.
2021-06-20 09:55:45 -07:00
Aliaksey Kandratsenka
f7c6fb6c8e bump version to 2.9.1 2021-03-02 19:32:07 -08:00
Aliaksey Kandratsenka
c2f60400a8 prefer backtrace() on OSX
It seems to work and _Unwind_Backtrace which is configured otherwise
doesn't.
2021-02-28 17:52:17 -08:00
Aliaksey Kandratsenka
a015377a54 Set tcmalloc heap limit prior to testing oom
Otherwise it can take long time to OOM on osex.
2021-02-28 17:47:56 -08:00
Aliaksey Kandratsenka
c939dd5531 correctly check sized delete hint when asserts are on
We previously tested wrong assumption that larger than page size size
classes have addresses aligned on page size. New code is making proper
check of size class.

Also added is unit test coverage for this previously failing
condition. And we now also run "assert-ful" unittests for big tcmalloc
too, not only tcmalloc_minimal configuration.

This fixes github issue #1254
2021-02-28 15:54:22 -08:00
Aliaksey Kandratsenka
47b5b59ca9 bump version to 2.9 2021-02-21 15:16:06 -08:00
Aliaksey Kandratsenka
d7cbc8c2ff unbreak cmake build
It was trying to use third_party/valgrind.h header which I recently
removed.
2021-02-21 15:01:01 -08:00
Aliaksey Kandratsenka
be0bbdb340 amputate various unused bits from elfcore.h 2021-02-21 14:29:40 -08:00
Aliaksey Kandratsenka
42bab59f25 liberate profile handler from linux_syscall_support
We can get thread's tid in more portable way via libc syscall wrapper.
2021-02-21 14:29:34 -08:00
Aliaksey Kandratsenka
4629511e99 liberate spinlock futex waits from linux_syscall_support includes
We've been using libc syscall wrapper some time now.
2021-02-21 14:28:44 -08:00
Aliaksey Kandratsenka
2e7094a862 liberate malloc_hook_mmap_linux.h from linux_syscall_support
It was not used some time now, as we're rightfully trusting libc
syscall wrapper instead.
2021-02-21 14:28:25 -08:00
Aliaksey Kandratsenka
35301e2e59 add missing noopt wrappings around more operator new calls
This fixes tests passing on clang which otherwise eliminates those
new/delete calls so checking for hooks being called failed.
2021-02-21 12:41:36 -08:00
Venkatesh Srinivas
fa412adfe3 Fix thread-safety (annotalysis) annotations
tcmalloc contains some thread-safety annotations; however those
annotations have not been exercised for some time, as they used
macros/attributes only supported by a legacy branch of gcc.

Pull request #1251 converted those macros to support modern
versions of clang; this CR fixes the annotations that were
enabled. For the most part, this just requires re-enabling
annotations on member functions that take/release locks. For the
tcmalloc fork (pre-fork and post-fork) handlers, we mark the
functions as exempt from this analysis, as it takes a dynamic
number of locks.
2021-02-17 17:50:43 -08:00