Overview
| Artifact ID: | 79be50c9e9dc43431f488a28a416a9d81548e36184fd1341b7c20e15b5d90bd3 |
|---|---|
| Ticket: | 7371b6270b727521cf0c7044a882d16ef5c4e96b
AddressSanitizer use-after-return detection breaks NRE tests, coroutines |
| User & Date: | chrstphrchvz on 2023-08-04 04:36:43 |
Changes
- assignee changed to: "nobody"
- closer changed to: "nobody"
- cmimetype changed to: "text/x-fossil-wiki"
- comment changed to:
AddressSanitizer (ASan) can detect use-after-return errors. Depending on the platform, this is enabled either by default, or by using the appropriate compiler flags or runtime environment variables (e.g. <tt>ASAN_OPTIONS=detect_use_after_return=1</tt>). But enabling this can completely break Tcl coroutines: there will be unexpected “cannot yield: C stack busy” errors, and numerous tests will fail or even hang (e.g. http-3.10.0, io-28.6). This is because the real stack gets replaced with a heap-allocated fake stack, and there is [https://github.com/google/sanitizers/wiki/AddressSanitizerUseAfterReturn#compatibility|no guarantee] that the address of a stack variable will be consistent for a given C stack depth, as assumed by the coroutines implementation. Rather than requiring AddressSanitizer use-after-return detection to be disabled, I suggest that Tcl use AddressSanitizer-friendly approaches instead. For GCC and Clang, there is <a href="https://gcc.gnu.org/onlinedocs/gcc/Return-Address.html#index-_005f_005fbuiltin_005fframe_005faddress"><tt>__builtin_frame_address(0)</tt></a>; and for MSVC, there is <a href="https://learn.microsoft.com/en-us/cpp/intrinsics/addressofreturnaddress"><tt>_AddressOfReturnAddress()</tt></a>. And I suggest always using these when available, for consistency between builds with and without AddressSanitizer, and in case of other use-after-return detection tools with similar limitations. See attached patch. [https://github.com/llvm/llvm-project/blob/llvmorg-10.0.0-rc1/clang/lib/Basic/Stack.cpp#L24] shows a very similar example.
- foundin changed to: "8.6.13"
- is_private changed to: "0"
- login: "chrstphrchvz"
- priority changed to: "5 Medium"
- private_contact changed to: "6133eb3026f9b10aa9b7b48da92ae2834fc225b0"
- resolution changed to: "None"
- severity changed to: "Important"
- status changed to: "Open"
- submitter changed to: "chrstphrchvz"
- subsystem changed to: "60. NRE and coroutines"
- title changed to:
AddressSanitizer use-after-return detection breaks coroutines
- type changed to: "Patch"