This is an archive of the discontinued LLVM Phabricator instance.

[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.

ljmf00 added a subscriber: ljmf00.Jan 12 2022, 11:15 AM

This patch makes compilation fail when running with sanitization and debug mode, it seems. Brief log here:

FAILED: lib/libLTO.so.14git                                                                                                                                   
: && /usr/bin/clang++ -fPIC -fPIC -fno-semantic-interposition -fvisibility-inlines-hidden -Werror -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-fallthroug
h -Wcovered-switch-default -Wno-noexcept-type -Wnon-virtual-dtor -Wdelete-non-virtual-dtor -Wsuggest-override -Wstring-conversion -Wmisleading-indentation -fn
o-omit-frame-pointer -O1 -fsanitize=address -fsanitize=undefined -fno-sanitize=vptr,function -fno-sanitize-recover=all -fsanitize-address-use-after-scope -fsa
nitize=fuzzer-no-link -fsanitize-blacklist=/mnt/Workspace/Repos/collab/github/llvm/llvm-project/llvm/utils/sanitizers/ubsan_ignorelist.txt -fdiagnostics-color
 -g  -Wl,-z,nodelete -fuse-ld=lld -Wl,--gdb-index -Wl,--color-diagnostics    -Wl,--version-script,"/mnt/Workspace/Repos/collab/github/llvm/llvm-project/build/
tools/lto/LTO.exports" -shared -Wl,-soname,libLTO.so.14git -o lib/libLTO.so.14git tools/lto/CMakeFiles/LTO.dir/LTODisassembler.cpp.o tools/lto/CMakeFiles/LTO.
dir/lto.cpp.o  -Wl,-rpath,"\$ORIGIN/../lib"  lib/libLLVM-14git.so && :                                                                                        
ld.lld: error: relocation R_X86_64_PC32 cannot be used against symbol lto_module_is_object_file_for_target; recompile with -fPIC                              
>>> defined in tools/lto/CMakeFiles/LTO.dir/lto.cpp.o                                                                                                         
>>> referenced by lto.cpp:175 (/mnt/Workspace/Repos/collab/github/llvm/llvm-project/llvm/tools/lto/lto.cpp:175)                                               
>>>               tools/lto/CMakeFiles/LTO.dir/lto.cpp.o:(lto_module_is_object_file_for_target)                                                               
                                                                                                                                                              
ld.lld: error: relocation R_X86_64_PC32 cannot be used against symbol lto_module_has_objc_category; recompile with -fPIC                                      
>>> defined in tools/lto/CMakeFiles/LTO.dir/lto.cpp.o
>>> referenced by lto.cpp:183 (/mnt/Workspace/Repos/collab/github/llvm/llvm-project/llvm/tools/lto/lto.cpp:183)
>>>               tools/lto/CMakeFiles/LTO.dir/lto.cpp.o:(lto_module_has_objc_category)

ld.lld: error: relocation R_X86_64_PC32 cannot be used against symbol lto_module_is_object_file_in_memory_for_target; recompile with -fPIC
>>> defined in tools/lto/CMakeFiles/LTO.dir/lto.cpp.o
>>> referenced by lto.cpp:200 (/mnt/Workspace/Repos/collab/github/llvm/llvm-project/llvm/tools/lto/lto.cpp:200)
>>>               tools/lto/CMakeFiles/LTO.dir/lto.cpp.o:(lto_module_is_object_file_in_memory_for_target)

ld.lld: error: relocation R_X86_64_PC32 cannot be used against symbol lto_module_create; recompile with -fPIC
>>> defined in tools/lto/CMakeFiles/LTO.dir/lto.cpp.o
>>> referenced by lto.cpp:208 (/mnt/Workspace/Repos/collab/github/llvm/llvm-project/llvm/tools/lto/lto.cpp:208)
>>>               tools/lto/CMakeFiles/LTO.dir/lto.cpp.o:(lto_module_create)

ld.lld: error: relocation R_X86_64_PC32 cannot be used against symbol lto_module_create_from_fd; recompile with -fPIC
>>> defined in tools/lto/CMakeFiles/LTO.dir/lto.cpp.o
>>> referenced by lto.cpp:219 (/mnt/Workspace/Repos/collab/github/llvm/llvm-project/llvm/tools/lto/lto.cpp:219)
>>>               tools/lto/CMakeFiles/LTO.dir/lto.cpp.o:(lto_module_create_from_fd)

ld.lld: error: relocation R_X86_64_PC32 cannot be used against symbol lto_module_create_from_fd_at_offset; recompile with -fPIC
>>> defined in tools/lto/CMakeFiles/LTO.dir/lto.cpp.o
>>> referenced by lto.cpp:233 (/mnt/Workspace/Repos/collab/github/llvm/llvm-project/llvm/tools/lto/lto.cpp:233)
>>>               tools/lto/CMakeFiles/LTO.dir/lto.cpp.o:(lto_module_create_from_fd_at_offset)

This patch makes compilation fail when running with sanitization and debug mode, it seems. Brief log here:

FAILED: lib/libLTO.so.14git                                                                                                                                   
: && /usr/bin/clang++ -fPIC -fPIC -fno-semantic-interposition -fvisibility-inlines-hidden -Werror -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-fallthroug
h -Wcovered-switch-default -Wno-noexcept-type -Wnon-virtual-dtor -Wdelete-non-virtual-dtor -Wsuggest-override -Wstring-conversion -Wmisleading-indentation -fn
o-omit-frame-pointer -O1 -fsanitize=address -fsanitize=undefined -fno-sanitize=vptr,function -fno-sanitize-recover=all -fsanitize-address-use-after-scope -fsa
nitize=fuzzer-no-link -fsanitize-blacklist=/mnt/Workspace/Repos/collab/github/llvm/llvm-project/llvm/utils/sanitizers/ubsan_ignorelist.txt -fdiagnostics-color
 -g  -Wl,-z,nodelete -fuse-ld=lld -Wl,--gdb-index -Wl,--color-diagnostics    -Wl,--version-script,"/mnt/Workspace/Repos/collab/github/llvm/llvm-project/build/
tools/lto/LTO.exports" -shared -Wl,-soname,libLTO.so.14git -o lib/libLTO.so.14git tools/lto/CMakeFiles/LTO.dir/LTODisassembler.cpp.o tools/lto/CMakeFiles/LTO.
dir/lto.cpp.o  -Wl,-rpath,"\$ORIGIN/../lib"  lib/libLLVM-14git.so && :                                                                                        
ld.lld: error: relocation R_X86_64_PC32 cannot be used against symbol lto_module_is_object_file_for_target; recompile with -fPIC                              
>>> defined in tools/lto/CMakeFiles/LTO.dir/lto.cpp.o                                                                                                         
>>> referenced by lto.cpp:175 (/mnt/Workspace/Repos/collab/github/llvm/llvm-project/llvm/tools/lto/lto.cpp:175)                                               
>>>               tools/lto/CMakeFiles/LTO.dir/lto.cpp.o:(lto_module_is_object_file_for_target)                                                               
                                                                                                                                                              
ld.lld: error: relocation R_X86_64_PC32 cannot be used against symbol lto_module_has_objc_category; recompile with -fPIC                                      
>>> defined in tools/lto/CMakeFiles/LTO.dir/lto.cpp.o
>>> referenced by lto.cpp:183 (/mnt/Workspace/Repos/collab/github/llvm/llvm-project/llvm/tools/lto/lto.cpp:183)
>>>               tools/lto/CMakeFiles/LTO.dir/lto.cpp.o:(lto_module_has_objc_category)

ld.lld: error: relocation R_X86_64_PC32 cannot be used against symbol lto_module_is_object_file_in_memory_for_target; recompile with -fPIC
>>> defined in tools/lto/CMakeFiles/LTO.dir/lto.cpp.o
>>> referenced by lto.cpp:200 (/mnt/Workspace/Repos/collab/github/llvm/llvm-project/llvm/tools/lto/lto.cpp:200)
>>>               tools/lto/CMakeFiles/LTO.dir/lto.cpp.o:(lto_module_is_object_file_in_memory_for_target)

ld.lld: error: relocation R_X86_64_PC32 cannot be used against symbol lto_module_create; recompile with -fPIC
>>> defined in tools/lto/CMakeFiles/LTO.dir/lto.cpp.o
>>> referenced by lto.cpp:208 (/mnt/Workspace/Repos/collab/github/llvm/llvm-project/llvm/tools/lto/lto.cpp:208)
>>>               tools/lto/CMakeFiles/LTO.dir/lto.cpp.o:(lto_module_create)

ld.lld: error: relocation R_X86_64_PC32 cannot be used against symbol lto_module_create_from_fd; recompile with -fPIC
>>> defined in tools/lto/CMakeFiles/LTO.dir/lto.cpp.o
>>> referenced by lto.cpp:219 (/mnt/Workspace/Repos/collab/github/llvm/llvm-project/llvm/tools/lto/lto.cpp:219)
>>>               tools/lto/CMakeFiles/LTO.dir/lto.cpp.o:(lto_module_create_from_fd)

ld.lld: error: relocation R_X86_64_PC32 cannot be used against symbol lto_module_create_from_fd_at_offset; recompile with -fPIC
>>> defined in tools/lto/CMakeFiles/LTO.dir/lto.cpp.o
>>> referenced by lto.cpp:233 (/mnt/Workspace/Repos/collab/github/llvm/llvm-project/llvm/tools/lto/lto.cpp:233)
>>>               tools/lto/CMakeFiles/LTO.dir/lto.cpp.o:(lto_module_create_from_fd_at_offset)

What's your Clang version? Clang -DLLVM_USE_SANITIZER=Address works well for me (and sanitizer* build bots) with both Debug and Release.
If it's problems in older Clang versions, we can just disable the older versions.

What's your Clang version? Clang -DLLVM_USE_SANITIZER=Address works well for me (and sanitizer* build bots) with both Debug and Release.
If it's problems in older Clang versions, we can just disable the older versions.

I'm running builds on an Arch Linux based docker container with Clang and LLVM tools with version 13.0.0 (rel version 2, for clang, on Arch Linux) on this target CPU https://termbin.com/82n2 . I'm also using ccache 4.4.2 to speed up builds.
I've done a full clean build and logged it here https://ipfs.io/ipfs/bafybeia4kdu4a55fcp5nfntwcqe33aucuwv3uacelmo6zcsmasnsuafvim/ . I'm sorry for including that many flags, but I have an automated CMake bootstrap script to do it but some of them are the default values.

I tried to debug this a bit and figure out if there is a combination of flags that can succeed. I consulted the infrastructure repository and confirmed that sanitisers are being built with gold linker. So perhaps is this something linker related? I can try gold if it is worth trying.

MaskRay added a comment.EditedJan 12 2022, 6:42 PM

What's your Clang version? Clang -DLLVM_USE_SANITIZER=Address works well for me (and sanitizer* build bots) with both Debug and Release.
If it's problems in older Clang versions, we can just disable the older versions.

I'm running builds on an Arch Linux based docker container with Clang and LLVM tools with version 13.0.0 (rel version 2, for clang, on Arch Linux) on this target CPU https://termbin.com/82n2 . I'm also using ccache 4.4.2 to speed up builds.
I've done a full clean build and logged it here https://ipfs.io/ipfs/bafybeia4kdu4a55fcp5nfntwcqe33aucuwv3uacelmo6zcsmasnsuafvim/ . I'm sorry for including that many flags, but I have an automated CMake bootstrap script to do it but some of them are the default values.

I tried to debug this a bit and figure out if there is a combination of flags that can succeed. I consulted the infrastructure repository and confirmed that sanitisers are being built with gold linker. So perhaps is this something linker related? I can try gold if it is worth trying.

I cannot reproduce your breakage with clang+llvm-13.0.0-x86_64-linux-gnu-ubuntu-20.04 on https://github.com/llvm/llvm-project/releases , or nearly trunk Clang from (curl -s https://raw.githubusercontent.com/chromium/chromium/main/tools/clang/scripts/update.py | python3 - --output-dir=~/Stable)

I dropped ccache related options and used something like -DCMAKE_C_COMPILER=~/llvm-prebuilt/clang+llvm-13.0.0-x86_64-linux-gnu-ubuntu-20.04/bin/clang -DCMAKE_CXX_COMPILER=~/llvm-prebuilt/clang+llvm-13.0.0-x86_64-linux-gnu-ubuntu-20.04/bin/clang++ '-DLLVM_ENABLE_PROJECTS=clang-tools-extra;clang;llvm;lldb;lld' -DCMAKE_BUILD_TYPE=Debug -DLLDB_EXPORT_ALL_SYMBOLS=OFF '-DLLVM_LIT_ARGS=-v -vv' -DLLVM_OPTIMIZED_TABLEGEN=ON -DLLVM_ENABLE_ASSERTIONS=ON -DLLDB_ENABLE_LUA=OFF -DLLDB_ENABLE_LZMA=ON -DLLDB_ENABLE_LIBXML2=ON -DLLDB_ENABLE_PYTHON=ON -DLLVM_TARGETS_TO_BUILD=all -DLLVM_EXPERIMENTAL_TARGETS_TO_BUILD=WebAssembly -DLLDB_TEST_USER_ARGS=-t -DLLVM_ENABLE_WERROR=ON -DLLVM_LINK_LLVM_DYLIB=ON -DCLANG_LINK_CLANG_DYLIB=ON -DBUILD_SHARED_LIBS=OFF -DLLVM_ENABLE_LLD=ON -DCLANG_DEFAULT_LINKER=lld -DLLVM_USE_SPLIT_DWARF=ON -DLLVM_ENABLE_LTO=OFF -DLLVM_ENABLE_EXPENSIVE_CHECKS=OFF -DLLVM_BUILD_INSTRUMENTED_COVERAGE=OFF -DLLVM_USE_SANITIZE_COVERAGE=ON '-DLLVM_USE_SANITIZER=Address;Undefined' plus ninja clang

Take this as an example:

ld.lld: error: relocation R_X86_64_PC32 cannot be used against symbol lto_module_is_object_file_for_target; recompile with -fPIC                              
>>> defined in tools/lto/CMakeFiles/LTO.dir/lto.cpp.o                                                                                                         
>>> referenced by lto.cpp:175 (/mnt/Workspace/Repos/collab/github/llvm/llvm-project/llvm/tools/lto/lto.cpp:175)                                               
>>>               tools/lto/CMakeFiles/LTO.dir/lto.cpp.o:(lto_module_is_object_file_for_target)

You can delete lto.cpp.o, rerun ninja with -v to get the compiler command line. You can then remove unneeded options and then add -S to get the assembly.
Check which instruction generates something like R_X86_64_PC32 (you may need to compile with -c and compare .o output with .s)

Take this as an example:

ld.lld: error: relocation R_X86_64_PC32 cannot be used against symbol lto_module_is_object_file_for_target; recompile with -fPIC                              
>>> defined in tools/lto/CMakeFiles/LTO.dir/lto.cpp.o                                                                                                         
>>> referenced by lto.cpp:175 (/mnt/Workspace/Repos/collab/github/llvm/llvm-project/llvm/tools/lto/lto.cpp:175)                                               
>>>               tools/lto/CMakeFiles/LTO.dir/lto.cpp.o:(lto_module_is_object_file_for_target)

You can delete lto.cpp.o, rerun ninja with -v to get the compiler command line. You can then remove unneeded options and then add -S to get the assembly.
Check which instruction generates something like R_X86_64_PC32 (you may need to compile with -c and compare .o output with .s)

I don't understand much about relocation linking issues and ELF interposition, although I produced some diffs that can be helpful here. I create two versions to compare with and without -fno-semantic-interposition and compare it with and without ASAN flags. To clarify, files with .asan means it was compiled with ASAN, .noasan the contrary, and files with .nosem means there is no -fno-semantic-interposition flag.

--- lto.cpp.asan.S   2022-01-13 03:56:53.144475998 +0000
+++ lto.cpp.asan.nosem.S        2022-01-13 04:19:12.177841103 +0000
@@ -1399,7 +1399,7 @@
        movq    $1102416563, (%r15)             # imm = 0x41B58AB3
        leaq    .L___asan_gen_.1059(%rip), %rax
        movq    %rax, 8(%r15)
-       leaq    lto_module_is_object_file_for_target(%rip), %rax
+       movq    lto_module_is_object_file_for_target@GOTPCREL(%rip), %rax
        movq    %rax, 16(%r15)
        movq    %r15, %r14
        shrq    $3, %r14
--- lto.cpp.noasan.S    2022-01-13 04:00:46.834481539 +0000
+++ lto.cpp.noasan.nosem.S     2022-01-13 04:08:47.411159589 +0000
@@ -352,7 +352,6 @@
        .p2align        4, 0x90
        .type   lto_get_version,@function
 lto_get_version:                        # @lto_get_version
-.Llto_get_version$local:
 .Lfunc_begin2:
        .loc    2 162 0                         # llvm/tools/lto/lto.cpp:162:0
        .cfi_startproc

Interestingly, objdump diffs only procudes differences for ASAN binaries:

--- /dev/fd/63  2022-01-13 04:42:05.491206955 +0000
+++ /dev/fd/62  2022-01-13 04:42:05.494540289 +0000
@@ -1,5 +1,5 @@
 
-lto.cpp.asan.o:     file format elf64-x86-64
+lto.cpp.asan.nosem.o:     file format elf64-x86-64
 
 
 Disassembly of section .text._ZN4llvm2cl3optIcLb0ENS0_6parserIcEEEC2IJA2_cNS0_4descENS0_15FormattingFlagsENS0_18NumOccurrencesFlagENS0_11initializerIcEEEEEDpRKT_:
@@ -845,8 +845,8 @@
   79:  48 8d 05 00 00 00 00    lea    0x0(%rip),%rax        # 80 <lto_module_is_object_file_for_target+0x80>
                        7c: R_X86_64_PC32       .L___asan_gen_.1059-0x4
   80:  49 89 47 08             mov    %rax,0x8(%r15)
-  84:  48 8d 05 00 00 00 00    lea    0x0(%rip),%rax        # 8b <lto_module_is_object_file_for_target+0x8b>
-                       87: R_X86_64_PC32       lto_module_is_object_file_for_target-0x4
+  84:  48 8b 05 00 00 00 00    mov    0x0(%rip),%rax        # 8b <lto_module_is_object_file_for_target+0x8b>
+                       87: R_X86_64_REX_GOTPCRELX      lto_module_is_object_file_for_target-0x4
   8b:  49 89 47 10             mov    %rax,0x10(%r15)
   8f:  4d 89 fe                mov    %r15,%r14
   92:  49 c1 ee 03             shr    $0x3,%r14

See the generated binaries and assembly code here: https://cloudflare-ipfs.com/ipfs/bafybeiacqbizm2k4pwrcq6i3tzfl7xq3qp6z2kbso23rfapgjutdvkxqca/

I'm sorry for not being able to interpret that relocation flags, although, tell me if I can help with something else. I would appreciate helping solve it. In the meanwhile, I created a patch to disable this flag, at least on debug mode https://reviews.llvm.org/D117144 (since it is an "optimization"?).

Ok, digging a bit more, I found out that this is a downstream issue and somehow the patch to enforce stack protection and fPIE is probably triggering this. See https://github.com/archlinux/svntogit-packages/blob/packages/clang/trunk/enable-SSP-and-PIE-by-default.patch and https://bugs.llvm.org/show_bug.cgi?id=13410 . I'm going to add a bug report on the Arch Linux bug tracker. Do you have any idea to correctly handle this when sanitization is on?

MaskRay added a comment.EditedJan 12 2022, 9:54 PM

We need to understand the precise condition and exclude the exact case.
-fno-semantic-interposition is used by projects like CPython. It's important to know what issues Clang has.

OK, I can reproduce now. I think the issue is the combination of -fsanitize=fuzzer-no-link -fPIC -fno-semantic-interposition (-DLLVM_USE_SANITIZE_COVERAGE=ON) when a shared object is built (e.g. -DLLVM_LINK_LLVM_DYLIB=ON).
-fsanitize=fuzzer-no-link has a bug that it incorrectly adds comdat to a dso_local function.
We can move the discussion to D117144.

We need to understand the precise condition and exclude the exact case.
-fno-semantic-interposition is used by projects like CPython. It's important to know what issues Clang has.

OK, I can reproduce now. I think the issue is the combination of -fsanitize=fuzzer-no-link -fPIC -fno-semantic-interposition (-DLLVM_USE_SANITIZE_COVERAGE=ON) when a shared object is built (e.g. -DLLVM_LINK_LLVM_DYLIB=ON).
-fsanitize=fuzzer-no-link has a bug that it incorrectly adds comdat to a dso_local function.
We can move the discussion to D117144.

D117190 will fix the -fPIC -fno-semantic-interposition -fsanitize-coverage incompatibility.
D117183 may be safe for release/13.x

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.

Hi!
Since this patch been up for discussion again, do you know if the gcc warning above is anything that needs to be taken care of?
It popped up with this patch and is still there.

We need to understand the precise condition and exclude the exact case.
-fno-semantic-interposition is used by projects like CPython. It's important to know what issues Clang has.

OK, I can reproduce now.

Right. To clarify and be in sync, I tried the prebuilt builds you suggested and they succeeded in my local environment and I can't reproduce the issue with them, hence my assumption. So, did you try the Arch Linux binaries?

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.

Hi!
Since this patch been up for discussion again, do you know if the gcc warning above is anything that needs to be taken care of?
It popped up with this patch and is still there.

If the GCC -Wuninitialized warning is related to -fno-semantic-interposition, it is worth filing a bug on https://gcc.gnu.org/bugzilla/ if you can still reproduce with its latest release

I believe we focus on fixing warnings in Clang builds but not that much for GCC warnings. If a warning is sufficiently annoying (sufficiently many files) perhaps a workaround will be considered in the CMake files.
For occasional GCC warnings I think we don't usually want to take code churn for them.