1
0
Fork 0
mirror of https://github.com/tobast/libunwind-eh_elf.git synced 2024-11-29 10:17:38 +01:00
Commit graph

1900 commits

Author SHA1 Message Date
Dave Watson
729772149f
aarch64: tune down size of unw_context_t and unw_cursor_t (#71)
aarch64 defines a huge __reserved field in sigcontext.  Cut it down
to only the used FP fields.

unw_cursor_t can also be cut down a bit, while still maintaining some reserved space.
2018-04-10 10:55:45 -07:00
Dave Watson
b5cbcaee13
dwarf: do not allocate in load_debug_frame (#72)
load_debug_frame calls malloc() in a couple spots, use mmap via
GET_MEMORY instead.  These call paths are infrequent, and are never
freed.

Found by running tcmalloc unit tests on aarch64, when DEBUG_FRAME support is on.
2018-04-10 10:55:34 -07:00
Dave Watson
c91974f30f dwarf: make dwarf_find_debug_frame public
linux kernel's perf tool depends on this being public.

reported-by: Luke Diamand <luke@diamand.org>
blame: b56e4cb889 ("ALIAS dwarf symbols")
2018-04-03 11:14:08 -07:00
laiwei-rice
7f04c2032f x86_64: support for RIP in unw_get_save_loc (#66)
Returns the location of RIP through unw_get_save_loc().
2018-03-06 08:04:45 -08:00
ShutterQuick
05d814b640 Don't check if the memory is in core (#64)
libunwind uses mincore() to validate that memory is mapped and available to the process.
For this purpose, checking the return value of mincore() is sufficient.
The result array tells us if the kernel has swapped out the page or not.
We don't care about this, and the check leads to failure in those
cases where the kernel has swapped out the page.
2018-02-09 07:41:54 -08:00
Dave Watson
7d6cc6696a Use syscall directly in write_validate to avoid ASAN errors
ASAN will complain about this write call with the following error:

ERROR: AddressSanitizer: stack-buffer-underflow on address
HINT: this may be a false positive if your program uses some custom stack unwind mechanism or swapcontext

This is similar to what google's abseil does to work around the issue.

Reported-by: qiwang@fb.com
2018-01-17 08:16:16 -08:00
Michael Munday
e1ca874882 s390x: remove unw_handle_signal_frame from public API. (#62)
Ports e287b69 to s390x and fixes the namespace check.
2018-01-11 10:53:09 -08:00
Dave Watson
647ca77f52 s390x: remove PROTECTED visibility 2018-01-09 07:41:19 -08:00
Michael Munday
441adc46ff Add port to Linux on IBM Z (s390x)
This adds a port to Linux on the IBM Z platform (a.k.a s390x). It only
supports the 64-bit ABI. Most functionality is working and all the tests
pass with the exception of the coredump tests*.

Unwinding is only supported if DWARF unwind information is present.
libunwind can't currently make use of the backchain (if present).

The getcontext/setcontext functions only preserve/restore a subset of
registers. Currently this only consists of callee-saved registers and
some parameter registers.

Vector registers and access registers are not saved (and aren't callee-
saved) by getcontext and cannot currently be modified. They will however
be restored unmodified after resuming a context from a signal handler.

There is no special libunwind support for setjmp, the functionality is
emulated using glibc (I think all the ports do this for modern Linux
kernels).

* Unwinding on s390x requires floating point register access which the
coredump library doesn't currently support.
2018-01-09 07:37:55 -08:00
Dave Watson
4c07b17037 ALIAS unwind_get_accessors 2017-12-28 09:42:16 -08:00
Dave Watson
b56e4cb889 ALIAS dwarf symbols 2017-12-28 09:31:11 -08:00
Dave Watson
e287b69068 Remove unw_handle_signal_frame from public API. 2017-12-28 09:07:08 -08:00
Dave Watson
a1437a3d27 Remove PROTECTED visibility
This only works on bfd ld, not lld or gold.
2017-12-28 08:26:42 -08:00
Michael Munday
29137c6fa9 dwarf: Fix size of state to avoid corrupting rs_stack
DW_CFA_remember_state used memcpy to overwrite state with the value
of rs_current. Unfortunately rs_current was slightly larger than state,
possibly resulting in rs_stack->next being overwritten.

Fix this by making the type of state match the type of rs_current and
using an assigment to perform the copy rather than memcpy. This should
ensure that the types match in future.
2017-11-28 07:55:25 -08:00
Hans-Christian Noren Egtvedt
46c336d18f elfxx: store elf image pointer and size after mapping image
If loading debug link is not successful, the initial NULL pointer for
ei->image will eventually be restored, causing segfault during a later
call to valid_object.

Move populating the prev_image and prev_size to after elf_map_image() to
fix this.

Signed-off-by: Hans-Christian Noren Egtvedt <hegtvedt@cisco.com>
2017-11-09 10:23:18 -08:00
Yichao Yu
f248ac0c6e dwarf: Fix incorrect cfi execution (#54)
During unwinding/resuming execution of a normal call frame,
it is not only necessary to use the previous instruction to lookup the unwind info
but also when executing the cfi program. Although the call usually don't modify
any unwinding state, it can happen for noreturn call or when the callee cleanup the stack.
In these cases, the next instruction after the call may have a cfi adjusting the state
(e.g. stack pointer) and such instruction should be executed.

3d9a694de8 worked around this issue by treating `cfi_restore_state`
specially. It works when the compiler use that instruction to restore the state, i.e.

```
    .cfi_remember_state
    je .L0
    push ...
    .cfi_def_cfi_offset <new_value>
    call noreturn
.L0
    .cfi_restore_state
```

which is what GCC ususally does. However, it is not necessarily the case and clang/LLVM doesn't
do that. Instead LLVM emits the following unwind info which is also perfectly valid but is not
handled by the special case.

```
    je .L0
    push ...
    .cfi_def_cfi_offset <new_value>
    call noreturn
.L0
    .cfi_def_cfi_offset <old_value>
```

e9e8ed73e3 also worked around this issue for another special case.

This patch fix this issue for all cfi types by adjusting the `end_ip` based on the type of the
current frame instead, similar to what's done in `fetch_proc_info`.
Since this requires using the same `use_prev_instr` value after `fetch_proc_info` returns,
the patch also remove the `need_unwind_info` parameter to the function and move the code updating
`use_prev_instr` after all use of the old value are done.
2017-11-01 09:14:37 -07:00
Yichao Yu
1870b26a00 dwarf: Allow DWARF version both 3 and 4 (#56) 2017-10-31 08:55:07 -07:00
Yichao Yu
9e81e9efee arm: Handle non-signal frame unwind info lookup in ARM exidx unwinder (#55) 2017-10-31 08:52:22 -07:00
Yichao Yu
b9fe811de9 Use ucontext_t instead of struct ucontext (#49)
Ref https://github.com/libunwind/libunwind/pull/40.
I didn't caught it last time since I don't have a 32bits buildbot.
2017-10-31 08:41:31 -07:00
Yichao Yu
ab39ae9e16 Fix local unwind compilation on ARM (#48)
This was broken by fd02fd59e7.
2017-10-23 08:37:59 -07:00
Konstantin Baladurin
36b46f1921 dwarf/Gparser: fix crash during unwinding (#46)
We should update locations of the registers after all of them will
be restored. Otherwise some locations will be incorrect.

For example if function stores ebp, edi, esi and ebx registers on
stack in its prologue, compiler can generate following unwind info:
DW_CFA_expression: r5 (ebp) (DW_OP_breg5 (ebp): 0)
DW_CFA_expression: r7 (edi) (DW_OP_breg5 (ebp): -4)
DW_CFA_expression: r6 (esi) (DW_OP_breg5 (ebp): -8)
DW_CFA_expression: r3 (ebx) (DW_OP_breg5 (ebp): -12)

In this case locations of the ebx and ebp will be calculated using
current ebp but locations of the esi and edi will be calculated using
previous (restored) one. Due to it their locations will be incorrect
and it could lead to crash if we will try to get esi or edi value.

This patch fixes this problem.
2017-10-17 11:27:43 -07:00
Konstantin Baladurin
38fe3bbb97 x86: Fix build (#45)
We should include <sys/syscall.h> for SYS_rt_sigreturn in x86/Gos-linux.c
2017-10-17 11:27:14 -07:00
Konstantin Belousov
fd02fd59e7 arm: FreeBSD/ARMv6 port
Sponsored by:	The FreeBSD Foundation
2017-08-24 09:08:58 -07:00
Dave Watson
7f1aebadbf x86: Add sigreturn asm stub
glibc no longer defines sigreturn, but we want to use it
when unwinding through signal stacks to resture the signal mask,
without forcing all uses of getcontext/setcontext to save and
restore the signal mask
2017-08-24 08:51:27 -07:00
Dave Watson
3d9a694de8 dwarf: Fix incorrect application of restore_state
Repro for a multilib binary on host x86_64:

CFLAGS="-m32" LDFLAGS="-m32" ./configure --enable-debug -- host=i686-pc-linux-gnu --target=i686-pc-linux-gnu --libdur=/usr/lib32 --prefix=/usr --disable-documentation

make check

Gtest-init function fails trying to step through libc_start_main.  The CFA function is:

DW_CFA_def_cfa_offset: 112
DW_CFA_advance_loc: 5 to ...643
DW_CFA_restore state

Where the return address is 643.

Generally, it appears we apply all ip <= end_ip, which is incorrect in some circumstances.

libgcc only applies ip < end_ip + is_signal_frame, but that seems to break async signal handling
tests in libunwind for unknown reasons.

This is somewhat simlar to the fix in e9e8ed73e for GNU_args_size,
where the same ip check was added.
2017-08-24 08:51:18 -07:00
Johannes Ziegenbalg
836c91c43d x86_64: fix mincore_validate and msync_validate
The calls to mincore() or msync() are not checking for actual accessibility
this could lead to SIGSEGV if the address from a mapped page with the
PROT_NONE property occurs on the stack.
Hence an attempt to write one byte from the checked address to a pipe will
fail if the address is not readable.
2017-08-24 08:50:07 -07:00
Yichao Yu
e9e50d07b0 x86_64: Use ucontext_t instead of struct ucontext
Ref https://sourceware.org/git/?p=glibc.git;a=commit;h=251287734e89a52da3db682a8241eb6bccc050c9
And this is what other part of the code uses.
2017-08-22 11:51:20 -07:00
Guillaume Blanc
c26b603cd0 arm: argument type for unw_init_local2
I tried to build libunwind for arm target and got a build error. Type
for "uc" argument is inconsistent between unw_init_local2 and
unw_init_local_common.

From 54fb6483e47916836c314a38715e8e0ce8c3da44 Mon Sep 17 00:00:00 2001
From: Guillaume Blanc <guillaume.blanc@parrot.com>
Date: Tue, 22 Aug 2017 16:46:20 +0200
Subject: [PATCH] arm: Fix unw_init_local2 argument type
2017-08-22 11:50:02 -07:00
Leonid Chistov
5a491cb2d8 arm64: Support for restore of ARM64 Neon callee-saved registers during unwind 2017-08-18 09:56:06 -07:00
Jonathan Byrd
1c190a8f9e aarch64: PLT entry recognition & fixes
Attached is a corrected version of my previous patch for aarch64 PLT
entry recognition. The comparison in the is_plt_entry function should
have been:

     ret = (((w0 & 0xff0000009f000000) == 0xf900000090000000)
            && ((w1 & 0xffffffffff000000) == 0xd61f022091000000));
2017-08-18 09:55:49 -07:00
Felipe Cerqueira
819bf51bbd dwarf: Fix uninitialized variable c->dwarf.eh_valid_mask.
We were testing libunwind-coredump and got some warnings about
uninitialized eh_valid_mask.
The code was working fine because the default value of the mask was 0, but
it could potentially take a wrong branch if there's garbage in memory.
2017-08-17 14:18:07 -07:00
Dave Watson
bd3fb89e11 Change unw_init_local_signal to unw_init_local2(..., UNW_INIT_SIGNAL_FRAME)
Add unw_init_local2 with a flag for better extensibility in the future
2017-08-16 13:11:24 -07:00
Dave Watson
644cce3d72 half finished unw_local_init2 2017-08-16 11:27:43 -07:00
Dave Watson
4e8b7a595e configure: Fix dangling link when --disable-static is specified
If I configure with ./configure --prefix= --enable-shared --disable-static, a
broken symlink lib/libunwind-generic.a is installed that points to a missing
architecture-specific version of that library (e.g. lib/libunwind-x86_64.a). I
suppose that not installing that library is the intended behavior with these
configuration settings, so the symlink should not be there in the first place.

Reported-by: MarcoKoch
2017-08-16 11:12:56 -07:00
Dave Watson
2acc55815c elf: Don't use .gnu_debuglink if it doesn't exist
Some binaries contain a gnu_debuglink, even though the actual
file it points to doesn't exist.  In those cases, continue
to use the existing binary instead of trying to load the debuglink file.
2017-08-16 10:59:32 -07:00
Bert Wesarg
57257060c9 Bring back support for UNW_CACHE_PER_THREAD.
Needs to be build with --enable-per-thread-cache. Default caching policy
is also UNW_CACHE_PER_THREAD than.
2017-08-15 10:34:28 -07:00
Yichao Yu
ac1427d87f Support dynamic unwind info on ARM 2017-08-15 10:34:23 -07:00
MyungJoo Ham
ed90c8387b arm: Fix is_signal_frame bug for Thumb/Thumb2 mode
If Thumb is used, the least bit of the retrived IP value is set,
which makes the retrived opcode based on the IP invalid.

This patch fixes such behavior and adds a missed condition
found with glibc built for recent ARMv7l with Thumb2.

Signed-off-by: MyungJoo Ham <myungjoo.ham@samsung.com>

CC: Yvan Roux
CC: Arun Sharma
CC: David Mosberger
2017-08-15 10:34:09 -07:00
MyungJoo Ham
022bb326a2 arm: Return code correction for unw_step()
Let's not drop error code or zero-return unconditionally.

This has been incurring occasional indefinite loop in
dotnet core when it already had hit the bottom by
continously returning 1 from unw_step();

Signed-off-by: MyungJoo Ham <myungjoo.ham@samsung.com>
2017-08-15 10:33:59 -07:00
MyungJoo Ham
74d7cd9898 arm: Expand memory validation
Prevent SIGSEGV for write as well as read.

Signed-off-by: MyungJoo Ham <myungjoo.ham@samsung.com>
2017-08-15 10:33:48 -07:00
Dave Watson
3b3a453a65 dwarf: Fix cache size calculation
The and mask trick only works for power-of-two sized things,
but must be computed using the full size.  This incorrectly
resulted in a very small cache size.

Found using bisect and 'make perf' in tests directory.

blame rev: 0b51f5892d
2017-08-15 10:33:40 -07:00
Felipe Cerqueira
152a96e291 core: Fix memory leak in libunwind-coredump.
_UCD_destroy() was not freeing all variables from UCD_info.
2017-08-14 18:39:37 -07:00
Stephen Chen
0314ff8522 aarch64: Use PTRACE_GETREGSET if available
In remote ptrace mode, we currently use PTRACE_PEEKUSER to read the registers.

PTRACE_PEEKUSER only works on x86 or arm 32 bit compatibility mode on linux. On aarch64 system,
it always return -EIO. https://github.com/torvalds/linux/blob/master/kernel/ptrace.c#L885-L1102

PTRACE_GETREGSET is the newer and more supported way of reading registers. Use that if it's available.
2017-08-07 09:33:23 -07:00
Doug Moore
23c3f24ea6 On aarch64, it is the X30 register, not the PC register, that is associated with the program counter. 2017-08-07 09:05:34 -07:00
Doug Moore
6150f2f426 Better imitate the choice of which register to identify as ip
for tilegx.
2017-08-07 09:05:27 -07:00
Doug Moore
e360c3ddbd For architectures that initialize the dwarf ip cache, but do not
update when the ip register is set, add those updates.
2017-08-07 09:05:17 -07:00
Doug Moore
93f319466f ppc: Add register state and iterate functions
Add register state and state iterate functions to ppc32 and ppc64
directories.  They were added to other arch directories in change
502ba27753... but not these, for some reason.
2017-07-25 11:33:23 -07:00
Sergei Trofimovich
85ce08b64a ia64: : disable dwarf-specific code (#35)
Commit dbce594d33
added unconditional dwarf usage into unw_get_proc_name.
Unfortunately ia64 is the only architecture that
does not support it in libunwind (configure.ac):

```
if test x$target_arch != xia64; then
  use_dwarf=yes
else
  use_dwarf=no
fi
```

As a result build fails on ia64 as:

```
ia64-unknown-linux-gnu-gcc ... -c mi/Lget_proc_name.c ...
In file included from mi/Lget_proc_name.c:4:0:
mi/Gget_proc_name.c: In function '_ULia64_get_proc_name':
mi/Gget_proc_name.c:107:8: error: 'struct cursor' has no member named 'dwarf'
   if (c->dwarf.use_prev_instr)
        ^~
mi/Gget_proc_name.c:111:8: error: 'struct cursor' has no member named 'dwarf'
   if (c->dwarf.use_prev_instr && offp != NULL && error == 0)
        ^~
```

Signed-off-by: Sergei Trofimovich <slyfox@gentoo.org>
2017-07-18 10:17:00 -04:00
Doug Moore
55eb47d6e5 dwarf: fix single_fde
Usage of the single_fde field in cb_data suggests that it should be
set only when dwarf_extract_proc_info_from_fde has completed successfully,
but instead it is set before the linear search for the matching ip has
begun.  Set it only when that search has completed successfully, and
has thus extracted the proc_info.
2017-07-10 10:18:14 -07:00
Doug Moore
90d0d15c4e dwarf: fix synthetic eh_frame_hdr
Ben Avison (bavison@riscopen.org) has observed that when a synthetic
eh_frame_hdr is generated, there is no space in it for the eh_frame,
so the eh_frame value is written to, and later read from, memory that
is not assigned to this purpose, with unpredictable results.

This change adds a new field to the dwarf_eh_frame_hdr type, to
make room for that value, and adds the (packed) attribute to the
struct defintion to avoid a problem with unused space in the struct.
2017-07-06 09:15:08 -07:00