Skip to content

build: fix C library DWARF defaults and runtime initialization#2125

Merged
xushiwei merged 3 commits into
xgo-dev:mainfrom
cpunion:codex/fix-c-library-dwarf-default
Jul 19, 2026
Merged

build: fix C library DWARF defaults and runtime initialization#2125
xushiwei merged 3 commits into
xgo-dev:mainfrom
cpunion:codex/fix-c-library-dwarf-default

Conversation

@cpunion

@cpunion cpunion commented Jul 19, 2026

Copy link
Copy Markdown
Collaborator

Problem

c-shared and c-archive failed when LLGo applied its default DWARF omission. After restoring the builds, C calls into the libraries could still crash in runtime.Callers because runtime TLS had not been initialized. #2083 exposed both failures by making the C build and execution tests gating.

Fix

  • support the same DWARF choices for c-shared and c-archive: LLGo default and explicit -w omit DWARF; explicit -w=false keeps it
  • initialize the LLGo runtime from an llvm.global_ctors library constructor before exported Go functions run
  • emit the constructor only when the library links the runtime

Coverage

  • link-option tests cover default, -w, and -w=false for both C library modes
  • macOS arm64 and Linux amd64 build, link, and run shared and static C consumers
  • C calls verify runtime.Callers, CallersFrames, and FuncForPC return function, file, and line information
  • explicit -w=false is checked with LLDB on macOS and llvm-dwarfdump on Linux, resolving captureCFuncInfo to export.go
  • go test ./internal/build: 73.4% package coverage; changed link-option and constructor paths: 100%
  • CI: 41 checks pass; the release publication job is skipped as expected

@codecov

codecov Bot commented Jul 19, 2026

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.

📢 Thoughts on this report? Let us know!

@cpunion cpunion changed the title build: keep default C library builds usable build: fix C library DWARF defaults and runtime initialization Jul 19, 2026
@xushiwei
xushiwei merged commit 3b00364 into xgo-dev:main Jul 19, 2026
42 checks passed
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.

2 participants