From 4a63d62f686546f5d7329a5e48def09ba817e42a Mon Sep 17 00:00:00 2001 From: Nico Weber Date: Thu, 30 May 2024 15:05:20 -0400 Subject: [PATCH] [gn] attempt to port 53a81d4d26f0 (win/asan dynamic runtime) Based on the output of llvm/utils/gn/build/sync_source_lists_from_cmake.py and reading the diff, but not actually tested on Windows. --- .../secondary/compiler-rt/lib/asan/BUILD.gn | 30 +++++++-------- .../compiler-rt/lib/sanitizer_common/BUILD.gn | 38 +++++++++---------- .../secondary/compiler-rt/lib/ubsan/BUILD.gn | 23 +++-------- 3 files changed, 37 insertions(+), 54 deletions(-) diff --git a/llvm/utils/gn/secondary/compiler-rt/lib/asan/BUILD.gn b/llvm/utils/gn/secondary/compiler-rt/lib/asan/BUILD.gn index 2bd940581913e6..c4d7c2f08e6353 100644 --- a/llvm/utils/gn/secondary/compiler-rt/lib/asan/BUILD.gn +++ b/llvm/utils/gn/secondary/compiler-rt/lib/asan/BUILD.gn @@ -154,13 +154,6 @@ if (current_toolchain == host_toolchain) { sources = [ "asan_preinit.cpp" ] } - source_set("weak_interception") { - configs -= [ "//llvm/utils/gn/build:llvm_code" ] - configs += [ "//llvm/utils/gn/build:crt_code" ] - sources = [ "asan_win_weak_interception.cpp" ] - defines = [ "SANITIZER_DYNAMIC" ] - } - shared_library("asan_shared_library") { output_dir = crt_current_out_dir if (current_os == "mac") { @@ -242,22 +235,25 @@ if (current_toolchain == host_toolchain) { } } if (current_os == "win") { - static_library("asan_dll_thunk") { + static_library("asan_static_runtime_thunk") { output_dir = crt_current_out_dir - output_name = "clang_rt.asan_dll_thunk$crt_current_target_suffix" + output_name = "clang_rt.asan_static_runtime_thunk$crt_current_target_suffix" configs -= [ "//llvm/utils/gn/build:llvm_code" ] configs += [ "//llvm/utils/gn/build:crt_code" ] complete_static_lib = true configs -= [ "//llvm/utils/gn/build:thin_archive" ] sources = [ "asan_globals_win.cpp", - "asan_win_dll_thunk.cpp", + "asan_malloc_win_thunk.cpp", + "asan_win_common_runtime_thunk.cpp", + "asan_win_static_runtime_thunk.cpp", ] - defines = [ "SANITIZER_DLL_THUNK" ] + defines = [ "SANITIZER_STATIC_RUNTIME_THUNK" ] deps = [ "//compiler-rt/lib/interception:sources", - "//compiler-rt/lib/sanitizer_common:dll_thunk", - "//compiler-rt/lib/ubsan:dll_thunk", + "//compiler-rt/lib/sanitizer_common:runtime_thunk", + "//compiler-rt/lib/sanitizer_common:sancov_runtime_thunk", + "//compiler-rt/lib/ubsan:runtime_thunk", ] } static_library("asan_dynamic_runtime_thunk") { @@ -270,12 +266,14 @@ if (current_toolchain == host_toolchain) { configs -= [ "//llvm/utils/gn/build:thin_archive" ] sources = [ "asan_globals_win.cpp", + "asan_win_common_runtime_thunk.cpp", "asan_win_dynamic_runtime_thunk.cpp", ] defines = [ "SANITIZER_DYNAMIC_RUNTIME_THUNK" ] deps = [ - "//compiler-rt/lib/sanitizer_common:dynamic_runtime_thunk", - "//compiler-rt/lib/ubsan:dynamic_runtime_thunk", + "//compiler-rt/lib/sanitizer_common:runtime_thunk", + "//compiler-rt/lib/sanitizer_common:sancov_runtime_thunk", + "//compiler-rt/lib/ubsan:runtime_thunk", ] cflags = [ "-Zl" ] } @@ -284,7 +282,7 @@ if (current_toolchain == host_toolchain) { deps = [ ":asan_shared_library" ] if (current_os == "win") { deps += [ - ":asan_dll_thunk", + ":asan_static_runtime_thunk", ":asan_dynamic_runtime_thunk", ] } diff --git a/llvm/utils/gn/secondary/compiler-rt/lib/sanitizer_common/BUILD.gn b/llvm/utils/gn/secondary/compiler-rt/lib/sanitizer_common/BUILD.gn index f7f1fce10bf5f5..450c419d25fe88 100644 --- a/llvm/utils/gn/secondary/compiler-rt/lib/sanitizer_common/BUILD.gn +++ b/llvm/utils/gn/secondary/compiler-rt/lib/sanitizer_common/BUILD.gn @@ -167,42 +167,38 @@ source_set("sources") { "sanitizer_vector.h", "sanitizer_win.cpp", "sanitizer_win.h", + "sanitizer_win_interception.cpp", + "sanitizer_win_interception.h", "sanitizer_win_defs.h", - "sanitizer_win_dll_thunk.h", - "sanitizer_win_weak_interception.h", + "sanitizer_win_thunk_interception.h", ] } -source_set("weak_interception") { +source_set("runtime_thunk") { configs -= [ "//llvm/utils/gn/build:llvm_code" ] configs += [ "//llvm/utils/gn/build:crt_code" ] - sources = [ - "sanitizer_coverage_win_weak_interception.cpp", - "sanitizer_win_weak_interception.cpp", + sources = [ "sanitizer_win_thunk_interception.cpp" ] + defines = [ + "SANITIZER_DYNAMIC_RUNTIME_THUNK", + "SANITIZER_STATIC_RUNTIME_THUNK", ] - defines = [ "SANITIZER_DYNAMIC" ] + cflags = [] + if (current_os == "win") { + cflags += [ "-Zl" ] + } } -source_set("dll_thunk") { +source_set("sancov_runtime_thunk") { configs -= [ "//llvm/utils/gn/build:llvm_code" ] configs += [ "//llvm/utils/gn/build:crt_code" ] sources = [ - "sanitizer_coverage_win_dll_thunk.cpp", + "sanitizer_coverage_win_runtime_thunk.cpp", "sanitizer_coverage_win_sections.cpp", - "sanitizer_win_dll_thunk.cpp", ] - defines = [ "SANITIZER_DLL_THUNK" ] -} - -source_set("dynamic_runtime_thunk") { - configs -= [ "//llvm/utils/gn/build:llvm_code" ] - configs += [ "//llvm/utils/gn/build:crt_code" ] - sources = [ - "sanitizer_coverage_win_dynamic_runtime_thunk.cpp", - "sanitizer_coverage_win_sections.cpp", - "sanitizer_win_dynamic_runtime_thunk.cpp", + defines = [ + "SANITIZER_DYNAMIC_RUNTIME_THUNK", + "SANITIZER_STATIC_RUNTIME_THUNK", ] - defines = [ "SANITIZER_DYNAMIC_RUNTIME_THUNK" ] cflags = [] if (current_os == "win") { cflags += [ "-Zl" ] diff --git a/llvm/utils/gn/secondary/compiler-rt/lib/ubsan/BUILD.gn b/llvm/utils/gn/secondary/compiler-rt/lib/ubsan/BUILD.gn index 230de4750d4f95..d3b4a406f8b50d 100644 --- a/llvm/utils/gn/secondary/compiler-rt/lib/ubsan/BUILD.gn +++ b/llvm/utils/gn/secondary/compiler-rt/lib/ubsan/BUILD.gn @@ -51,25 +51,14 @@ source_set("sources") { ] } -source_set("weak_interception") { +source_set("runtime_thunk") { configs -= [ "//llvm/utils/gn/build:llvm_code" ] configs += [ "//llvm/utils/gn/build:crt_code" ] - sources = [ "ubsan_win_weak_interception.cpp" ] - defines = [ "SANITIZER_DYNAMIC" ] -} - -source_set("dll_thunk") { - configs -= [ "//llvm/utils/gn/build:llvm_code" ] - configs += [ "//llvm/utils/gn/build:crt_code" ] - sources = [ "ubsan_win_dll_thunk.cpp" ] - defines = [ "SANITIZER_DLL_THUNK" ] -} - -source_set("dynamic_runtime_thunk") { - configs -= [ "//llvm/utils/gn/build:llvm_code" ] - configs += [ "//llvm/utils/gn/build:crt_code" ] - defines = [ "SANITIZER_DYNAMIC_RUNTIME_THUNK" ] - sources = [ "ubsan_win_dynamic_runtime_thunk.cpp" ] + sources = [ "ubsan_win_runtime_thunk.cpp" ] + defines = [ + "SANITIZER_DYNAMIC_RUNTIME_THUNK", + "SANITIZER_STATIC_RUNTIME_THUNK", + ] } source_set("standalone_sources") {