Since libtsan.a already has them:
ld.lld: error: duplicate symbol: RunningOnValgrind
>>> defined at dynamic_annotations.cc:99 (../contrib/abseil-cpp/absl/base/dynamic_annotations.cc:99)
>>> dynamic_annotations.cc.o:(RunningOnValgrind) in archive contrib/abseil-cpp/absl/base/libabsl_dynamic_annotations.a
>>> defined at tsan_interface_ann.o:(.text+0x15A0) in archive /usr/lib/gcc/x86_64-linux-gnu/10/libtsan.a
ld.lld: error: duplicate symbol: AnnotateMemoryIsInitialized
>>> defined at dynamic_annotations.cc:75 (../contrib/abseil-cpp/absl/base/dynamic_annotations.cc:75)
>>> dynamic_annotations.cc.o:(AnnotateMemoryIsInitialized) in archive contrib/abseil-cpp/absl/base/libabsl_dynamic_annotations.a
>>> defined at tsan_interface_ann.o:(.text+0x1600) in archive /usr/lib/gcc/x86_64-linux-gnu/10/libtsan.a
ld.lld: error: duplicate symbol: AnnotateMemoryIsUnt show initialized
>>> defined at dynamic_annotations.cc:75 (../contrib/abseil-cpp/absl/base/dynamic_annotations.cc:75)
>>> dynamic_annotations.cc.o:(AnnotateMemoryIsUninitialized) in archive contrib/abseil-cpp/absl/base/libabsl_dynamic_annotations.a
>>> defined at tsan_interface_ann.o:(.text+0x1610) in archive /usr/lib/gcc/x86_64-linux-gnu/10/libtsan.a
...
And after this patch I successfully managed to build with thread
sanitizer under gcc.
gcc with -nodefaultlibs does not add sanitizers library during linkage
with -static-libasan and similar, fix this, by add them explicitly.
From the gcc(1) about -nodefaultlibs:
Do not use the standard system libraries when linking. Only the
libraries you specify are passed to the linker, and options specifying
linkage of the system libraries, such as -static-libgcc or
-shared-libgcc, are ignored. The standard startup files are used
normally, unless -nostartfiles is used.
Plus checked it manually, w/o -nodefaultlibs everything works without
this explicit linkage.
After this patch UBSAN under gcc compiled successfully.
v2: freebsd and darwin
INTERFACE_COMPILE_DEFINITIONS does not work IMPORTED targets:
From 3.6:
Specify compile definitions to use when compiling a given <target>.
The named <target> must have been created by a command such as
add_executable() or add_library() and must not be an Imported Target.
Since 3.11:
Specify compile definitions to use when compiling a given <target>.
The named <target> must have been created by a command such as
add_executable() or add_library() and must not be an ALIAS target.
And this causes the -Wundef warning:
src/Functions/FunctionsHashing.h:1326:5: warning: 'USE_XXHASH' is not defined, evaluates to 0 [-Wundef]
Since libstdc++ has some of such compares for 3way compare:
/src/ch/clickhouse/src/Common/UInt128.h:61:71: warning: zero as null pointer constant [-Wzero-as-null-pointer-constant]
bool inline operator>= (const UInt128 rhs) const { return tuple() >= rhs.tuple(); }
^~
nullptr
/usr/include/c++/10.2.0/tuple:1426:5: note: while rewriting comparison as call to 'operator<=>' declared here
operator<=>(const tuple<_Tps...>& __t, const tuple<_Ups...>& __u)