[MDEV-23887] build failure on MacOS Created: 2020-10-05  Updated: 2022-11-06  Resolved: 2020-10-21

Status: Closed
Project: MariaDB Server
Component/s: Compiling
Affects Version/s: 10.1, 10.2, 10.3, 10.4, 10.5, 10.6
Fix Version/s: 10.1.48, 10.2.35, 10.3.26, 10.4.16, 10.5.7

Type: Bug Priority: Major
Reporter: Dmitry Shulga Assignee: Daniel Black
Resolution: Fixed Votes: 0
Labels: None

Attachments: Text File CMakeCache.txt     Text File CMakeError.log     Text File CMakeOutput.log    
Issue Links:
Relates
relates to MDEV-29925 Building failure on MacOS since the l... Stalled

 Description   

Building MariaDB server of any version starting from 10.1 fails on MacOS.
Building failure happens on attempt to link any executable file.
Building process breaks due to the use of the unsupported -z flag in the linker options.
In result cmake terminates building with the following output:
ld: unknown option: -z
clang: error: linker command failed with exit code 1 (use -v to see invocation)

Unsupported linker option is added by the following cmake macros

  MY_CHECK_AND_SET_LINKER_FLAG("-Wl,-z,relro,-z,now")

that was introduced by the commit

commit 7473e1841c630d86f1873a2a7afacb53955b3f6f (HEAD)
Author: Daniel Black <daniel@linux.ibm.com>
Date:   Tue May 5 11:57:20 2020 +1000
 
check_linker_flag: use for linker flags
 
-Wl,-z,relro,-z,now are linker flags and should
be checked as such.



 Comments   
Comment by Daniel Black [ 2020-10-05 ]

Can you attach CMakeCache.txt CMakeFiles/CMakeError.log CMakeFiles/CMakeOutput.log?

What link options are used cmake --build . --verbose ?

Comment by Sergei Golubchik [ 2020-10-05 ]

CMAKE_REQUIRED_LINK_OPTIONS was introduced only recently. The check has to be rewritten to work without it

Comment by Daniel Black [ 2020-10-06 ]

Yes, 3.14.0.

Check has been reworked to support all versions.

Thanks shulga for report, review and testing.

Comment by Daniel Black [ 2020-10-06 ]

kevg, you where crazy enough to review my original 7473e1841c63 and suggested the CHECK_LINKER_FLAGS in 3.18.0.

Can you review this fix please?

Comment by Daniel Black [ 2020-10-06 ]

https://cmake.org/cmake/help/latest/release/3.14.html#commands is the minimum version based on 'The try_compile() and try_run() commands gained a new LINK_OPTIONS option.'

cmake-3.11.4 output

 
Performing C++ SOURCE FILE Test HAVE_LINK_FLAG__Wl__z_relro__z_now succeeded with the following output:
Change Dir: /Users/shulga/projects/mariadb/server-10.1/build.dir/CMakeFiles/CMakeTmpRun Build Command:"/usr/bin/make" "cmTC_82b27/fast"
/Applications/Xcode.app/Contents/Developer/usr/bin/make -f CMakeFiles/cmTC_82b27.dir/build.make CMakeFiles/cmTC_
82b27.dir/build
Building CXX object CMakeFiles/cmTC_82b27.dir/src.cxx.o
/Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/c++    -DHAVE_LINK_FLAG__
Wl__z_relro__z_now -isysroot /Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs
/MacOSX10.15.sdk   -o CMakeFiles/cmTC_82b27.dir/src.cxx.o -c /Users/shulga/projects/mariadb/server-10.1/build.di
r/CMakeFiles/CMakeTmp/src.cxx
Linking CXX executable cmTC_82b27
/Applications/CMake.app/Contents/bin/cmake -E cmake_link_script CMakeFiles/cmTC_82b27.dir/link.txt --verbose=1
/Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/c++   -DHAVE_LINK_FLAG__W
l__z_relro__z_now -isysroot /Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/
MacOSX10.15.sdk -Wl,-search_paths_first -Wl,-headerpad_max_install_names   CMakeFiles/cmTC_82b27.dir/src.cxx.o
-o cmTC_82b27Source file was:
int main(void) { return 0; }

So effectively the flag wasn't being tested

Comment by Sergei Golubchik [ 2020-10-06 ]

that's way too complex.

Just add put the flag into CMAKE_REQUIRED_LIBRARIES instead of CMAKE_REQUIRED_LINK_OPTIONS.

This worked for me both on 2.8.8 and on 3.16.5

Comment by Daniel Black [ 2020-10-07 ]

ok done - bb-10.1-danielblack-MDEV-23887-check_linker_flags-oldcmakesupport repushed

Works for me on 3.11.4 and 3.17.4

Generated at Thu Feb 08 09:25:48 UTC 2024 using Jira 8.20.16#820016-sha1:9d11dbea5f4be3d4cc21f03a88dd11d8c8687422.