<div dir="ltr">Hi all,<div><br></div><div>I was interested in trying out the Xray profiling component in LLVM and was trying to compile a C program with Clang with Xray flags. Unfortunately, I keep getting a linker error everytime I try to compile the C program with Clang. However, the error goes away when I try to compile the same C program with Clang++ with -xc++ flag.</div><div><br></div><div>Searching around for this issue, looks like somebody has already filed a bug for this issue:</div><div><a rel="nofollow" target="_blank" href="https://bugs.llvm.org/show_bug.cgi?id=34904">https://bugs.llvm.org/show_bug.cgi?id=34904</a></div><div><br></div><div>Is there any way to get around this bug or to solve this issue?</div><div><br></div><div>Issue description from the filed bug:</div><div><pre class="gmail-bz_comment_text" style="font-size:small;font-family:monospace;white-space:pre-wrap;width:50em;color:rgb(0,0,0);font-style:normal;font-variant-ligatures:normal;font-variant-caps:normal;font-weight:400;letter-spacing:normal;text-align:start;text-indent:0px;text-transform:none;word-spacing:0px;background-color:rgb(255,255,255);text-decoration-style:initial;text-decoration-color:initial">According to documentation it should be possible to use xray instrumentation on C program by specifying the flags -fxray-instrument.

Linking fails when compiling the following program:

----8<----- (minimal.c)
int main ()
{
  return 0;
}
----8<-----
$ clang --version
clang version 6.0.0 (trunk 315272)
Target: x86_64-unknown-linux-gnu
Thread model: posix
InstalledDir: /home/jonasbu/local/bin

$ clang -fxray-instrument minimal.c                                                                                                                                                                                                                                                                
/home/jonasbu/local/lib/clang/6.0.0/lib/linux/libclang_rt.xray-x86_64.a(xray_inmemory_log.cc.o): In function `getGlobalFd()':
/home/jonasbu/llvm-clang/llvm/projects/compiler-rt/lib/xray/xray_inmemory_log.cc:123: undefined reference to `__cxa_guard_acquire'
/home/jonasbu/llvm-clang/llvm/projects/compiler-rt/lib/xray/xray_inmemory_log.cc:123: undefined reference to `__cxa_guard_release'
/home/jonasbu/local/lib/clang/6.0.0/lib/linux/libclang_rt.xray-x86_64.a(xray_inmemory_log.cc.o): In function `__xray_InMemoryRawLog<__xray_InMemoryEmulateTSC(int32_t, XRayEntryType)::<lambda(uint8_t&)> >':
/home/jonasbu/llvm-clang/llvm/projects/compiler-rt/lib/xray/xray_inmemory_log.cc:136: undefined reference to `__cxa_thread_atexit'
/home/jonasbu/local/lib/clang/6.0.0/lib/linux/libclang_rt.xray-x86_64.a(xray_inmemory_log.cc.o): In function `__xray_OpenLogFile':
/home/jonasbu/llvm-clang/llvm/projects/compiler-rt/lib/xray/xray_inmemory_log.cc:85: undefined reference to `__cxa_guard_acquire'
/home/jonasbu/llvm-clang/llvm/projects/compiler-rt/lib/xray/xray_inmemory_log.cc:85: undefined reference to `__cxa_guard_release'
/home/jonasbu/llvm-clang/llvm/projects/compiler-rt/lib/xray/xray_inmemory_log.cc:87: undefined reference to `__cxa_guard_acquire'
/home/jonasbu/llvm-clang/llvm/projects/compiler-rt/lib/xray/xray_inmemory_log.cc:87: undefined reference to `__cxa_guard_release'
...
...
...

As expected, the same program compiles and links fine as a C++ program:

$ clang++ -xc++ -fxray-instrument minimal.c
<no output></pre><br></div></div>