Issue 22374 - [REG 2.093] 'import std;' with -checkaction=context causes link error
Summary: [REG 2.093] 'import std;' with -checkaction=context causes link error
Status: NEW
Alias: None
Product: D
Classification: Unclassified
Component: dmd (show other issues)
Version: D2
Hardware: All All
: P1 regression
Assignee: No Owner
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2021-10-10 03:21 UTC by Paul Backus
Modified: 2024-09-30 10:45 UTC (History)
3 users (show)

See Also:


Attachments

Note You need to log in before you can comment on or make changes to this issue.
Description Paul Backus 2021-10-10 03:21:03 UTC
As of DMD 2.097.2, compiling the following program with the flag `-checkaction=context` results in a linker error.

---
import std;

void main()
{
    assert(0);
}
---

The error is:

---
/usr/bin/ld: bug.o: in function `_Dmain':
bug.d:(.text._Dmain[_Dmain]+0x33): undefined reference to `_D4core8internal7dassert__T14_d_assert_failTiZQtFNaNbNiNfMxAyaxiZAya'
collect2: error: ld returned 1 exit status
Error: linker exited with status 1
---

Demangled:

---
/usr/bin/ld: bug.o: in function `_Dmain':
bug.d:(.text._Dmain[_Dmain]+0x33): undefined reference to `pure nothrow @nogc @safe immutable(char)[] core.internal.dassert._d_assert_fail!(int)._d_assert_fail(scope const(immutable(char)[]), const(int))'
collect2: error: ld returned 1 exit status
Error: linker exited with status 1
---

Removing the line `import std;`, or changing it to import a different module such as `std.range`, causes the program to compile and link successfully.

According to run.dlang.io, this is a regression introduced in DMD 2.093.
Comment 1 Andrej Mitrovic 2022-09-08 15:18:48 UTC
Just ran into this one. So sad it's been broken for a year.

I don't recall what was the reason this option is enabled via the -checkaction=context switch? Is it to avoid additional memory allocations?
Comment 2 elpenguino+D 2022-12-19 23:03:13 UTC
I've just encountered this as well. Still fails on DMD 2.101.1 with the same missing symbol, but when combined with -allinst, it fails in a subtly different way: 
```
/dlang/dmd/linux/bin64/../../src/phobos/std/variant.d:941: error: undefined reference to '_D4core8internal7dassert__T14_d_assert_failTbZQtFNaNbNiNfMxAyaxbZAya'
```

This one is a `pure nothrow @nogc @safe immutable(char)[] core.internal.dassert._d_assert_fail!(bool)._d_assert_fail(scope const(immutable(char)[]), const(bool))`
Comment 3 kdevel 2024-09-30 10:41:44 UTC
(In reply to Paul Backus from comment #0)
> As of DMD 2.097.2, compiling the following program with the flag
> `-checkaction=context` results in a linker error.
> 
> ---
> import std;
> 
> void main()
> {
>     assert(0);
> }
> ---
> 

WORKSFORME 

$ dmd --version
DMD64 D Compiler v2.109.1
Copyright (C) 1999-2024 by The D Language Foundation, All Rights Reserved written by Walter Bright
$ cat asszer.d 
import std;

void main()
{
    assert(0);
}
$ dmd asszer.d
$ ./asszer
core.exception.AssertError@asszer.d(5): Assertion failure
----------------
??:? _d_assertp [0x4bbf14]
??:? _Dmain [0x4b30e0]
Comment 4 kdevel 2024-09-30 10:45:07 UTC
Correction: WORKSFORME

$ dmd -checkaction=context asszer.d
$ ./asszer 
core.exception.AssertError@asszer.d(5): Assertion failure
----------------
??:? _d_assertp [0x4bbf14]
??:? _Dmain [0x4b30e0]