]> git.ipfire.org Git - thirdparty/pdns.git/commitdiff
Move common sanitizer preprocessor handling to separate file
authorOtto Moerbeek <otto.moerbeek@open-xchange.com>
Mon, 5 Jan 2026 15:05:09 +0000 (16:05 +0100)
committerOtto Moerbeek <otto.moerbeek@open-xchange.com>
Mon, 5 Jan 2026 15:12:39 +0000 (16:12 +0100)
Signed-off-by: Otto Moerbeek <otto.moerbeek@open-xchange.com>
pdns/channel.hh
pdns/dnsdistdist/Makefile.am
pdns/dnsdistdist/dnsdist.cc
pdns/dnsdistdist/sanitizer.hh [new symlink]
pdns/recursordist/Makefile.am
pdns/recursordist/rec-main.cc
pdns/recursordist/rec_channel.cc
pdns/recursordist/rec_channel_rec.cc
pdns/recursordist/sanitizer.hh [new symlink]
pdns/sanitizer.hh [new file with mode: 0644]

index 33a554af3ad06af85504a6c6e2d135be79773e83..4263a0af46511d9730fab4fc34e72aab67a9e478 100644 (file)
 #include <optional>
 
 #include "misc.hh"
-
-/* g++ defines __SANITIZE_THREAD__
-   clang++ supports the nice __has_feature(thread_sanitizer),
-   let's merge them */
-#if defined(__has_feature)
-#if __has_feature(thread_sanitizer)
-#define __SANITIZE_THREAD__ 1
-#endif
-#endif
-
-#if __SANITIZE_THREAD__
-#if defined __has_include
-#if __has_include(<sanitizer/tsan_interface.h>)
-#include <sanitizer/tsan_interface.h>
-#else /* __has_include(<sanitizer/tsan_interface.h>) */
-extern "C" void __tsan_acquire(void* addr);
-extern "C" void __tsan_release(void* addr);
-#endif /* __has_include(<sanitizer/tsan_interface.h>) */
-#else /* defined __has_include */
-extern "C" void __tsan_acquire(void* addr);
-extern "C" void __tsan_release(void* addr);
-#endif /* defined __has_include */
-#endif /* __SANITIZE_THREAD__ */
+#include "sanitizer.hh"
 
 namespace pdns
 {
index 72fc709c65b02f9da392d6ef83d0443643576db6..f5e03c69f7ea7995b0de0057caf0aae0df29e6c6 100644 (file)
@@ -297,6 +297,7 @@ dnsdist_SOURCES = \
        qtype.cc qtype.hh \
        remote_logger.cc remote_logger.hh \
        remote_logger_pool.cc remote_logger_pool.hh \
+       sanitizer.hh \
        sholder.hh \
        snmp-agent.cc snmp-agent.hh \
        sstuff.hh \
index 4e85d911b029b1cd560e95b04932f6a8ab3873f2..2c0c9f76dbba451983f406cc946dfa84f109146e 100644 (file)
@@ -2921,17 +2921,7 @@ static void usage()
   cout << "-V,--version          Show dnsdist version information and exit\n";
 }
 
-/* g++ defines __SANITIZE_THREAD__
-   clang++ supports the nice __has_feature(thread_sanitizer),
-   let's merge them */
-#if defined(__has_feature)
-#if __has_feature(thread_sanitizer)
-#define __SANITIZE_THREAD__ 1
-#endif
-#if __has_feature(address_sanitizer)
-#define __SANITIZE_ADDRESS__ 1
-#endif
-#endif
+#include "sanitizer.hh"
 
 #if defined(__SANITIZE_ADDRESS__) && defined(HAVE_LEAK_SANITIZER_INTERFACE)
 #include <sanitizer/lsan_interface.h>
diff --git a/pdns/dnsdistdist/sanitizer.hh b/pdns/dnsdistdist/sanitizer.hh
new file mode 120000 (symlink)
index 0000000..d0c0a5e
--- /dev/null
@@ -0,0 +1 @@
+../sanitizer.hh
\ No newline at end of file
index e5873bc74e6049a6299f61d8db43d29b159a574e..cdad1c619d246ad5630ccd517867ae469d01f71c 100644 (file)
@@ -214,6 +214,7 @@ pdns_recursor_SOURCES = \
        root-addresses.hh \
        root-dnssec.hh \
        rpzloader.cc rpzloader.hh \
+       sanitizer.hh \
        secpoll-recursor.cc secpoll-recursor.hh \
        secpoll.cc secpoll.hh \
        sha.hh \
index ca87efa36ecff0003e1a65c0c0c39ab94cb35c97..b7e3137568eed189c733a127830720fc6fbaa4a7 100644 (file)
@@ -69,34 +69,7 @@ thread_local FrameStreamServersInfo t_frameStreamServersInfo;
 thread_local FrameStreamServersInfo t_nodFrameStreamServersInfo;
 #endif /* HAVE_FSTRM */
 
-/* g++ defines __SANITIZE_THREAD__
-   clang++ supports the nice __has_feature(thread_sanitizer),
-   let's merge them */
-#if defined(__has_feature)
-#if __has_feature(thread_sanitizer)
-#define __SANITIZE_THREAD__ 1
-#endif
-#if __has_feature(address_sanitizer)
-#define __SANITIZE_ADDRESS__ 1
-#endif
-#endif
-
-#if __SANITIZE_THREAD__
-#if defined __has_include
-#if __has_include(<sanitizer/tsan_interface.h>)
-#include <sanitizer/tsan_interface.h>
-#else /* __has_include(<sanitizer/tsan_interface.h>) */
-extern "C" void __tsan_acquire(void* addr);
-extern "C" void __tsan_release(void* addr);
-#endif /* __has_include(<sanitizer/tsan_interface.h>) */
-#else /* defined __has_include */
-extern "C" void __tsan_acquire(void* addr);
-extern "C" void __tsan_release(void* addr);
-#endif /* defined __has_include */
-#else
-#define __tsan_acquire(x)
-#define __tsan_release(x)
-#endif /* __SANITIZE_THREAD__ */
+#include "sanitizer.hh"
 
 string g_programname = "pdns_recursor";
 string g_pidfname;
@@ -1525,7 +1498,7 @@ void broadcastFunction(const pipefunc_t& func)
     tmsg->func = func;
     tmsg->wantAnswer = true;
 
-      __tsan_release(tmsg);
+    __tsan_release(tmsg);
 
     if (write(threadInfo.getPipes().writeToThread, &tmsg, sizeof(tmsg)) != sizeof(tmsg)) { // NOLINT: sizeof correct
 
@@ -2385,7 +2358,7 @@ static void handlePipeRequest(int fileDesc, FDMultiplexer::funcparam_t& /* var *
     unixDie("read from thread pipe returned wrong size or error");
   }
 
-   __tsan_acquire(tmsg);
+  __tsan_acquire(tmsg);
 
   void* resp = nullptr;
   try {
@@ -2407,7 +2380,7 @@ static void handlePipeRequest(int fileDesc, FDMultiplexer::funcparam_t& /* var *
   }
   if (tmsg->wantAnswer) {
 
-   __tsan_release(resp);
+    __tsan_release(resp);
 
     if (write(RecThreadInfo::self().getPipes().writeFromThread, &resp, sizeof(resp)) != sizeof(resp)) {
       delete tmsg; // NOLINT: manual ownership handling
index 136e20d31e7321878a426e026fddf9bb070963a1..6e19c7311fc266fee66fbf055c055ecec3649a49 100644 (file)
 #include "misc.hh"
 #include "namespaces.hh"
 #include "pdnsexception.hh"
-
-/* g++ defines __SANITIZE_THREAD__
-   clang++ supports the nice __has_feature(thread_sanitizer),
-   let's merge them */
-#if defined(__has_feature)
-#if __has_feature(thread_sanitizer)
-#define __SANITIZE_THREAD__ 1
-#endif
-#if __has_feature(address_sanitizer)
-#define __SANITIZE_ADDRESS__ 1
-#endif
-#endif
+#include "sanitizer.hh"
 
 std::atomic<bool> RecursorControlChannel::stop = false;
 
index 5be4e6d0067275a709ba10582577fb052d54a4ae..8d9505101a75de2ca99c4fc8cd3f013af8846129 100644 (file)
 #include "rec-system-resolve.hh"
 
 #include "rec-rust-lib/cxxsettings.hh"
-
-/* g++ defines __SANITIZE_THREAD__
-   clang++ supports the nice __has_feature(thread_sanitizer),
-   let's merge them */
-#if defined(__has_feature)
-#if __has_feature(thread_sanitizer)
-#define __SANITIZE_THREAD__ 1
-#endif
-#if __has_feature(address_sanitizer)
-#define __SANITIZE_ADDRESS__ 1
-#endif
-#endif
+#include "sanitizer.hh"
 
 #if defined(__SANITIZE_ADDRESS__) && defined(HAVE_LEAK_SANITIZER_INTERFACE)
 #include <sanitizer/lsan_interface.h>
diff --git a/pdns/recursordist/sanitizer.hh b/pdns/recursordist/sanitizer.hh
new file mode 120000 (symlink)
index 0000000..d0c0a5e
--- /dev/null
@@ -0,0 +1 @@
+../sanitizer.hh
\ No newline at end of file
diff --git a/pdns/sanitizer.hh b/pdns/sanitizer.hh
new file mode 100644 (file)
index 0000000..416415e
--- /dev/null
@@ -0,0 +1,51 @@
+/*
+ * This file is part of PowerDNS or dnsdist.
+ * Copyright -- PowerDNS.COM B.V. and its contributors
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of version 2 of the GNU General Public License as
+ * published by the Free Software Foundation.
+ *
+ * In addition, for the avoidance of any doubt, permission is granted to
+ * link this program with OpenSSL and to (re)distribute the binaries
+ * produced as the result of such linking.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
+ */
+#pragma once
+
+/* g++ defines __SANITIZE_THREAD__
+   clang++ supports the nice __has_feature(thread_sanitizer),
+   let's merge them */
+#if defined(__has_feature)
+#if __has_feature(thread_sanitizer)
+#define __SANITIZE_THREAD__ 1
+#endif
+#if __has_feature(address_sanitizer)
+#define __SANITIZE_ADDRESS__ 1
+#endif
+#endif
+
+#if __SANITIZE_THREAD__
+#if defined __has_include
+#if __has_include(<sanitizer/tsan_interface.h>)
+#include <sanitizer/tsan_interface.h>
+#else /* __has_include(<sanitizer/tsan_interface.h>) */
+extern "C" void __tsan_acquire(void* addr);
+extern "C" void __tsan_release(void* addr);
+#endif /* __has_include(<sanitizer/tsan_interface.h>) */
+#else /* defined __has_include */
+extern "C" void __tsan_acquire(void* addr);
+extern "C" void __tsan_release(void* addr);
+#endif /* defined __has_include */
+#else
+#define __tsan_acquire(x)
+#define __tsan_release(x)
+#endif /* __SANITIZE_THREAD__ */