From: Otto Moerbeek Date: Mon, 5 Jan 2026 15:05:09 +0000 (+0100) Subject: Move common sanitizer preprocessor handling to separate file X-Git-Tag: rec-5.4.0-beta1~53^2~1 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=3c32a98edd4e045898814f7d1e8273c9ac5d3f40;p=thirdparty%2Fpdns.git Move common sanitizer preprocessor handling to separate file Signed-off-by: Otto Moerbeek --- diff --git a/pdns/channel.hh b/pdns/channel.hh index 33a554af3a..4263a0af46 100644 --- a/pdns/channel.hh +++ b/pdns/channel.hh @@ -24,29 +24,7 @@ #include #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() -#include -#else /* __has_include() */ -extern "C" void __tsan_acquire(void* addr); -extern "C" void __tsan_release(void* addr); -#endif /* __has_include() */ -#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 { diff --git a/pdns/dnsdistdist/Makefile.am b/pdns/dnsdistdist/Makefile.am index 72fc709c65..f5e03c69f7 100644 --- a/pdns/dnsdistdist/Makefile.am +++ b/pdns/dnsdistdist/Makefile.am @@ -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 \ diff --git a/pdns/dnsdistdist/dnsdist.cc b/pdns/dnsdistdist/dnsdist.cc index 4e85d911b0..2c0c9f76db 100644 --- a/pdns/dnsdistdist/dnsdist.cc +++ b/pdns/dnsdistdist/dnsdist.cc @@ -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 diff --git a/pdns/dnsdistdist/sanitizer.hh b/pdns/dnsdistdist/sanitizer.hh new file mode 120000 index 0000000000..d0c0a5ea5f --- /dev/null +++ b/pdns/dnsdistdist/sanitizer.hh @@ -0,0 +1 @@ +../sanitizer.hh \ No newline at end of file diff --git a/pdns/recursordist/Makefile.am b/pdns/recursordist/Makefile.am index e5873bc74e..cdad1c619d 100644 --- a/pdns/recursordist/Makefile.am +++ b/pdns/recursordist/Makefile.am @@ -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 \ diff --git a/pdns/recursordist/rec-main.cc b/pdns/recursordist/rec-main.cc index ca87efa36e..b7e3137568 100644 --- a/pdns/recursordist/rec-main.cc +++ b/pdns/recursordist/rec-main.cc @@ -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() -#include -#else /* __has_include() */ -extern "C" void __tsan_acquire(void* addr); -extern "C" void __tsan_release(void* addr); -#endif /* __has_include() */ -#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 diff --git a/pdns/recursordist/rec_channel.cc b/pdns/recursordist/rec_channel.cc index 136e20d31e..6e19c7311f 100644 --- a/pdns/recursordist/rec_channel.cc +++ b/pdns/recursordist/rec_channel.cc @@ -34,18 +34,7 @@ #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 RecursorControlChannel::stop = false; diff --git a/pdns/recursordist/rec_channel_rec.cc b/pdns/recursordist/rec_channel_rec.cc index 5be4e6d006..8d9505101a 100644 --- a/pdns/recursordist/rec_channel_rec.cc +++ b/pdns/recursordist/rec_channel_rec.cc @@ -63,18 +63,7 @@ #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 diff --git a/pdns/recursordist/sanitizer.hh b/pdns/recursordist/sanitizer.hh new file mode 120000 index 0000000000..d0c0a5ea5f --- /dev/null +++ b/pdns/recursordist/sanitizer.hh @@ -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 index 0000000000..416415ec52 --- /dev/null +++ b/pdns/sanitizer.hh @@ -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() +#include +#else /* __has_include() */ +extern "C" void __tsan_acquire(void* addr); +extern "C" void __tsan_release(void* addr); +#endif /* __has_include() */ +#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__ */