Thread overview
Code compiles and run fine with LDC but segfault with DMD
Aug 29, 2022
ryuukk_
Aug 29, 2022
ryuukk_
Aug 30, 2022
zjh
Aug 30, 2022
wjoe
Aug 30, 2022
ryuukk_
Aug 30, 2022
ryuukk_
August 29, 2022

The following code compiles and run fine with LDC, but with DMD it compiles and then default at runtime

-- app.d
enum Test {A, B, C}

Test test = Test.A;

extern(C) void main()
{
    switch(test)
    {
        default:
        break;
    }
}

-- object.d
// empty for now

dmd -m64 app.d && ./app.exe compiles, running it segfault ⛔

ldc2 -m64 app.d && ./app.exe compiles, running it works ✅

Now the interesting part

dmd -g -m64 app.d && ./app.exe compiles, running it works! ✅

What -g does that makes this code compile and work with DMD?

August 29, 2022

I forgot to add: this is on Windows, the problem doesn't exist with linux

I reported a bug here: https://issues.dlang.org/show_bug.cgi?id=23310

August 30, 2022

On Monday, 29 August 2022 at 21:46:48 UTC, ryuukk_ wrote:

>

What -g does that makes this code compile and work with DMD?

I guess it's global sharing. not tls.

August 30, 2022
On Monday, 29 August 2022 at 21:46:48 UTC, ryuukk_ wrote:
> What `-g` does that makes this code compile and work with DMD?

This flag adds symbolic debug info. But I'm confident you knew that already.
August 30, 2022
On Tuesday, 30 August 2022 at 11:24:21 UTC, wjoe wrote:
> On Monday, 29 August 2022 at 21:46:48 UTC, ryuukk_ wrote:
>> What `-g` does that makes this code compile and work with DMD?
>
> This flag adds symbolic debug info. But I'm confident you knew that already.

You didn't understand the question


August 30, 2022

Problem fixed, i had to copy bunch of other code from druntime

Here is a working object.d: https://gist.github.com/ryuukk/53c133f29da5a8326c359a6bb1063207