Skip to content

Commit

Permalink
[lldb] use EXT_SUFFIX for python extension
Browse files Browse the repository at this point in the history
LLDB doesn't use only the python stable ABI, which means loading
it into an incompatible python can cause the process to crash.
_lldb.so should be named with the full EXT_SUFFIX from sysconfig
-- such as _lldb.cpython-39-darwin.so -- so this doesn't happen.

Reviewed By: JDevlieghere

Differential Revision: https://reviews.llvm.org/D112972
  • Loading branch information
lawrence-danna-apple committed Nov 16, 2021
1 parent 39e9f5d commit ae389b2
Show file tree
Hide file tree
Showing 3 changed files with 6 additions and 11 deletions.
4 changes: 3 additions & 1 deletion lldb/CMakeLists.txt
Expand Up @@ -35,8 +35,10 @@ if (LLDB_ENABLE_PYTHON)
"Path where Python modules are installed, relative to install prefix")
set(cachestring_LLDB_PYTHON_EXE_RELATIVE_PATH
"Path to python interpreter exectuable, relative to install prefix")
set(cachestring_LLDB_PYTHON_EXT_SUFFIX
"Filename extension for native code python modules")

foreach(var LLDB_PYTHON_RELATIVE_PATH LLDB_PYTHON_EXE_RELATIVE_PATH)
foreach(var LLDB_PYTHON_RELATIVE_PATH LLDB_PYTHON_EXE_RELATIVE_PATH LLDB_PYTHON_EXT_SUFFIX)
if(NOT DEFINED ${var} AND NOT CMAKE_CROSSCOMPILING)
execute_process(
COMMAND ${Python3_EXECUTABLE}
Expand Down
10 changes: 1 addition & 9 deletions lldb/bindings/python/CMakeLists.txt
Expand Up @@ -149,15 +149,7 @@ function(finish_swig_python swig_target lldb_python_bindings_dir lldb_python_tar
else()
set(LIBLLDB_SYMLINK_DEST "${LLVM_SHLIB_OUTPUT_INTDIR}/liblldb${CMAKE_SHARED_LIBRARY_SUFFIX}")
endif()
if(WIN32)
if(CMAKE_BUILD_TYPE STREQUAL Debug)
set(LIBLLDB_SYMLINK_OUTPUT_FILE "_lldb_d.pyd")
else()
set(LIBLLDB_SYMLINK_OUTPUT_FILE "_lldb.pyd")
endif()
else()
set(LIBLLDB_SYMLINK_OUTPUT_FILE "_lldb.so")
endif()
set(LIBLLDB_SYMLINK_OUTPUT_FILE "_lldb${LLDB_PYTHON_EXT_SUFFIX}")
create_relative_symlink(${swig_target} ${LIBLLDB_SYMLINK_DEST}
${lldb_python_target_dir} ${LIBLLDB_SYMLINK_OUTPUT_FILE})

Expand Down
3 changes: 2 additions & 1 deletion lldb/bindings/python/get-python-config.py
Expand Up @@ -39,7 +39,8 @@ def main():
print("tried:", e, file=sys.stderr)
print("sys.prefix:", sys.prefix, file=sys.stderr)
sys.exit(1)

elif args.variable_name == "LLDB_PYTHON_EXT_SUFFIX":
print(sysconfig.get_config_var('EXT_SUFFIX'))
else:
parser.error(f"unknown variable {args.variable_name}")

Expand Down

0 comments on commit ae389b2

Please sign in to comment.