www.digitalmars.com         C & C++   DMDScript  

digitalmars.D.learn - LDC2 with -fxray-instrument

reply =?UTF-8?B?TcOhcmNpbw==?= Martins <marcioapm gmail.com> writes:
Anyone has any idea how to build with LDC and -fxray-instrument?
I am running LDC 1.13 on Linux (x64)

The XRay section is in the binary, and the compiler-rt is linked 
in, but when I run the binary with 
XRAY_OPTIONS="patch_premain=true verbosity=1" in the environment, 
and I get nothing. No XRay logging or terminal output.
Jan 15
parent reply Johan Engelen <j j.nl> writes:
On Tuesday, 15 January 2019 at 14:32:03 UTC, Márcio Martins wrote:
 Anyone has any idea how to build with LDC and -fxray-instrument?
 I am running LDC 1.13 on Linux (x64)

 The XRay section is in the binary, and the compiler-rt is 
 linked in, but when I run the binary with 
 XRAY_OPTIONS="patch_premain=true verbosity=1" in the 
 environment, and I get nothing. No XRay logging or terminal 
 output.
Great that you are trying this! I added it to LDC (trivial), but I have not tested it because I develop on macOS (bad excuse). Back than at least, XRay did not function on macOS. What platform are you on? -Johan
Jan 15
parent reply =?UTF-8?B?TcOhcmNpbw==?= Martins <marcioapm gmail.com> writes:
On Tuesday, 15 January 2019 at 22:51:15 UTC, Johan Engelen wrote:
 What platform are you on?
Linux x64
Jan 16
parent reply Johan Engelen <j j.nl> writes:
On Wednesday, 16 January 2019 at 17:36:31 UTC, Márcio Martins 
wrote:
 On Tuesday, 15 January 2019 at 22:51:15 UTC, Johan Engelen 
 wrote:
 What platform are you on?
Linux x64
OK, so that should work. What is your testcase? Try with `-fxray-instruction-threshold=1` to also instrument small functions. Have you gotten things to work with C++ code? -Johan
Jan 16
parent reply Johan Engelen <j j.nl> writes:
On Wednesday, 16 January 2019 at 22:10:14 UTC, Johan Engelen 
wrote:
 On Wednesday, 16 January 2019 at 17:36:31 UTC, Márcio Martins 
 wrote:
 On Tuesday, 15 January 2019 at 22:51:15 UTC, Johan Engelen 
 wrote:
 What platform are you on?
Linux x64
OK, so that should work. What is your testcase? Try with `-fxray-instruction-threshold=1` to also instrument small functions.
I'm trying now and am having the same problem. I'm trying to figure out how to fix LDC so that it works. work in progress! -Johan
Jan 16
parent reply Johan Engelen <j j.nl> writes:
On Wednesday, 16 January 2019 at 23:29:45 UTC, Johan Engelen 
wrote:
 On Wednesday, 16 January 2019 at 22:10:14 UTC, Johan Engelen 
 wrote:
 On Wednesday, 16 January 2019 at 17:36:31 UTC, Márcio Martins 
 wrote:
 On Tuesday, 15 January 2019 at 22:51:15 UTC, Johan Engelen 
 wrote:
 What platform are you on?
Linux x64
OK, so that should work. What is your testcase? Try with `-fxray-instruction-threshold=1` to also instrument small functions.
I'm trying now and am having the same problem. I'm trying to figure out how to fix LDC so that it works. work in progress! -Johan
OK, got it :-) LLVM 7 changed things a little, so it's broken with LDC 1.13 [*]. For now, you can use LDC 1.12 (LLVM 6). You also have to add `-L-lstdc++` as compiler flag. So with LDC 1.12, Linux, and this commandline things work for me: ``` ldc2 -fxray-instrument -fxray-instruction-threshold=1 xraytest.d -L-lstdc++ XRAY_OPTIONS="patch_premain=true xray_mode=xray-basic verbosity=1" xraytest ``` Happy testing, Johan [*] XRay was split into several libraries, and we only copy+link with one of them. You can make things work by downloading the libs and linking with them.
Jan 16
parent reply =?UTF-8?B?TcOhcmNpbw==?= Martins <marcioapm gmail.com> writes:
On Thursday, 17 January 2019 at 00:11:10 UTC, Johan Engelen wrote:
 On Wednesday, 16 January 2019 at 23:29:45 UTC, Johan Engelen 
 wrote:
 On Wednesday, 16 January 2019 at 22:10:14 UTC, Johan Engelen 
 wrote:
 On Wednesday, 16 January 2019 at 17:36:31 UTC, Márcio Martins 
 wrote:
 On Tuesday, 15 January 2019 at 22:51:15 UTC, Johan Engelen 
 wrote:
 What platform are you on?
Linux x64
OK, so that should work. What is your testcase? Try with `-fxray-instruction-threshold=1` to also instrument small functions.
I'm trying now and am having the same problem. I'm trying to figure out how to fix LDC so that it works. work in progress! -Johan
OK, got it :-) LLVM 7 changed things a little, so it's broken with LDC 1.13 [*]. For now, you can use LDC 1.12 (LLVM 6). You also have to add `-L-lstdc++` as compiler flag. So with LDC 1.12, Linux, and this commandline things work for me: ``` ldc2 -fxray-instrument -fxray-instruction-threshold=1 xraytest.d -L-lstdc++ XRAY_OPTIONS="patch_premain=true xray_mode=xray-basic verbosity=1" xraytest ``` Happy testing, Johan [*] XRay was split into several libraries, and we only copy+link with one of them. You can make things work by downloading the libs and linking with them.
Great! Does it mean it will be fixed in next LDC release? :) I also played a bit with -finstrument-functions and it works fine for tools like uftrace... However, if you define your own __cyg_profile_func_* functions, it won't work (or be useful), because there is no way to disable instrumenting on these __cyg_profile_func_* functions, so you can imagine what happens. I tried llvmAttr("no_instrument_function"), supposedly the GCC compatible way to disable instrumentation on these, but it doesn't make a difference. There are few LLVM settings that will make this useful: - https://reviews.llvm.org/D40276 - https://reviews.llvm.org/D39331 (which enables instrumenting after inlining, which is more useful in my use case) - https://reviews.llvm.org/D37622 (is has not been merged yet, but necessary, to be able to conveniently call library functions from within the hooks)
Jan 21
parent Johan Engelen <j j.nl> writes:
On Monday, 21 January 2019 at 14:36:15 UTC, Márcio Martins wrote:
 On Thursday, 17 January 2019 at 00:11:10 UTC, Johan Engelen 
 wrote:
 OK, got it :-) LLVM 7 changed things a little, so it's broken 
 with LDC 1.13  [*].

 For now, you can use LDC 1.12 (LLVM 6). You also have to add 
 `-L-lstdc++` as compiler flag. So with LDC 1.12, Linux, and 
 this commandline things work for me:
 ```
 ldc2 -fxray-instrument -fxray-instruction-threshold=1 
 xraytest.d -L-lstdc++
 XRAY_OPTIONS="patch_premain=true xray_mode=xray-basic 
 verbosity=1" xraytest
 ```

 Happy testing,
   Johan

 [*] XRay was split into several libraries, and we only 
 copy+link with one of them. You can make things work by 
 downloading the libs and linking with them.
Great! Does it mean it will be fixed in next LDC release? :)
Yes: https://github.com/ldc-developers/ldc/pull/2965
 I also played a bit with -finstrument-functions and it works 
 fine for tools like uftrace... However, if you define your own 
 __cyg_profile_func_* functions, it won't work (or be useful), 
 because there is no way to disable instrumenting on these 
 __cyg_profile_func_* functions, so you can imagine what 
 happens. I tried  llvmAttr("no_instrument_function"), 
 supposedly the GCC compatible way to disable instrumentation on 
 these, but it doesn't make a difference.
You need: pragma(LDC_profile_instr, false), e.g.: ``` pragma(LDC_profile_instr, false) void fun () { ... } ``
 There are few LLVM settings that will make this useful:
 - https://reviews.llvm.org/D40276
 - https://reviews.llvm.org/D39331 (which enables instrumenting 
 after inlining, which is more useful in my use case)
 - https://reviews.llvm.org/D37622 (is has not been merged yet, 
 but necessary, to be able to conveniently call library 
 functions from within the hooks)
These are not too hard to implement in LDC. Whoever is interested in working on it, here are some pointers in addition to the LLVM links: https://github.com/ldc-developers/ldc/issues/2466 https://github.com/ldc-developers/ldc/pull/1845/files -Johan
Jan 21