Skip to content

Windows link: CodeView instead of DWARF in COFF objects (#1147); one CRT decision read from the link plan (#1267) - #1329

Merged
ehartford merged 2 commits into
mainfrom
windows-link-crt-and-debug-sections
Sep 22, 2026
Merged

ehartford merged 2 commits into
mainfrom
windows-link-crt-and-debug-sections

Conversation

@ehartford

Copy link
Copy Markdown
Contributor

Two Windows link-path defects, each root-caused and verified on the Windows 10 x64 box (C:\with-ci\with, LLVM SDK 22.1.6, MSVC 14.51, Kit 10.0.26100, seed v0.15.2.1). One commit per fix.

#1147 — nine lld-link: warning: section name .debug_* is longer than 8 characters

Cause. src/Codegen.w debug_init_module set the module flag "Dwarf Version" = 5 for every target and never "CodeView". AsmPrinter::doInitialization (llvm/lib/CodeGen/AsmPrinter/AsmPrinter.cpp:593-604) creates a DwarfDebug handler whenever the CodeView flag is absent or a Dwarf version is set, so every COFF object we emit — user objects and the embedded runtime objects alike — carried DWARF .debug_abbrev/.debug_addr/.debug_info/.debug_line/.debug_line_str/.debug_names/.debug_rnglists/.debug_str/.debug_str_offsets. Link.w links with /debug (= /debug:full), which sets includeDwarfChunks (lld/COFF/Driver.cpp:1783-1786), so those chunks land in the image as discardable long-named output sections and Writer::createSymbolAndStringTable (lld/COFF/Writer.cpp:1589) warns once per section. The PDB lld builds is made from CodeView, so the DWARF was dead weight in every Windows binary; the runtime's backtraces use dbghelp SymFromAddr, which reads the PDB.

Fix. A Windows target sets "CodeView" = 1 and no Dwarf version; every other target keeps DWARF 5. CodeView covers every DI type Codegen emits (lowerType handles DW_TAG_unspecified_type, basic, pointer, struct, member, subroutine).

Box before (seed and stage1, -e 'print("x")'):

lld-link: warning: section name .debug_abbrev is longer than 8 characters and will use a non-standard string table
... (.debug_addr .debug_info .debug_line .debug_line_str .debug_names .debug_rnglists .debug_str .debug_str_offsets)
x

Seed-built out/bootstrap-lib/rt_core.o sections: .text .data .bss .xdata .rdata… .debug$S .debug_abbrev .debug_info .debug_rnglists .debug_str_offsets .debug_str .debug_addr .debug_names .pdata .debug_line .debug_line_str

Box after (branch src\main.exe build → out/release/bin/with.exe, whose embedded runtime objects are stage2-built):

== release -e (after)
x
rc=0
== release hello (after)
rc=0
x
run rc=0
 Name: .text  Name: .rdata  Name: .data  Name: .pdata  Name: .reloc
-rw-r--r-- 1 SYSTEM 18 843776 Sep 22 07:54 /c/with-ci/tmp/hm.exe.pdb

Stage2-compiled rt/rt_core.w object sections: .text .data .bss .xdata .rdata… .debug$S .debug$T .pdata; a stage2-compiled user object: .text .data .bss .rdata .debug$S .debug$T. Panic location still resolves (panic at C:/with-ci/tmp/bt.w:1:12: bt). Stage1 on the branch still shows the nine warnings because its embedded runtime objects are seed-built; they go away with the stage2/release compiler and with the next reseed. Darwin stage1 from this branch still emits __debug_* (checked with objdump on a hello object).

#1267 — duplicate symbol: _invalid_parameter_noinfo / _wctype (libucrt.lib vs ucrt.lib)

Cause. The CRT was chosen in two places. build/compiler.w wrote libcpmt.lib + libcmt.lib into out/*/llvm_ld.rsp (lines 1889-1890) and set WITH_WINDOWS_CRT_STATIC=1 for its own child (line 509); src/compiler/Link.w link_stage_make_windows_llvm_link_command (line 667) added msvcprt msvcrt ucrt vcruntime whenever that variable was unset. The SDK archives are built MultiThreaded (static UCRT) and carry /DEFAULTLIB:libucrt directives, so with-stage1.exe build out/gen/main.w — the compiler as a program, the selfhost-windows failure probe — linked libucrt.lib (via the rsp's libcmt and the archives) and ucrt.lib (from Link.w) together.

Fix. link_stage_windows_crt_static(extras) in Link.w is the one decision, read from the link plan: a link carrying the LLVM static bridge response file (@…/llvm_ld.rsp) is a static-CRT link; an ordinary program keeps the DLL runtime that prebuilt Windows libraries expect; WITH_WINDOWS_CRT_STATIC=1 still forces static. The native rsp no longer carries a CRT (the cross rsps never did). build/compiler.w keeps setting the env override because the pinned seed's Link.w reads only the environment.

Box before (out/bootstrap/bin/with-stage1.exe build out/gen/main.w -O1 -o out/probe-before.exe):

lld-link: error: duplicate symbol: _invalid_parameter_noinfo
>>> defined at minkernel\crts\ucrt\src\appcrt\misc\invalid_parameter.cpp:129
>>>            libucrt.lib(invalid_parameter.obj)
>>> defined at ucrt.lib(api-ms-win-crt-runtime-l1-1-0.dll)
lld-link: error: duplicate symbol: _wctype
>>> defined at libucrt.lib(ctype.obj)
>>> defined at ucrt.lib(api-ms-win-crt-string-l1-1-0.dll)
error: build failed
rc=1

Box after (branch stage1, same command):

rc=0
-rwxr-xr-x 1 SYSTEM 18 97360384 Sep 22 04:12 out/probe-after.exe
probe-ok
probe run rc=0

and with the release compiler the same probe links with rc=0 and no warnings at all. (Running that release-built probe then reports embedded bundle 'pcre2' was built for ABI … but this compiler is WITHABISHASTAMPv1XXXX…: the probe is the unstamped image — build.w's link-compiler stamps .unstamped after the link — which is outside both issues and pre-exists them.)

Verification

  • Local: with check src/main.w ok; WITH=$PWD/src/main src/main build :dev green (stage1 160 s).
  • Box: src\main.exe build :dev green, :stage2 green, full build green (release compiler linked and running).
  • Tests: the harness matches a program's run stdout/stderr, so neither "the linker was quiet" nor "which CRT was linked" is expressible as a test/ marker; the box run above is the evidence. Battery not run (per instructions).

Eric Hartford added 2 commits September 22, 2026 13:35
AsmPrinter emits DWARF whenever the module has no "CodeView" flag or sets
"Dwarf Version"; Codegen.w set "Dwarf Version" 5 for every target, so a
COFF object carried nine .debug_* sections that lld-link's /debug never
read (the PDB is built from CodeView) and warned about on every link:
"section name .debug_info is longer than 8 characters and will use a
non-standard string table" (lld/COFF/Writer.cpp createSymbolAndStringTable,
for each discardable long-named output section). A Windows target now sets
the CodeView flag instead, so the PDB holds the debug info the runtime's
dbghelp backtraces read; every other target keeps DWARF 5.
The LLVM/Clang SDK archives are built MultiThreaded (static UCRT). Their
CRT was chosen in two places: build/compiler.w wrote libcpmt/libcmt into
llvm_ld.rsp and set WITH_WINDOWS_CRT_STATIC=1 for its child, while Link.w
chose the DLL runtime (msvcrt + ucrt + vcruntime) whenever that variable
was unset. The compiler built as a program (with-stage1.exe build
out/gen/main.w, the selfhost-windows failure probe) therefore linked
libucrt.lib and ucrt.lib together: duplicate _invalid_parameter_noinfo and
_wctype.

link_stage_windows_crt_static is now the one place that decides, from the
link's inputs: a link carrying the LLVM static bridge response file
(@…/llvm_ld.rsp) is a static-CRT link; an ordinary program keeps the DLL
runtime; WITH_WINDOWS_CRT_STATIC=1 still forces the static one. The rsp
carries no CRT any more (the cross rsps never did); the environment
override stays set by build/compiler.w for a pinned seed whose Link.w
reads only the environment.
@ehartford

Copy link
Copy Markdown
Contributor Author

Battery (seed-driven, rebased on main 980474c): build, :fixpoint rc=0; :test red only in main's own known reds — behav_distinct_compat (#1319 gap, fix forward in progress), da_match_place_observes (#1322), fizzbuzz (#1325). None in this change's paths. Mergeable on its own.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant