January 01, 2024
https://issues.dlang.org/show_bug.cgi?id=24314

          Issue ID: 24314
           Summary: Linker flag `-L-dead_strip`strips `static this()` and
                    `static ~this()`
           Product: D
           Version: D2
          Hardware: x86_64
                OS: Mac OS X
            Status: NEW
          Severity: normal
          Priority: P1
         Component: dmd
          Assignee: nobody@puremagic.com
          Reporter: codedan@hotmail.com

// file: test.d
//
// Problem description:
//
//     When using the additional linker flag `-L-dead_strip`
//     on macOS, executables produced by DMD strip
//     static constructors + destructors.
//     The program runs fine, but static init is silently removed.
//
//     It does not happen with LDC - only with DMD on macOS (x64).
//
//     The online compiler at run.dlang.org does not have the issue.
//     The compiler option for the online compiler is: `-L-strip-all`
//
//
// [OK] output:
//
//     Hi!
//        Hello D
//     Bye!
//
// [FAIL] output (static constructor/destructor not running):
//
//        Hello D
//
// Results using DMD:
//
//    [OK]   dmd -run test.d
//    [OK]   dmd -release -run test.d
//    [OK]   dmd -debug   -run test.d
//
//    [FAIL] dmd -L-dead_strip -run test.d
//    [FAIL] dmd -L-dead_strip -release -run test.d
//    [FAIL] dmd -L-dead_strip -debug   -run test.d
//
// Results using LDC:
//
//    [OK]   ldc2 --run test.d
//    [OK]   ldc2 --release --run test.d
//    [OK]   ldc2 --d-debug --run test.d
//    [OK]   ldc2 --d       --run test.d
//
//    [OK]   ldc2 -L-dead_strip --run test.d
//    [OK]   ldc2 -L-dead_strip --release --run test.d
//    [OK]   ldc2 -L-dead_strip --d-debug --run test.d
//    [OK]   ldc2 -L-dead_strip --d       --run test.d
//
import std.stdio : writeln;

void main()    => writeln("   Hello D");
static this()  => writeln("Hi!");
static ~this() => writeln("Bye!");

--