From 26d659bbe08028c0e04ddc3f4c698a995f41a131 Mon Sep 17 00:00:00 2001 From: Rainer Orth Date: Thu, 27 Aug 2020 10:59:51 +0200 Subject: [PATCH] [polly][cmake] Don't build LLVMPolly.so without PIC 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 | 6 ++++-- polly/cmake/CMakeLists.txt | 4 ++-- polly/lib/CMakeLists.txt | 5 +++-- 3 files changed, 9 insertions(+), 6 deletions(-) diff --git a/polly/CMakeLists.txt b/polly/CMakeLists.txt index 8b771f1..0f5f71b 100644 --- a/polly/CMakeLists.txt +++ b/polly/CMakeLists.txt @@ -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") diff --git a/polly/cmake/CMakeLists.txt b/polly/cmake/CMakeLists.txt index 211f955..fd8028a 100644 --- a/polly/cmake/CMakeLists.txt +++ b/polly/cmake/CMakeLists.txt @@ -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) diff --git a/polly/lib/CMakeLists.txt b/polly/lib/CMakeLists.txt index 2b9a77b..113ae5f 100644 --- a/polly/lib/CMakeLists.txt +++ b/polly/lib/CMakeLists.txt @@ -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 () -- 2.7.4