Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 3bfb5f7

Browse files
committed
gh-129223: Do not allow the compiler to optimise away symbols for debug sections
Signed-off-by: Pablo Galindo <[email protected]>
1 parent 5c9a63f commit 3bfb5f7

File tree

2 files changed

+16
-11
lines changed

2 files changed

+16
-11
lines changed

Include/internal/pycore_debug_offsets.h

Lines changed: 11 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -17,31 +17,32 @@ extern "C" {
1717

1818
// Macros to burn global values in custom sections so out-of-process
1919
// profilers can locate them easily.
20-
21-
#define GENERATE_DEBUG_SECTION(name, declaration) \
22-
_GENERATE_DEBUG_SECTION_WINDOWS(name) \
23-
_GENERATE_DEBUG_SECTION_APPLE(name) \
24-
declaration \
25-
_GENERATE_DEBUG_SECTION_LINUX(name)
20+
#define GENERATE_DEBUG_SECTION(name, declaration) \
21+
_GENERATE_DEBUG_SECTION_WINDOWS(name) \
22+
_GENERATE_DEBUG_SECTION_APPLE(name) \
23+
declaration \
24+
_GENERATE_DEBUG_SECTION_LINUX(name)
2625

2726
#if defined(MS_WINDOWS)
2827
#define _GENERATE_DEBUG_SECTION_WINDOWS(name) \
29-
_Pragma(Py_STRINGIFY(section(Py_STRINGIFY(name), read, write))) \
30-
__declspec(allocate(Py_STRINGIFY(name)))
28+
_Pragma(Py_STRINGIFY(section(Py_STRINGIFY(name), read, write))) \
29+
__declspec(allocate(Py_STRINGIFY(name)))
3130
#else
3231
#define _GENERATE_DEBUG_SECTION_WINDOWS(name)
3332
#endif
3433

3534
#if defined(__APPLE__)
3635
#define _GENERATE_DEBUG_SECTION_APPLE(name) \
37-
__attribute__((section(SEG_DATA "," Py_STRINGIFY(name))))
36+
__attribute__((section(SEG_DATA "," Py_STRINGIFY(name)))) \
37+
__attribute__((used))
3838
#else
3939
#define _GENERATE_DEBUG_SECTION_APPLE(name)
4040
#endif
4141

4242
#if defined(__linux__) && (defined(__GNUC__) || defined(__clang__))
4343
#define _GENERATE_DEBUG_SECTION_LINUX(name) \
44-
__attribute__((section("." Py_STRINGIFY(name))))
44+
__attribute__((section("." Py_STRINGIFY(name)))) \
45+
__attribute__((used))
4546
#else
4647
#define _GENERATE_DEBUG_SECTION_LINUX(name)
4748
#endif

Modules/_testexternalinspection.c

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -414,7 +414,11 @@ get_py_runtime(pid_t pid)
414414
static uintptr_t
415415
get_async_debug(pid_t pid)
416416
{
417-
return search_map_for_section(pid, "AsyncioDebug", "_asyncio.cpython");
417+
uintptr_t result = search_map_for_section(pid, "AsyncioDebug", "_asyncio.cpython");
418+
if (result == 0 && !PyErr_Occurred()) {
419+
PyErr_SetString(PyExc_RuntimeError, "Cannot find AsyncioDebug section");
420+
}
421+
return result;
418422
}
419423

420424

0 commit comments

Comments
 (0)