[Lldb-commits] [PATCH] D112972: [lldb] use EXT_SUFFIX for python extension

Lawrence D'Anna via Phabricator via lldb-commits lldb-commits at lists.llvm.org
Mon Nov 1 16:55:19 PDT 2021


lawrence_danna created this revision.
lawrence_danna added reviewers: jasonmolenda, JDevlieghere, jingham.
Herald added a subscriber: mgorny.
lawrence_danna requested review of this revision.
Herald added a project: LLDB.

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.


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D112972

Files:
  lldb/CMakeLists.txt
  lldb/bindings/python/CMakeLists.txt


Index: lldb/bindings/python/CMakeLists.txt
===================================================================
--- lldb/bindings/python/CMakeLists.txt
+++ lldb/bindings/python/CMakeLists.txt
@@ -138,13 +138,14 @@
     set(LIBLLDB_SYMLINK_DEST "${LLVM_SHLIB_OUTPUT_INTDIR}/liblldb${CMAKE_SHARED_LIBRARY_SUFFIX}")
   endif()
   if(WIN32)
+    # FIXME should we use EXT_SUFFIX on windows?
     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")
+    set(LIBLLDB_SYMLINK_OUTPUT_FILE "_lldb${LLDB_PYTHON_EXT_SUFFIX}")
   endif()
   create_relative_symlink(${swig_target} ${LIBLLDB_SYMLINK_DEST}
                           ${lldb_python_target_dir} ${LIBLLDB_SYMLINK_OUTPUT_FILE})
Index: lldb/CMakeLists.txt
===================================================================
--- lldb/CMakeLists.txt
+++ lldb/CMakeLists.txt
@@ -37,18 +37,29 @@
           -c "import distutils.sysconfig; print(distutils.sysconfig.get_python_lib(True, False, ''))"
       OUTPUT_VARIABLE LLDB_PYTHON_DEFAULT_RELATIVE_PATH
       OUTPUT_STRIP_TRAILING_WHITESPACE)
-
     file(TO_CMAKE_PATH ${LLDB_PYTHON_DEFAULT_RELATIVE_PATH} LLDB_PYTHON_DEFAULT_RELATIVE_PATH)
+    execute_process(
+      COMMAND ${Python3_EXECUTABLE}
+          -c "import sysconfig; print(sysconfig.get_config_var('EXT_SUFFIX'))"
+      OUTPUT_VARIABLE LLDB_PYTHON_DEFAULT_EXT_SUFFIX
+      OUTPUT_STRIP_TRAILING_WHITESPACE)
   else ()
     if ("${LLDB_PYTHON_RELATIVE_PATH}" STREQUAL "")
       message(FATAL_ERROR
         "Crosscompiling LLDB with Python requires manually setting
         LLDB_PYTHON_RELATIVE_PATH.")
     endif ()
+    if ("${LLDB_PYTHON_EXT_SUFFIX}" STREQUAL "")
+      message(FATAL_ERROR
+        "Crosscompiling LLDB with Python requires manually setting
+        LLDB_PYTHON_EXT_SUFFIX.")
+    endif ()
   endif ()
 
   set(LLDB_PYTHON_RELATIVE_PATH ${LLDB_PYTHON_DEFAULT_RELATIVE_PATH}
-    CACHE STRING "Path where Python modules are installed, relative to install prefix")
+    CACHE STRING "Path where Python modules are installed, relative to install prefix.")
+  set(LLDB_PYTHON_EXT_SUFFIX ${LLDB_PYTHON_DEFAULT_EXT_SUFFIX}
+    CACHE STRING "Filename suffix for Python modules.")
 endif ()
 
 if (LLDB_ENABLE_LUA)


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D112972.383925.patch
Type: text/x-patch
Size: 2369 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/lldb-commits/attachments/20211101/8cfd8cbc/attachment.bin>


More information about the lldb-commits mailing list