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

3140 commits

Author SHA1 Message Date
Dave Watson
60663c8f69 multilib: XFAIL some tests
Ptrace interface doesn't understand multilib registers, so tests all fail.
2017-08-24 08:51:39 -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
971985133b doc: Add generated doc files apply_reg_state and reg_states_iterate 2017-08-16 13:11:27 -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
Bernhard Rosenkraenzer
1a4b357598 arm: getcontext switches back to thumb mode
The ARM Thumb implementation of unw_tdep_getcontext switches to ARM
mode (".code 32"), but doesn't switch back to Thumb mode.
In gcc, this is fine (it automatically switches back to Thumb mode
at the end of an asm block), but in clang, this causes bad assembly
output (thumb instructions generated by C/C++ code later on are
interpreted as ARM mode assembly, which can't work).

Switching back to Thumb mode manually fixes clang, and is a no-op for gcc.
2017-08-15 10:34:19 -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
credmon
c4accd6ea2 Fix ARM jmpbuf header include bug.
tdep/jmpbuf.h was not including arm-tdep/jmpbuf.h.
2017-08-15 10:34:04 -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
Paul Pluzhnikov
cc0c170f53 tests: Fix heap overflow in coredump-unwind test
We've tried to run slightly modified test-coredump-unwind.c built with
tcmalloc, and it promptly crashed.  Attached patch fixes the heap buffer
overflow bug which caused it.
2017-08-07 09:07:20 -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
Romain Naour
ca6b6f3ad9 libunwind-arm: fix build failure due to asm()
mesa3d on ARM build with libunwind support enabled fail to build due to asm()
function used when building with -std=c99.
The gcc documentation [1] suggest to use __asm__ instead of asm.

Fixes:
https://urldefense.proofpoint.com/v2/url?u=http-3A__autobuild.buildroot.net_results_3ef_3efe156b6494e4392b6c31de447ee2c72acc1a53&d=DwICAg&c=5VD0RTtNlTh3ycd41b3MUw&r=vou6lT5jmE_fWQWZZgNrsMWu4RT87QAB9V07tPHlP5U&m=BlAszRQ0vewy5vW7raCh9FmNOACKez_juz55zoiNfUs&s=4sXL6_rFriQz7qi5ygKXBIVHMc7YSdCBnkkHoi347CU&e=

[1] https://gcc.gnu.org/onlinedocs/gcc/Alternate-Keywords.html#Alternate-Keywords

Signed-off-by: Romain Naour <romain.naour@smile.fr>
Cc: Bernd Kuhls <bernd.kuhls@t-online.de>
2017-07-05 10:07:28 -07:00
Doug Moore
38b2bdab33 Add a missing semicolon. 2017-07-05 09:53:46 -07:00
Stephen Chen
2934cf4052 aarch64: reduce UNW_TDEP_CURSOR_LEN to 512 on aarch64.
This allows libunwind to work in situations with limited stack size (ie. fibers). 512 is still more than enough for storing the cursor with some slack. (#25)
2017-06-20 09:49:16 -07:00
Doug Moore
0e74e583ae arm: Use dwarf_find_proc_info for arm dwarf processing
Rather than using a copy of dwarf_find_proc_info that differs from it slightly.
By using dwarf_find_proc_info, a potential search of the di table is
allowed, where it is omitted now.  Also, for ARM, avoid runtime
checks about which kind of unwind table search to use after dl_iterate_phdr.

A couple of Debug() warnings about ip lookup failure are lost here.
The dwarf callback struct defintion is moved to Gfind_proc_info-lsb.c,
which becomes the only source file that needs it.
2017-06-20 09:47:54 -07:00
Doug Moore
4f14d9714f Don't give up on proc finding if dwarf_callback fails, but
don't bother completing the dwarf search work either.  Move on
to the arm method.
2017-06-16 08:54:48 -07:00
Doug Moore
be06809b5f Arm code uses dwarf before arm for finding proc info, but unlike
dwarf code, ignores error return from dwarf_callback.  Change arm
code to behave like dwarf code in that case.
2017-06-16 08:54:47 -07:00
Doug Moore
0b51f5892d Dwarf cache nodes are allocated in a round-robin fashion, despite the
'lru' prefix used in several data fields.  Drop the unnecessary fields,
and just use a simple counter to track the next cache entry to be recycled.
2017-06-16 08:53:36 -07:00
Doug Moore
5c0e619f84 test: Add a test like test-mem, but using reg_states_iterate to find the state and
apply_reg_state to use it to complete the unw_step.
2017-06-07 08:36:23 -07:00
Doug Moore
27f5f9fa0b Leave ret_addr_column out of the data that gets copied when pushing/popping
data on/off the register state stack.
2017-05-20 14:36:25 -05:00
Doug Moore
c66661f73c Drop reference to dwarf.ret_addr_column. 2017-05-19 19:19:12 -05:00
Doug Moore
afb2491ccb Have dwarf_step return 0 or 1 for success, according to whether the
previous stack frame was the last, just as unw_step does.  For x86_64,
drop the null check for ret_addr_column, since that check is made already
in apply_reg_state.
2017-05-19 18:57:14 -05:00
Doug Moore
f3be411bc8 Use the register_state version of ret_addr_column, rather than the
cursor version, for frame-stashing.  They have the same value in master.
2017-05-19 18:22:08 -05:00
Doug Moore
7634874591 Move the change to c->ret_addr_column to the end of dwarf_step, to make sure
that it gets set in the cache hit case.
2017-05-19 17:59:08 -05:00
Doug Moore
ec1a021243 Move the ret_addr_column field from dwarf_reg_cache_entry to dwarf_reg_state,
so that it will get saved and restored with the register state.  Initialize
the rs_state version of ret_addr_column at the some time the dwarf_cursor
version is initialized, and don't bother copying ret_addr_column explicitly
from cursor to cache since it's copied implicitly as part of reg_state.
Use the reg_state version in apply_reg_state, instead of the cursor version.

Which brings up the question: why do we have ret_addr_column in the dwarf_cursor?
We call find_reg_state before calling apply_reg_state, so the value of ret_addr_column
in the cursor when dwarf_step gets called gets overwritten before it is used.  So
it's initial value doesn't matter.  But some architectures do funky things with
cursor->ret_addr_column, even though I don't see how they matter.

So I'm not deleting dwarf_cursor->ret_addr_column, even though I suspect this
patch makes it useless.
2017-05-16 22:00:38 -05:00
Doug Moore
028a60f064 Change dwarf_reg_state from an array of pairs of differently-sized objects
to a pair of arrays, to reduce internal fragmentation.  Reduces storage
use by 37.5% on x86_64.
2017-05-16 17:40:58 -05:00
Doug Moore
2b692db23f In dwarf_reg_states_table_iterate, the rs stack has to persist from
one run_cfi_program call to the next, so pull the stack out of run_cfi_program
and make the caller responsible for cleanup at the end.
2017-05-16 01:04:49 -05:00
Doug Moore
bb61e0bc2b Bury the last_ip field until it can reappear in version 2.0. 2017-05-12 23:45:56 -05:00
Doug Moore
1568d7afa2 Add documentation. 2017-05-12 22:24:00 -05:00