Merge pull request #904

f07f120 cmake: don't try to link with atomic on Apple (redfish)
19349d7 cmake: ARM: clang: make warning non-fatal: inline asm (redfish)
f3e09f3 cmake: link with -latomic for clang (redfish)
f4b35ae cmake: include -ldl via cmake built-in var (redfish)
fa85cd8 common: stack trace: make clang happy with func ptrs (redfish)
4dce26b cmake: do not pass -stdlib=c++ to clang >=3.7 (redfish)
This commit is contained in:
Riccardo Spagni 2016-07-20 13:56:59 +02:00
commit 77015e8132
No known key found for this signature in database
GPG key ID: 55432DF31CCD4FCD
2 changed files with 41 additions and 14 deletions

View file

@ -323,6 +323,9 @@ else()
endif() endif()
if(CMAKE_C_COMPILER_ID STREQUAL "Clang") if(CMAKE_C_COMPILER_ID STREQUAL "Clang")
set(WARNINGS "${WARNINGS} -Wno-error=mismatched-tags -Wno-error=null-conversion -Wno-overloaded-shift-op-parentheses -Wno-error=shift-count-overflow -Wno-error=tautological-constant-out-of-range-compare -Wno-error=unused-private-field -Wno-error=unneeded-internal-declaration") set(WARNINGS "${WARNINGS} -Wno-error=mismatched-tags -Wno-error=null-conversion -Wno-overloaded-shift-op-parentheses -Wno-error=shift-count-overflow -Wno-error=tautological-constant-out-of-range-compare -Wno-error=unused-private-field -Wno-error=unneeded-internal-declaration")
if(ARM6 OR ARM7)
set(WARNINGS "${WARNINGS} -Wno-error=inline-asm")
endif()
else() else()
set(WARNINGS "${WARNINGS} -Wlogical-op -Wno-error=maybe-uninitialized") set(WARNINGS "${WARNINGS} -Wlogical-op -Wno-error=maybe-uninitialized")
endif() endif()
@ -397,8 +400,10 @@ else()
# There is a clang bug that does not allow to compile code that uses AES-NI intrinsics if -flto is enabled, so explicitly disable # There is a clang bug that does not allow to compile code that uses AES-NI intrinsics if -flto is enabled, so explicitly disable
set(USE_LTO false) set(USE_LTO false)
# explicitly define stdlib for older versions of clang # explicitly define stdlib for older versions of clang
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -stdlib=libc++") if(CMAKE_C_COMPILER_VERSION VERSION_LESS 3.7)
set(CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} -stdlib=libc++") set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -stdlib=libc++")
set(CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} -stdlib=libc++")
endif()
endif() endif()
@ -458,9 +463,11 @@ elseif(NOT MSVC)
set(EXTRA_LIBRARIES ${RT}) set(EXTRA_LIBRARIES ${RT})
endif() endif()
if(CMAKE_CXX_COMPILER_ID STREQUAL "GNU" AND NOT MINGW) list(APPEND EXTRA_LIBRARIES ${CMAKE_DL_LIBS})
find_library(DL dl)
set(EXTRA_LIBRARIES ${DL}) if(NOT MINGW AND NOT APPLE)
find_library(ATOMIC atomic)
list(APPEND EXTRA_LIBRARIES ${ATOMIC})
endif() endif()
include(version.cmake) include(version.cmake)

View file

@ -38,14 +38,33 @@
#endif #endif
// from http://stackoverflow.com/questions/11665829/how-can-i-print-stack-trace-for-caught-exceptions-in-c-code-injection-in-c // from http://stackoverflow.com/questions/11665829/how-can-i-print-stack-trace-for-caught-exceptions-in-c-code-injection-in-c
// The decl of __cxa_throw in /usr/include/.../cxxabi.h uses
// 'std::type_info *', but GCC's built-in protype uses 'void *'.
#ifdef __clang__
#define CXA_THROW_INFO_T std::type_info
#else // !__clang__
#define CXA_THROW_INFO_T void
#endif // !__clang__
#ifdef STATICLIB #ifdef STATICLIB
#define CXA_THROW __wrap___cxa_throw #define CXA_THROW __wrap___cxa_throw
extern "C" void __real___cxa_throw(void *ex, void *info, void (*dest)(void*)); extern "C"
#else __attribute__((noreturn))
void __real___cxa_throw(void *ex, CXA_THROW_INFO_T *info, void (*dest)(void*));
#else // !STATICLIB
#define CXA_THROW __cxa_throw #define CXA_THROW __cxa_throw
#endif extern "C"
typedef
#ifdef __clang__ // only clang, not GCC, lets apply the attr in typedef
__attribute__((noreturn))
#endif // __clang__
void (cxa_throw_t)(void *ex, CXA_THROW_INFO_T *info, void (*dest)(void*));
#endif // !STATICLIB
extern "C" void CXA_THROW(void *ex, void *info, void (*dest)(void*)) extern "C"
__attribute__((noreturn))
void CXA_THROW(void *ex, CXA_THROW_INFO_T *info, void (*dest)(void*))
{ {
int status; int status;
@ -53,12 +72,13 @@ extern "C" void CXA_THROW(void *ex, void *info, void (*dest)(void*))
tools::log_stack_trace((std::string("Exception: ")+((!status && dsym) ? dsym : (const char*)info)).c_str()); tools::log_stack_trace((std::string("Exception: ")+((!status && dsym) ? dsym : (const char*)info)).c_str());
free(dsym); free(dsym);
#ifdef STATICLIB #ifndef STATICLIB
#ifndef __clang__ // for GCC the attr can't be applied in typedef like for clang
__attribute__((noreturn))
#endif // !__clang__
cxa_throw_t *__real___cxa_throw = (cxa_throw_t*)dlsym(RTLD_NEXT, "__cxa_throw");
#endif // !STATICLIB
__real___cxa_throw(ex, info, dest); __real___cxa_throw(ex, info, dest);
#else
static void (*const rethrow)(void*, void*, void(*)(void*)) __attribute__((noreturn)) = (void(*)(void*, void*, void(*)(void*)))dlsym(RTLD_NEXT, "__cxa_throw");
rethrow(ex, info, dest);
#endif
} }
namespace namespace