Skip to content

Commit 4cc78d7

Browse files
author
Asiri Rathnayake
committed
Fix exception address alignment test for EHABI
This test fails on ARM bare-metal targets because it assumes the Itanium ABI, whereas EHABI requires the exception address to be 8-byte aligned. I was a bit puzzled at first because this should've failed on the public arm-linux builder too. I think the reason it passes there is because we don't include libunwind headers in the include path when running the libcxxabi tests, so the system unwind.h gets picked up. Reviewers: rengolin, EricWF Differential revision: https://reviews.llvm.org/D31178 llvm-svn: 299435
1 parent dbdcfa1 commit 4cc78d7

File tree

4 files changed

+27
-5
lines changed

4 files changed

+27
-5
lines changed

libcxxabi/CMakeLists.txt

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -502,9 +502,14 @@ if (LIBCXXABI_USE_LLVM_UNWINDER OR LLVM_NATIVE_ARCH MATCHES ARM)
502502
set(LIBCXXABI_LIBUNWIND_SOURCES "")
503503
endif()
504504

505-
if (NOT LIBCXXABI_LIBUNWIND_INCLUDES_INTERNAL STREQUAL "LIBCXXABI_LIBUNWIND_INCLUDES_INTERNAL-NOTFOUND")
505+
if (LIBCXXABI_LIBUNWIND_INCLUDES_INTERNAL STREQUAL "LIBCXXABI_LIBUNWIND_INCLUDES_INTERNAL-NOTFOUND")
506+
set(LIBCXXABI_LIBUNWIND_INCLUDES_INTERNAL "")
507+
endif()
508+
509+
if (NOT LIBCXXABI_LIBUNWIND_INCLUDES_INTERNAL STREQUAL "")
506510
include_directories("${LIBCXXABI_LIBUNWIND_INCLUDES_INTERNAL}")
507511
endif()
512+
508513
if (NOT LIBCXXABI_LIBUNWIND_SOURCES STREQUAL "")
509514
include_directories("${LIBCXXABI_LIBUNWIND_SOURCES}")
510515
endif()

libcxxabi/test/libcxxabi/test/config.py

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -84,6 +84,13 @@ def configure_compile_flags_header_includes(self):
8484
% libcxxabi_headers)
8585
self.cxx.compile_flags += ['-I' + libcxxabi_headers]
8686

87+
libunwind_headers = self.get_lit_conf('libunwind_headers', None)
88+
if self.get_lit_bool('llvm_unwinder', False) and libunwind_headers:
89+
if not os.path.isdir(libunwind_headers):
90+
self.lit_config.fatal("libunwind_headers='%s' is not a directory."
91+
% libunwind_headers)
92+
self.cxx.compile_flags += ['-I' + libunwind_headers]
93+
8794
def configure_compile_flags_exceptions(self):
8895
pass
8996

libcxxabi/test/lit.site.cfg.in

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ config.libcxxabi_obj_root = "@LIBCXXABI_BINARY_DIR@"
66
config.abi_library_path = "@LIBCXXABI_LIBRARY_DIR@"
77
config.libcxx_src_root = "@LIBCXXABI_LIBCXX_PATH@"
88
config.cxx_headers = "@LIBCXXABI_LIBCXX_INCLUDES@"
9+
config.libunwind_headers = "@LIBCXXABI_LIBUNWIND_INCLUDES_INTERNAL@"
910
config.cxx_library_root = "@LIBCXXABI_LIBCXX_LIBRARY_PATH@"
1011
config.llvm_unwinder = "@LIBCXXABI_USE_LLVM_UNWINDER@"
1112
config.enable_threads = "@LIBCXXABI_ENABLE_THREADS@"

libcxxabi/test/test_exception_address_alignment.pass.cpp

Lines changed: 13 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -15,16 +15,25 @@
1515
// working around this failure.
1616
// XFAIL: darwin && libcxxabi-has-system-unwinder
1717

18-
// Test that the address of the exception object is properly aligned to the
19-
// largest supported alignment for the system.
18+
// Test that the address of the exception object is properly aligned as required
19+
// by the relevant ABI
2020

2121
#include <cstdint>
2222
#include <cassert>
2323

2424
#include <unwind.h>
2525

2626
struct __attribute__((aligned)) AlignedType {};
27-
static_assert(alignof(AlignedType) == alignof(_Unwind_Exception),
27+
28+
// EHABI : 8-byte aligned
29+
// Itanium: Largest supported alignment for the system
30+
#if defined(_LIBUNWIND_ARM_EHABI)
31+
# define EXPECTED_ALIGNMENT 8
32+
#else
33+
# define EXPECTED_ALIGNMENT alignof(AlignedType)
34+
#endif
35+
36+
static_assert(alignof(_Unwind_Exception) == EXPECTED_ALIGNMENT,
2837
"_Unwind_Exception is incorrectly aligned. This test is expected to fail");
2938

3039
struct MinAligned { };
@@ -35,7 +44,7 @@ int main() {
3544
try {
3645
throw MinAligned{};
3746
} catch (MinAligned const& ref) {
38-
assert(reinterpret_cast<uintptr_t>(&ref) % alignof(AlignedType) == 0);
47+
assert(reinterpret_cast<uintptr_t>(&ref) % EXPECTED_ALIGNMENT == 0);
3948
}
4049
}
4150
}

0 commit comments

Comments
 (0)