[llvm-dev] C interface with XRay

Henry Zhu via llvm-dev llvm-dev at lists.llvm.org
Fri Jun 8 07:57:21 PDT 2018


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.

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++)



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.



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?

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.



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.



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?



Thanks,

Henry
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.llvm.org/pipermail/llvm-dev/attachments/20180608/c2cbb228/attachment-0001.html>
-------------- next part --------------
#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;
}
-------------- next part --------------
#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;
}
-------------- next part --------------
/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)
-------------- next part --------------
In file included from test_pthread_fdr.c:5:
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.
-------------- next part --------------
//===- xray_interface.h -----------------------------------------*- C++ -*-===//
//
//                     The LLVM Compiler Infrastructure
//
// This file is distributed under the University of Illinois Open Source
// License. See LICENSE.TXT for details.
//
//===----------------------------------------------------------------------===//
//
// This file is a part of XRay, a dynamic runtime instrumentation system.
//
// APIs for controlling XRay functionality explicitly.
//===----------------------------------------------------------------------===//

#ifndef XRAY_XRAY_INTERFACE_H
#define XRAY_XRAY_INTERFACE_H

#include <stddef.h>
#include <stdint.h>

//extern "C" {

/// Synchronize this with AsmPrinter::SledKind in LLVM.
enum XRayEntryType {
  ENTRY = 0,
  EXIT = 1,
  TAIL = 2,
  LOG_ARGS_ENTRY = 3,
  CUSTOM_EVENT = 4,
  TYPED_EVENT = 5,
};

/// Provide a function to invoke for when instrumentation points are hit. This
/// is a user-visible control surface that overrides the default implementation.
/// The function provided should take the following arguments:
///
///   - function id: an identifier that indicates the id of a function; this id
///                  is generated by xray; the mapping between the function id
///                  and the actual function pointer is available through
///                  __xray_table.
///   - entry type: identifies what kind of instrumentation point was
///                 encountered (function entry, function exit, etc.). See the
///                 enum XRayEntryType for more details.
///
/// The user handler must handle correctly spurious calls after this handler is
/// removed or replaced with another handler, because it would be too costly for
/// XRay runtime to avoid spurious calls.
/// To prevent circular calling, the handler function itself and all its
/// direct&indirect callees must not be instrumented with XRay, which can be
/// achieved by marking them all with: __attribute__((xray_never_instrument))
///
/// Returns 1 on success, 0 on error.
extern int __xray_set_handler(void (*entry)(int32_t, XRayEntryType));

/// This removes whatever the currently provided handler is. Returns 1 on
/// success, 0 on error.
extern int __xray_remove_handler();

/// Use XRay to log the first argument of each (instrumented) function call.
/// When this function exits, all threads will have observed the effect and
/// start logging their subsequent affected function calls (if patched).
///
/// Returns 1 on success, 0 on error.
extern int __xray_set_handler_arg1(void (*entry)(int32_t, XRayEntryType,
                                                 uint64_t));

/// Disables the XRay handler used to log first arguments of function calls.
/// Returns 1 on success, 0 on error.
extern int __xray_remove_handler_arg1();

/// Provide a function to invoke when XRay encounters a custom event.
//extern int __xray_set_customevent_handler(void (*entry)(void *, std::size_t));
extern int __xray_set_customevent_handler(void (*entry)(void *, size_t));

/// This removes whatever the currently provided custom event handler is.
/// Returns 1 on success, 0 on error.
extern int __xray_remove_customevent_handler();

/// Set a handler for xray typed event logging. The first parameter is a type
/// identifier, the second is a payload, and the third is the payload size.
extern int __xray_set_typedevent_handler(void (*entry)(uint16_t, const void *,
                                                       size_t));

/// Removes the currently set typed event handler.
/// Returns 1 on success, 0 on error.
extern int __xray_remove_typedevent_handler();

extern uint16_t __xray_register_event_type(const char *event_type);

typedef enum XRayPatchingStatus {
  NOT_INITIALIZED = 0,
  SUCCESS = 1,
  ONGOING = 2,
  FAILED = 3,
} XRayPatchingStatus;

/// This tells XRay to patch the instrumentation points. See XRayPatchingStatus
/// for possible result values.
extern XRayPatchingStatus __xray_patch();

/// Reverses the effect of __xray_patch(). See XRayPatchingStatus for possible
/// result values.
extern XRayPatchingStatus __xray_unpatch();

/// This patches a specific function id. See XRayPatchingStatus for possible
/// result values.
extern XRayPatchingStatus __xray_patch_function(int32_t FuncId);

/// This unpatches a specific function id. See XRayPatchingStatus for possible
/// result values.
extern XRayPatchingStatus __xray_unpatch_function(int32_t FuncId);

/// This function returns the address of the function provided a valid function
/// id. We return 0 if we encounter any error, even if 0 may be a valid function
/// address.
extern uintptr_t __xray_function_address(int32_t FuncId);

/// This function returns the maximum valid function id. Returns 0 if we
/// encounter errors (when there are no instrumented functions, etc.).
extern size_t __xray_max_function_id();

/// Initialize the required XRay data structures. This is useful in cases where
/// users want to control precisely when the XRay instrumentation data
/// structures are initialized, for example when the XRay library is built with
/// the XRAY_NO_PREINIT preprocessor definition.
///
/// Calling __xray_init() more than once is safe across multiple threads.
extern void __xray_init();

//} // end extern "C"

#endif // XRAY_XRAY_INTERFACE_H
-------------- next part --------------
//===-- xray_log_interface.h ----------------------------------------------===//
//
//                     The LLVM Compiler Infrastructure
//
// This file is distributed under the University of Illinois Open Source
// License. See LICENSE.TXT for details.
//
//===----------------------------------------------------------------------===//
//
// This file is a part of XRay, a function call tracing system.
//
// APIs for installing a new logging implementation.
//
//===----------------------------------------------------------------------===//
///
/// XRay allows users to implement their own logging handlers and install them
/// to replace the default runtime-controllable implementation that comes with
/// compiler-rt/xray. The "flight data recorder" (FDR) mode implementation uses
/// this API to install itself in an XRay-enabled binary. See
/// compiler-rt/lib/xray_fdr_logging.{h,cc} for details of that implementation.
///
/// The high-level usage pattern for these APIs look like the following:
///
///   // We choose the mode which we'd like to install, and check whether this
///   // has succeeded. Each mode will have their own set of flags they will
///   // support, outside of the global XRay configuration options that are
///   // defined in the XRAY_OPTIONS environment variable.
///   auto select_status = __xray_log_select_mode("xray-fdr");
///   if (select_status != XRayLogRegisterStatus::XRAY_REGISTRATION_OK) {
///     // This failed, we should not proceed with attempting to initialise
///     // the currently selected mode.
///     return;
///   }
///
///   // Once that's done, we can now attempt to configure the implementation.
///   // To do this, we provide the string flags configuration for the mode.
///   auto config_status = __xray_log_init_mode(
///       "xray-fdr", "verbosity=1 some_flag=1 another_flag=2");
///   if (config_status != XRayLogInitStatus::XRAY_LOG_INITIALIZED) {
///     // deal with the error here, if there is one.
///   }
///
///   // When the log implementation has had the chance to initialize, we can
///   // now patch the instrumentation points. Note that we could have patched
///   // the instrumentation points first, but there's no strict ordering to
///   // these operations.
///   auto patch_status = __xray_patch();
///   if (patch_status != XRayPatchingStatus::SUCCESS) {
///     // deal with the error here, if it is an error.
///   }
///
///   // If we want to stop the implementation, we can then finalize it (before
///   // optionally flushing the log).
///   auto fin_status = __xray_log_finalize();
///   if (fin_status != XRayLogInitStatus::XRAY_LOG_FINALIZED) {
///     // deal with the error here, if it is an error.
///   }
///
///   // We can optionally wait before flushing the log to give other threads a
///   // chance to see that the implementation is already finalized. Also, at
///   // this point we can optionally unpatch the instrumentation points to
///   // reduce overheads at runtime.
///   auto unpatch_status = __xray_unpatch();
///   if (unpatch_status != XRayPatchingStatus::SUCCESS) {
///     // deal with the error here, if it is an error.
///   }
///
///   // If there are logs or data to be flushed somewhere, we can do so only
///   // after we've finalized the log. Some implementations may not actually
///   // have anything to log (it might keep the data in memory, or periodically
///   // be logging the data anyway).
///   auto flush_status = __xray_log_flushLog();
///   if (flush_status != XRayLogFlushStatus::XRAY_LOG_FLUSHED) {
///     // deal with the error here, if it is an error.
///   }
///
///   // Alternatively, we can go through the buffers ourselves without
///   // relying on the implementations' flushing semantics (if the
///   // implementation supports exporting this data directly).
///   auto MyBufferProcessor = +[](const char* mode, XRayBuffer buffer) {
///     // Check the "mode" to see if it's something we know how to handle...
///     // and/or do something with an XRayBuffer instance.
///   };
///   auto process_status = __xray_log_process_buffers(MyBufferProcessor);
///   if (process_status != XRayLogFlushStatus::XRAY_LOG_FLUSHED) {
///     // deal with the error here, if it is an error.
///   }
///
/// NOTE: Before calling __xray_patch() again, consider re-initializing the
/// implementation first. Some implementations might stay in an "off" state when
/// they are finalized, while some might be in an invalid/unknown state.
///
#ifndef XRAY_XRAY_LOG_INTERFACE_H
#define XRAY_XRAY_LOG_INTERFACE_H

#include "xray/xray_interface.h"
#include <stddef.h>
#include <stdbool.h>

//extern "C" {

/// This enum defines the valid states in which the logging implementation can
/// be at.
typedef enum XRayLogInitStatus {
  /// The default state is uninitialized, and in case there were errors in the
  /// initialization, the implementation MUST return XRAY_LOG_UNINITIALIZED.
  XRAY_LOG_UNINITIALIZED = 0,

  /// Some implementations support multi-stage init (or asynchronous init), and
  /// may return XRAY_LOG_INITIALIZING to signal callers of the API that
  /// there's an ongoing initialization routine running. This allows
  /// implementations to support concurrent threads attempting to initialize,
  /// while only signalling success in one.
  XRAY_LOG_INITIALIZING = 1,

  /// When an implementation is done initializing, it MUST return
  /// XRAY_LOG_INITIALIZED. When users call `__xray_patch()`, they are
  /// guaranteed that the implementation installed with
  /// `__xray_set_log_impl(...)` has been initialized.
  XRAY_LOG_INITIALIZED = 2,

  /// Some implementations might support multi-stage finalization (or
  /// asynchronous finalization), and may return XRAY_LOG_FINALIZING to signal
  /// callers of the API that there's an ongoing finalization routine running.
  /// This allows implementations to support concurrent threads attempting to
  /// finalize, while only signalling success/completion in one.
  XRAY_LOG_FINALIZING = 3,

  /// When an implementation is done finalizing, it MUST return
  /// XRAY_LOG_FINALIZED. It is up to the implementation to determine what the
  /// semantics of a finalized implementation is. Some implementations might
  /// allow re-initialization once the log is finalized, while some might always
  /// be on (and that finalization is a no-op).
  XRAY_LOG_FINALIZED = 4,
} XRayLogInitStatus;

/// This enum allows an implementation to signal log flushing operations via
/// `__xray_log_flushLog()`, and the state of flushing the log.
typedef enum XRayLogFlushStatus {
  XRAY_LOG_NOT_FLUSHING = 0,
  XRAY_LOG_FLUSHING = 1,
  XRAY_LOG_FLUSHED = 2,
} XRayLogFlushStatus;

/// This enum indicates the installation state of a logging implementation, when
/// associating a mode to a particular logging implementation through
/// `__xray_log_register_impl(...)` or through `__xray_log_select_mode(...`.
typedef enum XRayLogRegisterStatus {
  XRAY_REGISTRATION_OK = 0,
  XRAY_DUPLICATE_MODE = 1,
  XRAY_MODE_NOT_FOUND = 2,
  XRAY_INCOMPLETE_IMPL = 3,
} XRayLogRegisterStatus;

/// A valid XRay logging implementation MUST provide all of the function
/// pointers in XRayLogImpl when being installed through `__xray_set_log_impl`.
/// To be precise, ALL the functions pointers MUST NOT be nullptr.
typedef struct XRayLogImpl {
  /// The log initialization routine provided by the implementation, always
  /// provided with the following parameters:
  ///
  ///   - buffer size
  ///   - maximum number of buffers
  ///   - a pointer to an argument struct that the implementation MUST handle
  ///   - the size of the argument struct
  ///
  /// See XRayLogInitStatus for details on what the implementation MUST return
  /// when called.
  ///
  /// If the implementation needs to install handlers aside from the 0-argument
  /// function call handler, it MUST do so in this initialization handler.
  ///
  /// See xray_interface.h for available handler installation routines.
  XRayLogInitStatus (*log_init)(size_t, size_t, void *, size_t);

  /// The log finalization routine provided by the implementation.
  ///
  /// See XRayLogInitStatus for details on what the implementation MUST return
  /// when called.
  XRayLogInitStatus (*log_finalize)();

  /// The 0-argument function call handler. XRay logging implementations MUST
  /// always have a handler for function entry and exit events. In case the
  /// implementation wants to support arg1 (or other future extensions to XRay
  /// logging) those MUST be installed by the installed 'log_init' handler.
  ///
  /// Because we didn't want to change the ABI of this struct, the arg1 handler
  /// may be silently overwritten during initialization as well.
  void (*handle_arg0)(int32_t, XRayEntryType);

  /// The log implementation provided routine for when __xray_log_flushLog() is
  /// called.
  ///
  /// See XRayLogFlushStatus for details on what the implementation MUST return
  /// when called.
  XRayLogFlushStatus (*flush_log)();
} XRayLogImpl;

/// DEPRECATED: Use the mode registration workflow instead with
/// __xray_log_register_mode(...) and __xray_log_select_mode(...). See the
/// documentation for those function.
///
/// This function installs a new logging implementation that XRay will use. In
/// case there are any nullptr members in Impl, XRay will *uninstall any
/// existing implementations*. It does NOT patch the instrumentation points.
///
/// NOTE: This function does NOT attempt to finalize the currently installed
/// implementation. Use with caution.
///
/// It is guaranteed safe to call this function in the following states:
///
///   - When the implementation is UNINITIALIZED.
///   - When the implementation is FINALIZED.
///   - When there is no current implementation installed.
///
/// It is logging implementation defined what happens when this function is
/// called while in any other states.
void __xray_set_log_impl(XRayLogImpl Impl);

/// This function registers a logging implementation against a "mode"
/// identifier. This allows multiple modes to be registered, and chosen at
/// runtime using the same mode identifier through
/// `__xray_log_select_mode(...)`.
///
/// We treat the Mode identifier as a null-terminated byte string, as the
/// identifier used when retrieving the log impl.
///
/// Returns:
///   - XRAY_REGISTRATION_OK on success.
///   - XRAY_DUPLICATE_MODE when an implementation is already associated with
///     the provided Mode; does not update the already-registered
///     implementation.
XRayLogRegisterStatus __xray_log_register_mode(const char *Mode,
                                               XRayLogImpl Impl);

/// This function selects the implementation associated with Mode that has been
/// registered through __xray_log_register_mode(...) and installs that
/// implementation (as if through calling __xray_set_log_impl(...)). The same
/// caveats apply to __xray_log_select_mode(...) as with
/// __xray_log_set_log_impl(...).
///
/// Returns:
///   - XRAY_REGISTRATION_OK on success.
///   - XRAY_MODE_NOT_FOUND if there is no implementation associated with Mode;
///     does not update the currently installed implementation.
XRayLogRegisterStatus __xray_log_select_mode(const char *Mode);

/// Returns an identifier for the currently selected XRay mode chosen through
/// the __xray_log_select_mode(...) function call. Returns nullptr if there is
/// no currently installed mode.
const char *__xray_log_get_current_mode();

/// This function removes the currently installed implementation. It will also
/// uninstall any handlers that have been previously installed. It does NOT
/// unpatch the instrumentation points.
///
/// NOTE: This function does NOT attempt to finalize the currently installed
/// implementation. Use with caution.
///
/// It is guaranteed safe to call this function in the following states:
///
///   - When the implementation is UNINITIALIZED.
///   - When the implementation is FINALIZED.
///   - When there is no current implementation installed.
///
/// It is logging implementation defined what happens when this function is
/// called while in any other states.
void __xray_remove_log_impl();

/// DEPRECATED: Use __xray_log_init_mode() instead, and provide all the options
/// in string form.
/// Invokes the installed implementation initialization routine. See
/// XRayLogInitStatus for what the return values mean.
XRayLogInitStatus __xray_log_init(size_t BufferSize, size_t MaxBuffers,
                                  void *Args, size_t ArgsSize);

/// Invokes the installed initialization routine, which *must* support the
/// string based form.
///
/// NOTE: When this API is used, we still invoke the installed initialization
/// routine, but we will call it with the following convention to signal that we
/// are using the string form:
///
/// - BufferSize = 0
/// - MaxBuffers = 0
/// - ArgsSize = 0
/// - Args will be the pointer to the character buffer representing the
///   configuration.
///
/// FIXME: Updating the XRayLogImpl struct is an ABI breaking change. When we
/// are ready to make a breaking change, we should clean this up appropriately.
XRayLogInitStatus __xray_log_init_mode(const char *Mode, const char *Config);

/// Like __xray_log_init_mode(...) this version allows for providing
/// configurations that might have non-null-terminated strings. This will
/// operate similarly to __xray_log_init_mode, with the exception that
/// |ArgsSize| will be what |ConfigSize| is.
XRayLogInitStatus __xray_log_init_mode_bin(const char *Mode, const char *Config,
                                           size_t ConfigSize);

/// Invokes the installed implementation finalization routine. See
/// XRayLogInitStatus for what the return values mean.
XRayLogInitStatus __xray_log_finalize();

/// Invokes the install implementation log flushing routine. See
/// XRayLogFlushStatus for what the return values mean.
XRayLogFlushStatus __xray_log_flushLog();

/// An XRayBuffer represents a section of memory which can be treated by log
/// processing functions as bytes stored in the logging implementation's
/// buffers.
typedef struct XRayBuffer {
  const void *Data;
  size_t Size;
} XRayBuffer;

/// Registers an iterator function which takes an XRayBuffer argument, then
/// returns another XRayBuffer function representing the next buffer. When the
/// Iterator function returns an empty XRayBuffer (Data = nullptr, Size = 0),
/// this signifies the end of the buffers.
///
/// The first invocation of this Iterator function will always take an empty
/// XRayBuffer (Data = nullptr, Size = 0).
void __xray_log_set_buffer_iterator(XRayBuffer (*Iterator)(XRayBuffer));

/// Removes the currently registered buffer iterator function.
void __xray_log_remove_buffer_iterator();

/// Invokes the provided handler to process data maintained by the logging
/// handler. This API will be provided raw access to the data available in
/// memory from the logging implementation. The callback function must:
///
/// 1) Not modify the data, to avoid running into undefined behaviour.
///
/// 2) Either know the data layout, or treat the data as raw bytes for later
///    interpretation.
///
/// This API is best used in place of the `__xray_log_flushLog()` implementation
/// above to enable the caller to provide an alternative means of extracting the
/// data from the XRay implementation.
///
/// Implementations MUST then provide:
///
/// 1) A function that will return an XRayBuffer. Functions that return an
///    "empty" XRayBuffer signifies that there are no more buffers to be
///    processed. This function should be registered through the
///    `__xray_log_set_buffer_iterator(...)` function.
///
/// 2) Its own means of converting data it holds in memory into an XRayBuffer
///    structure.
///
/// See XRayLogFlushStatus for what the return values mean.
///
XRayLogFlushStatus __xray_log_process_buffers(void (*Processor)(const char *,
                                                                XRayBuffer));

//} extern "C"

//namespace __xray {

/// DEPRECATED: Use __xray_log_init_mode(...) instead, and provide flag
/// configuration strings to set the options instead.
/// Options used by the LLVM XRay FDR logging implementation.
typedef struct FDRLoggingOptions {
  bool ReportErrors;
  int Fd;
} FDRLoggingOptions;

/// DEPRECATED: Use __xray_log_init_mode(...) instead, and provide flag
/// configuration strings to set the options instead.
/// Options used by the LLVM XRay Basic (Naive) logging implementation.
typedef struct BasicLoggingOptions {
  int DurationFilterMicros;
  size_t MaxStackDepth;
  size_t ThreadBufferSize;
} BasicLoggingOptions;

//} // namespace __xray

#endif // XRAY_XRAY_LOG_INTERFACE_H


More information about the llvm-dev mailing list