gnustep/libobjc2

cxa_allocate_exception is not compatible with CLang 6

Closed this issue · 5 comments

kwhat commented

Hi,

It looks like there is an issue with clang 6 compatibility related to cxa_allocate_exception and related stuff. I have patched the issue against 1.8 as well as a bunch of warnings. I think the warnings were taken care of in master but I am not sure if the cxa_allocate_exception was addressed. I didn't see any reported bugs related to this issue so I have opened this.

clang_cxa_allocate_exception.patch

diff -Naur libobjc2-1.8.1/CMakeLists.txt libobjc2-1.8.1.new/CMakeLists.txt
--- libobjc2-1.8.1/CMakeLists.txt       2015-08-07 04:33:40.000000000 -0700
+++ libobjc2-1.8.1.new/CMakeLists.txt   2018-04-03 13:55:39.233515034 -0700
@@ -7,6 +7,7 @@
 set(CMAKE_C_FLAGS_DEBUG "-g -O0 -fno-inline ${CMAKE_C_FLAGS_DEBUG}")
 set(CMAKE_C_FLAGS_RELEASE "-O3 ${CMAKE_C_FLAGS_RELEASE}")
 set(CMAKE_C_FLAGS "-std=gnu99 ${CMAKE_C_FLAGS}")
+set(CMAKE_CXX_FLAGS "-std=c++11 -stdlib=libc++ ${CMAKE_CXX_FLAGS}")
 
 set(libobjc_VERSION 4.6)
 
@@ -14,7 +15,7 @@
 # Build configuration
 add_definitions( -DGNUSTEP -D__OBJC_RUNTIME_INTERNAL__=1)
 # Probably not needed anymore?
-add_definitions( -D_XOPEN_SOURCE=700 -D__BSD_VISIBLE=1 -D_BSD_SOURCE=1)
+add_definitions( -D_XOPEN_SOURCE=700 -D_DEFAULT_SOURCE=1)
 
 set(libobjc_ASM_SRCS 
        block_trampolines.S
diff -Naur libobjc2-1.8.1/Makefile libobjc2-1.8.1.new/Makefile
--- libobjc2-1.8.1/Makefile     2015-08-07 04:33:40.000000000 -0700
+++ libobjc2-1.8.1.new/Makefile 2018-04-03 13:52:44.593214733 -0700
@@ -18,7 +18,7 @@
 #CFLAGS += -Wno-deprecated-objc-isa-usage
 CXXFLAGS += -fPIC -fexceptions
 CPPFLAGS += -DTYPE_DEPENDENT_DISPATCH -DGNUSTEP
-CPPFLAGS += -D__OBJC_RUNTIME_INTERNAL__=1 -D_XOPEN_SOURCE=500 -D__BSD_VISIBLE=1 -D_BSD_SOURCE=1
+CPPFLAGS += -D__OBJC_RUNTIME_INTERNAL__=1 -D_XOPEN_SOURCE=500 -D_DEFAULT_SOURCE=1
 
 ASMFLAGS += `if $(CC) -v 2>&1| grep -q 'clang' ; then echo -no-integrated-as ; fi`
kwhat commented

Additional logs and info @ 651158

This doesn't look like a clang issue, it looks like a conflict with your system headers, which appear to come from GCC 7.x, according to the Gentoo bugzilla issue. I'm nervous about removing the __BSD* defines, because I'd expect that to break on other targets. Perhaps this needs to be conditional on targets that use a gcc 7.x+ C++ standard library?

kwhat commented

Yes, I agree. Conditional would be the safest choice. I will look into adding a cmake conditional for gcc 7.x. Thank you for your response.

Note: I think that this work around is not quite the right one. It appears that new versions of libsupc++ add a noexcept qualifier on __cxa_allocate_exception and there's some namespace pollution in the libstdc++ headers that make this definition visible. The correct solution is probably to check whether a simple test compiles with #include <exception> and __cxa_allocate_exception defined with or without the noexcept qualifier, and then a new macro that makes the declaration that we provide match whatever the host platform expects.

Should now be fixed by the fact that we no longer #include <exception>.