Skip to content

Allow runtime cgo implicit dependency - #1037

Merged
mvdan merged 2 commits into
burrowers:masterfrom
feicong:master
Aug 23, 2026
Merged

Allow runtime cgo implicit dependency#1037
mvdan merged 2 commits into
burrowers:masterfrom
feicong:master

Conversation

@feicong

@feicong feicong commented May 4, 2026

Copy link
Copy Markdown

No description provided.

@mvdan mvdan left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What bug is this fixing? And we need a test.

@feicong

feicong commented May 5, 2026

Copy link
Copy Markdown
Author

This patch is needed because cgo builds implicitly depend on runtime/cgo, but listPackage only treated runtime as an always-
allowed implicit dependency. When building the code with CGO_ENABLED=1, Garble fails with:

list runtime/cgo: not a dependency
exit status 1

Allowing runtime/cgo here matches the toolchain’s implicit cgo dependency behavior and fixes the failure.

@mvdan

mvdan commented May 5, 2026

Copy link
Copy Markdown
Member

Thanks. Do you have a reproducer? See the bug template when you file an issue. It doesn't make any sense to merge a fix without some sort of regression test.

@mvdan mvdan added the needs info Requires extra information to be solved label May 9, 2026
@mvdan

mvdan commented May 31, 2026

Copy link
Copy Markdown
Member

Closing this for now.

@mvdan mvdan closed this May 31, 2026
@tomac

tomac commented Jul 7, 2026

Copy link
Copy Markdown

Environment

  • garble version: v0.16.0
  • go version: go1.26.4 linux/amd64

Files

go.mod
module repro

go 1.26

main.go

package main

func main() { println("hello") }

Steps

fails

CGO_ENABLED=1 garble build -buildmode=pie
-ldflags '-linkmode external -extldflags "-static-pie"' -o /tmp/a .

succeeds — identical flags, plain toolchain (control)

CGO_ENABLED=1 go build -buildmode=pie
-ldflags '-linkmode external -extldflags "-static-pie"' -o /tmp/b .

Expected: garble builds the binary, like go build does.

Actual:

repro

list runtime/cgo: not a dependency
exit status 1

@mvdan mvdan reopened this Jul 7, 2026
@mvdan mvdan self-assigned this Jul 7, 2026
@tomac

tomac commented Jul 8, 2026

Copy link
Copy Markdown

Thanks @mvdan ! Do you need any further information to reproduce the error? Thanks!

@mvdan

mvdan commented Aug 23, 2026

Copy link
Copy Markdown
Member

Thanks @tomac for the pointer. I'll push a new version of this PR which adds a regression test and a more general fix.

mvdan added 2 commits August 23, 2026 18:38
The go command adds packages to a main package's dependencies on behalf of
the linker without them appearing in its imports, and garble rejects them:

	# repro
	list runtime/cgo: not a dependency
	exit status 1

That happens with CGO_ENABLED=1 and -linkmode=external, which links in
runtime/cgo even for a package which does not use cgo at all. GOARCH=arm
is broken in the same way for any main package which does not otherwise
depend on math.
The go command adds a handful of packages to a main package's dependencies
on behalf of the linker, such as runtime/cgo when linking externally or
math on 32-bit arm for soft floating point. They end up in the importcfg,
but not in the package's imports, which is how we rebuild the set of
dependencies, so we rejected them:

	# repro
	list runtime/cgo: not a dependency
	exit status 1

Allow all of cmd/go's linker dependencies, along with their own dependencies,
since runtime/cgo imports packages such as sync which runtime does not.

Thanks to feicong for an initial fix in burrowers#1037 and David Barroso for the
reproducer.
@mvdan mvdan removed the needs info Requires extra information to be solved label Aug 23, 2026
@mvdan
mvdan requested a review from luantak August 23, 2026 17:56
@mvdan mvdan removed their assignment Aug 23, 2026
@mvdan
mvdan merged commit 027bc65 into burrowers:master Aug 23, 2026
6 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Development

Successfully merging this pull request may close these issues.

3 participants