Skip to content

cmd/compile, cmd/asm, cmd/cgo: -trimpath with relative paths has no effect #77216

Closed as not planned

Description

@podtserkovskiy

The flag -trimpath=. has no effect because relative paths are not resolved.
This forces build systems to generate commands with absolute paths in the -trimpath flag:

$ go tool compile -trimpath=$(pwd) foo/foo.go && go tool objdump foo.o
TEXT <unlinkable>.Foo(SB) foo/foo.go        # trimmed

$ go tool compile -trimpath=. foo/foo.go && go tool objdump foo.o
TEXT <unlinkable>.Foo(SB) /Users/user/project/foo/foo.go   # not trimmed

Why this matters

Build systems like Buck generate build actions that are independent from the host machine. Using -trimpath=$(pwd) embeds the absolute path into the build action, breaking reproducibility across different executor machines. With -trimpath=., build actions remain portable and produce identical artifacts regardless of where they run.

Currently, we work around this by using wrapper scripts for the compiler that resolve absolute paths on the build machine. This adds unnecessary latency and complexity.

Proposed fix

In cmd/internal/objabi/line.go, convert relative prefixes to absolute:

if prefix != "" && !filepath.IsAbs(prefix) {
    if abs, err := filepath.Abs(prefix); err == nil {
        prefix = abs
    }
}

Test plan

$ (cd $GO/src && ./make.bash)
$ $GO/bin/go tool compile -trimpath=. foo/foo.go && go tool objdump foo.o
TEXT <unlinkable>.Foo(SB) foo/foo.go        # trimmed

Activity

  1. gopherbot commented on Jan 16, 2026

    @gopherbot
    Contributor

    Change https://go.dev/cl/737140 mentions this issue: cmd/internal/objabi: resolve relative paths in -trimpath flag

  2. added
    NeedsInvestigationSomeone must examine and confirm this is a valid issue and not a duplicate of an existing one.
    on Jan 20, 2026
  3. prattmic commented on Jan 28, 2026

    @prattmic
    Member

    cc @golang/compiler @cherrymui

  4. podtserkovskiy commented on Mar 23, 2026

    @podtserkovskiy
    ContributorAuthor

    Hi folks, CL 737140 stalled in the review for a while. Would anyone be able to take another look when you have a moment?

  5. podtserkovskiy commented on Apr 21, 2026

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    NeedsInvestigationSomeone must examine and confirm this is a valid issue and not a duplicate of an existing one.compiler/runtimeIssues related to the Go compiler and/or runtime.

    Type

    No type

    Projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions