|
2026-11-15
| ||
| 01:26 | • Ticket [7d47ba7d94] Stack overruns in regexp code status still Open with 3 o... artifact: 7eb572b882 user: chrstphrchvz | |
|
2025-05-20
| ||
| 18:39 | • Ticket [7371b6270b] AddressSanitizer use-after-return detection breaks NRE tests... artifact: 3c4e04d5c6 user: dgp | |
|
2025-05-16
| ||
| 21:20 | • Ticket [7371b6270b]: 5 changes artifact: 5782fc3d90 user: chrstphrchvz | |
| 18:10 | • Ticket [7371b6270b]: 5 changes artifact: a16d601953 user: dgp | |
|
2024-08-22
| ||
| 18:36 | Merge [4cfbfb312127679e]: Fix [7371b6270b]: AddressSanitizer use-after-return detection breaks. NRE ... check-in: 3e342ec2e5 user: pooryorick tags: unchained, INCOMPATIBLE_LICENSE | |
|
2023-10-22
| ||
| 16:24 | • Closed ticket [7371b6270b]: AddressSanitizer use-after-return detection breaks N... artifact: 8f9e067ff1 user: chrstphrchvz | |
|
2023-10-11
| ||
| 10:59 | • Ticket [7371b6270b]: 3 changes artifact: 690a5b076e user: chrstphrchvz | |
| 10:47 | • Ticket [7371b6270b]: 3 changes artifact: e3ec4f07fe user: chrstphrchvz | |
|
2023-10-05
| ||
| 08:14 | • Ticket [7371b6270b]: 3 changes artifact: c220c84bdb user: chrstphrchvz | |
|
2023-10-04
| ||
| 14:45 | Fix [7371b6270b]: AddressSanitizer use-after-return detection breaks NRE tests, coroutines check-in: 910b623484 user: jan.nijtmans tags: core-8-6-branch | |
|
2023-10-01
| ||
| 19:06 | Fix [7371b6270b]: AddressSanitizer use-after-return detection breaks NRE tests, coroutines. (patch b... closed check-in: 170afda2c2 user: jan.nijtmans tags: bug-7371b6270b | |
|
2023-09-30
| ||
| 08:37 | • Ticket [7371b6270b] AddressSanitizer use-after-return detection breaks NRE tests... artifact: fe0f180691 user: chrstphrchvz | |
| 08:36 | • Add attachment 7371b6270b.diff to ticket [7371b6270b] artifact: a1b7bf7d0e user: chrstphrchvz | |
|
2023-08-04
| ||
| 15:30 | • Ticket [7371b6270b] AddressSanitizer use-after-return detection breaks NRE tests... artifact: b2fa6943f6 user: chrstphrchvz | |
| 04:44 | • Add attachment 7371b6270b.diff to ticket [7371b6270b] artifact: 7e5c5c83e8 user: chrstphrchvz | |
| 04:36 | • New ticket [7371b6270b] AddressSanitizer use-after-return detection breaks corou... artifact: 79be50c9e9 user: chrstphrchvz | |
AddressSanitizer use-after-return detection breaks NRE tests, coroutines
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 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 __builtin_frame_address(0); and for MSVC, there is _AddressOfReturnAddress(). 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.
7eb572b882Ticket [7d47ba7d94] Stack overruns in regexp code status still Open with 3 other changes ticket2026-11-15 01:26:033e342ec2e5Merge [4cfbfb312127679e]: Fix [7371b6270b]: AddressSanitizer use-after-return detection breaks. NRE tests, coroutines; check-in2024-08-22 18:36:12910b623484Fix [7371b6270b]: AddressSanitizer use-after-return detection breaks NRE tests, coroutines check-in2023-10-04 14:45:41170afda2c2Fix [7371b6270b]: AddressSanitizer use-after-return detection breaks NRE tests, coroutines. (patch by chrstphrchvz, with some minor modifications) check-in2023-10-01 19:06:33
I now notice the same issue affecting NRE test functions. I will look into patching those as well.
See revised attached patch. It seems that factoring out code for use in both tclBasic.c and tclTest.c requires reserving a stub in tclInt.decls.
I notice the CI failure for GCC on Windows. It attempted to use _AddressOfReturnAddress() which is MSVC-specific, but the condition is HAVE_INTRIN_H even though intrin.h is not MSVC-specific. I am thinking that the condition for _AddressOfReturnAddress() should depend on defined(_MSC_VER) (whether or not in addition to HAVE_INTRIN_H); and/or the GCC/Clang __builtin_frame_address(0) case should go first (as done by LLVM).
Note to self regarding #if __GNUC__ being changed to #if defined(__GNUC__) in [df7a3fd9e118]: although the former is what the LLVM example used, and would seem more robust in case of someone/something else defining __GNUC__ to 0, the latter is more consistent with the rest of core Tcl.
…in other words, I consider the change to be justified.
I am not aware of anything else to do for this ticket; closing. Thanks for committing and revising this, Jan!
This patch was merged to the 8.6 branch in checkin [910b623484]. When I attempt a build of that checkin on a Macbook Pro, M1 model from 2021, running Sonoma 14.7.5, and the "gcc" compiler is clang-1600.0.26.6, I see crashes in the test suite in test files coroutine.test nre.test This is with a build under the tcl/unix build system. I have to guess that the compiler intrinsics added by this patch need some platform variation to fix the problem. The crashes seem to persist in all checkins of the 86 branch since then.
I do not know if I will return to help with this anytime soon.
clang-1600.0.26.6 is Xcode/command line tools 16.2, released late 2024--much more recent than what I had access to when testing this patch. Maybe try adding #error to see which approach is getting compiled instead.
It looks like the tcl/unix builds make it far too easy for a `make test` to test the installed library that is still buggy instead of testing the built library in the workspace which includes the fix. I think this was a false alarm.
Attachments:
- 7371b6270b.diff [download] added by chrstphrchvz on 2023-09-30 08:36:43. [details]