Commit Graph

107 Commits

Author SHA1 Message Date
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
Martin Storsjo 210d9f43a3 Support DWARF unwinding on i386 windows
In practice, with code built with clang, there are still unresolved
issues with DW_CFA_GNU_args_size though.

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

llvm-svn: 315498
2017-10-11 20:06:18 +00:00
Saleem Abdulrasool 5b93ea3b9f build: use POSITION_INDEPENDENT_CODE instead of -fPIC
Rather than hardcode the flag and check if the compiler supports it, use
the CMake property to get the right flag spelling for the compiler.
This makes it generally more portable.

llvm-svn: 314834
2017-10-03 20:22:26 +00:00
Martin Storsjo cbb415128e Fix building on macOS after SVN r314492
That commit incorrectly expanded the assumption that defined(__APPLE__)
implies SjLj exception handling, which only is true within ARM
code sections.

llvm-svn: 314695
2017-10-02 18:14:06 +00:00
Martin Storsjo 59a5004984 SjLj: Fix building after SVN r314632
The code moved from Unwind_AppleExtras.cpp to Unwind-sjlj.c needed
a few minor modifications to build as C instead of C++.

llvm-svn: 314635
2017-10-01 20:22:40 +00:00
Saleem Abdulrasool 9ebbda838f SjLj: make the SjLj implementation more portable
This moves the definition of the internal helpers
`__Unwind_SjLj_GetTopOfFunctionStack` and
`__Unwind_SjLj_SetTopOfFunctionStack` into `Unwind-sjlj.c`.  These are
not extra functions specific to Apple, but rather are internal
implementation details of SjLj support in the LLVM libunwind
implementation.

This allows us to remove the internal header unwind_ext.h, as these
functions are not meant to be used as SPI either.  Because they are
static, they will be given implicit hidden visibility, but due to the
simplicity should get fully inlined into the actual use.

Use the C11 standard static TLS annotation (`_Thread_local`) if
possible, otherwise, use the Windows specific `__declspec(thread)` when
targeting Windows or the GNU `__thread` extension.  In theory, it should
be possible for this implementation to use a `pthread_setspecific` and
`pthread_getspecific` on platforms with pthreads or `SetFlsValue` and
`GetFlsValue` on Windows for non-static TLS.  However, static TLS tends
to be significantly faster, so we really should prefer that over the
dynamic TLS approach.  On Apple environments, when not building for the
loader (dyld), use the pre-allocated TLS slot in the loader rather than
the local static TLS variable.

Note that the un-threaded support of libunwind is still present as
before, however, it is unsafe to use in a threaded environment as the
cleanup stack may be mutated incorrectly due to lack of locking across
threads.  In the static TLS model, the lock is unneeded as each thread
of execution retains its own copy of the cleanup stack.

Take the opportunity to clean up the comment block, removing the iOS
specific note as the SjLj implementation can be used outside of the
context of iOS.  Convert the rest of the explanation to a doxygen style
comment block.

llvm-svn: 314632
2017-10-01 20:06:48 +00:00
Martin Storsjo c2ec6ce65c Skip building x86 parts of UnwindRegisters*.S when targeting SjLj
This extends SVN r314197 from the arm parts to the whole file.

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

llvm-svn: 314492
2017-09-29 06:09:09 +00:00
Martin Storsjo b51c49aa52 Skip building unused parts when targeting SJLJ
When SJLJ exceptions are used, those functions aren't used.

This fixes build failures on ARM with SJLJ enabled (e.g. on armv7/iOS)
when built using the CMake project files.

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

llvm-svn: 314197
2017-09-26 08:07:26 +00:00
Martin Storsjo 3b6ea6a4e2 Correct data types in the _Unwind_FunctionContext struct
This makes it match the definition used within llvm and in libgcc,
we previously got the wrong layout in 64 bit environments.

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

llvm-svn: 314196
2017-09-26 08:07:17 +00:00
John Baldwin d51d38f6f9 [libunwind] Partially revert r297174 to fix build on at least FreeBSD.
The changes in r297174 moved the #include of <link.h> on FreeBSD (and
probably other systems) inside of the open 'libunwind' namespace
causing various system-provided types such as pid_t to be declared in
this namespace rather than the global namespace.  Fix this by moving
the relevant declarations before the 'libunwind' namespace is opened,
but still using the cleaned up declarations from r297174.

Reviewed By: ed, compnerd

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

llvm-svn: 313920
2017-09-21 21:28:48 +00:00
Alex Lorenz 341317fda4 Revert r312240
The buildbots have shown that -Wstrict-prototypes behaves differently in GCC
and Clang so we should keep it disabled until Clang follows GCC's behaviour

llvm-svn: 312246
2017-08-31 15:51:23 +00:00
Alex Lorenz fbac1ae062 Build LLVM with -Wstrict-prototypes enabled
Clang 5 supports -Wstrict-prototypes. We should use it to catch any C
declarations that declare a non-prototype function.

rdar://33705313

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

llvm-svn: 312240
2017-08-31 13:23:24 +00:00
Petr Hosek 7ec1a56baf [CMake] Allow overriding lib dir suffix independently from LLVM
This matches the options already supported by libc++ and libc++abi.

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

llvm-svn: 310327
2017-08-08 00:37:59 +00:00
Momchil Velikov 81806c5d4d [libunwind] Handle .ARM.exidx tables without sentinel last entry
UnwindCursor<A, R>::getInfoFromEHABISection assumes the last
entry in the index table never corresponds to a real function.
Indeed, GNU ld always inserts an EXIDX_CANTUNWIND entry,
containing the end of the .text section. However, the EHABI specification
(http://infocenter.arm.com/help/topic/com.arm.doc.ihi0038b/IHI0038B_ehabi.pdf)
does not seem to contain text that requires the presence of a sentinel entry.
In that sense the libunwind implementation isn't compliant with the specification.

This patch makes getInfoFromEHABISection examine the last entry in the index
table if upper_bound returns the end iterator.

Fixes https://bugs.llvm.org/show_bug.cgi?id=31091

Differential revision: https://reviews.llvm.org/D35265

llvm-svn: 308871
2017-07-24 09:19:32 +00:00
Petr Hosek 8bb0f6ec88 [libunwind][CMake] Add install path variable to allow overriding the destination
This is going to be used by the runtime build in the multi-target
setup to allow using different install prefix for each target.

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

llvm-svn: 307606
2017-07-11 01:12:09 +00:00
Nico Weber 205519b97e [libunwind] Add _LIBUNWIND_DISABLE_VISIBILITY_ANNOTATIONS
It's useful to be able to disable visibility annotations entirely; for
example, if we're building libunwind static to include in another library,
and we don't want any libunwind functions getting exported out of that
library.

https://reviews.llvm.org/D34637
Patch from Thomas Anderson <thomasanderson@chromium.org>!

llvm-svn: 306442
2017-06-27 18:37:06 +00:00
Marshall Clow 04ff3b15fa Change -1LL to -1ULL to silence a gcc warning about left shifting a negative value. Fixes https://bugs.llvm.org/show_bug.cgi?id=33358
llvm-svn: 305924
2017-06-21 16:02:53 +00:00
Manoj Gupta 2cbfd2506a [libunwind] Fix executable stack directive on Linux.
Summary:
Disable executable stack on Linux. Also remove redundant Android check
as it is covered by Android.

Reviewers: phosek, compnerd, rs, rmaprath, EricWF, krytarowski

Reviewed By: krytarowski

Subscribers: srhines, llvm-commits, krytarowski

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

llvm-svn: 303206
2017-05-16 20:18:57 +00:00
Ivan Krasin d44b262337 Fix unused typedef. Follow up to r299575.
llvm-svn: 299666
2017-04-06 17:35:35 +00:00
Saleem Abdulrasool 5c18b4406e AddressSpace: fix DWARF based unwinding handling on Android
It is possible that there are no program headers in the module.  Do not
attempt to dereference nullptr as a program header.

llvm-svn: 299591
2017-04-05 21:29:38 +00:00
Saleem Abdulrasool 9ac2cc7812 Fix invalid memory access on android x86
On certain versions of android x86, the main module `app_process` is not
built as PIE.  When accessing the PT_GNU_EH_FRAME_HDR in such a
scenario, the `dlpi_addr` is 0, but the virtual address is not
relocated.  Manually rebase the address to avoid an invalid memory
access.

llvm-svn: 299575
2017-04-05 18:33:23 +00:00
Ranjeet Singh 5808011bd9 [libunwind] Clean up macro usage.
Convention in libunwind is to use !defined(FOOT) not !FOO.

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

llvm-svn: 299225
2017-03-31 15:28:06 +00:00
Saleem Abdulrasool 01cf8d3348 DarwinParser: include limits
In debug mode, we have assertions that the values do not exceed the
limits of the type holding them.  In order to account for the type being
derived from the AddressSpace and thus a typedef, we use
`std::numeric_limits`.  Include the appropriate header.

Thanks to Marshal Clow for pointing out the missing include!

llvm-svn: 297744
2017-03-14 15:17:55 +00:00
Ed Schouten e2de03fd7d Fix up the places where AddressSpace.hpp is included.
The AddressSpace.hpp header declares two classes: LocalAddressSpace and
RemoteAddressSpace. These classes are only used in a very small number
of source files, but passed in as template arguments to many other
classes.

Let's go ahead and only include AddressSpace.hpp in source files where
at least one of these two classes is mentioned. This gets rid of a
cyclic header dependency that was already present, but only caused
breakage on macOS until recently.

Reported by:	Marshall Clow

llvm-svn: 297364
2017-03-09 08:04:07 +00:00
Saleem Abdulrasool e3baf13f8e DARWF: silence some warnings about conversions
Add a check for an overflow and explicitly cast the value.  We would
have silently overflowed previously.

llvm-svn: 297291
2017-03-08 16:03:27 +00:00
Ed Schouten 124472ce6f Tidy up the way we include EHHeaderParser.hpp.
Other source files in the source tree tend to include this header file
unconditionally. It also parses perfectly fine on ARM EHABI systems.

llvm-svn: 297175
2017-03-07 18:21:51 +00:00
Ed Schouten 3e29e7415e Improve readability and correctness of the OS specific libunwind bits.
All of the access to __exidx_*, dl_iterate_phdr(), etc. is specific to
the findUnwindSections() function. Right now all of the includes and
declarations related to them are scattered throughout the source file.
For example, for <link.h>, we have a full list of operating systems
guarding the #include, even though the code that uses dl_iterate_phdr()
miraculously doesn't use the same list.

Change the code so that findUnwindSections() is preceded by a block of
#ifdefs that share the same structure as the function itself. First
comes all of the macOS specific bits, followed by bare-metal ARM,
followed by ELF EHABI + DWARF.

This actually allows us to build a copy of libunwind without any
specific ifdefs for NetBSD, CloudABI, etc. It likely also unbreaks the
build of libunwind on FreeBSD/armv6, though I can't confirm.

Reviewed by:	compnerd
Differential Revision:	https://reviews.llvm.org/D30696

llvm-svn: 297174
2017-03-07 18:15:52 +00:00
Ed Schouten 4dd1292c3e Let arm_section_length store the number of bytes.
Exception section data that we extract for DWARF gets stored as the
offset and the number of bytes. For ARM exception info, we seem to
deviate from this by storing the number of entries. Attempt to make this
more consistent.

By storing the number of bytes, we can get rid of the EHTEntry structure
declared in AddressSpace.hpp. In UnwindCursor.hpp we already have
another structure declared for the same purpose.

Reviewed by:	Keith Walker
Differential Revision:	https://reviews.llvm.org/D30681

llvm-svn: 297149
2017-03-07 15:21:57 +00:00
Ed Schouten fa1ef7d89c Drop the dependency on dl_unwind_find_exidx().
While porting libunwind over to CloudABI for ARMv6, I observed that this
source file doesn't build, as it depends on dl_unwind_find_exidx(),
which CloudABI's C library was lacking. After I added that function, I
still needed to patch up libunwind to define _Unwind_Ptr.

Taking a step back, I wonder why we need to make use of this function
anyway. The unwinder already has some nice code to use dl_iterate_phdr()
to scan for a PT_GNU_EH_FRAME header. The dl_unwind_find_exidx() does
the same thing, except matching PT_ARM_EXIDX instead. We could also do
that ourselves.

This change gets rid of the dl_unwind_find_exidx() call and extends the
dl_iterate_phdr() loop. This approach has the advantage of getting rid
of some of those OS-specific #ifdefs. This now means that if an
operating system only provides dl_iterate_phdr(), it gets support for
unwinding on all architectures. There is no need to add more stuff, just
to get ARMv6 support.

This change is identical to r295944, except that it now adds the
necessary code to do bounds checking on PT_LOAD. The previous version of
this change lacked this, which didn't cause any problems on CloudABI,
but did break the Linux build bots. This is why I reverted it in
r295948.

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

llvm-svn: 296991
2017-03-05 19:11:24 +00:00
Ranjeet Singh 744dabcdcd [libunwind] Disable calls to fprintf for baremetal targets.
We've been having issues with using libcxxabi and libunwind for baremetal
targets because fprintf is dependent on io functions, this patch disables calls
to fprintf when building for baremetal in release mode.

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

llvm-svn: 296135
2017-02-24 16:38:05 +00:00
Ed Schouten 39af790bb1 Revert r295944.
Even though the change works perfectly fine on CloudABI, it fails to
work on the libcxx-libcxxabi-libunwind-arm-linux-noexceptions build bot.
Looking at the code, this may be attributed to the fact that the code
doesn't take the PT_LOAD addresses into consideration.

I will rework this change to fix that and send out an updated version
for review in the nearby future.

llvm-svn: 295948
2017-02-23 09:13:22 +00:00
Ed Schouten fd939c0f6c Drop the dependency on dl_unwind_find_exidx().
While porting libunwind over to CloudABI for ARMv6, I observed that this
source file doesn't build, as it depends on dl_unwind_find_exidx(),
which CloudABI's C library was lacking. After I added that function,
I still needed to patch up libunwind to define _Unwind_Ptr.

Taking a step back, I wonder why we need to make use of this function
anyway. The unwinder already has some nice code to use dl_iterate_phdr()
to scan for a PT_GNU_EH_FRAME header. The dl_unwind_find_exidx() does
the same thing, except matching PT_ARM_EXIDX instead. We could also do
that ourselves.

This change gets rid of the dl_unwind_find_exidx() call and extends the
dl_iterate_phdr() loop. In addition to making the code a bit shorter, it
has the advantage of getting rid of some of those OS-specific #ifdefs.

This now means that if an operating system only provides
dl_iterate_phdr(), it gets support for unwinding on all architectures.
There is no need to add more stuff, just to get ARMv6 support.

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

llvm-svn: 295944
2017-02-23 08:05:58 +00:00
Saleem Abdulrasool 2b2f4dadc4 Revert "DWARF: convert error logs to _LIBUNWIND_LOG"
This reverts SVN r292721.  Avoid the use of the GNU extension as the
preprocessor in C++11 mode requires at least one argument, and this
warning cannot be disabled, resulting in failing -Werror builds.

llvm-svn: 293257
2017-01-27 02:26:52 +00:00
Saleem Abdulrasool 9a75332cab DWARF: fix -Asserts builds
no-op the DWARF tracing macros in non-debug builds.

llvm-svn: 293008
2017-01-25 02:27:45 +00:00
Saleem Abdulrasool e6de7d333a DWARF: correct cast (NFC)
Change the case of a PRIu64 value from `long` to `uint64_t`.  NFC.

llvm-svn: 292728
2017-01-21 21:27:29 +00:00
Saleem Abdulrasool b64d3273a3 X86: swap EBP, ESP on !APPLE
Restore the `libunwind.h` enumeration values back to the inverted
values.  This diverges from the DWARF definition of the register values.
However, this allows our header to be compatible with other unwind
implementations (e.g. HP, GNU Savannah, GCC).

The register IDs are only swapped in the header and need to be unswapped
when accessing the unwind register file.  The flipped EBP and ESP only
applies on non-Apple x86 targets.

When optimizations were enabled, EBP and ESP would no longer be
equivalent.  As a result, the incorrect access on Linux would manifest
as a failure to unwind the stack.  We can now unwind the stack with and
without FPO on Linux x86.

Resolves PR30879!

llvm-svn: 292723
2017-01-21 16:22:59 +00:00
Saleem Abdulrasool c06f0cf88c DWARF: allow enabling tracing at runtime
Introduce `logDWARF` and the associated environment variable
`LIBUNWIND_PRINT_DWARF` to trace the CFI instructions.

llvm-svn: 292722
2017-01-21 16:22:57 +00:00
Saleem Abdulrasool c3bf7da9cf DWARF: convert error logs to _LIBUNWIND_LOG
Use the `_LIBUNWIND_LOG` macro instead of the explicit `fprintf` call.
NFC.

llvm-svn: 292721
2017-01-21 16:22:55 +00:00
Saleem Abdulrasool 8ecd010547 config: clean up some of the macro definition
Unify the definition of `_LIBUNWIND_LOG_NON_ZERO` to make it clear what
it is defined to and make the definition unconditional.  Reorder the
debug and tracing macros to be defined in the same order.  NFC.

llvm-svn: 292720
2017-01-21 16:22:53 +00:00
Saleem Abdulrasool eae1b66c1b rename OtherAddressSpace to RemoteAddressSpace; NFC
llvm-svn: 292719
2017-01-21 16:22:46 +00:00
Saleem Abdulrasool f27bfd256b EHABI: mark some functions as exported
These are part of the EHABI specification and are exported to be available to
users.  Mark them as `_LIBUNWIND_EXPORT` like the rest of the unwind interfaces.

llvm-svn: 287283
2016-11-17 23:53:35 +00:00
Marshall Clow b8292c3d65 Add conditions for PPC to libunwind. Fixes PR22200. Thanks to Jeremy for the bug report and the patch.
llvm-svn: 285831
2016-11-02 16:39:55 +00:00
Nick Kledzik 56e6135774 fix _dyld_find_unwind_sections() for pre-10.7. Patch by Jeremy Sequoia
llvm-svn: 285636
2016-10-31 21:04:17 +00:00
Petr Hosek 93d28f3507 [libunwind] Add support for Fuchsia
Fuchsia is a new operating system which uses libunwind as unwinder.

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

llvm-svn: 284951
2016-10-23 21:48:47 +00:00
Asiri Rathnayake 8295d54868 [libunwind] Add missing <stdint.h> include. NFC.
This missing include seems to cause compilation failures on older MacOS
versions (< 10.9). This is because r270692 has introduced uint64_t into
config.h without including this header.

Patch from: Jeremy Huddleston Sequoia (jeremyhu@apple.com)

llvm-svn: 284125
2016-10-13 14:32:24 +00:00
Ed Maste a2ebee6f50 libunwind: Add OpenBSD case for _Unwind_Ptr typedef
Patch by Mark Kettenis

llvm-svn: 282599
2016-09-28 15:37:21 +00:00
Asiri Rathnayake 6264758cc8 [libunwind] Add support for a single-threaded libunwind build
The EHABI unwinder is thread-agnostic, SJLJ unwinder and the DWARF unwinder have
a couple of pthread dependencies.

This patch makes it possible to build the whole of libunwind for a
single-threaded environment.

Reviewers: compnerd

Differential revision: https://reviews.llvm.org/D24984

llvm-svn: 282575
2016-09-28 10:57:15 +00:00