Skip to content

Commit fa4f032

Browse files
authored
Fix crashing core.thread.fiber unittest for AArch64. (#4648)
1 parent b514c6b commit fa4f032

File tree

3 files changed

+15
-5
lines changed

3 files changed

+15
-5
lines changed

.cirrus.yml

-2
Original file line numberDiff line numberDiff line change
@@ -49,8 +49,6 @@ common_steps_template: &COMMON_STEPS_TEMPLATE
4949
cd $CIRRUS_WORKING_DIR/../build
5050
excludes="dmd-testsuite|ldc2-unittest|lit-tests"
5151
if [[ "$CI_OS-$CI_ARCH" == "linux-aarch64" ]]; then
52-
# FIXME: segfaults with enabled optimizations
53-
excludes+='|^core.thread.fiber(-shared)?$'
5452
# FIXME: failing unittest(s)
5553
excludes+='|^std.internal.math.gammafunction'
5654
# FIXME: failing unittest(s) with enabled optimizations

.github/workflows/supported_llvm_versions.yml

-2
Original file line numberDiff line numberDiff line change
@@ -182,8 +182,6 @@ jobs:
182182
if [[ '${{ matrix.os }}' == macos-14 ]]; then
183183
# FIXME: crashes frequently with enabled optimizations on M1 runners
184184
excludes+='|^std.internal.math.gammafunction(-shared)?$'
185-
# FIXME: sporadically segfaults with enabled optimizations
186-
excludes+='|^core.thread.fiber(-shared)?$'
187185
fi
188186
else
189187
N=$(nproc)

runtime/druntime/src/core/thread/fiber.d

+15-1
Original file line numberDiff line numberDiff line change
@@ -558,6 +558,8 @@ version (LDC)
558558

559559
version (Android) version = CheckFiberMigration;
560560

561+
version (AArch64) version = CheckFiberMigration;
562+
561563
// Fiber migration across threads is (probably) not possible with ASan fakestack enabled (different parts of the stack
562564
// will contain fakestack pointers that were created on different threads...)
563565
version (SupportSanitizers) version = CheckFiberMigration;
@@ -1132,6 +1134,16 @@ class Fiber
11321134
*/
11331135
static Fiber getThis() @safe nothrow @nogc
11341136
{
1137+
// LDC NOTE:
1138+
// Currently, it is not safe to migrate fibers across threads when they
1139+
// use TLS at all, as LLVM might cache the TLS address lookup across a
1140+
// context switch (see https://github.com/ldc-developers/ldc/issues/666).
1141+
// Preventing inlining of this function, as well as switch{In,Out}
1142+
// below, enables users to do this at least as long as they are very
1143+
// careful about accessing TLS data themselves (such as in the shared
1144+
// fiber unittest below, which tends to sporadically crash with enabled
1145+
// optimizations if this prevent-inlining workaround is removed).
1146+
version (LDC) pragma(inline, false);
11351147
return sm_this;
11361148
}
11371149

@@ -1951,6 +1963,7 @@ private:
19511963
//
19521964
final void switchIn() nothrow @nogc
19531965
{
1966+
// see note in getThis()
19541967
version (LDC) pragma(inline, false);
19551968

19561969
ThreadBase tobj = ThreadBase.getThis();
@@ -2044,6 +2057,7 @@ private:
20442057
//
20452058
final void switchOut() nothrow @nogc
20462059
{
2060+
// see note in getThis()
20472061
version (LDC) pragma(inline, false);
20482062

20492063
ThreadBase tobj = m_curThread;
@@ -2320,7 +2334,7 @@ unittest
23202334
fibs[idx].call();
23212335
cont |= fibs[idx].state != Fiber.State.TERM;
23222336
}
2323-
locks[idx] = false;
2337+
locks[idx].atomicStore(false);
23242338
}
23252339
else
23262340
{

0 commit comments

Comments
 (0)