[llvm-branch-commits] [clang] b33de54 - [clang] Fix libclang linking on Solaris

Tom Stellard via llvm-branch-commits llvm-branch-commits at lists.llvm.org
Tue Aug 10 19:03:41 PDT 2021


Author: Rainer Orth
Date: 2021-08-10T19:03:12-07:00
New Revision: b33de5411594508c2ef357d5db10b8705e9b302a

URL: https://github.com/llvm/llvm-project/commit/b33de5411594508c2ef357d5db10b8705e9b302a
DIFF: https://github.com/llvm/llvm-project/commit/b33de5411594508c2ef357d5db10b8705e9b302a.diff

LOG: [clang] Fix libclang linking on Solaris

Linking `libclang.so` is currently broken on Solaris:

  ld: fatal: option --version-script requires option -z gnu-version-script-compat to be specified

While Solaris `ld` supports a considerable subset of `--version-script`,
there are some elements of the syntax that aren't.

The fix is equivalent to D78510 <https://reviews.llvm.org/D78510>.

Additionally, use of C-style comments is a GNU extension
that can easily be avoided by using `#` as comment character, which is
supported by GNU `ld`, `gold`, and `lld`.

Tested on `amd64-pc-solaris2.11`, `sparcv9-sun-solaris2.11`,
`x86_64-pc-linux-gnu`.

Differential Revision: https://reviews.llvm.org/D107559

(cherry picked from commit a382a746275b4a1eb1867331efa2319c614305d8)

Added: 
    

Modified: 
    clang/tools/libclang/CMakeLists.txt
    clang/tools/libclang/libclang.map

Removed: 
    


################################################################################
diff  --git a/clang/tools/libclang/CMakeLists.txt b/clang/tools/libclang/CMakeLists.txt
index 8cc0fc622174..7148bdccfba4 100644
--- a/clang/tools/libclang/CMakeLists.txt
+++ b/clang/tools/libclang/CMakeLists.txt
@@ -162,6 +162,11 @@ if(ENABLE_SHARED)
   endif()
   if (USE_VERSION_SCRIPT)
     target_link_options(libclang PRIVATE "-Wl,--version-script,${CMAKE_CURRENT_SOURCE_DIR}/libclang.map")
+    # The Solaris 11.4 linker supports a subset of GNU ld version scripts,
+    # but requires a special option to enable it.
+    if (${CMAKE_SYSTEM_NAME} MATCHES "SunOS")
+      target_link_options(libclang PRIVATE "-Wl,-z,gnu-version-script-compat")
+    endif()
     # Ensure that libclang.so gets rebuilt when the linker script changes.
     set_property(SOURCE ARCMigrate.cpp APPEND PROPERTY
                  OBJECT_DEPENDS ${CMAKE_CURRENT_SOURCE_DIR}/libclang.map)

diff  --git a/clang/tools/libclang/libclang.map b/clang/tools/libclang/libclang.map
index aee46b144845..716e2474966d 100644
--- a/clang/tools/libclang/libclang.map
+++ b/clang/tools/libclang/libclang.map
@@ -1,10 +1,8 @@
-/* If you add a symbol to this file, make sure to add it with the correct
- * version.  For example, if the LLVM main branch is LLVM 14.0.0, add new
- * symbols with the version LLVM_14.
- * On platforms where versions scripts are not used, this file will be used to
- * generate a list of exports for libclang.so
- */
-
+# If you add a symbol to this file, make sure to add it with the correct
+# version.  For example, if the LLVM main branch is LLVM 14.0.0, add new
+# symbols with the version LLVM_14.
+# On platforms where versions scripts are not used, this file will be used to
+# generate a list of exports for libclang.so
 
 LLVM_13 {
   global:
@@ -407,10 +405,9 @@ LLVM_13 {
   local: *;
 };
 
-/* Example of how to add a new symbol version entry.  If you do add a new symbol
- * version, please update the example to depend on the version you added.
- * LLVM_X {
- * global:
- *    clang_newsymbol;
- * };
- */
+# Example of how to add a new symbol version entry.  If you do add a new symbol
+# version, please update the example to depend on the version you added.
+# LLVM_X {
+# global:
+#   clang_newsymbol;
+# };


        


More information about the llvm-branch-commits mailing list