Page MenuHomePhabricator

[CMake][ELF] Add -fno-semantic-interposition for GCC and Clang>=13
ClosedPublic

Authored by MaskRay on May 13 2021, 5:00 PM.

Details

Summary

In a -DCMAKE_BUILD_TYPE=Release -DLLVM_TARGETS_TO_BUILD=X86 -DLLVM_LINK_LLVM_DYLIB=on -DCLANG_LINK_CLANG_DYLIB=on
build, libLLVM-13git.so is 2% smaller and libclang-cpp.so is 1% smaller (on top of -Wl,-Bsymbolic-functions).
There may be some small performance improvement as well because GCC
-fPIC suppresses interprocedural optimizations for non-inline
definitions by default.

Note: we cannot add -fno-semantic-interposition for Clang<13. Clang<13's
implementation additionally optimizes global variables, which is incompatible
with unfortunate ELF -fno-pic default: direct access relocations for external
data. If the executable has a -fno-pic object file referencing a global variable
declared in a public header, the direct access relocation will cause a copy
relocation. The executable and libLLVM.so/libclang-cpp.so will disagree on the
address.

Diff Detail

Event Timeline

MaskRay created this revision.May 13 2021, 5:00 PM
MaskRay requested review of this revision.May 13 2021, 5:00 PM
Herald added a project: Restricted Project. · View Herald TranscriptMay 13 2021, 5:00 PM

Is it possible that future GCC versions would optimize global variables like Clang does when -fno-semantic-interposition is used?

(Apologies in advance if this question is silly and/or the answer is obvious.)

MaskRay added a comment.EditedMay 14 2021, 8:57 PM

Is it possible that future GCC versions would optimize global variables like Clang does when -fno-semantic-interposition is used?

(Apologies in advance if this question is silly and/or the answer is obvious.)

This is a good question:) (and one goal I started these conversations: make distributions interested.)

For global variables, I have a feature request https://gcc.gnu.org/bugzilla/show_bug.cgi?id=100483 (it is not that useful an optimization, but will make the name -fno-semantic-interposition more appropriate)


Will GCC switch to the Clang model for interprocedural optimizations? I do not recommend it. The Clang tri-state is actually a bit confusing. Code should be clear on the bisection: -fno-semantic-interposition/-fsemantic-interposition.

I wish that the ELF world can shift to default -fno-semantic-interposition and (in the long term) -Wl,-Bsymbolic-functions, bring back the lost performance for decades.
Such interposition doesn't work with macOS (by default) and Windows, so there is good chance that most pieces of portable software are already in a good state.
However, I can imagine that there is still a decent amount of work. Distributions need to put into resources (likely less than the -fno-pic->-fPIE transition (GCC's --enable-default-pie)).
In return, shared objects will be no slower than static PIE.

Will GCC be able to change the default? Ultimately I think that will be a distribution's decision.
When sufficient distributions switch to -fno-semantic-interposition by default, maybe the upstream GCC switch will happen as well.

There is a trade-off and the downside is that LD_PRELOAD replacing a fragment of a shared object will be unsupported.
In some rare cases the user may need LD_PRELOAD: sometimes as a workaround for some broken software. I feel that distributions should not provide such flexibility by default at such a great cost.
The users can build the software by themselves.

For gcc/clang -fno-pic, there is one thing which should happen before -Bsymbolic-functions can be more safely deployed: https://gcc.gnu.org/bugzilla/show_bug.cgi?id=100593
"-fno-pic: Use GOT to take address of an external default visibility function"

For global variables, I have a feature request https://gcc.gnu.org/bugzilla/show_bug.cgi?id=100483

If that's implemented in GCC then this change here to build with -fno-semantic-interposition would mean that the test failures seen in D102090 would resurface. Perhaps it's not worth the risk compared to waiting for something like -fno-semantic-interposition-function (or -fno-semantic-function-interposition or -fno-semantic-interposition=function).

As for LD_PRELOAD, it's used by fakeroot during package creation in Arch Linux, and possibly elsewhere too. Like you said, there's likely a significant amount of work required to enable -fno-semantic-interposition by default. Switching to PIE by default was pretty uneventful as far as I recall (aside from having to patch clang to get PIE by default).

For global variables, I have a feature request https://gcc.gnu.org/bugzilla/show_bug.cgi?id=100483

If that's implemented in GCC then this change here to build with -fno-semantic-interposition would mean that the test failures seen in D102090 would resurface. Perhaps it's not worth the risk compared to waiting for something like -fno-semantic-interposition-function (or -fno-semantic-function-interposition or -fno-semantic-interposition=function).

I am waiting for GCC folks' response https://gcc.gnu.org/bugzilla/show_bug.cgi?id=100618 and hold off this patch.

As for LD_PRELOAD, it's used by fakeroot during package creation in Arch Linux, and possibly elsewhere too. Like you said, there's likely a significant amount of work required to enable -fno-semantic-interposition by default. Switching to PIE by default was pretty uneventful as far as I recall (aside from having to patch clang to get PIE by default).

fakeroot works without issue.

-fno-semantic-interposition applies to definitions seen in the translation unit.
-Bsymbolic applies to definitions seen in the linkage unit.

libc functions are defined in libc.so.6, so interposition always work.

If that's implemented in GCC then this change here to build with -fno-semantic-interposition would mean that the test failures seen in D102090 would resurface.

Add version check ? If gcc 11 or lower - known OK.

hold off this patch.

Not sure why, even if they introduce new flag, everybody needs to wait for gcc 12.

MaskRay updated this revision to Diff 346597.May 19 2021, 4:42 PM
MaskRay retitled this revision from [CMake][ELF] Add -fno-semantic-interposition for GCC to [CMake][ELF] Add -fno-semantic-interposition for GCC and Clang>=13.
MaskRay edited the summary of this revision. (Show Details)

Enable for Clang >= 13

MaskRay edited the summary of this revision. (Show Details)May 19 2021, 4:43 PM

Great, thanks!

Have you considered using -fvisibility=protected instead?

MaskRay added a comment.EditedMay 19 2021, 5:18 PM

Have you considered using -fvisibility=protected instead?

I have considered it and excluded that option. Options affecting variables are incompatible with -fno-pic caused copy relocations.

Worse, -fvisbility=protected is very broken in the GNU x86 world (not broken in clang/lld world, not broken in the non-x86 world). https://maskray.me/blog/2021-01-09-copy-relocations-canonical-plt-entries-and-protected

Sony is using -fvisbility=protected (either directly or via -fdeclspec) so clang/lld world is good if we don't consider pointer equality for variables.

piotr added a subscriber: piotr.May 21 2021, 4:26 AM

Ping. Note the variable interposition has been resolved. I have removed the variable optimization (which isn't very effective because global variables should not be in bottleneck)

phosek accepted this revision.May 24 2021, 10:38 PM

LGTM

This revision is now accepted and ready to land.May 24 2021, 10:38 PM

Thanks for measuring:) 3~4% means that GCC is using a really unfortunate default:(

It would be nice if we can have an agreed option https://gcc.gnu.org/bugzilla/show_bug.cgi?id=100593 https://sourceware.org/pipermail/binutils/2021-June/116831.html but communication with GNU has been difficult.

I noticed that when I compile this patch with gcc 9.3.0 I suddenly see

1122/2282] Building CXX object lib/Object/CMakeFiles/LLVMObject.dir/Archive.cpp.o
In file included from ../lib/Object/Archive.cpp:13:
../include/llvm/Object/Archive.h: In member function 'llvm::object::Archive::child_iterator llvm::object::Archive::child_end() const':
../include/llvm/Object/Archive.h:147:48: warning: '*((void*)&<anonymous> +40)' is used uninitialized in this function [-Wuninitialized]
  147 |     ChildFallibleIterator(const Child &C) : C(C) {}

Do you know if this is anything to worry about?
I just noticed the warning when compiling after a pull.

tambre added a subscriber: tambre.Jun 25 2021, 11:46 PM

Compiling Polly with ThinLTO in either Release or RelWithDebInfo fails after this with relocation errors:

root@xinux:/opt/deb/llvm/build# rm -r * .*
root@xinux:/opt/deb/llvm/build# cmake ../llvm -GNinja \
		-DCMAKE_BUILD_TYPE=Release \
		-DLLVM_ENABLE_PROJECTS="polly" \
		-DLLVM_ENABLE_LTO=Thin && ninja LLVMPolly.so
-- The C compiler identification is Clang 13.0.0
-- The CXX compiler identification is Clang 13.0.0
-- The ASM compiler identification is Clang
-- Found assembler: /usr/bin/clang
-- Detecting C compiler ABI info
-- Detecting C compiler ABI info - done
-- Check for working C compiler: /usr/bin/clang - skipped
-- Detecting C compile features
-- Detecting C compile features - done
-- Detecting CXX compiler ABI info
-- Detecting CXX compiler ABI info - done
-- Check for working CXX compiler: /usr/bin/clang++ - skipped
-- Detecting CXX compile features
-- Detecting CXX compile features - done
-- clang project is disabled
-- clang-tools-extra project is disabled
-- compiler-rt project is disabled
-- debuginfo-tests project is disabled
-- libc project is disabled
-- libclc project is disabled
-- libcxx project is disabled
-- libcxxabi project is disabled
-- libunwind project is disabled
-- lld project is disabled
-- lldb project is disabled
-- mlir project is disabled
-- openmp project is disabled
-- parallel-libs project is disabled
-- polly project is enabled
-- pstl project is disabled
-- flang project is disabled
-- Performing Test LLVM_LIBSTDCXX_MIN
-- Performing Test LLVM_LIBSTDCXX_MIN - Success
-- Performing Test LLVM_LIBSTDCXX_SOFT_ERROR
-- Performing Test LLVM_LIBSTDCXX_SOFT_ERROR - Success
-- Looking for dlfcn.h
-- Looking for dlfcn.h - found
-- Looking for errno.h
-- Looking for errno.h - found
-- Looking for fcntl.h
-- Looking for fcntl.h - found
-- Looking for link.h
-- Looking for link.h - found
-- Looking for malloc/malloc.h
-- Looking for malloc/malloc.h - not found
-- Looking for pthread.h
-- Looking for pthread.h - found
-- Looking for signal.h
-- Looking for signal.h - found
-- Looking for sys/ioctl.h
-- Looking for sys/ioctl.h - found
-- Looking for sys/mman.h
-- Looking for sys/mman.h - found
-- Looking for sys/param.h
-- Looking for sys/param.h - found
-- Looking for sys/resource.h
-- Looking for sys/resource.h - found
-- Looking for sys/stat.h
-- Looking for sys/stat.h - found
-- Looking for sys/time.h
-- Looking for sys/time.h - found
-- Looking for sys/types.h
-- Looking for sys/types.h - found
-- Looking for sysexits.h
-- Looking for sysexits.h - found
-- Looking for termios.h
-- Looking for termios.h - found
-- Looking for unistd.h
-- Looking for unistd.h - found
-- Looking for valgrind/valgrind.h
-- Looking for valgrind/valgrind.h - not found
-- Looking for fenv.h
-- Looking for fenv.h - found
-- Looking for FE_ALL_EXCEPT
-- Looking for FE_ALL_EXCEPT - found
-- Looking for FE_INEXACT
-- Looking for FE_INEXACT - found
-- Looking for mach/mach.h
-- Looking for mach/mach.h - not found
-- Looking for histedit.h
-- Looking for histedit.h - found
-- Looking for CrashReporterClient.h
-- Looking for CrashReporterClient.h - not found
-- Looking for linux/magic.h
-- Looking for linux/magic.h - found
-- Looking for pthread_create in pthread
-- Looking for pthread_create in pthread - found
-- Looking for pthread_getspecific in pthread
-- Looking for pthread_getspecific in pthread - found
-- Looking for pthread_rwlock_init in pthread
-- Looking for pthread_rwlock_init in pthread - found
-- Looking for pthread_mutex_lock in pthread
-- Looking for pthread_mutex_lock in pthread - found
-- Looking for dlopen in dl
-- Looking for dlopen in dl - found
-- Looking for clock_gettime in rt
-- Looking for clock_gettime in rt - found
-- Looking for pfm_initialize in pfm
-- Looking for pfm_initialize in pfm - found
-- Looking for perfmon/perf_event.h
-- Looking for perfmon/perf_event.h - found
-- Looking for perfmon/pfmlib.h
-- Looking for perfmon/pfmlib.h - found
-- Looking for perfmon/pfmlib_perf_event.h
-- Looking for perfmon/pfmlib_perf_event.h - found
-- Performing Test COMPILE_WITH_CYCLES
-- Performing Test COMPILE_WITH_CYCLES - Success
-- Looking for pthread.h
-- Looking for pthread.h - found
-- Performing Test CMAKE_HAVE_LIBC_PTHREAD
-- Performing Test CMAKE_HAVE_LIBC_PTHREAD - Failed
-- Looking for pthread_create in pthreads
-- Looking for pthread_create in pthreads - not found
-- Looking for pthread_create in pthread
-- Looking for pthread_create in pthread - found
-- Found Threads: TRUE
-- Found ZLIB: /usr/lib/x86_64-linux-gnu/libz.so (found version "1.2.11")
-- Looking for compress2
-- Looking for compress2 - found
-- Found LibXml2: /usr/lib/x86_64-linux-gnu/libxml2.so (found version "2.9.10")
-- Looking for xmlReadMemory
-- Looking for xmlReadMemory - found
-- Looking for el_init in edit
-- Looking for el_init in edit - found
-- Looking for xar_open in xar
-- Looking for xar_open in xar - not found
-- Looking for arc4random
-- Looking for arc4random - not found
-- Looking for backtrace
-- Looking for backtrace - found
-- backtrace facility detected in default set of libraries
-- Found Backtrace: /usr/include
-- Performing Test C_SUPPORTS_WERROR_UNGUARDED_AVAILABILITY_NEW
-- Performing Test C_SUPPORTS_WERROR_UNGUARDED_AVAILABILITY_NEW - Success
-- Looking for __register_frame
-- Looking for __register_frame - not found
-- Looking for __deregister_frame
-- Looking for __deregister_frame - not found
-- Looking for _Unwind_Backtrace
-- Looking for _Unwind_Backtrace - not found
-- Looking for getpagesize
-- Looking for getpagesize - found
-- Looking for sysconf
-- Looking for sysconf - found
-- Looking for getrusage
-- Looking for getrusage - found
-- Looking for setrlimit
-- Looking for setrlimit - found
-- Looking for isatty
-- Looking for isatty - found
-- Looking for futimens
-- Looking for futimens - found
-- Looking for futimes
-- Looking for futimes - found
-- Looking for posix_fallocate
-- Looking for posix_fallocate - found
-- Looking for sigaltstack
-- Looking for sigaltstack - found
-- Looking for lseek64
-- Looking for lseek64 - found
-- Looking for mallctl
-- Looking for mallctl - not found
-- Looking for mallinfo
-- Looking for mallinfo - found
-- Looking for mallinfo2
-- Looking for mallinfo2 - not found
-- Looking for malloc_zone_statistics
-- Looking for malloc_zone_statistics - not found
-- Looking for getrlimit
-- Looking for getrlimit - found
-- Looking for posix_spawn
-- Looking for posix_spawn - found
-- Looking for pread
-- Looking for pread - found
-- Looking for sbrk
-- Looking for sbrk - found
-- Looking for strerror
-- Looking for strerror - found
-- Looking for strerror_r
-- Looking for strerror_r - found
-- Looking for strerror_s
-- Looking for strerror_s - not found
-- Looking for setenv
-- Looking for setenv - found
-- Looking for dlopen
-- Looking for dlopen - found
-- Looking for dladdr
-- Looking for dladdr - not found
-- Performing Test HAVE_STRUCT_STAT_ST_MTIMESPEC_TV_NSEC
-- Performing Test HAVE_STRUCT_STAT_ST_MTIMESPEC_TV_NSEC - Failed
-- Performing Test HAVE_STRUCT_STAT_ST_MTIM_TV_NSEC
-- Performing Test HAVE_STRUCT_STAT_ST_MTIM_TV_NSEC - Success
-- Looking for __GLIBC__
-- Looking for __GLIBC__ - found
-- Looking for pthread_getname_np
-- Looking for pthread_getname_np - found
-- Looking for pthread_setname_np
-- Looking for pthread_setname_np - found
-- Looking for proc_pid_rusage
-- Looking for proc_pid_rusage - not found
-- Performing Test HAVE_STD_IS_TRIVIALLY_COPYABLE
-- Performing Test HAVE_STD_IS_TRIVIALLY_COPYABLE - Success
-- Performing Test HAVE_CXX_ATOMICS_WITHOUT_LIB
-- Performing Test HAVE_CXX_ATOMICS_WITHOUT_LIB - Success
-- Performing Test HAVE_CXX_ATOMICS64_WITHOUT_LIB
-- Performing Test HAVE_CXX_ATOMICS64_WITHOUT_LIB - Success
-- Performing Test LLVM_HAS_ATOMICS
-- Performing Test LLVM_HAS_ATOMICS - Success
-- Performing Test SUPPORTS_VARIADIC_MACROS_FLAG
-- Performing Test SUPPORTS_VARIADIC_MACROS_FLAG - Success
-- Performing Test SUPPORTS_GNU_ZERO_VARIADIC_MACRO_ARGUMENTS_FLAG
-- Performing Test SUPPORTS_GNU_ZERO_VARIADIC_MACRO_ARGUMENTS_FLAG - Success
-- Native target architecture is X86
-- Threads enabled.
-- Doxygen disabled.
-- Go bindings disabled.
-- Ninja version: 1.10.1
-- Found OCaml: /usr/bin/ocamlfind
-- OCaml bindings disabled, need ctypes >=0.4.
-- Could NOT find Python module pygments
-- Could NOT find Python module pygments.lexers.c_cpp
-- Could NOT find Python module yaml
-- LLVM host triple: x86_64-unknown-linux-gnu
-- LLVM default target triple: x86_64-unknown-linux-gnu
-- ThinLTO provides its own parallel linking - limiting parallel link jobs to 2.
-- Performing Test C_SUPPORTS_FPIC
-- Performing Test C_SUPPORTS_FPIC - Success
-- Performing Test CXX_SUPPORTS_FPIC
-- Performing Test CXX_SUPPORTS_FPIC - Success
-- Building with -fPIC
-- Performing Test C_SUPPORTS_FNO_SEMANTIC_INTERPOSITION
-- Performing Test C_SUPPORTS_FNO_SEMANTIC_INTERPOSITION - Success
-- Performing Test CXX_SUPPORTS_FNO_SEMANTIC_INTERPOSITION
-- Performing Test CXX_SUPPORTS_FNO_SEMANTIC_INTERPOSITION - Success
-- Performing Test SUPPORTS_FVISIBILITY_INLINES_HIDDEN_FLAG
-- Performing Test SUPPORTS_FVISIBILITY_INLINES_HIDDEN_FLAG - Success
-- Performing Test C_SUPPORTS_WERROR_DATE_TIME
-- Performing Test C_SUPPORTS_WERROR_DATE_TIME - Success
-- Performing Test CXX_SUPPORTS_WERROR_DATE_TIME
-- Performing Test CXX_SUPPORTS_WERROR_DATE_TIME - Success
-- Performing Test CXX_SUPPORTS_WERROR_UNGUARDED_AVAILABILITY_NEW
-- Performing Test CXX_SUPPORTS_WERROR_UNGUARDED_AVAILABILITY_NEW - Success
-- Performing Test CXX_SUPPORTS_MISSING_FIELD_INITIALIZERS_FLAG
-- Performing Test CXX_SUPPORTS_MISSING_FIELD_INITIALIZERS_FLAG - Success
-- Performing Test C_SUPPORTS_CXX98_COMPAT_EXTRA_SEMI_FLAG
-- Performing Test C_SUPPORTS_CXX98_COMPAT_EXTRA_SEMI_FLAG - Success
-- Performing Test CXX_SUPPORTS_CXX98_COMPAT_EXTRA_SEMI_FLAG
-- Performing Test CXX_SUPPORTS_CXX98_COMPAT_EXTRA_SEMI_FLAG - Success
-- Performing Test C_SUPPORTS_IMPLICIT_FALLTHROUGH_FLAG
-- Performing Test C_SUPPORTS_IMPLICIT_FALLTHROUGH_FLAG - Success
-- Performing Test CXX_SUPPORTS_IMPLICIT_FALLTHROUGH_FLAG
-- Performing Test CXX_SUPPORTS_IMPLICIT_FALLTHROUGH_FLAG - Success
-- Performing Test C_SUPPORTS_COVERED_SWITCH_DEFAULT_FLAG
-- Performing Test C_SUPPORTS_COVERED_SWITCH_DEFAULT_FLAG - Success
-- Performing Test CXX_SUPPORTS_COVERED_SWITCH_DEFAULT_FLAG
-- Performing Test CXX_SUPPORTS_COVERED_SWITCH_DEFAULT_FLAG - Success
-- Performing Test CXX_SUPPORTS_CLASS_MEMACCESS_FLAG
-- Performing Test CXX_SUPPORTS_CLASS_MEMACCESS_FLAG - Failed
-- Performing Test CXX_SUPPORTS_NOEXCEPT_TYPE_FLAG
-- Performing Test CXX_SUPPORTS_NOEXCEPT_TYPE_FLAG - Success
-- Performing Test CXX_WONT_WARN_ON_FINAL_NONVIRTUALDTOR
-- Performing Test CXX_WONT_WARN_ON_FINAL_NONVIRTUALDTOR - Success
-- Performing Test C_SUPPORTS_DELETE_NON_VIRTUAL_DTOR_FLAG
-- Performing Test C_SUPPORTS_DELETE_NON_VIRTUAL_DTOR_FLAG - Success
-- Performing Test CXX_SUPPORTS_DELETE_NON_VIRTUAL_DTOR_FLAG
-- Performing Test CXX_SUPPORTS_DELETE_NON_VIRTUAL_DTOR_FLAG - Success
-- Performing Test CXX_SUPPORTS_SUGGEST_OVERRIDE_FLAG
-- Performing Test CXX_SUPPORTS_SUGGEST_OVERRIDE_FLAG - Success
-- Performing Test CXX_WSUGGEST_OVERRIDE_ALLOWS_ONLY_FINAL
-- Performing Test CXX_WSUGGEST_OVERRIDE_ALLOWS_ONLY_FINAL - Success
-- Performing Test C_WCOMMENT_ALLOWS_LINE_WRAP
-- Performing Test C_WCOMMENT_ALLOWS_LINE_WRAP - Success
-- Performing Test C_SUPPORTS_STRING_CONVERSION_FLAG
-- Performing Test C_SUPPORTS_STRING_CONVERSION_FLAG - Success
-- Performing Test CXX_SUPPORTS_STRING_CONVERSION_FLAG
-- Performing Test CXX_SUPPORTS_STRING_CONVERSION_FLAG - Success
-- Performing Test C_SUPPORTS_MISLEADING_INDENTATION_FLAG
-- Performing Test C_SUPPORTS_MISLEADING_INDENTATION_FLAG - Success
-- Performing Test CXX_SUPPORTS_MISLEADING_INDENTATION_FLAG
-- Performing Test CXX_SUPPORTS_MISLEADING_INDENTATION_FLAG - Success
-- Performing Test LINKER_SUPPORTS_COLOR_DIAGNOSTICS
-- Performing Test LINKER_SUPPORTS_COLOR_DIAGNOSTICS - Success
-- Performing Test C_SUPPORTS_FNO_FUNCTION_SECTIONS
-- Performing Test C_SUPPORTS_FNO_FUNCTION_SECTIONS - Success
-- Performing Test C_SUPPORTS_FFUNCTION_SECTIONS
-- Performing Test C_SUPPORTS_FFUNCTION_SECTIONS - Success
-- Performing Test CXX_SUPPORTS_FFUNCTION_SECTIONS
-- Performing Test CXX_SUPPORTS_FFUNCTION_SECTIONS - Success
-- Performing Test C_SUPPORTS_FDATA_SECTIONS
-- Performing Test C_SUPPORTS_FDATA_SECTIONS - Success
-- Performing Test CXX_SUPPORTS_FDATA_SECTIONS
-- Performing Test CXX_SUPPORTS_FDATA_SECTIONS - Success
-- Looking for os_signpost_interval_begin
-- Looking for os_signpost_interval_begin - not found
-- Found Python3: /usr/bin/python3.9 (found suitable version "3.9.2", minimum required is "3.6") found components: Interpreter
-- Linker detection: unknown
-- Found Git: /usr/bin/git (found version "2.32.0")
-- Targeting AArch64
-- Targeting AMDGPU
-- Targeting ARM
-- Targeting AVR
-- Targeting BPF
-- Targeting Hexagon
-- Targeting Lanai
-- Targeting Mips
-- Targeting MSP430
-- Targeting NVPTX
-- Targeting PowerPC
-- Targeting RISCV
-- Targeting Sparc
-- Targeting SystemZ
-- Targeting WebAssembly
-- Targeting X86
-- Targeting XCore
-- ISL version: isl-0.23-61-g24e8cd12
-- Performing Test HAS_ATTRIBUTE_WARN_UNUSED_RESULT
-- Performing Test HAS_ATTRIBUTE_WARN_UNUSED_RESULT - Success
-- Performing Test HAVE___ATTRIBUTE__
-- Performing Test HAVE___ATTRIBUTE__ - Success
-- Performing Test HAVE_DECL_FFS
-- Performing Test HAVE_DECL_FFS - Success
-- Performing Test HAVE_DECL___BUILTIN_FFS
-- Performing Test HAVE_DECL___BUILTIN_FFS - Success
-- Performing Test HAVE_DECL__BITSCANFORWARD
-- Performing Test HAVE_DECL__BITSCANFORWARD - Failed
-- Performing Test HAVE_DECL_STRCASECMP
-- Performing Test HAVE_DECL_STRCASECMP - Success
-- Performing Test HAVE_DECL__STRICMP
-- Performing Test HAVE_DECL__STRICMP - Failed
-- Performing Test HAVE_DECL_STRNCASECMP
-- Performing Test HAVE_DECL_STRNCASECMP - Success
-- Performing Test HAVE_DECL__STRNICMP
-- Performing Test HAVE_DECL__STRNICMP - Failed
-- Performing Test HAVE_DECL_SNPRINTF
-- Performing Test HAVE_DECL_SNPRINTF - Success
-- Performing Test HAVE_DECL__SNPRINTF
-- Performing Test HAVE_DECL__SNPRINTF - Failed
-- Performing Test HAVE_UINT8T
-- Performing Test HAVE_UINT8T - Failed
-- Performing Test HAVE_STDINT_H
-- Performing Test HAVE_STDINT_H - Success
-- Performing Test HAVE_INTTYPES_H
-- Performing Test HAVE_INTTYPES_H - Success
-- Performing Test HAVE_SYS_INTTYPES_H
-- Performing Test HAVE_SYS_INTTYPES_H - Failed
-- Registering Polly as a pass plugin (static build: ON)
-- Registering Bye as a pass plugin (static build: OFF)
-- Failed to find LLVM FileCheck
-- Version: 0.0.0
-- Performing Test HAVE_CXX_FLAG_STD_CXX11
-- Performing Test HAVE_CXX_FLAG_STD_CXX11 - Success
-- Performing Test HAVE_CXX_FLAG_WALL
-- Performing Test HAVE_CXX_FLAG_WALL - Success
-- Performing Test HAVE_CXX_FLAG_WEXTRA
-- Performing Test HAVE_CXX_FLAG_WEXTRA - Success
-- Performing Test HAVE_CXX_FLAG_WSHADOW
-- Performing Test HAVE_CXX_FLAG_WSHADOW - Success
-- Performing Test HAVE_CXX_FLAG_PEDANTIC
-- Performing Test HAVE_CXX_FLAG_PEDANTIC - Success
-- Performing Test HAVE_CXX_FLAG_PEDANTIC_ERRORS
-- Performing Test HAVE_CXX_FLAG_PEDANTIC_ERRORS - Success
-- Performing Test HAVE_CXX_FLAG_WSHORTEN_64_TO_32
-- Performing Test HAVE_CXX_FLAG_WSHORTEN_64_TO_32 - Success
-- Performing Test HAVE_CXX_FLAG_WFLOAT_EQUAL
-- Performing Test HAVE_CXX_FLAG_WFLOAT_EQUAL - Success
-- Performing Test HAVE_CXX_FLAG_FSTRICT_ALIASING
-- Performing Test HAVE_CXX_FLAG_FSTRICT_ALIASING - Success
-- Performing Test HAVE_CXX_FLAG_FNO_EXCEPTIONS
-- Performing Test HAVE_CXX_FLAG_FNO_EXCEPTIONS - Success
-- Performing Test HAVE_CXX_FLAG_WNO_SUGGEST_OVERRIDE
-- Performing Test HAVE_CXX_FLAG_WNO_SUGGEST_OVERRIDE - Success
-- Performing Test HAVE_CXX_FLAG_WSTRICT_ALIASING
-- Performing Test HAVE_CXX_FLAG_WSTRICT_ALIASING - Success
-- Performing Test HAVE_CXX_FLAG_WD654
-- Performing Test HAVE_CXX_FLAG_WD654 - Failed
-- Performing Test HAVE_CXX_FLAG_WTHREAD_SAFETY
-- Performing Test HAVE_CXX_FLAG_WTHREAD_SAFETY - Success
-- Performing Test HAVE_THREAD_SAFETY_ATTRIBUTES
-- Performing Test HAVE_THREAD_SAFETY_ATTRIBUTES
-- Performing Test HAVE_THREAD_SAFETY_ATTRIBUTES -- failed to compile
-- Performing Test HAVE_CXX_FLAG_COVERAGE
-- Performing Test HAVE_CXX_FLAG_COVERAGE - Success
-- Performing Test HAVE_GNU_POSIX_REGEX
-- Performing Test HAVE_GNU_POSIX_REGEX
-- Performing Test HAVE_GNU_POSIX_REGEX -- failed to compile
-- Performing Test HAVE_POSIX_REGEX
-- Performing Test HAVE_POSIX_REGEX
-- Performing Test HAVE_POSIX_REGEX -- success
-- Performing Test HAVE_STEADY_CLOCK
-- Performing Test HAVE_STEADY_CLOCK
-- Performing Test HAVE_STEADY_CLOCK -- success
-- Configuring done
-- Generating done
-- Build files have been written to: /opt/deb/llvm/build
[380/380] Linking CXX shared module lib/LLVMPolly.so
FAILED: lib/LLVMPolly.so
: && /usr/bin/clang++ -fPIC -fPIC -fno-semantic-interposition -fvisibility-inlines-hidden -Werror=date-time -Werror=unguarded-availability-new -Wall -Wextra -Wno-unused-parameter -Wwrite-strings -Wcast-qual -Wmissing-field-initializers -pedantic -Wno-long-long -Wc++98-compat-extra-semi -Wimplicit-fallthrough -Wcovered-switch-default -Wno-noexcept-type -Wnon-virtual-dtor -Wdelete-non-virtual-dtor -Wsuggest-override -Wstring-conversion -Wmisleading-indentation -fdiagnostics-color -ffunction-sections -fdata-sections -flto=thin -fno-exceptions -fno-rtti -O3 -DNDEBUG  -Wl,-z,nodelete -Wl,--color-diagnostics -shared  -o lib/LLVMPolly.so tools/polly/lib/CMakeFiles/obj.Polly.dir/Analysis/DependenceInfo.cpp.o tools/polly/lib/CMakeFiles/obj.Polly.dir/Analysis/PolyhedralInfo.cpp.o tools/polly/lib/CMakeFiles/obj.Polly.dir/Analysis/ScopDetection.cpp.o tools/polly/lib/CMakeFiles/obj.Polly.dir/Analysis/ScopDetectionDiagnostic.cpp.o tools/polly/lib/CMakeFiles/obj.Polly.dir/Analysis/ScopInfo.cpp.o tools/polly/lib/CMakeFiles/obj.Polly.dir/Analysis/ScopBuilder.cpp.o tools/polly/lib/CMakeFiles/obj.Polly.dir/Analysis/ScopGraphPrinter.cpp.o tools/polly/lib/CMakeFiles/obj.Polly.dir/Analysis/ScopPass.cpp.o tools/polly/lib/CMakeFiles/obj.Polly.dir/Analysis/PruneUnprofitable.cpp.o tools/polly/lib/CMakeFiles/obj.Polly.dir/CodeGen/BlockGenerators.cpp.o tools/polly/lib/CMakeFiles/obj.Polly.dir/CodeGen/IslAst.cpp.o tools/polly/lib/CMakeFiles/obj.Polly.dir/CodeGen/IslExprBuilder.cpp.o tools/polly/lib/CMakeFiles/obj.Polly.dir/CodeGen/IslNodeBuilder.cpp.o tools/polly/lib/CMakeFiles/obj.Polly.dir/CodeGen/CodeGeneration.cpp.o tools/polly/lib/CMakeFiles/obj.Polly.dir/CodeGen/LoopGenerators.cpp.o tools/polly/lib/CMakeFiles/obj.Polly.dir/CodeGen/LoopGeneratorsGOMP.cpp.o tools/polly/lib/CMakeFiles/obj.Polly.dir/CodeGen/LoopGeneratorsKMP.cpp.o tools/polly/lib/CMakeFiles/obj.Polly.dir/CodeGen/IRBuilder.cpp.o tools/polly/lib/CMakeFiles/obj.Polly.dir/CodeGen/Utils.cpp.o tools/polly/lib/CMakeFiles/obj.Polly.dir/CodeGen/RuntimeDebugBuilder.cpp.o tools/polly/lib/CMakeFiles/obj.Polly.dir/CodeGen/CodegenCleanup.cpp.o tools/polly/lib/CMakeFiles/obj.Polly.dir/CodeGen/PerfMonitor.cpp.o tools/polly/lib/CMakeFiles/obj.Polly.dir/Exchange/JSONExporter.cpp.o tools/polly/lib/CMakeFiles/obj.Polly.dir/Support/GICHelper.cpp.o tools/polly/lib/CMakeFiles/obj.Polly.dir/Support/SCEVAffinator.cpp.o tools/polly/lib/CMakeFiles/obj.Polly.dir/Support/SCEVValidator.cpp.o tools/polly/lib/CMakeFiles/obj.Polly.dir/Support/RegisterPasses.cpp.o tools/polly/lib/CMakeFiles/obj.Polly.dir/Support/ScopHelper.cpp.o tools/polly/lib/CMakeFiles/obj.Polly.dir/Support/ScopLocation.cpp.o tools/polly/lib/CMakeFiles/obj.Polly.dir/Support/ISLTools.cpp.o tools/polly/lib/CMakeFiles/obj.Polly.dir/Support/DumpModulePass.cpp.o tools/polly/lib/CMakeFiles/obj.Polly.dir/Support/VirtualInstruction.cpp.o tools/polly/lib/CMakeFiles/obj.Polly.dir/Transform/Canonicalization.cpp.o tools/polly/lib/CMakeFiles/obj.Polly.dir/Transform/CodePreparation.cpp.o tools/polly/lib/CMakeFiles/obj.Polly.dir/Transform/DeadCodeElimination.cpp.o tools/polly/lib/CMakeFiles/obj.Polly.dir/Transform/ScheduleOptimizer.cpp.o tools/polly/lib/CMakeFiles/obj.Polly.dir/Transform/ScheduleTreeTransform.cpp.o tools/polly/lib/CMakeFiles/obj.Polly.dir/Transform/FlattenSchedule.cpp.o tools/polly/lib/CMakeFiles/obj.Polly.dir/Transform/FlattenAlgo.cpp.o tools/polly/lib/CMakeFiles/obj.Polly.dir/Transform/ForwardOpTree.cpp.o tools/polly/lib/CMakeFiles/obj.Polly.dir/Transform/DeLICM.cpp.o tools/polly/lib/CMakeFiles/obj.Polly.dir/Transform/ZoneAlgo.cpp.o tools/polly/lib/CMakeFiles/obj.Polly.dir/Transform/Simplify.cpp.o tools/polly/lib/CMakeFiles/obj.Polly.dir/Transform/MaximalStaticExpansion.cpp.o tools/polly/lib/CMakeFiles/obj.Polly.dir/Transform/RewriteByReferenceParameters.cpp.o tools/polly/lib/CMakeFiles/obj.Polly.dir/Transform/ScopInliner.cpp.o tools/polly/lib/CMakeFiles/obj.Polly.dir/Transform/ManualOptimizer.cpp.o tools/polly/lib/CMakeFiles/obj.Polly.dir/Transform/MatmulOptimizer.cpp.o tools/polly/lib/CMakeFiles/LLVMPolly.dir/Plugin/Polly.cpp.o  lib/libPollyISL.a && :
ld.lld: error: relocation R_X86_64_PC32 cannot be used against symbol isl_map_coalesce; recompile with -fPIC
>>> defined in lto.tmp
>>> referenced by DependenceInfo.cpp
>>>               lto.tmp:(polly::Dependences::addPrivatizationDependences())

ld.lld: error: relocation R_X86_64_PC32 cannot be used against symbol isl_map_coalesce; recompile with -fPIC
>>> defined in lto.tmp
>>> referenced by DependenceInfo.cpp
>>>               lto.tmp:(polly::Dependences::calculateDependences(polly::Scop&))

ld.lld: error: relocation R_X86_64_PC32 cannot be used against symbol isl_map_coalesce; recompile with -fPIC
>>> defined in lto.tmp
>>> referenced by DependenceInfo.cpp
>>>               lto.tmp:(polly::Dependences::calculateDependences(polly::Scop&))

ld.lld: error: relocation R_X86_64_PC32 cannot be used against symbol isl_map_coalesce; recompile with -fPIC
>>> defined in lto.tmp
>>> referenced by DependenceInfo.cpp
>>>               lto.tmp:(polly::Dependences::calculateDependences(polly::Scop&))

ld.lld: error: relocation R_X86_64_PC32 cannot be used against symbol isl_map_coalesce; recompile with -fPIC
>>> defined in lto.tmp
>>> referenced by DependenceInfo.cpp
>>>               lto.tmp:(polly::Dependences::getDependences(int) const)

ld.lld: error: relocation R_X86_64_PC32 cannot be used against symbol isl_map_coalesce; recompile with -fPIC
>>> defined in lto.tmp
>>> referenced by PolyhedralInfo.cpp
>>>               lto.tmp:(polly::PolyhedralInfo::getScheduleForLoop(polly::Scop const*, llvm::Loop*) const)

ld.lld: error: relocation R_X86_64_PC32 cannot be used against symbol isl_aff_add; recompile with -fPIC
>>> defined in lto.tmp
>>> referenced by ScopBuilder.cpp
>>>               lto.tmp:(polly::ScopBuilder::calculateMinMaxAccess(llvm::SmallVector<polly::MemoryAccess*, 4u>, llvm::SmallVector<std::__1::pair<isl::noexceptions::pw_multi_aff, isl::noexceptions::pw_multi_aff>, 4u>&))

ld.lld: error: relocation R_X86_64_PC32 cannot be used against symbol isl_aff_add; recompile with -fPIC
>>> defined in lto.tmp
>>> referenced by SCEVAffinator.cpp
>>>               lto.tmp:(polly::SCEVAffinator::interpretAsUnsigned(std::__1::pair<isl::noexceptions::pw_aff, isl::noexceptions::set>&, unsigned int))

ld.lld: error: relocation R_X86_64_PC32 cannot be used against symbol isl_aff_mul; recompile with -fPIC
>>> defined in lto.tmp
>>> referenced by SCEVAffinator.cpp
>>>               lto.tmp:(polly::SCEVAffinator::visit(llvm::SCEV const*))

ld.lld: error: relocation R_X86_64_PC32 cannot be used against symbol isl_aff_add; recompile with -fPIC
>>> defined in lto.tmp
>>> referenced by SCEVAffinator.cpp
>>>               lto.tmp:(polly::SCEVAffinator::addModuloSemantic(isl::noexceptions::pw_aff, llvm::Type*) const)

ld.lld: error: relocation R_X86_64_PC32 cannot be used against symbol isl_aff_add; recompile with -fPIC
>>> defined in lto.tmp
>>> referenced by SCEVAffinator.cpp
>>>               lto.tmp:(polly::SCEVAffinator::visitAddExpr(llvm::SCEVAddExpr const*))

ld.lld: error: relocation R_X86_64_PC32 cannot be used against symbol isl_aff_mul; recompile with -fPIC
>>> defined in lto.tmp
>>> referenced by SCEVAffinator.cpp
>>>               lto.tmp:(polly::SCEVAffinator::visitMulExpr(llvm::SCEVMulExpr const*))

ld.lld: error: relocation R_X86_64_PC32 cannot be used against symbol isl_aff_add; recompile with -fPIC
>>> defined in lto.tmp
>>> referenced by SCEVAffinator.cpp
>>>               lto.tmp:(polly::SCEVAffinator::visitAddRecExpr(llvm::SCEVAddRecExpr const*))

ld.lld: error: relocation R_X86_64_PC32 cannot be used against symbol isl_aff_mul; recompile with -fPIC
>>> defined in lto.tmp
>>> referenced by SCEVAffinator.cpp
>>>               lto.tmp:(polly::SCEVAffinator::visitAddRecExpr(llvm::SCEVAddRecExpr const*))

ld.lld: error: relocation R_X86_64_PC32 cannot be used against symbol isl_aff_add; recompile with -fPIC
>>> defined in lto.tmp
>>> referenced by SCEVAffinator.cpp
>>>               lto.tmp:(polly::SCEVAffinator::visitUDivExpr(llvm::SCEVUDivExpr const*))

ld.lld: error: relocation R_X86_64_PC32 cannot be used against symbol isl_aff_mul; recompile with -fPIC
>>> defined in lto.tmp
>>> referenced by ScheduleTreeTransform.cpp
>>>               lto.tmp:(isl::noexceptions::stat std::__1::__function::__policy_invoker<isl::noexceptions::stat (isl::noexceptions::pw_aff)>::__call_impl<std::__1::__function::__default_alloc_func<polly::applyPartialUnroll(isl::noexceptions::schedule_node, int)::$_2, isl::noexceptions::stat (isl::noexceptions::pw_aff)> >(std::__1::__function::__policy_storage const*, isl::noexceptions::pw_aff&&))

ld.lld: error: relocation R_X86_64_PC32 cannot be used against symbol isl_aff_add; recompile with -fPIC
>>> defined in lto.tmp
>>> referenced by FlattenAlgo.cpp
>>>               lto.tmp:((anonymous namespace)::tryFlattenSequence(isl::noexceptions::union_map))

ld.lld: error: relocation R_X86_64_PC32 cannot be used against symbol isl_aff_add; recompile with -fPIC
>>> defined in lto.tmp
>>> referenced by FlattenAlgo.cpp
>>>               lto.tmp:((anonymous namespace)::tryFlattenSequence(isl::noexceptions::union_map))

ld.lld: error: relocation R_X86_64_PC32 cannot be used against symbol isl_aff_add; recompile with -fPIC
>>> defined in lto.tmp
>>> referenced by FlattenAlgo.cpp
>>>               lto.tmp:((anonymous namespace)::tryFlattenSequence(isl::noexceptions::union_map))

ld.lld: error: relocation R_X86_64_PC32 cannot be used against symbol isl_aff_mul; recompile with -fPIC
>>> defined in lto.tmp
>>> referenced by FlattenAlgo.cpp
>>>               lto.tmp:(isl::noexceptions::stat std::__1::__function::__policy_invoker<isl::noexceptions::stat (isl::noexceptions::pw_aff)>::__call_impl<std::__1::__function::__default_alloc_func<(anonymous namespace)::multiply(isl::noexceptions::union_pw_aff, isl::noexceptions::val)::$_1, isl::noexceptions::stat (isl::noexceptions::pw_aff)> >(std::__1::__function::__policy_storage const*, isl::noexceptions::pw_aff&&))

ld.lld: error: too many errors emitted, stopping now (use -error-limit=0 to see all errors)
clang-13: error: linker command failed with exit code 1 (use -v to see invocation)
MaskRay added a comment.EditedJun 26 2021, 4:51 PM

Compiling Polly with ThinLTO in either Release or RelWithDebInfo fails after this with relocation errors:

Thanks for the detailed reproduce! There is a ThinLTO issue. I sent D104986 to fix it.