From d4dbbe4cff591122d44c3bd1af8f7f59a39e9fc4 Mon Sep 17 00:00:00 2001 From: Artem Dinaburg Date: Fri, 25 Mar 2022 23:19:53 -0400 Subject: [PATCH] Fix ASAN Builds (#921) * Do not build libcxx/libcxxabi when building llvm * Update triplets for asan flags * Remove unneeded flags for sanitizers Co-authored-by: Eric Kilmer --- ports/llvm-12/vcpkg.json | 2 -- ports/llvm-13/vcpkg.json | 2 -- triplets/arm64-osx-asan.cmake | 6 +++--- triplets/x64-linux-asan.cmake | 11 +++++++---- triplets/x64-linux-rel-asan.cmake | 6 +++--- triplets/x64-osx-asan.cmake | 6 +++--- triplets/x64-osx-rel-asan.cmake | 6 +++--- 7 files changed, 19 insertions(+), 20 deletions(-) diff --git a/ports/llvm-12/vcpkg.json b/ports/llvm-12/vcpkg.json index a6ba0516..22cafd35 100644 --- a/ports/llvm-12/vcpkg.json +++ b/ports/llvm-12/vcpkg.json @@ -20,8 +20,6 @@ "compiler-rt", "default-options", "cxx-common-targets", - "libcxx", - "libcxxabi", "mlir", "tools", "utils" diff --git a/ports/llvm-13/vcpkg.json b/ports/llvm-13/vcpkg.json index 266f8b2f..85701c46 100644 --- a/ports/llvm-13/vcpkg.json +++ b/ports/llvm-13/vcpkg.json @@ -21,8 +21,6 @@ "compiler-rt", "default-options", "cxx-common-targets", - "libcxx", - "libcxxabi", "mlir", "tools", "utils" diff --git a/triplets/arm64-osx-asan.cmake b/triplets/arm64-osx-asan.cmake index 4cf27600..e710b8e0 100644 --- a/triplets/arm64-osx-asan.cmake +++ b/triplets/arm64-osx-asan.cmake @@ -8,9 +8,9 @@ set(VCPKG_USE_SANITIZER "Address") # If the following flags cause errors during build, you might need to manually # ignore the PORT and check VCPKG_USE_SANITIZER -if(NOT PORT MATCHES "^((llvm)|(llvm-[0-9]+)|(upb))$") - set(VCPKG_CXX_FLAGS "-fsanitize=address -fno-omit-frame-pointer -fno-optimize-sibling-calls -ffunction-sections -fdata-sections") - set(VCPKG_C_FLAGS "-fsanitize=address -fno-omit-frame-pointer -fno-optimize-sibling-calls -ffunction-sections -fdata-sections") +if(NOT PORT MATCHES "^((upb))$") + set(VCPKG_CXX_FLAGS "-O1 -g -fsanitize=address -fno-omit-frame-pointer -fno-optimize-sibling-calls") + set(VCPKG_C_FLAGS "-O1 -g -fsanitize=address -fno-omit-frame-pointer -fno-optimize-sibling-calls") endif() # Always apply sanitizer to linker flags diff --git a/triplets/x64-linux-asan.cmake b/triplets/x64-linux-asan.cmake index 45f529ec..a3f1a592 100644 --- a/triplets/x64-linux-asan.cmake +++ b/triplets/x64-linux-asan.cmake @@ -5,12 +5,15 @@ set(VCPKG_LIBRARY_LINKAGE static) # ASAN # Make sure this value matches up with https://llvm.org/docs/CMake.html "LLVM_USE_SANITIZER" set(VCPKG_USE_SANITIZER "Address") + # If the following flags cause errors during build, you might need to manually # ignore the PORT and check VCPKG_USE_SANITIZER -if(NOT PORT MATCHES "^((llvm)|(llvm-[0-9]+)|(upb))$") - set(VCPKG_CXX_FLAGS "-fsanitize=address -fno-omit-frame-pointer -fno-optimize-sibling-calls -ffunction-sections -fdata-sections") - set(VCPKG_C_FLAGS "-fsanitize=address -fno-omit-frame-pointer -fno-optimize-sibling-calls -ffunction-sections -fdata-sections") - set(VCPKG_LINKER_FLAGS "-fsanitize=address") +if(NOT PORT MATCHES "^((upb))$") + set(VCPKG_CXX_FLAGS "-O1 -g -fsanitize=address -fno-omit-frame-pointer -fno-optimize-sibling-calls") + set(VCPKG_C_FLAGS "-O1 -g -fsanitize=address -fno-omit-frame-pointer -fno-optimize-sibling-calls") endif() +# Always apply sanitizer to linker flags +set(VCPKG_LINKER_FLAGS "-fsanitize=address") + set(VCPKG_CMAKE_SYSTEM_NAME Linux) diff --git a/triplets/x64-linux-rel-asan.cmake b/triplets/x64-linux-rel-asan.cmake index a27f04e8..6c1c595c 100644 --- a/triplets/x64-linux-rel-asan.cmake +++ b/triplets/x64-linux-rel-asan.cmake @@ -8,9 +8,9 @@ set(VCPKG_USE_SANITIZER "Address") # If the following flags cause errors during build, you might need to manually # ignore the PORT and check VCPKG_USE_SANITIZER -if(NOT PORT MATCHES "^((llvm)|(llvm-[0-9]+)|(upb))$") - set(VCPKG_CXX_FLAGS "-fsanitize=address -fno-omit-frame-pointer -fno-optimize-sibling-calls -ffunction-sections -fdata-sections") - set(VCPKG_C_FLAGS "-fsanitize=address -fno-omit-frame-pointer -fno-optimize-sibling-calls -ffunction-sections -fdata-sections") +if(NOT PORT MATCHES "^((upb))$") + set(VCPKG_CXX_FLAGS "-fsanitize=address -g -fno-omit-frame-pointer -fno-optimize-sibling-calls") + set(VCPKG_C_FLAGS "-fsanitize=address -g -fno-omit-frame-pointer -fno-optimize-sibling-calls") endif() # Always apply sanitizer to linker flags diff --git a/triplets/x64-osx-asan.cmake b/triplets/x64-osx-asan.cmake index 504fbdb9..7d6314c0 100644 --- a/triplets/x64-osx-asan.cmake +++ b/triplets/x64-osx-asan.cmake @@ -8,9 +8,9 @@ set(VCPKG_USE_SANITIZER "Address") # If the following flags cause errors during build, you might need to manually # ignore the PORT and check VCPKG_USE_SANITIZER -if(NOT PORT MATCHES "^((llvm)|(llvm-[0-9]+)|(upb))$") - set(VCPKG_CXX_FLAGS "-fsanitize=address -fno-omit-frame-pointer -fno-optimize-sibling-calls -ffunction-sections -fdata-sections") - set(VCPKG_C_FLAGS "-fsanitize=address -fno-omit-frame-pointer -fno-optimize-sibling-calls -ffunction-sections -fdata-sections") +if(NOT PORT MATCHES "^((upb))$") + set(VCPKG_CXX_FLAGS "-O1 -g -fsanitize=address -fno-omit-frame-pointer -fno-optimize-sibling-calls") + set(VCPKG_C_FLAGS "-O1 -g -fsanitize=address -fno-omit-frame-pointer -fno-optimize-sibling-calls") set(VCPKG_LINKER_FLAGS "-fsanitize=address") endif() diff --git a/triplets/x64-osx-rel-asan.cmake b/triplets/x64-osx-rel-asan.cmake index 3e6bb039..1117f946 100644 --- a/triplets/x64-osx-rel-asan.cmake +++ b/triplets/x64-osx-rel-asan.cmake @@ -9,9 +9,9 @@ set(VCPKG_USE_SANITIZER "Address") # If the following flags cause errors during build, you might need to manually # ignore the PORT and check VCPKG_USE_SANITIZER -if(NOT PORT MATCHES "^((llvm)|(llvm-[0-9]+)|(upb))$") - set(VCPKG_CXX_FLAGS "-fsanitize=address -fno-omit-frame-pointer -fno-optimize-sibling-calls -ffunction-sections -fdata-sections") - set(VCPKG_C_FLAGS "-fsanitize=address -fno-omit-frame-pointer -fno-optimize-sibling-calls -ffunction-sections -fdata-sections") +if(NOT PORT MATCHES "^((upb))$") + set(VCPKG_CXX_FLAGS "-fsanitize=address -g -fno-omit-frame-pointer -fno-optimize-sibling-calls") + set(VCPKG_C_FLAGS "-fsanitize=address -g -fno-omit-frame-pointer -fno-optimize-sibling-calls") endif() # Always apply sanitizer to linker flags