[PATCH] D70972: [AIX] Make sure we use export lists for plugins

David Tenty via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Tue Dec 3 11:01:21 PST 2019


daltenty created this revision.
Herald added subscribers: llvm-commits, mgorny.
Herald added a project: LLVM.
daltenty added reviewers: jasonliu, DiggerLin, stevewan.

Besides just generating and consuming the lists, this includes:

- Calling  nm with the right options in extract_symbols.py. Such as not demangling C++ names, which AIX nm does by default, and accepting both 32/64-bit names.
- Not having nm sort the list of symbols or we may run in to memory issues on debug builds, as nm calls a 32-bit sort.
- Defaulting to having LLVM_EXPORT_SYMBOLS_FOR_PLUGINS on for AIX
- CMake versions prior to 3.16 set the -brtl linker flag globally on AIX. Clear it out early on so we don't run into failures. We will set it as needed.


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D70972

Files:
  llvm/CMakeLists.txt
  llvm/cmake/modules/AddLLVM.cmake
  llvm/cmake/modules/HandleLLVMOptions.cmake
  llvm/utils/extract_symbols.py


Index: llvm/utils/extract_symbols.py
===================================================================
--- llvm/utils/extract_symbols.py
+++ llvm/utils/extract_symbols.py
@@ -42,9 +42,14 @@
     process.wait()
 
 def nm_get_symbols(lib):
-    process = subprocess.Popen(['nm','-P',lib], bufsize=1,
-                               stdout=subprocess.PIPE, stdin=subprocess.PIPE,
-                               universal_newlines=True)
+    if sys.platform.startswith('aix'):
+        process = subprocess.Popen(['nm','-P','-Xany','-C','-p',lib], bufsize=1,
+                                   stdout=subprocess.PIPE, stdin=subprocess.PIPE,
+                                   universal_newlines=True)
+    else:
+        process = subprocess.Popen(['nm','-P',lib], bufsize=1,
+                                   stdout=subprocess.PIPE, stdin=subprocess.PIPE,
+                                   universal_newlines=True)
     process.stdin.close()
     for line in process.stdout:
         # Look for external symbols that are defined in some section
Index: llvm/cmake/modules/HandleLLVMOptions.cmake
===================================================================
--- llvm/cmake/modules/HandleLLVMOptions.cmake
+++ llvm/cmake/modules/HandleLLVMOptions.cmake
@@ -909,11 +909,18 @@
 endif()
 
 # This option makes utils/extract_symbols.py be used to determine the list of
-# symbols to export from LLVM tools. This is necessary when using MSVC if you
-# want to allow plugins, though note that the plugin has to explicitly link
-# against (exactly one) tool so we can't unilaterally turn on
-# LLVM_ENABLE_PLUGINS when it's enabled.
-option(LLVM_EXPORT_SYMBOLS_FOR_PLUGINS "Export symbols from LLVM tools so that plugins can import them" OFF)
+# symbols to export from LLVM tools. This is necessary when on AIX or using MSVC
+# if you want to allow plugins, though note that the plugin has to explicitly
+# link against (exactly one) tool so we can't unilaterally turn on
+# LLVM_ENABLE_PLUGINS when it's enabled. We enable this by default on AIX.
+set(LLVM_EXPORT_SYMBOLS_FOR_PLUGINS_default OFF)
+if (${CMAKE_SYSTEM_NAME} MATCHES "AIX" AND NOT (BUILD_SHARED_LIBS OR LLVM_LINK_LLVM_DYLIB))
+  set(LLVM_EXPORT_SYMBOLS_FOR_PLUGINS_default ON)
+endif()
+
+option(LLVM_EXPORT_SYMBOLS_FOR_PLUGINS
+       "Export symbols from LLVM tools so that plugins can import them"
+       ${LLVM_EXPORT_SYMBOLS_FOR_PLUGINS_default})
 if(BUILD_SHARED_LIBS AND LLVM_EXPORT_SYMBOLS_FOR_PLUGINS)
   message(FATAL_ERROR "BUILD_SHARED_LIBS not compatible with LLVM_EXPORT_SYMBOLS_FOR_PLUGINS")
 endif()
Index: llvm/cmake/modules/AddLLVM.cmake
===================================================================
--- llvm/cmake/modules/AddLLVM.cmake
+++ llvm/cmake/modules/AddLLVM.cmake
@@ -90,6 +90,7 @@
     set_property(TARGET ${target_name} APPEND_STRING PROPERTY
                  LINK_FLAGS " -Wl,-exported_symbols_list,\"${CMAKE_CURRENT_BINARY_DIR}/${native_export_file}\"")
   elseif(${CMAKE_SYSTEM_NAME} MATCHES "AIX")
+    set(native_export_file "${export_file}")
     set_property(TARGET ${target_name} APPEND_STRING PROPERTY
                  LINK_FLAGS " -Wl,-bE:${export_file}")
   elseif(LLVM_HAVE_LINK_VERSION_SCRIPT)
Index: llvm/CMakeLists.txt
===================================================================
--- llvm/CMakeLists.txt
+++ llvm/CMakeLists.txt
@@ -851,6 +851,12 @@
 if (UNIX AND ${CMAKE_SYSTEM_NAME} MATCHES "AIX")
           add_definitions("-D_XOPEN_SOURCE=700")
           add_definitions("-D_LARGE_FILE_API")
+
+  # CMake versions less than 3.16 set linker flags to include -brtl by default,
+  # so clear it out.
+  string(REPLACE "-Wl,-brtl" "" CMAKE_SHARED_LINKER_FLAGS  "${CMAKE_SHARED_LINKER_FLAGS}")
+  string(REPLACE "-Wl,-brtl" "" CMAKE_MODULE_LINKER_FLAGS "${CMAKE_MODULE_LINKER_FLAGS}")
+  string(REPLACE "-Wl,-brtl" "" CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS}")
 endif()
 
 # Build with _FILE_OFFSET_BITS=64 on Solaris to match g++ >= 9.


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D70972.231948.patch
Type: text/x-patch
Size: 3975 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20191203/6d400fd8/attachment.bin>


More information about the llvm-commits mailing list