Skip to content

Commit 2fa032f

Browse files
authored
Fix duplicated cookies (#564)
1 parent 33ba000 commit 2fa032f

2 files changed

Lines changed: 24 additions & 13 deletions

File tree

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
/*
2+
* Copyright 2026, Datadog, Inc.
3+
* SPDX-License-Identifier: Apache-2.0
4+
*/
5+
6+
#include "signalCookie.h"
7+
8+
namespace SignalCookie {
9+
namespace detail {
10+
// Place tags in a named section on Linux to prevent LTO from merging
11+
// or reordering them across TUs (their addresses must be unique per DSO).
12+
#ifdef __linux__
13+
[[gnu::section(".data.signal_cookie")]] char cpu_tag;
14+
[[gnu::section(".data.signal_cookie")]] char wallclock_tag;
15+
#else
16+
char cpu_tag;
17+
char wallclock_tag;
18+
#endif
19+
}
20+
void* cpu() { return &detail::cpu_tag; }
21+
void* wallclock() { return &detail::wallclock_tag; }
22+
}

ddprof-lib/src/main/cpp/signalCookie.h

Lines changed: 2 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -21,19 +21,8 @@
2121
// forged by an unrelated in-process sender without reading our symbols, and
2222
// never collide with legitimate user-space pointers in third-party code.
2323
namespace SignalCookie {
24-
namespace detail {
25-
// Place tags in a named section on Linux to prevent LTO from merging
26-
// or reordering them across TUs (their addresses must be unique per DSO).
27-
#ifdef __linux__
28-
[[gnu::section(".data.signal_cookie")]] inline char cpu_tag;
29-
[[gnu::section(".data.signal_cookie")]] inline char wallclock_tag;
30-
#else
31-
inline char cpu_tag;
32-
inline char wallclock_tag;
33-
#endif
34-
}
35-
inline void* cpu() { return &detail::cpu_tag; }
36-
inline void* wallclock() { return &detail::wallclock_tag; }
24+
void* cpu();
25+
void* wallclock();
3726
}
3827

3928
#endif // SIGNAL_COOKIE_H

0 commit comments

Comments
 (0)