[llvm-dev] C interface with XRay

Dean Michael Berris via llvm-dev llvm-dev at lists.llvm.org
Mon Jun 11 17:18:32 PDT 2018



> On 9 Jun 2018, at 00:57, Henry Zhu via llvm-dev <llvm-dev at lists.llvm.org> wrote:
> 
> Hello,
> 
> 
>  
> XRay has some issues working with C code.
> 
> There are two problems I want to mention:
> 
> 1: Getting clang to compile C code with XRay enabled.
> 

I’ve recently landed patches to address this. Please try again with the latest in HEAD?

> 2: Getting the header interfaces to work with C, so fdr-mode can be enabled programmatically (in a similar manner to how it can be enabled for C++)
> 

Yeah, this one was kind-of a known issue. We have marked a lot of functions in log interface headers 

>  
> I had to resolve multiple issues before C code would compile and link correctly. Included below are the steps I had to take to resolve the problems.
> 

Thanks!

In the future, can you follow the procedures outlined in https://llvm.org/docs/Contributing.html — in particular, using Phabricator for patches and code reviews (please add me, or @kpw for reviews for XRay specific changes). More in-lined below.

>  
> Changes I had to make:
> Use clang++ instead of clang
> 
> Use –xc flag to force clang++ to compile the code as C
> 
> In order to use fdr programmatically, I changed xray_interface.h and xray_log_interface.h to remove compilation errors by porting c++ to c.
> 
>  
> Problem 1
> 
> ==========
> 
> Would it be possible to make C XRay interface easier to work with?
> 

In general, yes — and we’re working on making this easier to do incrementally. Right now we’re working on profiling mode [0] which is taking up all/most of my time. We need additional reviewers/testers and it would be great if you can help with some of that (if you’re interested).

That being said, the intent is definitely to support using the XRay APIs in C. We haven’t prioritised making this work yet, but I’m definitely open to reviewing patches to making this a first-class supported use-case for XRay.

Note that we’ve marked a lot of APIs in the logging API in preparation for this as deprecated, with the intent of reducing the API surface even further (or providing more convenient APIs). Your feedback would be really helpful in shaping that API not just for C but potentially for other languages that have support for C bindings.

[0] http://lists.llvm.org/pipermail/llvm-dev/2018-February/121237.html

> The documentation mentions XRay works with C/C++/Objective-C/Objective-C++ under “Using XRay” (https://llvm.org/docs/XRay.html) and the white paper mentions that “XRay is not specific to a class of applications and is applicable to any C/C++-based binary -- from storage servers handling multiple thousands of requests per second to debugging command-line tools and unit tests”.
> 
>  
> I give more detail about the problem below.
> 
> 
> I am running Ubuntu 16.04.1 on a x86_64 machine and am using clang 7.0.
> 
> henry at OptiPlex-9010:~$ uname -a
> 
> Linux OptiPlex-9010 4.13.0-43-generic #48~16.04.1-Ubuntu SMP Thu May 17 12:56:46 UTC 2018 x86_64 x86_64 x86_64 GNU/Linux
> 
>  
> Below is a C test file I wrote: (test_pthread.c)
> 
> 
> ==============================
> 
> #include <stdio.h>
> 
> #include <pthread.h>
> 
>  
> __attribute__((xray_always_instrument))
> 
> void print_parent()
> 
> {
> 
>                 printf("I am parent\n");
> 
> }
> 
>  
> __attribute__((xray_always_instrument))
> 
> void* print_child(void* unused)
> 
> {
> 
>  
>                 printf("I am child\n");
> 
>                 return NULL;
> 
> }
> 
>  
> int main()
> 
> {
> 
>                 print_parent();
> 
>                 int num_threads = 10;
> 
>                 pthread_t tids[num_threads];
> 
>                 for(int i = 0; i < num_threads; i++)
> 
>                 {
> 
>                                 pthread_create(&tids[i], NULL, print_child, NULL);
> 
>                 }
> 
>                 for(int i = 0; i < num_threads; i++)
> 
>                 {
> 
>                                 pthread_join(tids[i], NULL);
> 
>                 }
> 
>                 return 0;
> 
> }
> 
>  
> ./clang -fxray-instrument test_pthread.c
> 
>  
> Clang produces errors about c++: (xray_clang_error.txt)
> 
>  
> /home/henry/build_xray/llvm-instrumented-build/lib/clang/7.0.0/lib/linux/libclang_rt.xray-basic-x86_64.a(xray_basic_logging.cc.o): In function `__xray::thresholdTicks()':
> 
> /home/henry/build_xray/llvm-project/compiler-rt/lib/xray/xray_basic_logging.cc:79: undefined reference to `__cxa_guard_acquire'
> 
> /home/henry/build_xray/llvm-project/compiler-rt/lib/xray/xray_basic_logging.cc:79: undefined reference to `__cxa_guard_release'
> 
> /home/henry/build_xray/llvm-project/compiler-rt/lib/xray/xray_basic_logging.cc:81: undefined reference to `__cxa_guard_acquire'
> 
> /home/henry/build_xray/llvm-project/compiler-rt/lib/xray/xray_basic_logging.cc:81: undefined reference to `__cxa_guard_release'
> 
> /home/henry/build_xray/llvm-instrumented-build/lib/clang/7.0.0/lib/linux/libclang_rt.xray-basic-x86_64.a(xray_basic_logging.cc.o): In function `__xray::basicLoggingInit(unsigned long, unsigned long, void*, unsigned long)':
> 
> /home/henry/build_xray/llvm-project/compiler-rt/lib/xray/xray_basic_logging.cc:423: undefined reference to `__cxa_guard_acquire'
> 
> /home/henry/build_xray/llvm-project/compiler-rt/lib/xray/xray_basic_logging.cc:423: undefined reference to `__cxa_guard_release'
> 
> /home/henry/build_xray/llvm-project/compiler-rt/lib/xray/xray_basic_logging.cc:385: undefined reference to `__cxa_guard_acquire'
> 
> /home/henry/build_xray/llvm-project/compiler-rt/lib/xray/xray_basic_logging.cc:385: undefined reference to `__cxa_guard_release'
> 
> /home/henry/build_xray/llvm-instrumented-build/lib/clang/7.0.0/lib/linux/libclang_rt.xray-basic-x86_64.a(xray_basic_logging.cc.o): In function `__xray::getGlobalFd()':
> 
> /home/henry/build_xray/llvm-project/compiler-rt/lib/xray/xray_basic_logging.cc:113: undefined reference to `__cxa_guard_acquire'
> 
> /home/henry/build_xray/llvm-project/compiler-rt/lib/xray/xray_basic_logging.cc:113: undefined reference to `__cxa_guard_release'
> 
> /home/henry/build_xray/llvm-instrumented-build/lib/clang/7.0.0/lib/linux/libclang_rt.xray-basic-x86_64.a(xray_basic_logging.cc.o): In function `openLogFile':
> 
> /home/henry/build_xray/llvm-project/compiler-rt/lib/xray/xray_basic_logging.cc:91: undefined reference to `__cxa_guard_acquire'
> 
> /home/henry/build_xray/llvm-project/compiler-rt/lib/xray/xray_basic_logging.cc:91: undefined reference to `__cxa_guard_release'
> 
> /home/henry/build_xray/llvm-project/compiler-rt/lib/xray/xray_basic_logging.cc:93: undefined reference to `__cxa_guard_acquire'
> 
> /home/henry/build_xray/llvm-project/compiler-rt/lib/xray/xray_basic_logging.cc:93: undefined reference to `__cxa_guard_release'
> 
> /home/henry/build_xray/llvm-instrumented-build/lib/clang/7.0.0/lib/linux/libclang_rt.xray-basic-x86_64.a(xray_basic_logging.cc.o): In function `operator()':
> 
> /home/henry/build_xray/llvm-project/compiler-rt/lib/xray/xray_basic_logging.cc:151: undefined reference to `__cxa_guard_acquire'
> 
> /home/henry/build_xray/llvm-project/compiler-rt/lib/xray/xray_basic_logging.cc:151: undefined reference to `__cxa_guard_release'
> 
> /home/henry/build_xray/llvm-instrumented-build/lib/clang/7.0.0/lib/linux/libclang_rt.xray-basic-x86_64.a(xray_basic_logging.cc.o): In function `thresholdTicks':
> 
> /home/henry/build_xray/llvm-project/compiler-rt/lib/xray/xray_basic_logging.cc:81: undefined reference to `__cxa_guard_acquire'
> 
> /home/henry/build_xray/llvm-project/compiler-rt/lib/xray/xray_basic_logging.cc:81: undefined reference to `__cxa_guard_release'
> 
> /home/henry/build_xray/llvm-project/compiler-rt/lib/xray/xray_basic_logging.cc:79: undefined reference to `__cxa_guard_acquire'
> 
> /home/henry/build_xray/llvm-project/compiler-rt/lib/xray/xray_basic_logging.cc:79: undefined reference to `__cxa_guard_release'
> 
> /home/henry/build_xray/llvm-instrumented-build/lib/clang/7.0.0/lib/linux/libclang_rt.xray-basic-x86_64.a(xray_basic_logging.cc.o): In function `__xray::getGlobalFd()':
> 
> /home/henry/build_xray/llvm-project/compiler-rt/lib/xray/xray_basic_logging.cc:113: undefined reference to `__cxa_guard_acquire'
> 
> /home/henry/build_xray/llvm-project/compiler-rt/lib/xray/xray_basic_logging.cc:113: undefined reference to `__cxa_guard_release'
> 
> /home/henry/build_xray/llvm-instrumented-build/lib/clang/7.0.0/lib/linux/libclang_rt.xray-basic-x86_64.a(xray_basic_logging.cc.o): In function `openLogFile':
> 
> /home/henry/build_xray/llvm-project/compiler-rt/lib/xray/xray_basic_logging.cc:93: undefined reference to `__cxa_guard_acquire'
> 
> /home/henry/build_xray/llvm-project/compiler-rt/lib/xray/xray_basic_logging.cc:93: undefined reference to `__cxa_guard_release'
> 
> /home/henry/build_xray/llvm-project/compiler-rt/lib/xray/xray_basic_logging.cc:91: undefined reference to `__cxa_guard_acquire'
> 
> /home/henry/build_xray/llvm-project/compiler-rt/lib/xray/xray_basic_logging.cc:91: undefined reference to `__cxa_guard_release'
> 
> /home/henry/build_xray/llvm-instrumented-build/lib/clang/7.0.0/lib/linux/libclang_rt.xray-basic-x86_64.a(xray_basic_logging.cc.o): In function `__xray::getGlobalFd()':
> 
> /home/henry/build_xray/llvm-project/compiler-rt/lib/xray/xray_basic_logging.cc:113: undefined reference to `__cxa_guard_acquire'
> 
> /home/henry/build_xray/llvm-project/compiler-rt/lib/xray/xray_basic_logging.cc:113: undefined reference to `__cxa_guard_release'
> 
> /home/henry/build_xray/llvm-instrumented-build/lib/clang/7.0.0/lib/linux/libclang_rt.xray-basic-x86_64.a(xray_basic_logging.cc.o): In function `openLogFile':
> 
> /home/henry/build_xray/llvm-project/compiler-rt/lib/xray/xray_basic_logging.cc:93: undefined reference to `__cxa_guard_acquire'
> 
> /home/henry/build_xray/llvm-project/compiler-rt/lib/xray/xray_basic_logging.cc:93: undefined reference to `__cxa_guard_release'
> 
> /home/henry/build_xray/llvm-project/compiler-rt/lib/xray/xray_basic_logging.cc:91: undefined reference to `__cxa_guard_acquire'
> 
> /home/henry/build_xray/llvm-project/compiler-rt/lib/xray/xray_basic_logging.cc:91: undefined reference to `__cxa_guard_release'
> 
> /home/henry/build_xray/llvm-instrumented-build/lib/clang/7.0.0/lib/linux/libclang_rt.xray-basic-x86_64.a(xray_basic_logging.cc.o): In function `__xray::getGlobalFd()':
> 
> /home/henry/build_xray/llvm-project/compiler-rt/lib/xray/xray_basic_logging.cc:113: undefined reference to `__cxa_guard_acquire'
> 
> /home/henry/build_xray/llvm-project/compiler-rt/lib/xray/xray_basic_logging.cc:113: undefined reference to `__cxa_guard_release'
> 
> /home/henry/build_xray/llvm-project/compiler-rt/lib/xray/xray_basic_logging.cc:113: undefined reference to `__cxa_guard_acquire'
> 
> /home/henry/build_xray/llvm-project/compiler-rt/lib/xray/xray_basic_logging.cc:113: undefined reference to `__cxa_guard_release'
> 
> /home/henry/build_xray/llvm-instrumented-build/lib/clang/7.0.0/lib/linux/libclang_rt.xray-basic-x86_64.a(xray_basic_logging.cc.o): In function `openLogFile':
> 
> /home/henry/build_xray/llvm-project/compiler-rt/lib/xray/xray_basic_logging.cc:93: undefined reference to `__cxa_guard_acquire'
> 
> /home/henry/build_xray/llvm-project/compiler-rt/lib/xray/xray_basic_logging.cc:93: undefined reference to `__cxa_guard_release'
> 
> /home/henry/build_xray/llvm-project/compiler-rt/lib/xray/xray_basic_logging.cc:91: undefined reference to `__cxa_guard_acquire'
> 
> /home/henry/build_xray/llvm-project/compiler-rt/lib/xray/xray_basic_logging.cc:91: undefined reference to `__cxa_guard_release'
> 
> /home/henry/build_xray/llvm-project/compiler-rt/lib/xray/xray_basic_logging.cc:93: undefined reference to `__cxa_guard_acquire'
> 
> /home/henry/build_xray/llvm-project/compiler-rt/lib/xray/xray_basic_logging.cc:93: undefined reference to `__cxa_guard_release'
> 
> /home/henry/build_xray/llvm-project/compiler-rt/lib/xray/xray_basic_logging.cc:91: undefined reference to `__cxa_guard_acquire'
> 
> /home/henry/build_xray/llvm-project/compiler-rt/lib/xray/xray_basic_logging.cc:91: undefined reference to `__cxa_guard_release'
> 
> /home/henry/build_xray/llvm-instrumented-build/lib/clang/7.0.0/lib/linux/libclang_rt.xray-basic-x86_64.a(xray_basic_logging.cc.o): In function `__xray::getGlobalFd()':
> 
> /home/henry/build_xray/llvm-project/compiler-rt/lib/xray/xray_basic_logging.cc:113: undefined reference to `__cxa_guard_acquire'
> 
> /home/henry/build_xray/llvm-project/compiler-rt/lib/xray/xray_basic_logging.cc:113: undefined reference to `__cxa_guard_release'
> 
> /home/henry/build_xray/llvm-instrumented-build/lib/clang/7.0.0/lib/linux/libclang_rt.xray-basic-x86_64.a(xray_basic_logging.cc.o): In function `openLogFile':
> 
> /home/henry/build_xray/llvm-project/compiler-rt/lib/xray/xray_basic_logging.cc:93: undefined reference to `__cxa_guard_acquire'
> 
> /home/henry/build_xray/llvm-project/compiler-rt/lib/xray/xray_basic_logging.cc:93: undefined reference to `__cxa_guard_release'
> 
> /home/henry/build_xray/llvm-project/compiler-rt/lib/xray/xray_basic_logging.cc:91: undefined reference to `__cxa_guard_acquire'
> 
> /home/henry/build_xray/llvm-project/compiler-rt/lib/xray/xray_basic_logging.cc:91: undefined reference to `__cxa_guard_release'
> 
> /home/henry/build_xray/llvm-instrumented-build/lib/clang/7.0.0/lib/linux/libclang_rt.xray-basic-x86_64.a(xray_basic_logging.cc.o): In function `operator()':
> 
> /home/henry/build_xray/llvm-project/compiler-rt/lib/xray/xray_basic_logging.cc:151: undefined reference to `__cxa_guard_acquire'
> 
> /home/henry/build_xray/llvm-project/compiler-rt/lib/xray/xray_basic_logging.cc:151: undefined reference to `__cxa_guard_release'
> 
> /home/henry/build_xray/llvm-instrumented-build/lib/clang/7.0.0/lib/linux/libclang_rt.xray-basic-x86_64.a(xray_basic_logging.cc.o): In function `thresholdTicks':
> 
> /home/henry/build_xray/llvm-project/compiler-rt/lib/xray/xray_basic_logging.cc:81: undefined reference to `__cxa_guard_acquire'
> 
> /home/henry/build_xray/llvm-project/compiler-rt/lib/xray/xray_basic_logging.cc:81: undefined reference to `__cxa_guard_release'
> 
> /home/henry/build_xray/llvm-project/compiler-rt/lib/xray/xray_basic_logging.cc:79: undefined reference to `__cxa_guard_acquire'
> 
> /home/henry/build_xray/llvm-project/compiler-rt/lib/xray/xray_basic_logging.cc:79: undefined reference to `__cxa_guard_release'
> 
> /home/henry/build_xray/llvm-instrumented-build/lib/clang/7.0.0/lib/linux/libclang_rt.xray-basic-x86_64.a(xray_basic_logging.cc.o): In function `__xray::basicLogDynamicInitializer()':
> 
> /home/henry/build_xray/llvm-project/compiler-rt/lib/xray/xray_basic_logging.cc:497: undefined reference to `__cxa_guard_acquire'
> 
> /home/henry/build_xray/llvm-project/compiler-rt/lib/xray/xray_basic_logging.cc:497: undefined reference to `__cxa_guard_release'
> 
> /home/henry/build_xray/llvm-instrumented-build/lib/clang/7.0.0/lib/linux/libclang_rt.xray-basic-x86_64.a(xray_basic_logging.cc.o): In function `operator()':
> 
> /home/henry/build_xray/llvm-project/compiler-rt/lib/xray/xray_basic_logging.cc:494: undefined reference to `__cxa_guard_acquire'
> 
> /home/henry/build_xray/llvm-project/compiler-rt/lib/xray/xray_basic_logging.cc:494: undefined reference to `__cxa_guard_release'
> 
> /home/henry/build_xray/llvm-instrumented-build/lib/clang/7.0.0/lib/linux/libclang_rt.xray-fdr-x86_64.a(xray_fdr_logging.cc.o): In function `__xray::thresholdTicks()':
> 
> /home/henry/build_xray/llvm-project/compiler-rt/lib/xray/xray_fdr_logging.cc:325: undefined reference to `__cxa_guard_acquire'
> 
> /home/henry/build_xray/llvm-project/compiler-rt/lib/xray/xray_fdr_logging.cc:325: undefined reference to `__cxa_guard_release'
> 
> /home/henry/build_xray/llvm-project/compiler-rt/lib/xray/xray_fdr_logging.cc:323: undefined reference to `__cxa_guard_acquire'
> 
> /home/henry/build_xray/llvm-project/compiler-rt/lib/xray/xray_fdr_logging.cc:323: undefined reference to `__cxa_guard_release'
> 
> /home/henry/build_xray/llvm-instrumented-build/lib/clang/7.0.0/lib/linux/libclang_rt.xray-fdr-x86_64.a(xray_fdr_logging.cc.o): In function `__xray::(anonymous namespace)::fdrCommonHeaderInfo()':
> 
> /home/henry/build_xray/llvm-project/compiler-rt/lib/xray/xray_fdr_logging.cc:688: undefined reference to `__cxa_guard_acquire'
> 
> /home/henry/build_xray/llvm-project/compiler-rt/lib/xray/xray_fdr_logging.cc:688: undefined reference to `__cxa_guard_release'
> 
> /home/henry/build_xray/llvm-instrumented-build/lib/clang/7.0.0/lib/linux/libclang_rt.xray-fdr-x86_64.a(xray_fdr_logging.cc.o): In function `operator()':
> 
> /home/henry/build_xray/llvm-project/compiler-rt/lib/xray/xray_fdr_logging.cc:680: undefined reference to `__cxa_guard_acquire'
> 
> /home/henry/build_xray/llvm-project/compiler-rt/lib/xray/xray_fdr_logging.cc:680: undefined reference to `__cxa_guard_release'
> 
> /home/henry/build_xray/llvm-project/compiler-rt/lib/xray/xray_fdr_logging.cc:678: undefined reference to `__cxa_guard_acquire'
> 
> /home/henry/build_xray/llvm-project/compiler-rt/lib/xray/xray_fdr_logging.cc:678: undefined reference to `__cxa_guard_release'
> 
> /home/henry/build_xray/llvm-instrumented-build/lib/clang/7.0.0/lib/linux/libclang_rt.xray-fdr-x86_64.a(xray_fdr_logging.cc.o): In function `__xray::fdrIterator(XRayBuffer)':
> 
> /home/henry/build_xray/llvm-project/compiler-rt/lib/xray/xray_fdr_logging.cc:726: undefined reference to `__cxa_guard_acquire'
> 
> /home/henry/build_xray/llvm-project/compiler-rt/lib/xray/xray_fdr_logging.cc:726: undefined reference to `__cxa_guard_release'
> 
> /home/henry/build_xray/llvm-instrumented-build/lib/clang/7.0.0/lib/linux/libclang_rt.xray-fdr-x86_64.a(xray_fdr_logging.cc.o): In function `getTimestamp':
> 
> /home/henry/build_xray/llvm-project/compiler-rt/lib/xray/xray_fdr_logging.cc:884: undefined reference to `__cxa_guard_acquire'
> 
> /home/henry/build_xray/llvm-project/compiler-rt/lib/xray/xray_fdr_logging.cc:884: undefined reference to `__cxa_guard_release'
> 
> /home/henry/build_xray/llvm-instrumented-build/lib/clang/7.0.0/lib/linux/libclang_rt.xray-fdr-x86_64.a(xray_fdr_logging.cc.o): In function `__xray::fdrLoggingHandleCustomEvent(void*, unsigned long)':
> 
> /home/henry/build_xray/llvm-project/compiler-rt/lib/xray/xray_fdr_logging.cc:928: undefined reference to `__cxa_guard_acquire'
> 
> /home/henry/build_xray/llvm-project/compiler-rt/lib/xray/xray_fdr_logging.cc:928: undefined reference to `__cxa_guard_release'
> 
> /home/henry/build_xray/llvm-instrumented-build/lib/clang/7.0.0/lib/linux/libclang_rt.xray-fdr-x86_64.a(xray_fdr_logging.cc.o): In function `getTimestamp':
> 
> /home/henry/build_xray/llvm-project/compiler-rt/lib/xray/xray_fdr_logging.cc:884: undefined reference to `__cxa_guard_acquire'
> 
> /home/henry/build_xray/llvm-project/compiler-rt/lib/xray/xray_fdr_logging.cc:884: undefined reference to `__cxa_guard_release'
> 
> /home/henry/build_xray/llvm-instrumented-build/lib/clang/7.0.0/lib/linux/libclang_rt.xray-fdr-x86_64.a(xray_fdr_logging.cc.o): In function `__xray::fdrLoggingHandleTypedEvent(unsigned short, void const*, unsigned long)':
> 
> /home/henry/build_xray/llvm-project/compiler-rt/lib/xray/xray_fdr_logging.cc:978: undefined reference to `__cxa_guard_acquire'
> 
> /home/henry/build_xray/llvm-project/compiler-rt/lib/xray/xray_fdr_logging.cc:978: undefined reference to `__cxa_guard_release'
> 
> /home/henry/build_xray/llvm-instrumented-build/lib/clang/7.0.0/lib/linux/libclang_rt.xray-fdr-x86_64.a(xray_fdr_logging.cc.o): In function `getTimestamp':
> 
> /home/henry/build_xray/llvm-project/compiler-rt/lib/xray/xray_fdr_logging.cc:884: undefined reference to `__cxa_guard_acquire'
> 
> /home/henry/build_xray/llvm-project/compiler-rt/lib/xray/xray_fdr_logging.cc:884: undefined reference to `__cxa_guard_release'
> 
> /home/henry/build_xray/llvm-instrumented-build/lib/clang/7.0.0/lib/linux/libclang_rt.xray-fdr-x86_64.a(xray_fdr_logging.cc.o): In function `processFunctionHook':
> 
> /home/henry/build_xray/llvm-project/compiler-rt/lib/xray/xray_fdr_logging.cc:633: undefined reference to `__cxa_guard_acquire'
> 
> /home/henry/build_xray/llvm-project/compiler-rt/lib/xray/xray_fdr_logging.cc:633: undefined reference to `__cxa_guard_release'
> 
> /home/henry/build_xray/llvm-project/compiler-rt/lib/xray/xray_fdr_logging.cc:643: undefined reference to `__cxa_guard_acquire'
> 
> /home/henry/build_xray/llvm-project/compiler-rt/lib/xray/xray_fdr_logging.cc:643: undefined reference to `__cxa_guard_release'
> 
> /home/henry/build_xray/llvm-instrumented-build/lib/clang/7.0.0/lib/linux/libclang_rt.xray-fdr-x86_64.a(xray_fdr_logging.cc.o): In function `writeFunctionRecord':
> 
> /home/henry/build_xray/llvm-project/compiler-rt/lib/xray/xray_fdr_logging.cc:309: undefined reference to `__cxa_guard_acquire'
> 
> /home/henry/build_xray/llvm-project/compiler-rt/lib/xray/xray_fdr_logging.cc:309: undefined reference to `__cxa_guard_release'
> 
> /home/henry/build_xray/llvm-instrumented-build/lib/clang/7.0.0/lib/linux/libclang_rt.xray-fdr-x86_64.a(xray_fdr_logging.cc.o): In function `thresholdTicks':
> 
> /home/henry/build_xray/llvm-project/compiler-rt/lib/xray/xray_fdr_logging.cc:325: undefined reference to `__cxa_guard_acquire'
> 
> /home/henry/build_xray/llvm-project/compiler-rt/lib/xray/xray_fdr_logging.cc:325: undefined reference to `__cxa_guard_release'
> 
> /home/henry/build_xray/llvm-project/compiler-rt/lib/xray/xray_fdr_logging.cc:323: undefined reference to `__cxa_guard_acquire'
> 
> /home/henry/build_xray/llvm-project/compiler-rt/lib/xray/xray_fdr_logging.cc:323: undefined reference to `__cxa_guard_release'
> 
> /home/henry/build_xray/llvm-instrumented-build/lib/clang/7.0.0/lib/linux/libclang_rt.xray-fdr-x86_64.a(xray_fdr_logging.cc.o): In function `writeFunctionRecord':
> 
> /home/henry/build_xray/llvm-project/compiler-rt/lib/xray/xray_fdr_logging.cc:299: undefined reference to `__cxa_guard_acquire'
> 
> /home/henry/build_xray/llvm-project/compiler-rt/lib/xray/xray_fdr_logging.cc:299: undefined reference to `__cxa_guard_release'
> 
> /home/henry/build_xray/llvm-instrumented-build/lib/clang/7.0.0/lib/linux/libclang_rt.xray-fdr-x86_64.a(xray_fdr_logging.cc.o): In function `getTimestamp':
> 
> /home/henry/build_xray/llvm-project/compiler-rt/lib/xray/xray_fdr_logging.cc:884: undefined reference to `__cxa_guard_acquire'
> 
> /home/henry/build_xray/llvm-project/compiler-rt/lib/xray/xray_fdr_logging.cc:884: undefined reference to `__cxa_guard_release'
> 
> /home/henry/build_xray/llvm-instrumented-build/lib/clang/7.0.0/lib/linux/libclang_rt.xray-fdr-x86_64.a(xray_fdr_logging.cc.o): In function `processFunctionHook':
> 
> /home/henry/build_xray/llvm-project/compiler-rt/lib/xray/xray_fdr_logging.cc:633: undefined reference to `__cxa_guard_acquire'
> 
> /home/henry/build_xray/llvm-project/compiler-rt/lib/xray/xray_fdr_logging.cc:633: undefined reference to `__cxa_guard_release'
> 
> /home/henry/build_xray/llvm-project/compiler-rt/lib/xray/xray_fdr_logging.cc:643: undefined reference to `__cxa_guard_acquire'
> 
> /home/henry/build_xray/llvm-project/compiler-rt/lib/xray/xray_fdr_logging.cc:643: undefined reference to `__cxa_guard_release'
> 
> /home/henry/build_xray/llvm-instrumented-build/lib/clang/7.0.0/lib/linux/libclang_rt.xray-fdr-x86_64.a(xray_fdr_logging.cc.o): In function `writeFunctionRecord':
> 
> /home/henry/build_xray/llvm-project/compiler-rt/lib/xray/xray_fdr_logging.cc:309: undefined reference to `__cxa_guard_acquire'
> 
> /home/henry/build_xray/llvm-project/compiler-rt/lib/xray/xray_fdr_logging.cc:309: undefined reference to `__cxa_guard_release'
> 
> /home/henry/build_xray/llvm-instrumented-build/lib/clang/7.0.0/lib/linux/libclang_rt.xray-fdr-x86_64.a(xray_fdr_logging.cc.o): In function `thresholdTicks':
> 
> /home/henry/build_xray/llvm-project/compiler-rt/lib/xray/xray_fdr_logging.cc:325: undefined reference to `__cxa_guard_acquire'
> 
> /home/henry/build_xray/llvm-project/compiler-rt/lib/xray/xray_fdr_logging.cc:325: undefined reference to `__cxa_guard_release'
> 
> /home/henry/build_xray/llvm-project/compiler-rt/lib/xray/xray_fdr_logging.cc:323: undefined reference to `__cxa_guard_acquire'
> 
> /home/henry/build_xray/llvm-project/compiler-rt/lib/xray/xray_fdr_logging.cc:323: undefined reference to `__cxa_guard_release'
> 
> /home/henry/build_xray/llvm-instrumented-build/lib/clang/7.0.0/lib/linux/libclang_rt.xray-fdr-x86_64.a(xray_fdr_logging.cc.o): In function `writeFunctionRecord':
> 
> /home/henry/build_xray/llvm-project/compiler-rt/lib/xray/xray_fdr_logging.cc:299: undefined reference to `__cxa_guard_acquire'
> 
> /home/henry/build_xray/llvm-project/compiler-rt/lib/xray/xray_fdr_logging.cc:299: undefined reference to `__cxa_guard_release'
> 
> /home/henry/build_xray/llvm-instrumented-build/lib/clang/7.0.0/lib/linux/libclang_rt.xray-fdr-x86_64.a(xray_fdr_logging.cc.o): In function `__xray::fdrLoggingFlush()':
> 
> /home/henry/build_xray/llvm-project/compiler-rt/lib/xray/xray_fdr_logging.cc:790: undefined reference to `operator delete(void*)'
> 
> /home/henry/build_xray/llvm-instrumented-build/lib/clang/7.0.0/lib/linux/libclang_rt.xray-fdr-x86_64.a(xray_fdr_logging.cc.o): In function `__xray::fdrLoggingInit(unsigned long, unsigned long, void*, unsigned long)':
> 
> /home/henry/build_xray/llvm-project/compiler-rt/lib/xray/xray_fdr_logging.cc:1096: undefined reference to `operator delete(void*)'
> 
> /home/henry/build_xray/llvm-project/compiler-rt/lib/xray/xray_fdr_logging.cc:1101: undefined reference to `operator new(unsigned long)'
> 
> /home/henry/build_xray/llvm-project/compiler-rt/lib/xray/xray_fdr_logging.cc:1106: undefined reference to `operator delete(void*)'
> 
> /home/henry/build_xray/llvm-project/compiler-rt/lib/xray/xray_fdr_logging.cc:1123: undefined reference to `__cxa_guard_acquire'
> 
> /home/henry/build_xray/llvm-project/compiler-rt/lib/xray/xray_fdr_logging.cc:1123: undefined reference to `__cxa_guard_release'
> 
> clang-7: error: linker command failed with exit code 1 (use -v to see invocation)
> 
>  
> Instead, I compiled using clang++ with the –xc flag mentioned in this post: http://lists.llvm.org/pipermail/llvm-dev/2018-March/121716.html
> 
>  
> ./clang++ -fxray-instrument -xc test_pthread.c
> 
>  
> It compiles without any errors and the executable works fine.
> 
>  

Yes, this particular problem has been fixed very recently (Friday last week). Please try with the most recent version in HEAD.

> Problem 2
> 
> ==================================
> 
> Also, I want to use fdr and want to programmatically configure fdr to flush its buffers when the program exits, but since the XRay interface headers are written in c++, clang complains.
> 
>  
> Here is the file I am trying to compile: (test_pthread_fdr.c)
> 
>  
> ./clang++ -fxray-instrument -xc test_pthread_fdr.c
> 
>  
> #include <stdio.h>
> 
> #include <pthread.h>
> 
> #include <assert.h>
> 
>  
> #include "xray/xray_log_interface.h"
> 
>  
> __attribute__((xray_always_instrument))
> 
> void print_parent()
> 
> {
> 
>                 printf("I am parent\n");
> 
> }
> 
>  
> __attribute__((xray_always_instrument))
> 
> void* print_child(void* unused)
> 
> {
> 
>  
>                 printf("I am child\n");
> 
>                 return NULL;
> 
> }
> 
>  
> //code adapted from test case fdr-mode.cc
> 
>  
> int main()
> 
> {
> 
>                 assert(__xray_log_select_mode("xray-fdr") == XRAY_REGISTRATION_OK);
> 
>                 assert(__xray_log_init_mode("xray-fdr", "buffer_size=16384:buffer_max=10") == XRAY_LOG_INITIALIZED);
> 
>                 __xray_patch();
> 
>  
>                 print_parent();
> 
>                 int num_threads = 10;
> 
>                 pthread_t tids[num_threads];
> 
>                 for(int i = 0; i < num_threads; i++)
> 
>                 {
> 
>                                 pthread_create(&tids[i], NULL, print_child, NULL);
> 
>                 }
> 
>                 for(int i = 0; i < num_threads; i++)
> 
>                 {
> 
>                                 pthread_join(tids[i], NULL);
> 
>                 }
> 
>  
>                 __xray_log_finalize();
> 
>                 __xray_log_flushLog();
> 
>                 __xray_unpatch();
> 
>                 return 0;
> 
> }
> 
>  
> I get this error:
> 
>  
> In file included from test_pthread_fdr.c:5: (xray_fdr_headers_error.txt)
> 
> In file included from /home/henry/build_xray/llvm-instrumented-build/lib/clang/7.0.0/include/xray/xray_log_interface.h:96:
> 
> /home/henry/build_xray/llvm-instrumented-build/lib/clang/7.0.0/include/xray/xray_interface.h:18:10: fatal error: 'cstddef' file not found
> 
> #include <cstddef>
> 
>          ^~~~~~~~~
> 
> 1 error generated.
> 
>  
> I changed xray_interface.h and xray_log_interface.h by removing the extern “C”, namespaces and adding typedefs to the structs and enums to make the headers C compatible. I have included them as in the attachment.
> 

These are going to change soon, as we remove the (deprecated) way of configuring FDR mode to only support the string-based configuration.

>  
> Finally, clang compiles cleanly and the program works fine.
> 
>  
> Is possible to have XRay interface with C cleanly without messing with the headers and compiler options? If not, are there easier methods to make C work with XRay cleanly?
> 

For FDR mode, we can certainly make some changes in the header to make the C++-specific parts conditional on whether it’s being compiled in C++ or C. Optionally we can also accelerate the removal of the struct-based config in favour of the flag-based config support only.

Patches would be welcome for either direction.

Cheers

-- Dean



More information about the llvm-dev mailing list