Comment 3 for bug 1902760

Revision history for this message
In , D-i-j (d-i-j) wrote :

(In reply to H.J. Lu from comment #1)
> clang has different behavior depending on -fuse-ld=XXX:
>
> ...
>
> It looks like a clang bug.

Thanks for the report. It is an LLVMgold.so bug. LLVMgold.so is used by GNU ld and gold for clang LTO (full LTO or ThinLTO). The problem is that

clang -fuse-ld=bfd -flto a.o -o a -Wl,-plugin-opt=save-temps # override a.o

I will fix it in https://reviews.llvm.org/D84132 and cherry pick it into llvm-project's release/11.x branch (newly created for the 11.0.0 release).

Let's move back to the original topic. Use a different output filename (than the basename of the source file) to avoid the -plugin-opt=save-temps issue.

-----

% clang -fuse-ld=bfd -fprofile-generate=out -flto a.c -Wl,-y,__llvm_profile_raw_version -Wl,-plugin-opt=save-temps -o aa
/usr/bin/ld.bfd: /tmp/a-1cd442.o (symbol from plugin): definition of __llvm_profile_raw_version
/usr/bin/ld.bfd: /tmp/RelA/lib/clang/12.0.0/lib/linux/libclang_rt.profile-x86_64.a(InstrProfiling.c.o): definition of __llvm_profile_raw_version
% ./aa
% llvm-profdata merge out -o a.profdata
% llvm-profdata show a.profdata
Instrumentation level: Front-end ### incorrect, it should be IR
Total functions: 1
Maximum function count: 1
Maximum internal block count: 0

% rm -r out
% clang -fuse-ld=gold -fprofile-generate=out -flto a.c -Wl,-y,__llvm_profile_raw_version -Wl,-plugin-opt=save-temps -o aa
/tmp/a-3b2969.o: definition of __llvm_profile_raw_version
/tmp/RelA/lib/clang/12.0.0/lib/linux/libclang_rt.profile-x86_64.a(InstrProfiling.c.o): definition of __llvm_profile_raw_version
aa.o: definition of __llvm_profile_raw_version
% ./aa
% llvm-profdata merge out -o a.profdata
% llvm-profdata show a.profdata
Instrumentation level: IR
Total functions: 1
Maximum function count: 1
Maximum internal block count: 0

----

As my first comment says, you can inspect aa.resolution.txt to see that GNU ld incorrectly thinks that __llvm_profile_raw_versio is non-prevailing.