Files
swift-mirror/cmake/modules/GoldVersion.cmake
Alastair Houghton a014bd2cc8 [Build] Detect ld.gold version and prefer lld if gold is too old.
If we're on a system that has ld.gold 2.35 or earlier, we want to use
lld instead because otherwise we end up with duplicate sections in the
output.

rdar://123504095
2024-04-29 10:48:23 +01:00

19 lines
697 B
CMake

# Find the version of ld.gold, if installed.
#
# Versions prior to 2.36 break Swift programs because they won't coalesce
# sections with different SHF_GNU_RETAIN flags.
function(get_gold_version result_var_name)
find_program(gold_executable "ld.gold")
if(gold_executable)
execute_process(
COMMAND "${gold_executable}" "--version"
COMMAND "head" "-n" "1"
COMMAND "sed" "-e" "s/^.* (\\([^)]*\\)).*$/\\1/g;s/.* \\([0-9][0-9]*\\(\\.[0-9][0-9]*\\)*\\).*/\\1/g"
OUTPUT_VARIABLE gold_version
OUTPUT_STRIP_TRAILING_WHITESPACE)
set("${result_var_name}" "${gold_version}" PARENT_SCOPE)
else()
set("${result_var_name}" "" PARENT_SCOPE)
endif()
endfunction()