Skip to content

Commit 3140c4b

Browse files
Merge pull request #8663 from usama54321/sanitizer-ci-cherry-picks
[Cherrypicks] Sanitizer ci fixes and a test fix
2 parents 7b8e634 + aa603a7 commit 3140c4b

File tree

7 files changed

+50
-22
lines changed

7 files changed

+50
-22
lines changed

clang/CMakeLists.txt

Lines changed: 9 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -13,8 +13,16 @@ if(CMAKE_SOURCE_DIR STREQUAL CMAKE_CURRENT_SOURCE_DIR)
1313
set(CLANG_BUILT_STANDALONE TRUE)
1414
endif()
1515

16+
# Make sure that our source directory is on the current cmake module path so that
17+
# we can include cmake files from this directory.
18+
list(INSERT CMAKE_MODULE_PATH 0
19+
"${CMAKE_CURRENT_SOURCE_DIR}/cmake/modules"
20+
"${LLVM_COMMON_CMAKE_UTILS}/Modules"
21+
)
22+
1623
# Must go below project(..)
1724
include(GNUInstallDirs)
25+
include(GetDarwinLinkerVersion)
1826

1927
if(CLANG_BUILT_STANDALONE)
2028
set(CMAKE_CXX_STANDARD 17 CACHE STRING "C++ standard to conform to")
@@ -140,13 +148,6 @@ if(CLANG_BUILT_STANDALONE)
140148
endif() # LLVM_INCLUDE_TESTS
141149
endif() # standalone
142150

143-
# Make sure that our source directory is on the current cmake module path so that
144-
# we can include cmake files from this directory.
145-
list(INSERT CMAKE_MODULE_PATH 0
146-
"${CMAKE_CURRENT_SOURCE_DIR}/cmake/modules"
147-
"${LLVM_COMMON_CMAKE_UTILS}/Modules"
148-
)
149-
150151
# This allows disabling clang's XML dependency even if LLVM finds libxml2.
151152
# By default, clang depends on libxml2 if LLVM does.
152153
option(CLANG_ENABLE_LIBXML2 "Whether libclang may depend on libxml2"
@@ -320,20 +321,7 @@ endif ()
320321
# Determine HOST_LINK_VERSION on Darwin.
321322
set(HOST_LINK_VERSION)
322323
if (APPLE AND NOT CMAKE_LINKER MATCHES ".*lld.*")
323-
set(LD_V_OUTPUT)
324-
execute_process(
325-
COMMAND sh -c "${CMAKE_LINKER} -v 2>&1 | head -1"
326-
RESULT_VARIABLE HAD_ERROR
327-
OUTPUT_VARIABLE LD_V_OUTPUT
328-
)
329-
if (HAD_ERROR)
330-
message(FATAL_ERROR "${CMAKE_LINKER} failed with status ${HAD_ERROR}")
331-
endif()
332-
if ("${LD_V_OUTPUT}" MATCHES ".*ld64-([0-9.]+).*")
333-
string(REGEX REPLACE ".*ld64-([0-9.]+).*" "\\1" HOST_LINK_VERSION ${LD_V_OUTPUT})
334-
elseif ("${LD_V_OUTPUT}" MATCHES "[^0-9]*([0-9.]+).*")
335-
string(REGEX REPLACE "[^0-9]*([0-9.]+).*" "\\1" HOST_LINK_VERSION ${LD_V_OUTPUT})
336-
endif()
324+
get_darwin_linker_version(HOST_LINK_VERSION)
337325
message(STATUS "Host linker version: ${HOST_LINK_VERSION}")
338326
endif()
339327

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
# Get the linker version on Darwin
2+
function(get_darwin_linker_version variable)
3+
set(LINK_VERSION)
4+
set(LD_V_OUTPUT)
5+
execute_process(
6+
COMMAND sh -c "${CMAKE_LINKER} -v 2>&1 | head -1"
7+
RESULT_VARIABLE HAD_ERROR
8+
OUTPUT_VARIABLE LD_V_OUTPUT
9+
)
10+
if (HAD_ERROR)
11+
message(FATAL_ERROR "${CMAKE_LINKER} failed with status ${HAD_ERROR}")
12+
endif()
13+
if ("${LD_V_OUTPUT}" MATCHES ".*ld64-([0-9.]+).*")
14+
string(REGEX REPLACE ".*ld64-([0-9.]+).*" "\\1" LINK_VERSION ${LD_V_OUTPUT})
15+
elseif ("${LD_V_OUTPUT}" MATCHES "[^0-9]*([0-9.]+).*")
16+
string(REGEX REPLACE "[^0-9]*([0-9.]+).*" "\\1" LINK_VERSION ${LD_V_OUTPUT})
17+
endif()
18+
set(${variable} ${LINK_VERSION} PARENT_SCOPE)
19+
endfunction()

compiler-rt/CMakeLists.txt

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,7 @@ include(SetPlatformToolchainTools)
3434
include(base-config-ix)
3535
include(CompilerRTUtils)
3636
include(CMakeDependentOption)
37+
include(GetDarwinLinkerVersion)
3738

3839
option(COMPILER_RT_BUILD_BUILTINS "Build builtins" ON)
3940
mark_as_advanced(COMPILER_RT_BUILD_BUILTINS)
@@ -456,6 +457,15 @@ else()
456457
set(SANITIZER_USE_SYMBOLS FALSE)
457458
endif()
458459

460+
# Get the linker version while configuring compiler-rt and explicitly pass it
461+
# in cflags during testing. This fixes the compiler/linker version mismatch
462+
# issue when running a clang built with a newer Xcode in an older Xcode
463+
set(COMPILER_RT_DARWIN_LINKER_VERSION)
464+
if (APPLE AND NOT CMAKE_LINKER MATCHES ".*lld.*")
465+
get_darwin_linker_version(COMPILER_RT_DARWIN_LINKER_VERSION)
466+
message(STATUS "Host linker version: ${COMPILER_RT_DARWIN_LINKER_VERSION}")
467+
endif()
468+
459469
# Build sanitizer runtimes with debug info.
460470
if(MSVC)
461471
# Use /Z7 instead of /Zi for the asan runtime. This avoids the LNK4099

compiler-rt/test/asan/TestCases/Darwin/odr-lto.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55

66
// RUN: %clangxx_asan -DPART=0 -c %s -o %t-1.o -flto -mllvm -asan-use-private-alias
77
// RUN: %clangxx_asan -DPART=1 -c %s -o %t-2.o -flto -mllvm -asan-use-private-alias
8-
// RUN: %clangxx_asan_lto %t-1.o %t-2.o -o %t -flto -mlinker-version=133
8+
// RUN: %clangxx_asan_lto %t-1.o %t-2.o -o %t -flto
99
// RUN: %run %t 2>&1 | FileCheck %s
1010

1111
#include <stdio.h>

compiler-rt/test/fuzzer/lit.cfg.py

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -89,6 +89,12 @@ def generate_compiler_cmd(is_cpp=True, fuzzer_enabled=True, msan_enabled=False):
8989
if fuzzer_enabled:
9090
sanitizers.append("fuzzer")
9191
sanitizers_cmd = "-fsanitize=%s" % ",".join(sanitizers)
92+
93+
if "darwin" in config.available_features and getattr(
94+
config, "darwin_linker_version", None
95+
):
96+
extra_cmd = extra_cmd + " -mlinker-version=" + config.darwin_linker_version
97+
9298
return " ".join(
9399
[
94100
compiler_cmd,

compiler-rt/test/lit.common.cfg.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -895,6 +895,10 @@ def is_windows_lto_supported():
895895
elif config.use_lld and (not config.has_lld):
896896
config.unsupported = True
897897

898+
if config.host_os == "Darwin":
899+
if getattr(config, "darwin_linker_version", None):
900+
extra_cflags += ["-mlinker-version=" + config.darwin_linker_version]
901+
898902
# Append any extra flags passed in lit_config
899903
append_target_cflags = lit_config.params.get("append_target_cflags", None)
900904
if append_target_cflags:

compiler-rt/test/lit.common.configured.in

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,7 @@ set_default("have_rpc_xdr_h", @HAVE_RPC_XDR_H@)
4949
set_default("gwp_asan", @COMPILER_RT_HAS_GWP_ASAN_PYBOOL@)
5050
set_default("expensive_checks", @LLVM_ENABLE_EXPENSIVE_CHECKS_PYBOOL@)
5151
set_default("test_standalone_build_libs", @COMPILER_RT_TEST_STANDALONE_BUILD_LIBS_PYBOOL@)
52+
set_default("darwin_linker_version", "@COMPILER_RT_DARWIN_LINKER_VERSION@")
5253
# True iff the test suite supports ignoring the test compiler's runtime library path
5354
# and using `config.compiler_rt_libdir` instead. This only matters when the runtime
5455
# library paths differ.

0 commit comments

Comments
 (0)