[llvm-dev] Using Xray compilation with C programs

Harsh 00 via llvm-dev llvm-dev at lists.llvm.org
Sun Mar 11 10:41:25 PDT 2018


Hi all,

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.

Searching around for this issue, looks like somebody has already filed a
bug for this issue:
https://bugs.llvm.org/show_bug.cgi?id=34904

Is there any way to get around this bug or to solve this issue?

Issue description from the filed bug:

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>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.llvm.org/pipermail/llvm-dev/attachments/20180311/63a74415/attachment.html>


More information about the llvm-dev mailing list