From ae032e2714675354457c474f4c8f5581714e33d1 Mon Sep 17 00:00:00 2001 From: David Tenty Date: Tue, 10 Nov 2020 12:03:30 -0500 Subject: [PATCH] [CMake][ExecutionEngine] add HAVE_(DE)REGISTER_FRAME as a config.h macros The macro HAVE_EHTABLE_SUPPORT is used by parts of ExecutionEngine to tell __register_frame/__deregister_frame is available to register the FDE for a generated (JIT) code. It's currently set by a slowly growing set of macro tests in the respective headers, which is updated now and then when it fails to link on some platform or another due to the symbols being missing (see for example https://bugs.llvm.org/show_bug.cgi?id=5715). This change converts the macro in two HAVE_(DE)REGISTER_FRAME config.h macros (like most of the other HAVE_* macros) and set's them based on whether CMake can actually find a definition for these symbols to link to at configuration time. Reviewed By: hubert.reinterpretcast Differential Revision: https://reviews.llvm.org/D87114 --- llvm/cmake/config-ix.cmake | 4 ++++ llvm/cmake/unwind.h | 7 +++++++ llvm/include/llvm/Config/config.h.cmake | 6 ++++++ llvm/lib/ExecutionEngine/JITLink/EHFrameSupport.cpp | 13 +++---------- .../lib/ExecutionEngine/RuntimeDyld/RTDyldMemoryManager.cpp | 12 ++---------- 5 files changed, 22 insertions(+), 20 deletions(-) create mode 100644 llvm/cmake/unwind.h diff --git a/llvm/cmake/config-ix.cmake b/llvm/cmake/config-ix.cmake index 797485e..818fafb 100644 --- a/llvm/cmake/config-ix.cmake +++ b/llvm/cmake/config-ix.cmake @@ -207,6 +207,10 @@ if(C_SUPPORTS_WERROR_UNGUARDED_AVAILABILITY_NEW) set(CMAKE_REQUIRED_FLAGS "${CMAKE_REQUIRED_FLAGS} -Werror=unguarded-availability-new") endif() +# Determine whether we can register EH tables. +check_symbol_exists(__register_frame "${CMAKE_CURRENT_LIST_DIR}/unwind.h" HAVE_REGISTER_FRAME) +check_symbol_exists(__deregister_frame "${CMAKE_CURRENT_LIST_DIR}/unwind.h" HAVE_DEREGISTER_FRAME) + check_symbol_exists(_Unwind_Backtrace "unwind.h" HAVE__UNWIND_BACKTRACE) check_symbol_exists(getpagesize unistd.h HAVE_GETPAGESIZE) check_symbol_exists(sysconf unistd.h HAVE_SYSCONF) diff --git a/llvm/cmake/unwind.h b/llvm/cmake/unwind.h new file mode 100644 index 0000000..e7f5346 --- /dev/null +++ b/llvm/cmake/unwind.h @@ -0,0 +1,7 @@ +// NOLINT: llvm-header-guard +// __register_frame() is used with dynamically generated code to register the +// FDE for a generated (JIT) code. This header provides protypes, since the gcc +// version of unwind.h may not, so CMake can check if the corresponding symbols +// exist in the runtime. +extern void __register_frame(const void *fde); // NOLINT +extern void __deregister_frame(const void *fde); // NOLINT diff --git a/llvm/include/llvm/Config/config.h.cmake b/llvm/include/llvm/Config/config.h.cmake index fc3f945..6664ad3 100644 --- a/llvm/include/llvm/Config/config.h.cmake +++ b/llvm/include/llvm/Config/config.h.cmake @@ -58,6 +58,12 @@ /* Define if dladdr() is available on this platform. */ #cmakedefine HAVE_DLADDR ${HAVE_DLADDR} +/* Define to 1 if we can register EH frames on this platform. */ +#cmakedefine HAVE_REGISTER_FRAME ${HAVE_REGISTER_FRAME} + +/* Define to 1 if we can deregister EH frames on this platform. */ +#cmakedefine HAVE_DEREGISTER_FRAME ${HAVE_DEREGISTER_FRAME} + /* Define to 1 if you have the header file. */ #cmakedefine HAVE_ERRNO_H ${HAVE_ERRNO_H} diff --git a/llvm/lib/ExecutionEngine/JITLink/EHFrameSupport.cpp b/llvm/lib/ExecutionEngine/JITLink/EHFrameSupport.cpp index 9eda6fb..b94a2b3 100644 --- a/llvm/lib/ExecutionEngine/JITLink/EHFrameSupport.cpp +++ b/llvm/lib/ExecutionEngine/JITLink/EHFrameSupport.cpp @@ -10,6 +10,7 @@ #include "EHFrameSupportImpl.h" #include "llvm/BinaryFormat/Dwarf.h" +#include "llvm/Config/config.h" #include "llvm/Support/DynamicLibrary.h" #define DEBUG_TYPE "jitlink" @@ -629,16 +630,8 @@ Expected EHFrameEdgeFixer::getOrCreateSymbol(ParseContext &PC, return PC.G.addAnonymousSymbol(*B, Addr - B->getAddress(), 0, false, false); } -// Determine whether we can register EH tables. -#if (defined(__GNUC__) && !defined(__ARM_EABI__) && !defined(__ia64__) && \ - !(defined(_AIX) && defined(__ibmxl__)) && !defined(__MVS__) && \ - !defined(__SEH__) && !defined(__USING_SJLJ_EXCEPTIONS__)) -#define HAVE_EHTABLE_SUPPORT 1 -#else -#define HAVE_EHTABLE_SUPPORT 0 -#endif - -#if HAVE_EHTABLE_SUPPORT +#if defined(HAVE_REGISTER_FRAME) && defined(HAVE_DEREGISTER_FRAME) && \ + !defined(__SEH__) && !defined(__USING_SJLJ_EXCEPTIONS__) extern "C" void __register_frame(const void *); extern "C" void __deregister_frame(const void *); diff --git a/llvm/lib/ExecutionEngine/RuntimeDyld/RTDyldMemoryManager.cpp b/llvm/lib/ExecutionEngine/RuntimeDyld/RTDyldMemoryManager.cpp index 6aa8f1c..b6ccd02 100644 --- a/llvm/lib/ExecutionEngine/RuntimeDyld/RTDyldMemoryManager.cpp +++ b/llvm/lib/ExecutionEngine/RuntimeDyld/RTDyldMemoryManager.cpp @@ -31,16 +31,8 @@ namespace llvm { RTDyldMemoryManager::~RTDyldMemoryManager() {} -// Determine whether we can register EH tables. -#if (defined(__GNUC__) && !defined(__ARM_EABI__) && !defined(__ia64__) && \ - !(defined(_AIX) && defined(__ibmxl__)) && !defined(__MVS__) && \ - !defined(__SEH__) && !defined(__USING_SJLJ_EXCEPTIONS__)) -#define HAVE_EHTABLE_SUPPORT 1 -#else -#define HAVE_EHTABLE_SUPPORT 0 -#endif - -#if HAVE_EHTABLE_SUPPORT +#if defined(HAVE_REGISTER_FRAME) && defined(HAVE_DEREGISTER_FRAME) && \ + !defined(__SEH__) && !defined(__USING_SJLJ_EXCEPTIONS__) extern "C" void __register_frame(void *); extern "C" void __deregister_frame(void *); #else -- 2.7.4