Commit Graph

793 Commits

Author SHA1 Message Date
Aliaksey Kandratsenka
f56c27910a extend generic frame pointer backtracer to support i386 2023-07-02 22:30:00 -04:00
Aliaksey Kandratsenka
58d6842576 more coverage for stacktrace_unittest 2023-07-02 22:30:00 -04:00
Aliaksey Kandratsenka
25698cd1b8 improve diagnostics for stacktrace_unittest 2023-07-02 22:30:00 -04:00
Aliaksey Kandratsenka
a25e7fa8b0 cleanup cmake's config.h stuff
Some header defines were not cmakedefine01.
2023-07-02 22:30:00 -04:00
Aliaksey Kandratsenka
88d7e65cc2 drop unused libtool target in our Makefile.am
Not sure what it was for, but it is not useful today.
2023-07-02 22:30:00 -04:00
Aliaksey Kandratsenka
ae4aafa468 freebsd+x86-64 pc-from-ucontext is not untested 2023-07-02 22:30:00 -04:00
Aliaksey Kandratsenka
cddd759bd1 disable libgcc stack trace capturing on freebsd 2023-07-02 22:30:00 -04:00
Aliaksey Kandratsenka
4c72b14d35 support proc maps iterator on NetBSD
Turns out it's procfs is available by default, and is fairly similar
to Linux's. So we can just reuse our Linux codes. All tests now pass
on NetBSD!
2023-07-02 22:30:00 -04:00
Aliaksey Kandratsenka
7ffd35a54b correctly detect and link to backtrace_symbols
BSDs need -lexecinfo
2023-07-02 22:30:00 -04:00
Aliaksey Kandratsenka
5b86aa0a51 reimplement GetProgramInvocationName via reading /proc/self/exe
This enables us to support NetBSD, as it lacks
program_invocation_name, but has fairly full-featured procfs.
2023-07-02 22:30:00 -04:00
Aliaksey Kandratsenka
50b5219635 don't NO_INTR close
This is wrong. See man 2 close.
2023-07-02 22:30:00 -04:00
Aliaksey Kandratsenka
7dd1b82378 simplify project by making it C++-only
I.e. no need for any AC_LANG_PUSH stuff in configure. Most usefully,
only CXXFLAGS needs to be set now when you need to tweak compile
flags.
2023-07-02 22:30:00 -04:00
Aliaksey Kandratsenka
cf28e03567 correctly order weakening step to avoid race
Previously we allowed test programs to be linked at the same time as
weakening is performed, rewriting the .a archives. So lets be more
explicit. We weaken after all-am (which "runs" everything including
libraries and programs), but before all target.
2023-07-02 22:30:00 -04:00
Aliaksey Kandratsenka
a39073886a unbreak symbol weakening
It is kinda minor feature, and apparently we never had it working. But
is a nice to have. Allows our users to override malloc/free/etc while
still being able to link to us (for tc_malloc for example). With
broken weakening we had this use-case broken for static library
case. And it should now work.
2023-07-02 22:30:00 -04:00
Aliaksey Kandratsenka
630dac81ea implement simpler ChangeLog generation for source tarballs
We used ax_generate_changelog which works great. But it made our
makefile require GNU make, which was causing annoyance on bsd systems.
2023-07-02 22:30:00 -04:00
Aliaksey Kandratsenka
b30b984281 [osx] make profiler unittest pass
somehow VerifyIdentical tests fail for some formatting details. But
since it tests --raw feature of our deprecated perl pprof
implementation, which we don't intend supporting anyways, we drop this
test.

There is some details about how wc -l returns stuff and how zsh uses
it to compare to 3. So we now explicitly strip whitespace and it
works.
2023-07-02 22:30:00 -04:00
Aliaksey Kandratsenka
7437e0f612 [osx] make heap profiler unittest pass
Apparently awk's comparison $2 > 90 doesn't work when $2 is 100.0. I
frobbed it some and it works now.
2023-07-02 22:30:00 -04:00
Aliaksey Kandratsenka
6683e4f6ee [osx] implement native c++ allocation operators on osx
OSX has really screwed performance for it's memory allocator due to
their malloc zones stuff. We and our competitors hook into that
facility instead directly overriding allocation functions. Which has
massive performance overhead. This is, apparently, so that malloc is
same as allocating from default zone.

As a result, osx'es C++ operator new/delete performance is even worse.
Because we call operator new, it calls malloc, which calls
malloc_zone_malloc, which calls more stuff and eventually tc_malloc.

Thankfully, for C++ API there is no need for such "integration"
between 'stock' memory allocator and malloc zones stuff. So we can
hook those APIs directly. This speeds up malloc_bench numbers on OSX
about 3x.

This change also unbreaks couple tests (e.g. heap profiler unittest)
which depend on MallocHook_GetCallerStackTrace to return precisely
stack trace up to memory allocator call.

Performance-wise, OSX still lacks good TLS and there is still one jump
indirection even for operator new/delete API due to lack support of
aliases. So Linux or BSD, or even windows would still be significantly
faster on malloc performance on same hardware.
2023-07-02 22:30:00 -04:00
Aliaksey Kandratsenka
11d4253ead [osx] don't crash debugallocator on 0-sized allocations
OSX's malloc zones facility is calling 'usable size' before each (!)
free and uses size to choose between our allocator and something
else. And returning 0 breaks this choice. Which happens if we got
0-sized malloc request, which our tests exercise couple times. So we
don't let debug allocator on OSX to have 0 sized chunks. This unbreaks
debug allocation tests on OSX.
2023-07-02 22:30:00 -04:00
Aliaksey Kandratsenka
b0c2ab298a [osx] place malloc-zone-related functions to google_malloc section
On OSX we hook into "system's" malloc through this zones facility, so
we need to place those those interface functions into google_malloc
section. This largely unbreaks MallocHook_GetCallerStackTrace on OSX.
2023-07-02 22:30:00 -04:00
Aliaksey Kandratsenka
531ca4fdca [osx] unbreak LowLevelAlloc
For some reason clang shipped with osx miscompiles LowLevelAlloc when
it tries to place Alloc methods into malloc_hooks section. But since
we don't really need that placement on OSX, we can simply drop that
section placement.
2023-07-02 22:30:00 -04:00
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