[tarantool-patches] Re: [PATCH] Fix libgomp linking for static build
Alexander Turenko
alexander.turenko at tarantool.org
Fri Sep 7 20:10:58 MSK 2018
Hi!
The patch looks good to me. Two comments about formatting are below.
Checked static + dynamic build locally (on Gentoo) with gcc and checked
dynamic build locally with clang. It works.
I think we should file an issue re adding Linux/clang target into CI.
WBR, Alexander Turenko.
On Fri, Sep 07, 2018 at 12:17:33PM +0300, Kirill Yukhin wrote:
> Since addition of -fopenmp to compiler also means
> addition of -lgomp to the link stage, pass -fno-openmp
> to the linking stage in case of static build. In that
> case OMP functions are statically linked into libmisc.
>
> Also, emit error if trying to perform static build using
> clang.
> ---
> Branch: https://github.com/tarantool/tarantool/commits/kyukhin/gh-xxxx-fix-gomp-in-static-build
> Issue: n/a
>
> cmake/compiler.cmake | 5 ++++-
> src/CMakeLists.txt | 7 +++++++
> 2 files changed, 11 insertions(+), 1 deletion(-)
>
> diff --git a/cmake/compiler.cmake b/cmake/compiler.cmake
> index b3a0702..5b323c7 100644
> --- a/cmake/compiler.cmake
> +++ b/cmake/compiler.cmake
> @@ -33,6 +33,10 @@ if (CMAKE_COMPILER_IS_GNUCC)
> Your GCC version is ${CMAKE_CXX_COMPILER_VERSION}, please update
> ")
> endif()
> +else()
> + if (BUILD_STATIC)
> + message(FATAL_ERROR "Static build is supported for GCC only")
Double indent.
> + endif()
> endif()
>
> #
> @@ -284,7 +288,6 @@ if (HAVE_OPENMP)
> add_compile_flags("C;CXX" "-fopenmp")
> endif()
>
> -
> if (CMAKE_COMPILER_IS_CLANG OR CMAKE_COMPILER_IS_GNUCC)
> set(HAVE_BUILTIN_CTZ 1)
> set(HAVE_BUILTIN_CTZLL 1)
> diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt
> index ebda098..aa39d8b 100644
> --- a/src/CMakeLists.txt
> +++ b/src/CMakeLists.txt
> @@ -277,6 +277,13 @@ if(BUILD_STATIC)
> endif()
> endforeach(libstatic)
> string(REPLACE ";" " " EXPORT_LIST "${EXPORT_LIST}")
> +
> + if (HAVE_OPENMP)
> + # Link libgomp explicitly to make it static. Avoid linking
> + # against DSO version of libgomp, which implied by -fopenmp
> + set (common_libraries ${common_libraries} "libgomp.a")
> + set(CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} -fno-openmp")
> + endif ()
endif () -> endif()
> endif()
>
> # Exports syntax is toolchain-dependent, preprocessing is necessary
> --
> 2.16.2
>
More information about the Tarantool-patches
mailing list