8d419f
From e5ecc772a0bb0813cdcf0a24f48ba3278da6e276 Mon Sep 17 00:00:00 2001
8d419f
From: Frantisek Sumsal <frantisek@sumsal.cz>
8d419f
Date: Wed, 15 Jun 2022 19:43:11 +0200
8d419f
Subject: [PATCH] test: don't wrap binaries built with ASan
8d419f
8d419f
since they should handle loading other instrumented libraries without
8d419f
issues.
8d419f
8d419f
(cherry picked from commit b727d7e02d6c88476ae9e46211e1f9c24720d5c3)
8d419f
8d419f
Related: #2087652
8d419f
---
8d419f
 test/test-functions | 10 +++++++---
8d419f
 1 file changed, 7 insertions(+), 3 deletions(-)
8d419f
8d419f
diff --git a/test/test-functions b/test/test-functions
8d419f
index f55e64493d..57d4df3e7e 100644
8d419f
--- a/test/test-functions
8d419f
+++ b/test/test-functions
8d419f
@@ -228,6 +228,8 @@ DEBUGTOOLS=(
8d419f
 )
8d419f
 
8d419f
 is_built_with_asan() {
8d419f
+    local _bin="${1:?}"
8d419f
+
8d419f
     if ! type -P objdump >/dev/null; then
8d419f
         ddebug "Failed to find objdump. Assuming systemd hasn't been built with ASAN."
8d419f
         return 1
8d419f
@@ -235,7 +237,7 @@ is_built_with_asan() {
8d419f
 
8d419f
     # Borrowed from https://github.com/google/oss-fuzz/blob/cd9acd02f9d3f6e80011cc1e9549be526ce5f270/infra/base-images/base-runner/bad_build_check#L182
8d419f
     local _asan_calls
8d419f
-    _asan_calls="$(objdump -dC "$SYSTEMD_JOURNALD" | grep -E "(callq?|brasl?|bl)\s.+__asan" -c)"
8d419f
+    _asan_calls="$(objdump -dC "$_bin" | grep -E "(callq?|brasl?|bl)\s.+__asan" -c)"
8d419f
     if ((_asan_calls < 1000)); then
8d419f
         return 1
8d419f
     else
8d419f
@@ -251,7 +253,7 @@ is_built_with_coverage() {
8d419f
     meson configure "${BUILD_DIR:?}" | grep 'b_coverage' | awk '{ print $2 }' | grep -q 'true'
8d419f
 }
8d419f
 
8d419f
-IS_BUILT_WITH_ASAN=$(is_built_with_asan && echo yes || echo no)
8d419f
+IS_BUILT_WITH_ASAN=$(is_built_with_asan "$SYSTEMD_JOURNALD" && echo yes || echo no)
8d419f
 IS_BUILT_WITH_COVERAGE=$(is_built_with_coverage && echo yes || echo no)
8d419f
 
8d419f
 if get_bool "$IS_BUILT_WITH_ASAN"; then
8d419f
@@ -2415,7 +2417,9 @@ inst_binary() {
8d419f
         wrap_binary=1
8d419f
     fi
8d419f
 
8d419f
-    if get_bool "$wrap_binary"; then
8d419f
+    # If the target binary is built with ASan support, we don't need to wrap
8d419f
+    # it, as it should handle everything by itself
8d419f
+    if get_bool "$wrap_binary" && ! is_built_with_asan "$bin"; then
8d419f
         dinfo "Creating ASan-compatible wrapper for binary '$target'"
8d419f
         # Install the target binary with a ".orig" suffix
8d419f
         inst_simple "$bin" "${target}.orig"