Skip to content

Commit d155853

Browse files
author
Tor Didriksen
committed
Bug #30562248 ADD SUPPORT FOR GCC AND CLANG ON SOLARIS
Do not reject clang or gcc as unsupported compilers on Solaris. Note that both compilers are experimental, and cannot currently be used for production code. Add misc FLAGS settings for using clang on Solaris. It uses gcc9 libraries and headers, so we need explicit -Wl,-L... arguments. Fix a few cmake places where we assume that SunPro is the only compiler available on Solaris. Silence some gcc warnings previously only relevant on Linux. Note that clang is completely unusable at this point, 'static thread_local' variables will cause segfault during atexit processing. There is a new test executable to prove it. For non-trivial uses of static thread_local, the compiler will give an error: storage/temptable/src/allocator.cc:45:32: error: cannot compile this non-trivial TLS destruction yet static thread_local End_thread end_thread; gcc seems to work reasonably well on Intel, except for GIS boost code. gcc on Sparc works OK for DEBUG builds. Non-DEBUG builds however fail to bootstrap. The stack is garbled when handle_bootstrap() does: if (handler) { args->m_bootstrap_error = (*handler)(thd); when called from Dictionary_impl::init() like this: // Creation of Data Dictionary through current server if (dd_init == enum_dd_init_type::DD_INITIALIZE) result = ::bootstrap::run_bootstrap_thread( nullptr, nullptr, &bootstrap::initialize, SYSTEM_THREAD_DD_INITIALIZE); Tested with clang on Intel: /bin/clang --version clang version 6.0.1 (tags/RELEASE_601/final) uname -a SunOS xxxxxx 5.11 11.4.15.5.0 i86pc i386 i86pc Tested with gcc on Intel and Sparc: /usr/gcc/9/bin/gcc --version gcc (GCC) 9.2.0 uname -a SunOS xxxxxx 5.11 11.4.15.5.0 i86pc i386 i86pc uname -a SunOS xxxxxx 5.11 11.4.15.5.0 sun4v sparc sun4v Change-Id: Ia57ef8cd6e448804ece0dbfd66da1695a8e7361f
1 parent ce7f1ec commit d155853

File tree

18 files changed

+157
-20
lines changed

18 files changed

+157
-20
lines changed

CMakeLists.txt

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -400,6 +400,8 @@ IF(CMAKE_CXX_COMPILER_ID MATCHES "Clang")
400400
SET(MY_COMPILER_IS_CLANG 1)
401401
ELSEIF(CMAKE_CXX_COMPILER_ID MATCHES "GNU")
402402
SET(MY_COMPILER_IS_GNU 1)
403+
ELSEIF(CMAKE_CXX_COMPILER_ID MATCHES "SunPro")
404+
SET(MY_COMPILER_IS_SUNPRO 1)
403405
ENDIF()
404406

405407
IF(MY_COMPILER_IS_CLANG OR MY_COMPILER_IS_GNU)
@@ -1296,7 +1298,8 @@ IF(NOT WITHOUT_SERVER)
12961298
# We *could* test 'uname -v' VERSION_LESS 11.4 here.
12971299
# A clean build takes roughly the same time with or without -xO1
12981300
# Link time of mysqld is roughly 10% faster with -xO1.
1299-
IF(SOLARIS_SPARC AND CMAKE_BUILD_TYPE_UPPER STREQUAL "DEBUG")
1301+
IF(SOLARIS_SPARC AND MY_COMPILER_IS_SUNPRO AND
1302+
CMAKE_BUILD_TYPE_UPPER STREQUAL "DEBUG")
13001303
MESSAGE(STATUS
13011304
"Adding -xO1 for debug builds on Solaris ${MY_KERNEL_VERSION}")
13021305
STRING_APPEND(CMAKE_CXX_FLAGS_DEBUG " -xO1")

client/CMakeLists.txt

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,8 @@ IF(NOT WITHOUT_SERVER)
4747
ENDIF()
4848

4949
# Enable inlining, to avoid stack overflow for some long regular expressions.
50-
IF(SOLARIS_SPARC AND CMAKE_BUILD_TYPE_UPPER STREQUAL "DEBUG")
50+
IF(SOLARIS_SPARC AND MY_COMPILER_IS_SUNPRO AND
51+
CMAKE_BUILD_TYPE_UPPER STREQUAL "DEBUG")
5152
ADD_COMPILE_FLAGS(mysqltest/regular_expressions.cc
5253
COMPILE_FLAGS "-xO3"
5354
)

cmake/build_configurations/compiler_options.cmake

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ SET(CMAKE_POSITION_INDEPENDENT_CODE ON)
3636
# Compiler options
3737
IF(UNIX)
3838

39-
IF(MY_COMPILER_IS_GNU_OR_CLANG)
39+
IF(MY_COMPILER_IS_GNU_OR_CLANG AND NOT SOLARIS_SPARC)
4040
SET(SECTIONS_FLAG "-ffunction-sections -fdata-sections")
4141
ELSE()
4242
SET(SECTIONS_FLAG)
@@ -76,7 +76,7 @@ IF(UNIX)
7676
# Link mysqld with mtmalloc on Solaris 10 and later
7777
SET(WITH_MYSQLD_LDFLAGS "-lmtmalloc" CACHE STRING "")
7878

79-
IF(CMAKE_C_COMPILER_ID MATCHES "SunPro")
79+
IF(MY_COMPILER_IS_SUNPRO)
8080
SET(SUNPRO_FLAGS "")
8181
STRING_APPEND(SUNPRO_FLAGS " -xbuiltin=%all")
8282
STRING_APPEND(SUNPRO_FLAGS " -xlibmil")

cmake/googletest.cmake

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -207,7 +207,7 @@ IF(MY_COMPILER_IS_GNU_OR_CLANG)
207207
COMPILE_FLAGS "-Wno-undef -Wno-conversion")
208208
ENDIF()
209209

210-
IF(SOLARIS)
210+
IF(MY_COMPILER_IS_SUNPRO)
211211
## https://community.oracle.com/thread/4106985
212212
## Assertion: (../lnk/symdescr.cc, line 96) while processing ....
213213
IF(NOT EXISTS ${CMAKE_BINARY_DIR}/hack/src/)
@@ -266,7 +266,7 @@ FOREACH(googletest_library
266266
)
267267
ENDFOREACH()
268268

269-
IF(SOLARIS)
269+
IF(MY_COMPILER_IS_SUNPRO)
270270
ADD_DEFINITIONS(-DGTEST_LANG_CXX11=1)
271271
LIST(INSERT GMOCK_INCLUDE_DIRS 0 ${CMAKE_BINARY_DIR}/hack)
272272
ENDIF()

cmake/os/SunOS.cmake

Lines changed: 42 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,7 @@ CHECK_TYPE_SIZE("void *" SIZEOF_VOIDP)
4747

4848
# We require at least SunStudio 12.6 (CC 5.15)
4949
IF(NOT FORCE_UNSUPPORTED_COMPILER)
50-
IF(CMAKE_C_COMPILER_ID MATCHES "SunPro")
50+
IF(MY_COMPILER_IS_SUNPRO)
5151
IF(SIZEOF_VOIDP MATCHES 4)
5252
MESSAGE(FATAL_ERROR "32 bit Solaris builds are not supported. ")
5353
ENDIF()
@@ -71,6 +71,10 @@ IF(NOT FORCE_UNSUPPORTED_COMPILER)
7171
IF(${CC_MINOR_VERSION} LESS 15)
7272
MESSAGE(FATAL_ERROR "Oracle Studio 12.6 or newer is required!")
7373
ENDIF()
74+
ELSEIF(MY_COMPILER_IS_CLANG)
75+
MESSAGE(WARNING "Clang is (highly) experimental!!")
76+
ELSEIF(MY_COMPILER_IS_GNU)
77+
MESSAGE(WARNING "gcc is experimental")
7478
ELSE()
7579
MESSAGE(FATAL_ERROR "Unsupported compiler!")
7680
ENDIF()
@@ -137,8 +141,7 @@ MACRO(DIRNAME IN OUT)
137141
ENDMACRO()
138142

139143
# We assume that developer studio runtime libraries are installed.
140-
IF(CMAKE_SYSTEM_NAME MATCHES "SunOS" AND
141-
CMAKE_CXX_COMPILER_ID STREQUAL "SunPro")
144+
IF(MY_COMPILER_IS_SUNPRO)
142145
DIRNAME(${CMAKE_CXX_COMPILER} CXX_PATH)
143146

144147
SET(LIBRARY_SUFFIX "lib/compilers/CC-gcc/lib")
@@ -199,3 +202,39 @@ IF(CMAKE_SYSTEM_NAME MATCHES "SunOS" AND
199202
SET(QUOTED_CMAKE_CXX_LINK_FLAGS
200203
"${QUOTED_CMAKE_CXX_LINK_FLAGS} -lstatomic ")
201204
ENDIF()
205+
206+
# Experimental support for clang on Intel Solaris.
207+
# Try to build and run static_thread_local_test.
208+
IF(MY_COMPILER_IS_CLANG AND SOLARIS_INTEL)
209+
SET(CLANG_OUTPUT_FILE ${CMAKE_BINARY_DIR}/clang-output)
210+
EXECUTE_PROCESS(
211+
COMMAND ${CMAKE_CXX_COMPILER} --print-search-dirs
212+
OUTPUT_FILE ${CLANG_OUTPUT_FILE}
213+
)
214+
FILE(READ ${CLANG_OUTPUT_FILE} OUTPUT_FILE_CONTENTS)
215+
STRING(REPLACE "\n" ";" OUTPUT_FILE_CONTENTS ${OUTPUT_FILE_CONTENTS})
216+
FOREACH(LINE ${OUTPUT_FILE_CONTENTS})
217+
STRING(REGEX MATCH "(libraries: =)(.*)" XXX ${LINE})
218+
IF(CMAKE_MATCH_1)
219+
SET(LIBRARIES_STRING "${CMAKE_MATCH_2}")
220+
ENDIF()
221+
ENDFOREACH()
222+
STRING(REPLACE ":" ";" LIBRARIES_LIST "${LIBRARIES_STRING}")
223+
224+
SET(LRFLAGS "")
225+
FOREACH(LIB_PATH ${LIBRARIES_LIST})
226+
GET_FILENAME_COMPONENT(REAL_PATH ${LIB_PATH} REALPATH)
227+
STRING_APPEND(LRFLAGS " -Wl,-L${REAL_PATH} -Wl,-R${REAL_PATH}")
228+
ENDFOREACH()
229+
230+
STRING_APPEND(CMAKE_C_LINK_FLAGS "${LRFLAGS}")
231+
STRING_APPEND(CMAKE_CXX_LINK_FLAGS "${LRFLAGS}")
232+
STRING_APPEND(CMAKE_MODULE_LINKER_FLAGS "${LRFLAGS}")
233+
STRING_APPEND(CMAKE_SHARED_LINKER_FLAGS "${LRFLAGS}")
234+
235+
STRING_APPEND(CMAKE_C_LINK_FLAGS " -lc")
236+
STRING_APPEND(CMAKE_CXX_LINK_FLAGS " -lstdc++ -lgcc_s -lc")
237+
STRING_APPEND(CMAKE_MODULE_LINKER_FLAGS " -lstdc++ -lgcc_s -lc")
238+
STRING_APPEND(CMAKE_SHARED_LINKER_FLAGS " -lstdc++ -lgcc_s -lc")
239+
STRING_APPEND(QUOTED_CMAKE_CXX_LINK_FLAGS " -lstdc++ -lgcc_s -lc")
240+
ENDIF()

cmake/rapidjson.cmake

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@
2323
# We require rapidjson version 1.1.0 or higher.
2424
# -DWITH_RAPIDJSON=bundled is the default
2525

26-
IF(CMAKE_CXX_COMPILER_ID STREQUAL "SunPro")
26+
IF(MY_COMPILER_IS_SUNPRO)
2727
# Oracle Developer Studio 12.x isn't detected as c++11 compliant by rapidjson
2828
# automatically.
2929
ADD_DEFINITIONS(-DRAPIDJSON_HAS_CXX11_RANGE_FOR=1)

extra/icu/CMakeLists.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@
4040

4141
PROJECT (ICU)
4242

43-
IF(LINUX)
43+
IF(MY_COMPILER_IS_GNU_OR_CLANG)
4444
SET(ICU_LINUX_COMPILE_OPTIONS
4545
"-Wno-undef"
4646
"-Wno-deprecated-declarations"

extra/libevent/CMakeLists.txt

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -789,8 +789,8 @@ if (EVENT__BUILD_SHARED_LIBRARIES)
789789
set(EVENT__LIBRARY_TYPE SHARED)
790790

791791
if (MY_COMPILER_IS_GNU_OR_CLANG)
792-
add_compiler_flags(-fvisibility=hidden)
793-
elseif ("${CMAKE_C_COMPILER_ID}" STREQUAL "SunPro")
792+
add_compiler_flags(-fvisibility=hidden)
793+
elseif (MY_COMPILER_IS_SUNPRO)
794794
add_compiler_flags(-xldscope=hidden)
795795
endif()
796796

extra/protobuf/protobuf-3.6.1/cmake/CMakeLists.txt

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -198,6 +198,12 @@ if (protobuf_UNICODE)
198198
add_definitions(-DUNICODE -D_UNICODE)
199199
endif (protobuf_UNICODE)
200200

201+
# Bug in std::call_once in optimized mode
202+
IF(SOLARIS_SPARC AND MY_COMPILER_IS_GNU AND
203+
CMAKE_BUILD_TYPE_UPPER MATCHES "REL")
204+
ADD_COMPILE_OPTIONS("-O0")
205+
ENDIF()
206+
201207
include(libprotobuf-lite.cmake)
202208
include(libprotobuf.cmake)
203209
if (protobuf_BUILD_PROTOC_BINARIES)

mysys/CMakeLists.txt

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ ADD_WSHADOW_WARNING()
2525
SET(MY_TIME_SOURCES my_time.cc my_systime.cc)
2626

2727
ADD_CONVENIENCE_LIBRARY(mytime ${MY_TIME_SOURCES})
28-
IF(SOLARIS_INTEL)
28+
IF(SOLARIS_INTEL AND MY_COMPILER_IS_SUNPRO)
2929
# Sun Studio 12.6 generates code that segfaults for std::chrono stuff.
3030
TARGET_COMPILE_OPTIONS(mytime_objlib PRIVATE $<$<CONFIG:RelWithDebInfo>:-xO1>)
3131
ENDIF()
@@ -187,10 +187,16 @@ IF(WIN32)
187187
ENDIF()
188188

189189
# Bug in std::call_once in optimized mode
190-
IF(SOLARIS_SPARC AND MY_COMPILER_IS_GNU)
190+
IF(SOLARIS_SPARC AND MY_COMPILER_IS_GNU AND
191+
CMAKE_BUILD_TYPE_UPPER MATCHES "REL")
191192
ADD_COMPILE_FLAGS(charset.cc COMPILE_FLAGS "-O0")
192193
ENDIF()
193194

195+
# MD5_Init() and others are deprecated.
196+
IF(SOLARIS AND MY_COMPILER_IS_GNU_OR_CLANG)
197+
ADD_COMPILE_FLAGS(my_md5.cc COMPILE_FLAGS "-Wno-deprecated-declarations")
198+
ENDIF()
199+
194200
MYSQL_ADD_EXECUTABLE(thr_lock
195201
thr_lock.cc
196202
LINK_LIBRARIES mysys

0 commit comments

Comments
 (0)