99#include "pycore_jit_unwind.h"
1010#include "pycore_lock.h"
1111
12- #if defined(_Py_JIT ) && defined( __linux__ ) && defined( __ELF__ )
12+ #if defined(PY_HAVE_JIT_GDB_UNWIND )
1313# include "jit_unwind_info.h"
1414# if !JIT_UNWIND_INFO_SUPPORTED
1515# error "JIT unwind info was not generated for this target"
1616# endif
17- # define PY_HAVE_JIT_GDB_UNWIND 1
18- #else
19- # define PY_HAVE_JIT_GDB_UNWIND 0
2017#endif
2118
22- #if defined(PY_HAVE_PERF_TRAMPOLINE ) || ( defined(__linux__ ) && defined( __ELF__ ) )
19+ #if defined(PY_HAVE_PERF_TRAMPOLINE ) || defined(PY_HAVE_JIT_GDB_UNWIND )
2320
24- #if defined(__linux__ )
21+ #if defined(PY_HAVE_JIT_GDB_UNWIND )
2522# include <elf.h>
2623#endif
2724#include <stdio.h>
@@ -215,13 +212,13 @@ static void elfctx_append_uleb128(ELFObjectContext* ctx, uint32_t v) {
215212// =============================================================================
216213
217214static void elf_init_ehframe_perf (ELFObjectContext * ctx );
218- #if PY_HAVE_JIT_GDB_UNWIND
215+ #if defined( PY_HAVE_JIT_GDB_UNWIND )
219216static void elf_init_ehframe_gdb (ELFObjectContext * ctx );
220217#endif
221218
222219static inline void elf_init_ehframe (ELFObjectContext * ctx , int absolute_addr ) {
223220 if (absolute_addr ) {
224- #if PY_HAVE_JIT_GDB_UNWIND
221+ #if defined( PY_HAVE_JIT_GDB_UNWIND )
225222 elf_init_ehframe_gdb (ctx );
226223#else
227224 Py_UNREACHABLE ();
@@ -638,7 +635,7 @@ static void elf_init_ehframe_perf(ELFObjectContext* ctx) {
638635 * and the FDE body is empty. Tools/jit/_targets.py derives the initial CFI
639636 * rules from the row active at the executor call in the compiled shim object.
640637 */
641- #if PY_HAVE_JIT_GDB_UNWIND
638+ #if defined( PY_HAVE_JIT_GDB_UNWIND )
642639static void elf_init_ehframe_gdb (ELFObjectContext * ctx ) {
643640 int fde_ptr_enc = DWRF_EH_PE_absptr ;
644641 uint8_t * p = ctx -> p ;
@@ -677,7 +674,7 @@ static void elf_init_ehframe_gdb(ELFObjectContext* ctx) {
677674}
678675#endif
679676
680- #if defined(__linux__ ) && defined( __ELF__ )
677+ #if defined(PY_HAVE_JIT_GDB_UNWIND )
681678enum {
682679 JIT_NOACTION = 0 ,
683680 JIT_REGISTER_FN = 1 ,
@@ -699,7 +696,7 @@ struct jit_descriptor {
699696 struct jit_code_entry * first_entry ;
700697};
701698
702- static PyMutex jit_debug_mutex = {0 };
699+ PyMutex _Py_jit_debug_mutex = {0 };
703700
704701Py_EXPORTED_SYMBOL volatile struct jit_descriptor __jit_debug_descriptor = {
705702 1 , JIT_NOACTION , NULL , NULL
@@ -892,7 +889,7 @@ gdb_jit_register_code(
892889 entry -> symfile_size = total_size ;
893890 entry -> code_addr = code_addr ;
894891
895- PyMutex_Lock (& jit_debug_mutex );
892+ PyMutex_Lock (& _Py_jit_debug_mutex );
896893 entry -> prev = NULL ;
897894 entry -> next = __jit_debug_descriptor .first_entry ;
898895 if (entry -> next != NULL ) {
@@ -904,18 +901,18 @@ gdb_jit_register_code(
904901 __jit_debug_register_code ();
905902 __jit_debug_descriptor .action_flag = JIT_NOACTION ;
906903 __jit_debug_descriptor .relevant_entry = NULL ;
907- PyMutex_Unlock (& jit_debug_mutex );
904+ PyMutex_Unlock (& _Py_jit_debug_mutex );
908905 return entry ;
909906}
910- #endif // __linux__ && __ELF__
907+ #endif // defined(PY_HAVE_JIT_GDB_UNWIND)
911908
912909void *
913910_PyJitUnwind_GdbRegisterCode (const void * code_addr ,
914911 size_t code_size ,
915912 const char * entry ,
916913 const char * filename )
917914{
918- #if defined(__linux__ ) && defined( __ELF__ )
915+ #if defined(PY_HAVE_JIT_GDB_UNWIND )
919916 /* GDB expects a stable symbol name and absolute addresses in .eh_frame. */
920917 if (entry == NULL ) {
921918 entry = "" ;
@@ -954,13 +951,13 @@ _PyJitUnwind_GdbRegisterCode(const void *code_addr,
954951void
955952_PyJitUnwind_GdbUnregisterCode (void * handle )
956953{
957- #if defined(__linux__ ) && defined( __ELF__ )
954+ #if defined(PY_HAVE_JIT_GDB_UNWIND )
958955 struct jit_code_entry * entry = (struct jit_code_entry * )handle ;
959956 if (entry == NULL ) {
960957 return ;
961958 }
962959
963- PyMutex_Lock (& jit_debug_mutex );
960+ PyMutex_Lock (& _Py_jit_debug_mutex );
964961 if (entry -> prev != NULL ) {
965962 entry -> prev -> next = entry -> next ;
966963 }
@@ -977,7 +974,7 @@ _PyJitUnwind_GdbUnregisterCode(void *handle)
977974 __jit_debug_descriptor .action_flag = JIT_NOACTION ;
978975 __jit_debug_descriptor .relevant_entry = NULL ;
979976
980- PyMutex_Unlock (& jit_debug_mutex );
977+ PyMutex_Unlock (& _Py_jit_debug_mutex );
981978
982979 PyMem_RawFree ((void * )entry -> symfile_addr );
983980 PyMem_RawFree (entry );
@@ -986,4 +983,4 @@ _PyJitUnwind_GdbUnregisterCode(void *handle)
986983#endif
987984}
988985
989- #endif // defined(PY_HAVE_PERF_TRAMPOLINE) || ( defined(__linux__) && defined(__ELF__) )
986+ #endif // defined(PY_HAVE_PERF_TRAMPOLINE) || defined(PY_HAVE_JIT_GDB_UNWIND )
0 commit comments