From 08bbdf171a17e6d10852b129645ae75cd6c0cc22 Mon Sep 17 00:00:00 2001 From: Zhengyu Gu Date: Fri, 29 May 2026 21:14:14 +0000 Subject: [PATCH 1/2] Fix duplicated cookies --- ddprof-lib/src/main/cpp/signalCookie.cpp | 17 +++++++++++++++++ ddprof-lib/src/main/cpp/signalCookie.h | 15 ++------------- 2 files changed, 19 insertions(+), 13 deletions(-) create mode 100644 ddprof-lib/src/main/cpp/signalCookie.cpp diff --git a/ddprof-lib/src/main/cpp/signalCookie.cpp b/ddprof-lib/src/main/cpp/signalCookie.cpp new file mode 100644 index 000000000..8536270b2 --- /dev/null +++ b/ddprof-lib/src/main/cpp/signalCookie.cpp @@ -0,0 +1,17 @@ +#include "signalCookie.h" + +namespace SignalCookie { + namespace detail { + // Place tags in a named section on Linux to prevent LTO from merging + // or reordering them across TUs (their addresses must be unique per DSO). +#ifdef __linux__ + [[gnu::section(".data.signal_cookie")]] char cpu_tag; + [[gnu::section(".data.signal_cookie")]] char wallclock_tag; +#else + char cpu_tag; + char wallclock_tag; +#endif + } + void* cpu() { return &detail::cpu_tag; } + void* wallclock() { return &detail::wallclock_tag; } +} diff --git a/ddprof-lib/src/main/cpp/signalCookie.h b/ddprof-lib/src/main/cpp/signalCookie.h index c448680fa..8744307b0 100644 --- a/ddprof-lib/src/main/cpp/signalCookie.h +++ b/ddprof-lib/src/main/cpp/signalCookie.h @@ -21,19 +21,8 @@ // forged by an unrelated in-process sender without reading our symbols, and // never collide with legitimate user-space pointers in third-party code. namespace SignalCookie { - namespace detail { - // Place tags in a named section on Linux to prevent LTO from merging - // or reordering them across TUs (their addresses must be unique per DSO). -#ifdef __linux__ - [[gnu::section(".data.signal_cookie")]] inline char cpu_tag; - [[gnu::section(".data.signal_cookie")]] inline char wallclock_tag; -#else - inline char cpu_tag; - inline char wallclock_tag; -#endif - } - inline void* cpu() { return &detail::cpu_tag; } - inline void* wallclock() { return &detail::wallclock_tag; } + void* cpu(); + void* wallclock(); } #endif // SIGNAL_COOKIE_H From eee6fe81df705f1afc1af176f5327e012b452b5c Mon Sep 17 00:00:00 2001 From: Zhengyu Gu Date: Sun, 31 May 2026 18:11:57 +0000 Subject: [PATCH 2/2] Add copyright to new file --- ddprof-lib/src/main/cpp/signalCookie.cpp | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/ddprof-lib/src/main/cpp/signalCookie.cpp b/ddprof-lib/src/main/cpp/signalCookie.cpp index 8536270b2..7c2688248 100644 --- a/ddprof-lib/src/main/cpp/signalCookie.cpp +++ b/ddprof-lib/src/main/cpp/signalCookie.cpp @@ -1,3 +1,8 @@ +/* + * Copyright 2026, Datadog, Inc. + * SPDX-License-Identifier: Apache-2.0 + */ + #include "signalCookie.h" namespace SignalCookie {