<div dir="ltr">Hi,<div><br></div><div>The following three patches, when applied cleanly to LLVM+Clang+compiler-rt will now allow for building and running binaries with a very simple version of XRay included:</div><div><br></div><div><a href="http://reviews.llvm.org/D21612" target="_blank">http://reviews.llvm.org/D21612</a> (compiler-rt)<br></div><div><a href="http://reviews.llvm.org/D20352" target="_blank">http://reviews.llvm.org/D20352</a> (clang)<br></div><div><a href="http://reviews.llvm.org/D19904" target="_blank">http://reviews.llvm.org/D19904</a> (llvm)<br></div><div><br></div><div>To use this on x86_64-unknown-linux-gnu you'd need to set the flags '-fxray-instrument' and if you'd like to instrument all functions, set '-fxray-instruction-threshold=1'. Apply those flags to all your object files, and link statically for best effect.</div><div><br></div><div>Now, some questions before I continue:</div><div><br></div><div>- What is the preferred way of controlling the behaviour of the runtime library for something like XRay? Do the sanitizers check/use environment variables or commandline-flags to control behaviour at runtime/init?</div><div>- We would like to be able to trigger the patching/unpatching routines at runtime in a portable manner. In Linux and other UNIX-like environments signals (SIGUSR1 and SIGUSR2) might be good candidates for signalling the tracing infrastructure to start/stop at user-controlled times (useful for long-running servers). Is there a preference for this, or are there alternatives in this space that might make better sense?</div><div>- Currently we are using 'printf' for the logging, but could use a simple thread-local in-memory log that flushes to disk when full. Any other preferred ways of doing this?</div><div>- Documentation for how to use/run XRay may need to live in a central location, but since the changes to the LLVM pieces are currently in three different places, are there suggestions for where the docs should live?</div><div><br></div><div>Cheers</div><div><br></div><div>PS. An example log of how to use XRay with clang+llvm+compiler-rt with the above patches:</div><div><br></div><div><div>[16-06-28 17:21:02] dberris@dberris: ~/xray/llvm-build% cat test.cc</div><div>#include <cstdio></div><div>#include <cassert></div><div><br></div><div>[[clang::xray_always_instrument]] void foo() { std::printf("Hello, XRay!\n"); }</div><div><br></div><div>[[clang::xray_never_instrument]] void bar() { std::printf("Not instrumented\n"); }</div><div><br></div><div>extern void baz();  // defined in other.cc</div><div><br></div><div>int main(int argc, char* argv[]) {</div><div>  printf("main has started.\n");</div><div>  bar();</div><div>  foo();</div><div>  baz();</div><div>}</div><div>[16-06-28 17:30:13] dberris@dberris: ~/xray/llvm-build% cat other.cc</div><div>#include <cstdio></div><div><br></div><div>[[clang::xray_always_instrument]] void baz() {</div><div>  std::printf("Welcome!\n");</div><div>}</div><div><br></div><div>[16-06-28 17:30:16] dberris@dberris: ~/xray/llvm-build% ./bin/clang -c test.cc -x c++ -std=c++11 -fxray-instrument</div><div>[16-06-28 17:30:34] dberris@dberris: ~/xray/llvm-build% ./bin/clang -c other.cc -x c++ -std=c++11 -fxray-instrument</div><div>[16-06-28 17:30:46] dberris@dberris: ~/xray/llvm-build% ./bin/clang -o test.bin test.o other.o -fxray-instrument</div><div>[16-06-28 17:30:55] dberris@dberris: ~/xray/llvm-build% ./test.bin</div><div>__xray_instr_map@0x400f5b..0x400fdb</div><div>400cf0  E       *       @function(400cf0)</div><div>400d1c  X       *       @function(400cf0)</div><div>400da0  E       *       @function(400da0)</div><div>400dcc  X       *       @function(400da0)</div><div>main has started.</div><div>Not instrumented</div><div>4133: [9699491610577808] E1</div><div>Hello, XRay!</div><div>4133: [9699491610592074] X1</div><div>4133: [9699491610599840] E2</div><div>Welcome!</div><div>4133: [9699491610611254] X2</div></div></div>