undefined reference to 'llvm_gcda_start_file', 'llvm_gcda_emit_arcs', etc

Hi,
I am trying to test my project and get the code coverage with a version of clang compiler that was built from the latest llvm/clang codebase.

It worked for a while. But today, after I updated my local checkout, and re-build llvm, clang and compiler-rt, when I test my project again, I got the errors with undefined reference to ‘llvm_gcda_start_file’, ‘llvm_gcda_emit_arcs’, ‘llvm_gcda_emit_function’, and ‘llvm_gcda_end_file’.

I have searched the codebase, and have found the functions are defined in GCDAProfiling.c file, but not sure why this suddenly doesn’t work for me.

Anyone can give any suggestions?

Thanks very much in advance.
Qun

Hi Qun,

The 'runtime' recently removed these. You'll need to download and build compiler-rt. Put it in the 'projects' directory and it should just build when you compile LLVM.

-bw

Qun Fa wrote:

Hi,
I am trying to test my project and get the code coverage with a version
of clang compiler that was built from the latest llvm/clang codebase.

It worked for a while. But today, after I updated my local checkout, and
re-build llvm, clang and compiler-rt, when I test my project again, I
got the errors with undefined reference to 'llvm_gcda_start_file',
'llvm_gcda_emit_arcs', 'llvm_gcda_emit_function', and 'llvm_gcda_end_file'.

I have searched the codebase, and have found the functions are defined
in GCDAProfiling.c file, but not sure why this suddenly doesn't work for me.

Anyone can give any suggestions?

Those symbols should be provided by compiler-rt/lib/profile/GCDAProfiling.c. There used to be a copy in llvm's tree, but I deleted that one recently. It's possible you used to be using the one from llvm, but now need to switch to using the one from compiler-rt?

Nick

Thanks for your reply.

May I know which is the recommended library that should be linked against?

I am currently linking libprofile_rt.a.

And I have noticed the differences that, if we do

nm libprofile_rt.a | grep llvm

with my old copy of the llvm/clang installation, I can see

00000000000005e0 T _llvm_gcda_emit_arcs
0000000000000b48 S _llvm_gcda_emit_arcs.eh
0000000000000430 T _llvm_gcda_emit_function
0000000000000aa8 S _llvm_gcda_emit_function.eh
00000000000006c0 T _llvm_gcda_end_file
0000000000000b98 S _llvm_gcda_end_file.eh
00000000000003d0 T _llvm_gcda_increment_indirect_counter
0000000000000a80 S _llvm_gcda_increment_indirect_counter.eh
0000000000000000 T _llvm_gcda_start_file
0000000000000a08 S _llvm_gcda_start_file.eh

They are the symbols that my test build is looking for.

But with the latest codebase, here is what I saw

00000000000000a8 T llvm_start_basic_block_tracing
0000000000000067 T llvm_trace_basic_block
0000000000000467 T llvm_decrement_path_count
000000000000042a T llvm_increment_path_count
0000000000000662 T llvm_start_path_profiling
0000000000000020 T llvm_start_edge_profiling
0000000000000020 T llvm_start_opt_edge_profiling

Thanks again,
Qun

Hi All,

I think Nick’s suggestion is correct, my code was linked against libprofile_rt.a, which had gcda profiling code before, but was removed https://github.com/llvm-mirror/llvm/commit/218042a02305a3cc38d968a97ff9ecf4b4abe6ff

So, I couldn’t find the correct symbols from libprofile_rt.a any more.

Now my assumption is I need to use the correct library that is provided by compiler-rt. May I know which one?

I am building the entire llvm/clang including compiler-rt based on the instructions given on the clang get started page (http://clang.llvm.org/get_started.html), but with CMake instead of Makefile. But I also noticed in the compiler-rt/lib/CMakeLists.txt file, we have the following FIXME.

FIXME: Add support for the profile library.

So, if I want to use the correct library, do I have to switch to Makefile? Any ideas?

Thanks very much,
Qun

Hi All,

I think Nick's suggestion is correct, my code was linked against
libprofile_rt.a, which had gcda profiling code before, but was removed
https://github.com/llvm-mirror/llvm/commit/218042a02305a3cc38d968a97ff9ecf4b4abe6ff

So, I couldn't find the correct symbols from libprofile_rt.a any more.

Now my assumption is I need to use the correct library that is provided by
compiler-rt. May I know which one?

I am building the entire llvm/clang including compiler-rt based on the
instructions given on the clang get started page (
http://clang.llvm.org/get_started.html), but with CMake instead of
Makefile. But I also noticed in the compiler-rt/lib/CMakeLists.txt file, we
have the following FIXME.

# FIXME: Add support for the profile library.

So, if I want to use the correct library, do I have to switch to Makefile?
Any ideas?

Yeah, can you try Makefile (I think it should build libprofile_rt from
GCDAProfiling.c that you need). I'll see if I can add CMake support for
profile in compiler-rt any time soon.
However, looks like Clang driver won't be smart enough to link two archives
(lib/libprofile_rt.a and the one under lib/clang/3.3/linux/...), so we may
need to patch the driver as well.

Thank you Alexey.

I have tried to use Makefile. This will generate the correct symbols that I need.

Any idea on the schedule of adding CMake support to compiler-rt?

Sincerely,
Qun

Hi!

Thank you Alexey.

I have tried to use Makefile. This will generate the correct symbols that
I need.

Any idea on the schedule of adding CMake support to compiler-rt?

Starting from r177382 CMake on Linux should build the same profile
compiler-rt library
as Makefiles.

Thank you Alexey. I will try this out this week. Any idea on supporting this for Mac?

My raw idea is to add this to compiler-rt/lib/profile/CMakeLists.txt


if(APPLE)

  foreach(arch ${PROFILE_SUPPORTED_ARCH})

    add_compiler_rt_static_runtime(clang_rt.profile-${arch} ${arch}

      SOURCES ${PROFILE_SOURCES}

      CFLAGS --sysroot=${COMPILER_RT_DARWIN_SDK_SYSROOT})

  endforeach()

endif()

Do you think it will then support Mac?

Longyi

Thank you Alexey. I will try this out this week. Any idea on supporting
this for Mac?

My raw idea is to add this to compiler-rt/lib/profile/CMakeLists.txt

if(APPLE)
  foreach(arch ${PROFILE_SUPPORTED_ARCH})
    add_compiler_rt_static_runtime(clang_rt.profile-${arch} ${arch}
      SOURCES ${PROFILE_SOURCES}
      CFLAGS --sysroot=${COMPILER_RT_DARWIN_SDK_SYSROOT})
  endforeach()
endif()

Do you think it will then support Mac?

Generally we build universal libraries on Mac OS X, so that one static
library has sources compiled for
multiple arches. I've added basic Mac support in r177870, hope this will
work for you.

This works great! Thanks Alexey for your help.

Qun