June 20, 2023
https://issues.dlang.org/show_bug.cgi?id=24002

          Issue ID: 24002
           Summary: "The CodeView record is corrupted" heisenbug
           Product: D
           Version: D2
          Hardware: x86_64
                OS: Windows
            Status: NEW
          Keywords: DebugInfo, link-failure
          Severity: blocker
          Priority: P1
         Component: dmd
          Assignee: nobody@puremagic.com
          Reporter: dlang-bugzilla@thecybershadow.net

Created attachment 1882
  --> https://issues.dlang.org/attachment.cgi?id=1882&action=edit
Reproducer

Given certain inputs, dmd will produce output that lld-link refuses to consume, failing with the message:

lld-link: error: codeview::mergeTypeAndIdRecords failed: The CodeView record is corrupted.

Unfortunately it is difficult to reduce the exact inputs which trigger this bug. It seems to be related to the size of the program being compiled, and maybe things like exact alignment. It may be a buffer overflow that causes the output to be corrupted only under certain conditions.

I am attaching an input which reliably reproduces the problem with DMD 2.101.0 for Windows, as obtainable from https://downloads.dlang.org/releases/2.x/2.101.0/dmd.2.101.0.windows.7z.  Other versions of D may or may not reproduce the bug, as I'm sure that changes in Phobos/Druntime affect the outcome as well.

To reproduce, edit reproduce.cmd to point it to the path to where your copy of the 2.101.0 dmd.exe is located, and run it. You should get a bunch of deprecation warnings followed by the link error above.

--