Commit Graph

200 Commits

Author SHA1 Message Date
whitequark 4f9c59f863 [OR1K] Add the EPCR special-purpose register to register state.
This makes it possible to unwind hardware exception stack frames,
which necessarily save every register and so need an extra column
for storing the return address. CFI for the exception handler could
then look as follows:

.globl exception_vector
exception_vector:
    .cfi_startproc
    .cfi_signal_frame
    .cfi_return_column 32
    l.addi  r1, r1, -0x100
    .cfi_def_cfa_offset 0x100
    l.sw    0x00(r1), r2
    .cfi_offset 2, 0x00-0x100
    l.sw    0x04(r1), r3
    .cfi_offset 3, 0x04-0x100
    l.sw    0x08(r1), r4
    .cfi_offset 4, 0x08-0x100
    l.mfspr r3, r0, SPR_EPCR_BASE
    l.sw    0x78(r1), r3
    .cfi_offset 32, 0x78-0x100
    l.jal   exception_handler
     l.nop
    l.lwz   r2, 0x00(r1)
    l.lwz   r3, 0x04(r1)
    l.lwz   r4, 0x08(r1)
    l.jr    r9
     l.nop
    .cfi_endproc

This register could, of course, also be accessed by the trace
callback or personality function, if so desired.

llvm-svn: 332513
2018-05-16 19:09:48 +00:00
whitequark 3f948cd79d [OR1K] Add a dedicated PC register to register state.
Before this commit, R9, the link register, was used as PC register.
However, a stack frame may have R9 not set to PC on entry, either
because it uses a custom calling convention, or, more likely,
because this is a signal or exception stack frame. Using R9 as
PC register made it impossible to unwind such frames.

All other architectures similarly use a dedicated PC register.

llvm-svn: 332512
2018-05-16 19:09:41 +00:00
John Baldwin c3f240f7dc [libunwind][MIPS] Support MIPS floating-point registers for hard-float ABIs.
Summary:
For MIPS ABIs with 64-bit floating point registers including newabi
and O32 with 64-bit floating point registers, just save and restore the
32 floating-point registers as doubles.

For O32 MIPS with 32-bit floating-point registers, save and restore the
individual floating-point registers as "plain" registers.  These registers
are encoded as floats rather than doubles, but the DWARF unwinder
assumes that floating-point registers are stored as doubles when reading
them from memory (via AddressSpace::getDouble()).  Treating the
registers as "normal" registers instead causes the DWARF unwinder to
fetch them from memory as a 32-bit register.  This does mean that for
O32 with 32-bit floating-point registers unw_get_fpreg() and
unw_set_fpreg() do not work.  One would have to use unw_get_reg()
and unw_set_reg() instead.  However, DWARF unwinding works
correctly as the DWARF CFI emits records for individual 32-bit
floating-point registers even when they are treated as doubles stored
in paired registers.  If the lack of unw_get/set_fpreg() becomes a pressing
need in the future for O32 MIPS we could add in special handling to
make it work.

Reviewers: sdardis, compnerd

Reviewed By: sdardis

Differential Revision: https://reviews.llvm.org/D41968

llvm-svn: 332414
2018-05-15 22:44:56 +00:00
Aaron Smith 596b0f03a0 [cmake] Remove duplicate command line options from build
CMAKE_CXX_FLAGS and CMAKE_C_FLAGS are added twice to the command line.
This causes the command line options to be doubled which works until
it doesn't as not all options can be specified twice. 

For example,

clang-cl foo.c /GS- /GS- -mllvm -small-loop-cost=1 -mllvm -small-loop-cost=1
clang (LLVM option parsing): for the -small-loop-cost option: may only occur zero or one times!

llvm-svn: 329340
2018-04-05 20:27:50 +00:00
Petr Hosek 2dcd1d0989 [CMake] Support for monorepo layout
Support finding libcxx sources in monorepo style layout.

Differential Revision: https://reviews.llvm.org/D45270

llvm-svn: 329212
2018-04-04 17:57:15 +00:00
John Baldwin 0594aee52f [libunwind][MIPS]: Add support for unwinding in N32 processes.
Summary:
N32 uses the same register context as N64.  However, N32 requires one
change to properly fetch addresses from registers stored in memory.
Since N32 is an ILP32 platform, getP() only fetches the first 32-bits
of a stored register.  For a big-endian platform this fetches the
upper 32-bits which will be zero.  To fix this, add a new
getRegister() method to AddressSpace which is responsible for
extracting the address stored in a register in memory.  This matches
getP() for all current ABIs except for N32 where it reads the 64-bit
register and returns the low 32-bits as an address.  The
DwarfInstructions::getSavedRegister() method uses
AddressSpace::getRegister() instead of AddressSpace::getP().

Reviewers: sdardis, compnerd

Reviewed By: sdardis

Differential Revision: https://reviews.llvm.org/D39074

llvm-svn: 326250
2018-02-27 21:24:02 +00:00
John Baldwin e3e433b038 [libunwind] Permit additional compiler and linker flags to be passed to tests.
Summary:
This is done via new LIBUNWIND_TEST_COMPILER_FLAGS and
LIBUNWIND_TEST_LINKER_FLAGS variables.

Reviewed By: sdardis

Differential Revision: https://reviews.llvm.org/D43585

llvm-svn: 326223
2018-02-27 18:40:04 +00:00
Don Hinton 73e88d394b [cmake] [libunwind] LLVM_FOUND isn't always set, so just test if
llvm_setup_rpath() is available instead.

llvm-svn: 323601
2018-01-27 19:31:44 +00:00
Martin Storsjo 25a37a894e Don't enable _LIBUNWIND_BUILD_ZERO_COST_APIS if building the SJLJ APIs
Otherwise, a shared library build with SJLJ APIs enabled would
end up with duplicate symbols.

This didn't occur for the apple && arm case due to specifically
checking for that in the surrounding ifdef.

Differential Revision: https://reviews.llvm.org/D42555

llvm-svn: 323499
2018-01-26 06:50:07 +00:00
Don Hinton 3a667b9bd8 [cmake] [libunwind] Call llvm_setup_rpath() when adding shared libraries.
Clang and llvm already use llvm_setup_rpath(), so this change will
help standarize rpath usage across all projects.

Differential Revision: https://reviews.llvm.org/D42461

llvm-svn: 323496
2018-01-26 04:01:50 +00:00
Don Hinton 82c5878575 [cmake] [libunwind] Fix find_path() problems when cross compiling
When CMAKE_SYSROOT or CMAKE_FIND_ROOT_PATH is set, cmake
recommends setting CMAKE_FIND_ROOT_PATH_MODE_INCLUDE=ONLY
globally which means find_path() always prepends CMAKE_SYSROOT or
CMAKE_FIND_ROOT_PATH to all paths used in the search.

However, this find_path() invocation is looking for a path in the
libcxx project on the host system, not the target system,
which can be done by passing NO_CMAKE_FIND_ROOT_PATH.

Differential Revision: https://reviews.llvm.org/D41621

llvm-svn: 323141
2018-01-22 19:15:06 +00:00
Martin Storsjo 89e636c87c [PPC64] Added vector registers.
The Registers_ppc64 class needed a couple of changes, both to accommodate the
new registers as well as to handle the overlaps of VS register set
without wasting space.

The save/restore code of V and VS registers was added.
As VS registers depend on the VMX extension, they are processed only if
VMX support is detected (_ARCH_PWR8 for now).

Patch by Leandro Lupori!

Differential Revision: https://reviews.llvm.org/D41906

llvm-svn: 322596
2018-01-16 20:54:10 +00:00
Petr Hosek 78df28e876 [libunwind] Set up .arcconfig to point to new Diffusion UNW repository
See http://lists.llvm.org/pipermail/cfe-dev/2017-November/056032.html
for related discussion and context.

Differential Revision: https://reviews.llvm.org/D41918

llvm-svn: 322228
2018-01-10 22:20:03 +00:00
John Baldwin 40bab37551 [libunwind][MIPS]: Rename Registers_mips_n64 to Registers_mips_newabi.
This is in preparation for adding support for N32 unwinding which reuses
the newabi register class.

Reviewed By: compnerd

Differential Revision: https://reviews.llvm.org/D41842

llvm-svn: 322093
2018-01-09 17:07:18 +00:00
Hans Wennborg 70dfbf2b2b Update PACKAGE_VERSION to 7.0.0svn
llvm-svn: 321743
2018-01-03 16:59:48 +00:00
Hans Wennborg d511616a96 Update docs version to 7.0
llvm-svn: 321732
2018-01-03 15:58:08 +00:00
Martin Storsjo 7c907061aa Reland [PPC64] Port to ppc64le - initial version
Initial working version of libunwind for PowerPC 64. Tested on
little-endian ppc64 host only.
Based on the existing PowerPC 32 code.

It supports:

- context save/restore (unw_getcontext, unw_init_local, unw_resume)
- read/write from/to saved registers
- backtrace (unw_step)

Patch by Leandro Lupori!

Differential Revision: https://reviews.llvm.org/D41386

Now builds with LIBUNWIND_ENABLE_CROSS_UNWINDING=ON should
work.

llvm-svn: 321680
2018-01-02 22:11:30 +00:00
Martin Storsjo ecf9054544 Don't use a strict larger-than comparison in the check_fit/does_fit static assert
For builds that only target one architecture, this was required to
be an exact match, while it previously required the allocation to be
strictly larger than the largest concrete one. Requiring it to be
larger than on equal should be enough.

This makes it more straightforward to update _LIBUNWIND_CONTEXT_SIZE
and _LIBUNWIND_CURSOR_SIZE.

llvm-svn: 321679
2018-01-02 22:11:22 +00:00
Tim Shen f5d150037a Revert `rL321667: [PPC64] Port to ppc64le - initial version`
Differential Revision: https://reviews.llvm.org/D41386

llvm-svn: 321678
2018-01-02 22:04:03 +00:00
Martin Storsjo 0aa55fdbba [PPC64] Port to ppc64le - initial version
Initial working version of libunwind for PowerPC 64. Tested on
little-endian ppc64 host only.
Based on the existing PowerPC 32 code.

It supports:

- context save/restore (unw_getcontext, unw_init_local, unw_resume)
- read/write from/to saved registers
- backtrace (unw_step)

Patch by Leandro Lupori!

Differential Revision: https://reviews.llvm.org/D41386

llvm-svn: 321667
2018-01-02 20:10:54 +00:00
Chandler Carruth e243ff8141 There is no portable format string for printing `uintptr_t` values.
Instead, cast them to `void *` which has a portable format string syntax
of `%p`.

This fixes a -Wformat error when building libunwind.

llvm-svn: 321469
2017-12-27 05:46:53 +00:00
whitequark 99bbb213b5 [libunwind] Remove dubious template function. NFC.
Per review by Don Hinton.

llvm-svn: 321448
2017-12-25 21:08:41 +00:00
whitequark 3560fde80f [libunwind] Unbreak debug builds after r321440.
llvm-svn: 321446
2017-12-25 20:04:47 +00:00
whitequark dcd93505da [libunwind] Add proper support for DWARF unwind on bare metal.
Right now, ARM EHABI unwind on bare metal expects to find the symbols
__exidx_start and __exidx_end defined, and uses those to locate
the EH tables. However, DWARF unwind on bare metal expects to find
dl_iterate_phdr, which, although possible to provide, is inconvenient
and mildly absurd.

This commit provides feature parity with ARM EHABI unwind by looking
for symbols __eh_frame_start, __eh_frame_end, __eh_frame_hdr_start
and __eh_frame_hdr_end, denoting the start and end of the sections
with corresponding names. As far as I know, there is no de jure or
de facto ABI providing any such names, so I chose the obvious ones.

The .eh_frame_hdr support is optional for maximum flexibility and
possible space savings (e.g. if libunwind is only used to provide
backtraces when a device crashes, providing the .eh_frame_hdr, which
is an index for rapid access to EH tables, would be a waste.)

The support for .eh_frame_hdr/DWARF index in the first place is
conditional on defined(_LIBUNWIND_SUPPORT_DWARF_INDEX), although
right now config.h will always define this macro.

The support for DWARF unwind on bare metal has been validated within
the ARTIQ environment[1].

  [1]: https://m-labs.hk/artiq/

llvm-svn: 321445
2017-12-25 17:05:07 +00:00
whitequark 2b2a02ea13 [libunwind] fix a typo in r321441.
llvm-svn: 321442
2017-12-25 13:42:41 +00:00
whitequark fa83ee2523 [libunwind] convert error logs to _LIBUNWIND_LOG/_LIBUNWIND_LOG0.
Use the `_LIBUNWIND_LOG` and `_LIBUNWIND_LOG0` macros instead of
the explicit `fprintf` call.

This was previously done in r292721 as a cleanup and then reverted
in r293257 because the implementation in r292721 relied on a GNU
extension. This implementation avoids the use of an extension
by using a second macro instead, and allows to avoid the dependency
on fprintf if _LIBUNWIND_BARE_METAL is defined.

llvm-svn: 321441
2017-12-25 13:27:56 +00:00
whitequark 91e49066e3 [libunwind] Avoid using C++ headers.
This is useful for building libunwind on libcxx-free systems.

llvm-svn: 321440
2017-12-25 13:06:09 +00:00
John Baldwin dfbbbdf8cd [libunwind][MIPS]: Add support for unwinding in O32 and N64 processes.
This supports the soft-float ABI only and has been tested with both clang
and gcc on FreeBSD.

Reviewed By: sdardis, compnerd

Differential Revision: https://reviews.llvm.org/D38110

llvm-svn: 320528
2017-12-12 21:43:36 +00:00
Shoaib Meenai 7bd1c95a95 [libunwind] Create install-unwind-stripped target manually
This supports using a newer libunwind with an older installation of LLVM
(whose cmake modules wouldn't have add_llvm_install_targets).

llvm-svn: 320163
2017-12-08 17:15:05 +00:00
Petr Hosek 27d887878d [libunwind][CMake] Set TARGET_TRIPLE if LIBUNWND_TARGET_TRIPLE is set
This follows the setup used by other runtimes and is expected by
the lit configuration.

Differential Revision: https://reviews.llvm.org/D40820

llvm-svn: 319830
2017-12-05 20:48:05 +00:00
Petr Hosek 9d30c313f1 [libunwind] Pass LIBUNWIND_SYSROOT and LIBUNWIND_GCC_TOOLCHAIN to lit
These are expected to be set by the shared lit scripts used from
libc++.

Differential Revision: https://reviews.llvm.org/D40817

llvm-svn: 319823
2017-12-05 20:22:10 +00:00
Shoaib Meenai e0c51f688f [libunwind] Switch to add_llvm_install_targets
This gains us the install-unwind-stripped target, to perform stripping
during installation.

Differential Revision: https://reviews.llvm.org/D40685

llvm-svn: 319498
2017-11-30 23:24:08 +00:00
Martin Storsjo 5a546f99ec Support building libunwind as a DLL
Differential Revision: https://reviews.llvm.org/D40483

llvm-svn: 319300
2017-11-29 08:21:12 +00:00
Martin Storsjo d7fe2f7f60 [CMake] Use the variable from the right project in install-unwind
llvm-svn: 319299
2017-11-29 08:20:57 +00:00
Petr Hosek b74f98c4e4 [libunwind][CMake] Provide option to disable instalation of the library
This is useful in cases where we only build static library and
libunwind.a is combined with libc++abi.a into a single archive in which
case we don't want to have libunwind.a installed separately. The same
option is already provided by libcxx CMake build.

This change also adds the install-unwind target for consistency with the
libcxxabi and libcxx CMake build.

Differential Revision: https://reviews.llvm.org/D40195

llvm-svn: 318569
2017-11-17 23:29:46 +00:00
Martin Storsjo e95d73958d Remove a FIXME about truncated section names
If the linker chose to store the full section name instead of truncating
it, this field doesn't contain a truncated name, but an offset into
the string table of the binary. The string table isn't loaded/mapped
into memory during runtime though, so it's not possible to read the
full section name, unless we try to locate the DLL/EXE on disk that
the HMODULE corresponds to and load that manually.

Due to this, lld now always prefers writing a truncated section name
for sections that will be mapped at runtime, even when debug info is
enabled.

Differential Revision: https://reviews.llvm.org/D39918

llvm-svn: 318446
2017-11-16 19:36:48 +00:00
Martin Storsjo 3920189bcc [docs] Mention that dwarf unwinding should be supported on arm64/windows
This didn't require any further changes to libunwind as long as win64
in general is handled correctly.

Differential Revision: https://reviews.llvm.org/D39632

llvm-svn: 318383
2017-11-16 07:16:36 +00:00
Martin Storsjo 7ed1188c27 Add ifdefs around ELF specific parts of UnwindRegisters*.S for arm
This allows using dwarf exceptions on MinGW/ARM.

Differential Revision: https://reviews.llvm.org/D39534

llvm-svn: 317423
2017-11-04 21:01:31 +00:00
Martin Storsjo 6a3ed9bfd0 Fix building for ARM with dwarf exception handling
The previous definition of _LIBUNWIND_HIGHEST_DWARF_REGISTER seems
to be a copy of the ARM64 value (introduced in SVN r276128); since
the code actually hasn't compiled properly for arm in dwarf mode
before, this hasn't actually been used. Set it to the correct value
based on the UNW_ARM_* enum values.

The iwmmx control variables have to be made mutable, since they are
touched from within getRegister (which previously wasn't const), and
getRegister is used on a const Registers object in DwarfInstructions.hpp.

Differential Revision: https://reviews.llvm.org/D39251

llvm-svn: 317192
2017-11-02 08:16:16 +00:00
Dan Albert 9288938561 [libunwind] Don't use dl_iterate_phdr if __ANDROID_API__ < 21
Summary:
On ARM, dl_iterate_phdr is only implemented in the Android NDK version 21 or later:
https://android.googlesource.com/platform/prebuilts/ndk/+/dev/platform/sysroot/usr/include/link.h#55

Reviewers: thakis, danalbert

Reviewed By: danalbert

Subscribers: dtzWill, aemerson, srhines, kristof.beyls

Differential Revision: https://reviews.llvm.org/D39468

llvm-svn: 317125
2017-11-01 21:26:06 +00:00
Martin Storsjo c18d5c05cb Change unw_word_t to always have the same size as the pointer size
This matches the original libunwind API. This also unifies the
type between ARM EHABI and the other configurations, and allows
getting rid of a number of casts in log messages.

The cursor size updates for ppc and or1k are untested, but
unw_proc_info_t shrinks by 4 uint64_t units on i386 at least.

Differential Revision: https://reviews.llvm.org/D39365

llvm-svn: 316942
2017-10-30 19:06:34 +00:00
Martin Storsjo d9e8909261 Restore arch specific lastDwarfRegNum in builds without _LIBUNWIND_IS_NATIVE_ONLY
This restores the previous behaviour of the Registers_* classes
after SVN r316745.

Differential Revision: https://reviews.llvm.org/D39382

llvm-svn: 316843
2017-10-28 20:19:49 +00:00
Martin Storsjo 66bb841f64 Add support for dwarf unwinding on windows on x86_64
Clang doesn't currently support building for windows/x86_64 with
dwarf by setting command line parameters, but if manually modified
to use dwarf, we can make libunwind work in this configuration
as well.

Also include i386 in the docs when adding this as a supported
configuration; libunwind already works for i386 windows, but
can fail due to an issue unrelated to windows itself.

Differential Revision: https://reviews.llvm.org/D38819

llvm-svn: 316747
2017-10-27 08:11:36 +00:00
Martin Storsjo 62dd9d20d5 Express Registers_*::lastDwarfReg using _LIBUNWIND_HIGHEST_DWARF_REGISTER
This avoids having to keep the same information duplicated in multiple
places.

Adjust _LIBUNWIND_HIGHEST_DWARF_REGISTER to actually have the value
of the highest used register and only use the value
_LIBUNWIND_HIGHEST_DWARF_REGISTER + 1 (kMaxRegisterNumber + 1) for
allocating the savedRegisters array.

Differential Revision: https://reviews.llvm.org/D39281

llvm-svn: 316745
2017-10-27 07:59:01 +00:00
Peter Smith 7f6e910745 [libunwind] Always use unwind tables in tests
For many targets setting -fno-exceptions will prevent unwinding tables from
being generated for the test programs. As libunwind depends on the tables to
unwind the stack several tests will fail.

This change always adds -funwind-tables so that even when -fno-exceptions
is set unwind tables are generated.

fixes PR33858

Differential Revision: https://reviews.llvm.org/D37484

llvm-svn: 316657
2017-10-26 12:02:03 +00:00
Martin Storsjo dd45ea16f3 Fix the context/cursor size for ARM with WMMX enabled
This was missed in SVN r274744 when the WMMX part was made optional;
when made optional, some struct fields were reordered, which caused
the total struct size to grow due to padding/alignment.

llvm-svn: 316559
2017-10-25 08:07:19 +00:00
Martin Storsjo d3abd15d8c Add missing checks for register number
Most other cases that touch savedRegisters[reg] have got this check,
but these three seemed to lack it.

Differential Revision: https://reviews.llvm.org/D39206

llvm-svn: 316415
2017-10-24 07:16:40 +00:00
Martin Storsjo ed4a317c55 Abstract rwlocks into a class, provide a SRW lock implementation for windows
This requires _WIN32_WINNT >= 0x0600.

If someone wants to spend effort on supporting earlier versions,
one can easily add another fallback implementation based on
critical sections, or try to load SRW lock functions dynamically.

This makes sure that the FDE cache is thread safe on windows.

Differential Revision: https://reviews.llvm.org/D38704

llvm-svn: 316364
2017-10-23 19:29:36 +00:00
Martin Storsjo c5115b9e65 Make HIDDEN_DIRECTIVE a function-like macro. NFCI.
This avoids a hack for making it a no-op for windows.

Also explicitly check for _WIN32 instead of assuming it.

Differential Revision: https://reviews.llvm.org/D39156

llvm-svn: 316300
2017-10-22 19:39:26 +00:00
Saleem Abdulrasool f7596ece76 GNU: do not read the FDE count if omitted
If there is no binary search table computed, the FDECount encoding is
DW_EH_PE_omit.  Do not attempt to read the FDECount in such a situation
as we will read an incorrect value.  binutils only writes out the
FDECount if the encoding is not DW_EH_PE_omit.

llvm-svn: 316224
2017-10-20 18:47:35 +00:00