Add sanitizer support (notably AddressSanitizer) to core.thread.Fiber.#152
Add sanitizer support (notably AddressSanitizer) to core.thread.Fiber.#152JohanEngelen merged 1 commit intoldcfrom
Conversation
|
I think it should keep being versioned. Building druntime oneself isn't rocket-science with ldc-build-runtime and should be acceptable for advanced instrumentation with according overhead. |
|
Yeah. I'll keep it versioned and I'll do the dynamic loading / weak link thing such that the resulting library can also be used without asan linked in. |
80f5584 to
090730c
Compare
|
How's this? I can use the same method for other sanitizer support additions needed. |
| else version (Windows) | ||
| { | ||
| import core.sys.windows.windows : GetModuleHandleA, GetProcAddress; | ||
| fptr = cast(typeof(fptr)) GetProcAddress(GetModuleHandleA(null), functionName); |
There was a problem hiding this comment.
This requires the binary containing druntime executable to explicitly dllexport a function with matching name.
There was a problem hiding this comment.
That's what LLVM appears to be doing.
To be honest, I don't expect there to be much support for sanitizers on windows.
93dfd18 to
37f9af1
Compare
37f9af1 to
2a7f21b
Compare
|
Mergable? |
| // Note that the fake stack mechanism is disabled during fiber switch, so if a | ||
| // signal callback runs during the switch, it will not benefit from the stack | ||
| // use-after-return detection. | ||
| void __sanitizer_start_switch_fiber(void** fake_stack_save, |
There was a problem hiding this comment.
only thing i think is missing is a code example.
There was a problem hiding this comment.
This is such specific stuff that a code example would be the size of a book :P Here I copied the documentation that is in the LLVM interface file, which is kindof the only documentation there is.
Updated to latest state:
Here are the changes that are needed to support ASan with fibers.
To enable support, the runtime must be built with
version = SupportSanitizers, which is done by passing-DRT_SUPPORT_SANITIZERS=ONtocmakewhen building LDC. This is OFF per default. See ldc-developers/ldc#2975The calls to
__sanitizer_finish_switch_fiberand__sanitizer_start_switch_fiberpass through a layer that makes linking with AddressSanitizer library optional, such that the runtime can be used without ASan aswell with only a small overhead. This optional linking method is the same as Folly, see: facebook/folly@2ea64dd).The same layer will be used to add other sanitizer support to the runtime (e.g. GC support).