1
0
Fork 0
mirror of https://github.com/tobast/libunwind-eh_elf.git synced 2024-05-19 03:25:18 +02:00
Commit graph

138 commits

Author SHA1 Message Date
Keno Fischer 8afc33ce9f Add an option to have start_ip_offset be relative to start_ip
By default, the start_ip_offset in libunwind's table_entry struct is
relative to the unw_dyn_info_t's segbase. This presents a problem
for us in conjunction with using LLVM's MCJIT because it likes to
spread text sections and the corresponding eh_frame sections quite
far apart. This represents my attempt to support this use case in the
simplest manner that is backwards compatible, by adding a new format
kind (UNW_INFO_FORMAT_REMOTE_TABLE2) that indicates that the
`start_ip_offset` should be interpreted as relative to `start_ip`
rather than segbase.
2015-09-15 12:18:30 -07:00
Paul Pluzhnikov 1bca6eb8ea Remove unnecessary calls to labs()
We've just traced a large memory increase to that patch (Google ref:
b/18069427).
It appears that labs() was there for a good reason.

Sorry about that :-(

For the curious:

  unsigned long u1 = ~0UL;
  unsigned long u2 = labs(u1);

  assert(u1 != u2);  // labs on unsigned *may* have an effect, despite
what Clang says.

Attached patch suppresses the Clang warning, while still keeping the
original behavior (which I believe to be correct).

Thanks,
--
Paul Pluzhnikov
2014-10-24 22:29:15 -07:00
Arun Sharma 781d5d5263 One time whitespace fixup.
for f in $(find src include -name '*.[ch]'); do
  expand -t 8 $f > $tmp; mv $tmp $f;
done
2014-09-27 09:47:23 -07:00
Arun Sharma 0808aa6737 Stop unwinding on undefined return address
Milian Wolff <mail@milianw.de> reported that this greatly
improved unwinding perf on some his apps.
2014-09-07 03:32:57 -07:00
Paul Pluzhnikov e63cadf76d Remove unnecessary calls to labs()
Greetings,

Roman reports that Clang warns on unnecessary calls to labs():

  taking the absolute value of unsigned type 'unw_word_t' (aka
'unsigned long') has no effect [-Werror,-Wabsolute-value]

Since rs->reg[...].val is unw_word_t and unsigned on all platforms,
this patch removes the unnecessary calls to labs().

Tested on Linux x86_64, no regressions.

Thanks,
--
Paul Pluzhnikov
2014-08-15 13:01:47 -07:00
Konstantin Belousov 3723511003 Adjust use_prev_instr for syscall and frame-chain frames.
Mark frames which are unwound with the frame-chain walker or
syscall frame code, as non-interrupted.  The return PC in the frame
points to the instruction after the call.
2014-08-15 13:01:36 -07:00
Kevin Modzelewski 4509adb853 x86_64: Handle edge conditions with zero length frames
When JITs generate code without unwind information, it may be possible
to continue unwinding via RBP chaining. However, we currently disallow
RBP==RSP condition even though we can make forward progress.

Relax the check a bit in the code where we switch from one type of
unwinding to another to handle this situation. JIT authors
are encouraged to use the dynamic unwind info registration API when
the underlying platform supports it.

Signed-off-by: Kevin Modzelewski <kmod@dropbox.com>
2014-05-18 19:39:26 -07:00
Tommi Rantala adae66d2e2 Fix x86-64 debug build -Wformat warning
src/x86_64/Gstep.c: In function '_ULx86_64_step':
src/x86_64/Gstep.c:204:4: warning: unknown conversion type character 'r' in format [-Wformat]
2012-10-05 21:24:36 -07:00
Tommi Rantala 890e23eb9d Prefer NULL over zero 2012-09-28 14:51:21 +03:00
Tommi Rantala aebba1f8a7 Apply `define_lock()'
We have a nice macro for defining pthread mutexes, use it.
2012-09-28 14:51:21 +03:00
Tommi Rantala ee8df26288 Constify `dwarf_to_unw_regnum_map' 2012-09-28 14:50:03 +03:00
Tommi Rantala ded94b98ff Stop including `memory.h'
I am unable to find any reference to `memory.h' in the C99 and C11
committee drafts, so include `string.h' instead when we need memset() or
similar.
2012-09-28 14:50:03 +03:00
Tommi Rantala 0941dedb70 Remove unused src/x86_64/Lis_signal_frame.c 2012-09-28 14:06:07 +03:00
Tommi Rantala 5d0f376b08 Invert tdep_init() flag logic
Invert the flag that signals that tdep_init() was called, to move the
symbol from data to BSS.
2012-09-28 14:06:07 +03:00
Konstantin Belousov d0cbc51955 x86_64: stop unwinding when %rbp location is NULL 2012-09-21 23:06:17 -07:00
ariel.burton@roguewave.com d00b621090 PATCH: fix build with --enable-msabi-support
This attached patch, relative to libuninwd-1.0.1,
will fix building with --enable-msabi-support on linux x86_64.

Ariel Burton
2012-09-15 10:47:34 -07:00
Tommi Rantala 5fef17c05d Fix memory leaks in unw_create_addr_space() wrong-endian error paths
Check the endianness earlier in unw_create_addr_space() on all
architectures to avoid leaking the dynamically allocated address space
struct.

This was already fixed for ARM in commit cf6a998796 ("Fix memory leak
in ARM unw_create_addr_space()"). Move the endianness check also on ARM
to avoid malloc() & free() in the error case.
2012-08-21 22:33:29 +03:00
Arun Sharma dd297ea92e Revert "x86_64: unbreak test-ptrace"
This reverts commit c9c5a40be1.
dwarf_get() returns 0 on success. We should continue unwinding
in that case.

TBD: investigate test-ptrace failure on some platforms.
2012-05-18 15:24:02 -07:00
Arun Sharma c9c5a40be1 x86_64: unbreak test-ptrace
If dwarf_get returns 0 (indicating the end of call chain), we should
not override the return value to 1. This may result in the caller
continuing to unwind and getting spurious errors.
2012-05-16 07:49:30 -07:00
Konstantin Belousov 1a6ea3da60 freebsd: Fix boundary conditions for non-dwarf walker on x86_64.
In the commit d04dc94cc2, the check for
dwarf.ip == 0 was removed from non-dwarf walker in x86_64 version of
unw_step(). Apparently this broke the detection of the end of frame
chain when NULL %rbp is specified, because the case just marked
dwarf.ip as 0. Explicitly set ret to 0 to indicate the end of
iteration.
2012-05-14 23:18:00 -07:00
Konstantin Belousov 3bb74aae3d freebsd: Account for the possible ERESTART handling of the syscalls. 2012-05-14 23:07:52 -07:00
Arun Sharma d04dc94cc2 dwarf: ip == 0 should't terminate unwind 2012-03-25 18:10:10 -07:00
Arun Sharma 52ca68c770 Fix a race condition
There is a window of time between the munmap and the tls_cache being
marked as destroyed, where there could be a bad access to memory that
has been unmapped/freed. Reorder the code a bit to close the window.

Signed-off-by: Paul Pluzhnikov <ppluzhnikov@google.com>
2011-12-16 10:45:51 -08:00
Arun Sharma cf2f3d3b75 Correct the inverted check
Typo when manually applying the previous commit.
2011-12-02 08:35:00 -08:00
Arun Sharma 2f328202ee Fix a compiler warning
Signed-off-by: Paul Pluzhnikov <ppluzhnikov@google.com>
2011-12-01 22:08:08 -08:00
Arun Sharma 1010880548 Address x86_64 crashes when using sigaltstack
The crashes were tracked down to f->rpb_cfa_offset being incorrect.

The problem is that {rsp,rbp}_cfa_offset only have 15 bits, but for
SIGRETURN frame they are filled with:

// src/x86_64/Gstash_frame.c

   f->cfa_reg_offset = d->cfa - c->sigcontext_addr;
   f->rbp_cfa_offset = DWARF_GET_LOC(d->loc[RBP]) - d->cfa;
   f->rsp_cfa_offset = DWARF_GET_LOC(d->loc[RSP]) - d->cfa;

The problem is that the delta here can be arbitrarily large when
sigaltstack is used, and can easily overflow the 15 and 30-bit fields.

When signal handler starts running, the stack layout is:

 ... higher addresses ...
        ucontext
 CFA->
        __restore_rt (== pretcode in rt_sigframe from
                      linux-2.6/arch/x86/include/asm/sigframe.h)
 SP ->
       ... sighandler runs on this stack.

 ... lower addresses ...

This makes it very convenient to find ucontext from the CFA.

Attached patch re-tested on Linux/x86_64, no new failures.

Signed-off-by: Paul Pluzhnikov <ppluzhnikov@google.com>
Reviwed-by: Lassi Tuura <lat@cern.ch>
2011-11-27 18:34:38 -08:00
Arun Sharma 0a26727ea2 Fix TLS destructor ordering problems
Glibc calls thread-specific dtors in the order in which the keys were added,
so the first dtor is the trace_cache_free() one. Then thread-specific
data for some other key is free()d, which calls into unw_backtrace(),
which uses dangling cache and munmapped cache->frames.

[ Minor rename + compiler warning fix: asharma@fb.com ]
Signed-off-by: Paul Pluzhnikov <ppluzhnikov@google.com>
2011-10-29 17:12:36 -07:00
Arun Sharma 08077a4962 pthread_once() workaround for FreeBSD and Solaris
On FreeBSD, as well as on the Solaris < 10, weak pthread_once stub is
always exported from libc. But it does nothing, which means that if
threaded library is not loaded, then pthread_once() call do not actually
call the initializer finction. The construct
  if (likely (pthread_once != 0))
  {
    pthread_once(&trace_cache_once, &trace_cache_init_once);
then fails to initialize the trace cache on x86_64.

Work around by checking that the initializer was indeed called.
Note that this can break if libthr is loaded dynamically, but my belief
is that there is no platforms which allow dynamic loading of the threading
library.
2011-10-29 16:53:30 -07:00
Arun f89fb17695 Fix incorrect calls to memset.
Found when compiling libunwind with clang.

Signed-off-by: Paul Pluzhnikov <ppluzhnikov@google.com>
2011-10-02 22:43:28 -07:00
Arun Sharma e09f9701ff Handle register nums > 16 on x86_64
gcc generates them when using ms-abi. Support disabled by
default since it increases the cache footprint of the library.
2011-06-18 20:48:49 -07:00
Lassi Tuura d2525ec936 Use single level hash table for fast trace. 2011-05-06 22:09:07 -07:00
Lassi Tuura 5c2cade264 Inline access to initial register values as it's known to be safe. 2011-05-06 20:19:36 -07:00
Lassi Tuura ae5c1f2adf Performance optimisations for fast trace.
Insert static branch prediction predicates in useful places and avoid
unnecessary code in the hottest paths. Bypass unnecessary indirect
calls, in particular to access_mem(), when known to be safe.
2011-04-17 20:34:38 -07:00
Arun Sharma e2962af9d3 Implement a cheaper getcontext()
Since the fast unwinding code path doesn't need the full context,
a faster target dependent getcontext is implemented.

Signed-off-by: Lassi Tuura <lat@cern.ch>
2011-04-05 22:07:05 -07:00
Arun Sharma 15f182828d Use __thread instead of pthread_getspecific() 2011-04-05 22:06:51 -07:00
Lassi Tuura 5f38f35d5d Drop a call frame in tdep_trace and avoid a call to unw_step.
Dropping the extra frame for unw_backtrace itself using unw_step is
approximately 15% slower than skipping the frame in tdep_trace.  So
drop the frame in the latter, and make the function a private
implementation detail for libunwind, not an exported interface.

Also moves unw_getcontext call back into unw_backtrace to avoid an
extra call frame in case slow_backtrace does not get inlined into
unw_backtrace.
2011-04-01 00:00:39 -07:00
Lassi Tuura 3b9fd99cb7 Assign copyright as requested by the author. 2011-03-25 00:20:49 -07:00
Lassi Tuura f1ea02be58 Reset 'used' to zero after expanding frame cache hash table. 2011-03-25 00:20:48 -07:00
Lassi Tuura 44a14d1364 Integrate fast trace into backtrace(). 2011-03-24 22:33:55 -07:00
Lassi Tuura 9e98f15e9a Fast back-trace for x86_64 for only collecting the call stack.
Adds new function to perform a pure stack walk without unwinding,
functionally similar to backtrace() but accelerated by an address
attribute cache the caller maintains across calls.
2011-03-24 22:33:17 -07:00
Lassi Tuura 28f33c8ce0 Auto-detect whether to use msync() or mincore() for address validation. 2011-03-24 21:02:28 -07:00
Arun Sharma 99e60be5a4 Fix the page boundary crossing bug.
Signed-off-by: Jason Evans <jasone@canonware.com>
2010-06-08 14:44:07 -07:00
Konstantin Belousov e1493dc011 Merge branch 'master' into freebsd 2010-05-03 17:59:50 +03:00
Arun Sharma aa3bb307a3 Fix merge errors 2010-05-03 07:47:41 -07:00
Konstantin Belousov b73c618a31 Merge branch 'master' into freebsd 2010-05-02 16:29:02 +03:00
Arun Sharma 0176c4f723 Merge commit 'fdc534ccb05d1e6c0438345d292203343a811701' 2010-04-28 17:27:38 -07:00
Arun Sharma fdc534ccb0 Silence a compiler warning 2010-04-28 16:38:27 -07:00
Arun Sharma 215afa30b7 Add unwind descriptors to getcontext.S 2010-04-28 16:32:30 -07:00
Arun Sharma c140d8598d Undo commit f252f5ff4e for now.
Seems to introduce a couple of test breakages.
2010-04-25 09:44:59 -07:00
Arun Sharma d3c4bc4295 Fix a compiler warning 2010-04-25 09:24:40 -07:00