[llvm] 26947d7 - [tools][remarks-shlib] Don't build libRemarks.so without PIC

Rainer Orth via llvm-commits llvm-commits at lists.llvm.org
Sun Sep 20 03:41:45 PDT 2020


Author: Rainer Orth
Date: 2020-09-20T12:40:21+02:00
New Revision: 26947d7b63809413b96b0bb6033f168488836289

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

LOG: [tools][remarks-shlib] Don't build libRemarks.so without PIC

A build on `sparcv9-sun-solaris2.11` with `-DLLVM_ENABLE_PIC=Off` failed
linking `libRemarks.so`:

  [27/2297] Linking CXX shared library lib/libRemarks.so.12git
  FAILED: lib/libRemarks.so.12git
  [...]
  ld: fatal: relocation error: R_SPARC_H44: file lib/libLLVMRemarks.a(Remark.cpp.o): symbol _ZTVN4llvm18raw_string_ostreamE: invalid shared object relocation type: ABS44 code model unsupported
  [...]

On Solaris/sparcv9 as on many other targets you cannot link non-PIC objects
into a shared object.

The following patch avoids this by not building the library with PIC.  It
allowed the build to complete and `ninja check-all` showed no errors.

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

Added: 
    

Modified: 
    llvm/tools/remarks-shlib/CMakeLists.txt

Removed: 
    


################################################################################
diff  --git a/llvm/tools/remarks-shlib/CMakeLists.txt b/llvm/tools/remarks-shlib/CMakeLists.txt
index cb22434d3662..865436247270 100644
--- a/llvm/tools/remarks-shlib/CMakeLists.txt
+++ b/llvm/tools/remarks-shlib/CMakeLists.txt
@@ -1,27 +1,32 @@
-set(LLVM_LINK_COMPONENTS
-  Remarks
-  )
+# Building shared libraries requires PIC objects.
+if(LLVM_ENABLE_PIC)
 
-set(SOURCES
-  libremarks.cpp
-  )
+  set(LLVM_LINK_COMPONENTS
+    Remarks
+    )
 
-set(LLVM_EXPORTED_SYMBOL_FILE ${CMAKE_CURRENT_SOURCE_DIR}/Remarks.exports)
+  set(SOURCES
+    libremarks.cpp
+    )
 
-add_llvm_library(Remarks SHARED INSTALL_WITH_TOOLCHAIN ${SOURCES})
+  set(LLVM_EXPORTED_SYMBOL_FILE ${CMAKE_CURRENT_SOURCE_DIR}/Remarks.exports)
 
-if (LLVM_INTEGRATED_CRT_ALLOC AND MSVC)
-  # Make sure we search LLVMSupport first, before the CRT libs
-  set(CMAKE_SHARED_LINKER_FLAGS "${CMAKE_SHARED_LINKER_FLAGS} -INCLUDE:malloc")
-endif()
+  add_llvm_library(Remarks SHARED INSTALL_WITH_TOOLCHAIN ${SOURCES})
+
+  if (LLVM_INTEGRATED_CRT_ALLOC AND MSVC)
+    # Make sure we search LLVMSupport first, before the CRT libs
+    set(CMAKE_SHARED_LINKER_FLAGS "${CMAKE_SHARED_LINKER_FLAGS} -INCLUDE:malloc")
+  endif()
   
-install(FILES ${LLVM_MAIN_INCLUDE_DIR}/llvm-c/Remarks.h
-  DESTINATION include/llvm-c
-  COMPONENT Remarks)
+  install(FILES ${LLVM_MAIN_INCLUDE_DIR}/llvm-c/Remarks.h
+    DESTINATION include/llvm-c
+    COMPONENT Remarks)
+
+  if (APPLE)
+    set(REMARKS_VERSION ${LLVM_VERSION_MAJOR})
+    set_property(TARGET Remarks APPEND_STRING PROPERTY
+                 LINK_FLAGS
+                 " -compatibility_version 1 -current_version ${REMARKS_VERSION}.${LLVM_VERSION_MINOR}.${LLVM_VERSION_PATCH}")
+  endif()
 
-if (APPLE)
-  set(REMARKS_VERSION ${LLVM_VERSION_MAJOR})
-  set_property(TARGET Remarks APPEND_STRING PROPERTY
-              LINK_FLAGS
-              " -compatibility_version 1 -current_version ${REMARKS_VERSION}.${LLVM_VERSION_MINOR}.${LLVM_VERSION_PATCH}")
 endif()


        


More information about the llvm-commits mailing list