Quuxplusone / LLVMBugzillaTest

0 stars 0 forks source link

duplicate symbol ___llvm_profile_runtime #35943

Open Quuxplusone opened 6 years ago

Quuxplusone commented 6 years ago
Bugzilla Link PR36970
Status NEW
Importance P normal
Reported by David van Laatum (david@vanlaatum.id.au)
Reported on 2018-03-31 23:38:02 -0700
Last modified on 2018-04-02 11:43:15 -0700
Version 6.0
Hardware Macintosh MacOS X
CC llvm-bugs@lists.llvm.org, vsk@apple.com
Fixed by commit(s)
Attachments
Blocks
Blocked by
See also
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
Quuxplusone 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.