Details
Diff Detail
- Repository
- rL LLVM
Event Timeline
@yln Could you take a look? Do the tests actually pass on Darwin?
The _XOPEN_SOURCE stuff is ugly, but I guess it's necessary to use swapcontext on Darwin. For the pragma diagnostic push/ignore stuff, we might be better off just redeclaring the function ourselves without including ucontext.h. TBH, I'm not sure if there's a lot of value in supporting swapcontext on Darwin, as they are very likely broken when using many system libraries.
test/tsan/fiber_asm.cc | ||
---|---|---|
21–22 ↗ | (On Diff #186428) | Can we use something like the ASM_SYMBOL macro from sanitizer_asm.h and put it into test.h please? |
For tsan_interceptors_mac.cc it can be done. For me such solution is more ugly than usage of #define and #pragma; but if you insist on it, I can do such change.
For tests it is bad idea because test should use API the same way as real-world clients. I moved declarations to the separate header. Now code looks better.
TBH, I'm not sure if there's a lot of value in supporting swapcontext on Darwin, as they are very likely broken when using many system libraries.
- QEMU is an important projected user of fiber API and it actually use swapcontext.
- We need to test fiber API somehow and swapcontext is the only portable way to do it.
PS. I want to explain why swapcontext interceptor is required on macOS and not on Linux.
__tsan_switch_to_fiber is called immediately before or after context switch.
Actual context switch code should not introduce memory dependancies; otherwise false positive races can be reported.
On Linux swapcontext implementation does not call any intercepted function, so condition is fulfilled.
On macOS we have to intercept swapcontext and disable interceptors inside it in order to achieve the same effect.
For the pragma diagnostic push/ignore stuff, we might be better off just redeclaring the function ourselves without including ucontext.h.
For tsan_interceptors_mac.cc it can be done. For me such solution is more ugly than usage of #define and #pragma; but if you insist on it, I can do such change.
I also think it's more ugly, but I'm afraid the code won't build against watchOS and tvOS, where swapcontext is not just deprecated, but it's completely unavailable. @yln Can you please try to build this for watchOS/tvOS?
I verified that the watchOS/tvOS runtimes (libclang_rt.tsan_*) are building with this patch applied to our internal master.
watchOS/tvOS build is broken right now in trunk:
https://pastebin.com/Y3gsxtA7
The watchOS/tvOS parts of ASan require an internal SDK that's not publicly available to build. I guess that counts as "broken", but it's an expected state.
I think the tests are still going to fail on watchOS and tvOS, they need to be marked as UNSUPPORTED. At this point, I'm inclined to prefer to declare swapcontext ourselves (as swapcontext *is* available at runtime on watchOS/tvOS, it's just not allowed in the SDK) to avoid this much ifdef'ing and platform-specific workarounds. But if you strongly disagree, I'm okay with this approach also. (The tests still need updating.)
I don't know exactly what/how should be done (Kuba, please advise), but the definition of the features is here:
https://github.com/llvm/llvm-project/blob/master/compiler-rt/test/lit.common.cfg#L130
Sorry for the huge delay. @yln can you test this patch (that is passes all tests) and if yes, land it?