@@ -540,95 +540,6 @@ if(ARROW_CPU_FLAG STREQUAL "aarch64")
540540 endif ()
541541endif ()
542542
543- # ----------------------------------------------------------------------
544- # Setup Gold linker, if available. Code originally from Apache Kudu
545-
546- # Interrogates the linker version via the C++ compiler to determine whether
547- # we're using the gold linker, and if so, extracts its version.
548- #
549- # If the gold linker is being used, sets GOLD_VERSION in the parent scope with
550- # the extracted version.
551- #
552- # Any additional arguments are passed verbatim into the C++ compiler invocation.
553- function (GET_GOLD_VERSION)
554- # The gold linker is only for ELF binaries, which macOS doesn't use.
555- execute_process (COMMAND ${CMAKE_CXX_COMPILER} "-Wl,--version" ${ARGN}
556- ERROR_QUIET
557- OUTPUT_VARIABLE LINKER_OUTPUT)
558- # We're expecting LINKER_OUTPUT to look like one of these:
559- # GNU gold (version 2.24) 1.11
560- # GNU gold (GNU Binutils for Ubuntu 2.30) 1.15
561- if (LINKER_OUTPUT MATCHES "GNU gold" )
562- string (REGEX MATCH "GNU gold \\ ([^\\ )]*\\ ) (([0-9]+\\ .?)+)" _ "${LINKER_OUTPUT} " )
563- if (NOT CMAKE_MATCH_1)
564- message (SEND_ERROR "Could not extract GNU gold version. "
565- "Linker version output: ${LINKER_OUTPUT} " )
566- endif ()
567- set (GOLD_VERSION
568- "${CMAKE_MATCH_1} "
569- PARENT_SCOPE)
570- endif ()
571- endfunction ()
572-
573- # Is the compiler hard-wired to use the gold linker?
574- if (NOT WIN32 AND NOT APPLE )
575- get_gold_version()
576- if (GOLD_VERSION)
577- set (MUST_USE_GOLD 1)
578- elseif (ARROW_USE_LD_GOLD)
579- # Can the compiler optionally enable the gold linker?
580- get_gold_version("-fuse-ld=gold" )
581-
582- # We can't use the gold linker if it's inside devtoolset because the compiler
583- # won't find it when invoked directly from make/ninja (which is typically
584- # done outside devtoolset).
585- execute_process (COMMAND which ld.gold
586- OUTPUT_VARIABLE GOLD_LOCATION
587- OUTPUT_STRIP_TRAILING_WHITESPACE ERROR_QUIET)
588- if ("${GOLD_LOCATION} " MATCHES "^/opt/rh/devtoolset" )
589- message (STATUS "Skipping optional gold linker (version ${GOLD_VERSION} ) because "
590- "it's in devtoolset" )
591- set (GOLD_VERSION)
592- endif ()
593- endif ()
594-
595- if (GOLD_VERSION)
596- # Older versions of the gold linker are vulnerable to a bug [1] which
597- # prevents weak symbols from being overridden properly. This leads to
598- # omitting of dependencies like tcmalloc (used in Kudu, where this
599- # workaround was written originally)
600- #
601- # How we handle this situation depends on other factors:
602- # - If gold is optional, we won't use it.
603- # - If gold is required, we'll either:
604- # - Raise an error in RELEASE builds (we shouldn't release such a product), or
605- # - Drop tcmalloc in all other builds.
606- #
607- # 1. https://sourceware.org/bugzilla/show_bug.cgi?id=16979.
608- if ("${GOLD_VERSION} " VERSION_LESS "1.12" )
609- set (ARROW_BUGGY_GOLD 1)
610- endif ()
611- if (MUST_USE_GOLD)
612- message (STATUS "Using hard-wired gold linker (version ${GOLD_VERSION} )" )
613- if (ARROW_BUGGY_GOLD)
614- if ("${ARROW_LINK} " STREQUAL "d" AND "${UPPERCASE_BUILD_TYPE} " STREQUAL "RELEASE" )
615- message (SEND_ERROR "Configured to use buggy gold with dynamic linking "
616- "in a RELEASE build" )
617- endif ()
618- endif ()
619- elseif (NOT ARROW_BUGGY_GOLD)
620- # The Gold linker must be manually enabled.
621- set (CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -fuse-ld=gold" )
622- set (CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -fuse-ld=gold" )
623- message (STATUS "Using optional gold linker (version ${GOLD_VERSION} )" )
624- else ()
625- message (STATUS "Optional gold linker is buggy, using ld linker instead" )
626- endif ()
627- else ()
628- message (STATUS "Using ld linker" )
629- endif ()
630- endif ()
631-
632543if (NOT WIN32 AND NOT APPLE )
633544 if (ARROW_USE_MOLD)
634545 find_program (LD_MOLD ld.mold)
0 commit comments