OSDN Git Service

[polly][cmake] Don't build LLVMPolly.so without PIC
authorRainer Orth <ro@gcc.gnu.org>
Thu, 27 Aug 2020 08:59:51 +0000 (10:59 +0200)
committerRainer Orth <ro@gcc.gnu.org>
Thu, 27 Aug 2020 08:59:51 +0000 (10:59 +0200)
A build on `sparcv9-sun-solaris2.11` with `-DLLVM_ENABLE_PIC=Off` failed
linking `LLVMPolly.so`:

  [2277/2297] Linking CXX shared module lib/LLVMPolly.so
  FAILED: lib/LLVMPolly.so
  [...]
  ld: fatal: relocation error: R_SPARC_H44: file tools/polly/lib/CMakeFiles/obj.Polly.dir/Analysis/DependenceInfo.cpp.o: symbol .data._ZL16__gthread_active (section): invalid shared object relocation type: ABS44 code model unsupported
  [...]

As on many other targets, one cannot link non-PIC objects into a shared
object on Solaris/sparcv9.

The following patch avoids this by not building the library without PIC.
It allowed the build to finish.

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

polly/CMakeLists.txt
polly/cmake/CMakeLists.txt
polly/lib/CMakeLists.txt

index 8b771f1..0f5f71b 100644 (file)
@@ -39,8 +39,10 @@ if (NOT DEFINED LLVM_MAIN_SRC_DIR)
     set(POLLY_GTEST_AVAIL 1)
   endif()
 
-  # Make sure the isl c files are built as fPIC
-  set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -fPIC")
+  if (LLVM_ENABLE_PIC)
+    # Make sure the isl c files are built as fPIC if possible
+    set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -fPIC")
+  endif ()
 
   # Set directory for polly-isl-test.
   set(CMAKE_RUNTIME_OUTPUT_DIRECTORY "${CMAKE_CURRENT_BINARY_DIR}/bin")
index 211f955..fd8028a 100644 (file)
@@ -10,8 +10,8 @@ else()
 endif()
 
 set(POLLY_CONFIG_EXPORTED_TARGETS Polly ${ISL_TARGET})
-if (NOT MSVC)
-  # LLVMPolly is a dummy target on Win
+if (NOT MSVC AND LLVM_ENABLE_PIC)
+  # LLVMPolly is a dummy target on Win or if PIC code is disabled.
   list(APPEND POLLY_CONFIG_EXPORTED_TARGETS LLVMPolly)
 endif()
 if (POLLY_ENABLE_GPGPU_CODEGEN)
index 2b9a77b..113ae5f 100644 (file)
@@ -137,8 +137,9 @@ endif ()
 
 # Create a loadable module Polly.so that can be loaded using
 # LLVM's/clang's "-load" option.
-if (MSVC)
-  # Add dummy target, because loadable modules are not supported on Windows
+if (MSVC OR NOT LLVM_ENABLE_PIC)
+  # Add dummy target, either because loadable modules are not supported
+  # as on Windows or because PIC code has been disabled
   add_custom_target(LLVMPolly)
   set_target_properties(LLVMPolly PROPERTIES FOLDER "Polly")
 else ()