llvm / llvm-project

The LLVM Project is a collection of modular and reusable compiler and toolchain technologies.
http://llvm.org
Other
27.72k stars 11.41k forks source link

duplicate symbol ___llvm_profile_runtime #36318

Open llvmbot opened 6 years ago

llvmbot commented 6 years ago
Bugzilla Link 36970
Version 6.0
OS MacOS X
Reporter LLVM Bugzilla Contributor
CC @vedantk

Extended Description

http://releases.llvm.org/6.0.0/tools/clang/docs/SourceBasedCodeCoverage.html#using-the-profiling-runtime-without-static-initializers says Export a int __llvm_profile_runtime symbol from each instrumented shared library and executable. When the linker finds a definition of this symbol, it knows to skip loading the object which contains the profiling runtime’s static initializer.

/opt/local/bin/clang++-mp-6.0 -Weverything -fcolor-diagnostics -fcomment-block-commands=requirement,internal,endinternal,nosubgrouping -fdebug-macro -fdiagnostics-color -fdiagnostics-show-template-tree -fmessage-length=160 -fspell-checking -fstrict-aliasing -Qunused-arguments -Wno-c++98-compat -Wno-c++98-compat-bind-to-temporary-copy -Wno-c++98-compat-pedantic -Wno-c99-extensions -Wno-covered-switch-default -Wno-documentation-unknown-command -Wno-error=unknown-pragmas -Wno-exit-time-destructors -Wno-global-constructors -Wno-long-long -Wno-missing-prototypes -Wno-packed -Wno-padded -Wno-reserved-id-macro -Wno-undef -Wno-unknown-pragmas -Wno-unused-command-line-argument -Wno-used-but-marked-unused -Wno-variadic-macros -Wno-weak-vtables -Wno-zero-as-null-pointer-constant -Wno-unknown-warning-option -Werror -g -dynamiclib -Wl,-headerpad_max_install_names -o testproject/libatestlibrary.dylib -install_name @​rpath/libatestlibrary.dylib testproject/CMakeFiles/atestlibrary.dir/atestfile.cpp.o testproject/CMakeFiles/atestlibrary.dir/auntestedfile.cpp.o -fprofile-instr-generate -fcoverage-mapping src/libcoveragedumper-clang.a -Wl,-u,_main_coverage_reset,-u,_main_coverage_dump && : duplicate symbol ___llvm_profile_runtime in: /opt/local/libexec/llvm-6.0/lib/clang/6.0.0/lib/darwin/libclang_rt.profile_osx.a(InstrProfilingRuntime.cc.o) src/libcoveragedumper-clang.a(coveragedumper.cpp.o) ld: 1 duplicate symbol for architecture x86_64

extern "C" int __llvm_profile_runtime() { return 0; }

This works with 5.0.0

vedantk commented 6 years ago

You might be seeing this issue because the linker is visiting static archives in a different order. If it visits the profile runtime archive before libcoveragedumper-clang.a, it will import __llvm_profile_runtime from the profile runtime first, and then unconditionally import it again from libcoveragedumper-clang.a.

The order in which the profile runtime archive is specified to the linker, in relation to other archives, hasn't changed since 5.0.

To break the dependence on the linker's visitation order, you could define a static int __llvm_profile_runtime in each .o file.