From c8ae65d626558b0eab8ee5f629c6c6a0bd376bb2 Mon Sep 17 00:00:00 2001 From: Stefano Bonicatti Date: Mon, 9 Sep 2024 18:45:00 +0200 Subject: [PATCH] build: Cleanups and fixes for a newer clang toolchain (#8412) - Force the use of the DWARF debug symbols version 4, since only very recent versions of gdb support any version higher than that and on newer clang versions, 5 is the default. - Correct the secure_getenv check; GLIBC 2.17 is the first version that adds supports for it, so it should be included - Move the selection of the standard library implementation and corollary library on Linux to be a toolchain specific setting, making it slightly easier to build with a different toolchain. --- cmake/flags.cmake | 3 --- cmake/toolchain.cmake | 3 +++ osquery/tables/system/linux/rpm_packages.cpp | 2 +- 3 files changed, 4 insertions(+), 4 deletions(-) diff --git a/cmake/flags.cmake b/cmake/flags.cmake index 29b531c7c51..d295cad104e 100644 --- a/cmake/flags.cmake +++ b/cmake/flags.cmake @@ -84,11 +84,9 @@ function(setupBuildFlags) -Woverloaded-virtual -Wnon-virtual-dtor -Weffc++ - -stdlib=libc++ ) set(posix_cxx_link_options - -stdlib=libc++ -ldl ) @@ -179,7 +177,6 @@ function(setupBuildFlags) ) set(linux_cxx_link_libraries - c++abi.a rt dl ) diff --git a/cmake/toolchain.cmake b/cmake/toolchain.cmake index 9bafb128d4e..a6c25e2d2d6 100644 --- a/cmake/toolchain.cmake +++ b/cmake/toolchain.cmake @@ -8,6 +8,9 @@ if(OSQUERY_TOOLCHAIN_SYSROOT) overwrite_cache_variable("CMAKE_CXX_LINK_PIE_SUPPORTED" "INTERNAL" "TRUE") overwrite_cache_variable("CMAKE_C_LINK_NO_PIE_SUPPORTED" "INTERNAL" "TRUE") overwrite_cache_variable("CMAKE_C_LINK_PIE_SUPPORTED" "INTERNAL" "TRUE") + overwrite_cache_variable("CMAKE_CXX_FLAGS_INIT" "STRING" "-stdlib=libc++ -gdwarf-4") + overwrite_cache_variable("CMAKE_C_FLAGS_INIT" "STRING" "-gdwarf-4") + overwrite_cache_variable("CMAKE_EXE_LINKER_FLAGS" "STRING" "-stdlib=libc++ -lc++abi") else() option(OSQUERY_STATIC_BUILD "Whether to prefer linking static libraries or not") diff --git a/osquery/tables/system/linux/rpm_packages.cpp b/osquery/tables/system/linux/rpm_packages.cpp index effb3b773e8..287c9167b4f 100644 --- a/osquery/tables/system/linux/rpm_packages.cpp +++ b/osquery/tables/system/linux/rpm_packages.cpp @@ -26,7 +26,7 @@ #include // librpm may be configured and compiled with glibc < 2.17. -#if defined(__GLIBC__) && __GLIBC_MINOR__ > 17 +#if defined(__GLIBC__) && __GLIBC_MINOR__ >= 17 extern "C" char* __secure_getenv(const char* _s) __attribute__((weak)); extern "C" char* __secure_getenv(const char* _s) { return secure_getenv(_s);