Repository: mesos
Updated Branches:
  refs/heads/master bffa9f3c5 -> 3fb36f158


Made FreeBSD default to non-GNU ld.

This patch fixes linking on FreeBSD (when building with Clang) by
adding the necessary linker flags to use either LLD or GOLD (whichever
is found first) instead of GNU LD (BFD), which is incompatible.

Review: https://reviews.apache.org/r/66493/


Project: http://git-wip-us.apache.org/repos/asf/mesos/repo
Commit: http://git-wip-us.apache.org/repos/asf/mesos/commit/3fb36f15
Tree: http://git-wip-us.apache.org/repos/asf/mesos/tree/3fb36f15
Diff: http://git-wip-us.apache.org/repos/asf/mesos/diff/3fb36f15

Branch: refs/heads/master
Commit: 3fb36f1581cac36ad946fe3916f635c6429f0b9a
Parents: bffa9f3
Author: David Forsythe <dforsy...@gmail.com>
Authored: Thu Apr 12 13:07:44 2018 -0700
Committer: Andrew Schwartzmeyer <and...@schwartzmeyer.com>
Committed: Thu Apr 12 13:11:10 2018 -0700

----------------------------------------------------------------------
 cmake/CompilationConfigure.cmake | 28 ++++++++++++++++++++++++++++
 1 file changed, 28 insertions(+)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/mesos/blob/3fb36f15/cmake/CompilationConfigure.cmake
----------------------------------------------------------------------
diff --git a/cmake/CompilationConfigure.cmake b/cmake/CompilationConfigure.cmake
index 1c327ac..08d154e 100644
--- a/cmake/CompilationConfigure.cmake
+++ b/cmake/CompilationConfigure.cmake
@@ -357,6 +357,34 @@ string(COMPARE EQUAL ${CMAKE_SYSTEM_NAME} "Linux" LINUX)
 ######################
 string(COMPARE EQUAL ${CMAKE_SYSTEM_NAME} "FreeBSD" FREEBSD)
 
+# There is a problem linking with BFD linkers when using Clang on
+# FreeBSD (MESOS-8761). CMake uses the compiler to link, and the
+# compiler uses `/usr/bin/ld` by default. On FreeBSD the default
+# compiler is Clang but the default linker is GNU ld (BFD). Since LLD
+# is available in the base system, and GOLD is available from
+# `devel/binutils`, we look for a more modern linker and tell Clang to
+# use that instead.
+#
+# TODO(dforsyth): Understand why this is failing and add a check to
+# make sure we have a compatible linker (MESOS-8765), or wait until
+# FreeBSD makes lld the default linker.
+if (${CMAKE_SYSTEM_NAME} MATCHES FreeBSD
+    AND CMAKE_CXX_COMPILER_ID MATCHES Clang)
+
+  find_program(LD_PROGRAM
+    NAMES ld.lld ld.gold)
+
+  if (NOT LD_PROGRAM)
+    message(FATAL_ERROR
+      "Please set LD_PROGRAM to a working (non-BFD) linker (MESOS-8761) to \
+      build on FreeBSD.")
+  endif ()
+
+  foreach (type EXE SHARED STATIC MODULE)
+    string(APPEND CMAKE_${type}_LINKER_FLAGS " -fuse-ld=${LD_PROGRAM}")
+  endforeach ()
+endif ()
+
 # WINDOWS CONFIGURATION.
 ########################
 if (WIN32)

Reply via email to