diff --git a/llvm/utils/gn/build/BUILD.gn b/llvm/utils/gn/build/BUILD.gn --- a/llvm/utils/gn/build/BUILD.gn +++ b/llvm/utils/gn/build/BUILD.gn @@ -370,6 +370,14 @@ cflags_objcc = cflags_cc } +config("zdefs") { + # -Wl,-z,defs doesn't work with sanitizers. + # https://clang.llvm.org/docs/AddressSanitizer.html + if (current_os != "ios" && current_os != "mac" && current_os != "win" && !(use_asan || use_tsan || use_ubsan)) { + ldflags = [ "-Wl,-z,defs" ] + } +} + # To make an archive that can be distributed, you need to remove this config and # set complete_static_lib. config("thin_archive") { diff --git a/llvm/utils/gn/build/BUILDCONFIG.gn b/llvm/utils/gn/build/BUILDCONFIG.gn --- a/llvm/utils/gn/build/BUILDCONFIG.gn +++ b/llvm/utils/gn/build/BUILDCONFIG.gn @@ -22,7 +22,7 @@ configs = shared_binary_target_configs } set_defaults("shared_library") { - configs = shared_binary_target_configs + configs = shared_binary_target_configs + [ "//llvm/utils/gn/build:zdefs" ] } set_defaults("source_set") { configs = shared_binary_target_configs diff --git a/llvm/utils/gn/build/toolchain/BUILD.gn b/llvm/utils/gn/build/toolchain/BUILD.gn --- a/llvm/utils/gn/build/toolchain/BUILD.gn +++ b/llvm/utils/gn/build/toolchain/BUILD.gn @@ -109,7 +109,7 @@ command = "$ld -shared {{ldflags}} -o $outfile {{inputs}} {{libs}} {{frameworks}}" default_output_extension = ".dylib" } else { - command = "$ld -shared {{ldflags}} -Wl,-z,defs -Wl,-soname,{{target_output_name}}{{output_extension}} -o $outfile {{inputs}} {{libs}}" + command = "$ld -shared {{ldflags}} -Wl,-soname,{{target_output_name}}{{output_extension}} -o $outfile {{inputs}} {{libs}}" default_output_extension = ".so" } description = "SOLINK $outfile"