[go] cmd/internal/objabi: resolve relative paths in -trimpath flag

0 views
Skip to first unread message

Michael Podtserkovskii (Gerrit)

unread,
Jan 16, 2026, 5:00:32 PM (yesterday) Jan 16
to goph...@pubsubhelper.golang.org, golang-co...@googlegroups.com

Michael Podtserkovskii has uploaded the change for review

Commit message

cmd/internal/objabi: resolve relative paths in -trimpath flag

The -trimpath flag now resolves relative paths to absolute paths
before matching against source file paths. This makes -trimpath=.
work the same as -trimpath=$(pwd).

This is useful for build systems like Buck that generate build actions
independent from the host machine. Using relative paths in -trimpath
keeps build actions portable and produces reproducible artifacts
across different executor machines.

Fixes #77216
Change-Id: If798b2e07f63bb4c49d71b9046b1b45db86034ee

Change diff

diff --git a/src/cmd/internal/objabi/line.go b/src/cmd/internal/objabi/line.go
index 80a1137..e251b51 100644
--- a/src/cmd/internal/objabi/line.go
+++ b/src/cmd/internal/objabi/line.go
@@ -87,6 +87,14 @@
prefix, replace = rewrite[:j], rewrite[j+len("=>"):]
}

+ // Convert relative prefix to absolute path so that -trimpath=.
+ // works the same as -trimpath=$(pwd).
+ if prefix != "" && !filepath.IsAbs(prefix) {
+ if abs, err := filepath.Abs(prefix); err == nil {
+ prefix = abs
+ }
+ }
+
if prefix == "" || !hasPathPrefix(path, prefix) {
return path, false
}

Change information

Files:
  • M src/cmd/internal/objabi/line.go
Change size: XS
Delta: 1 file changed, 8 insertions(+), 0 deletions(-)
Open in Gerrit

Related details

Attention set is empty
Submit Requirements:
  • requirement is not satisfiedCode-Review
  • requirement satisfiedNo-Unresolved-Comments
  • requirement is not satisfiedReview-Enforcement
  • requirement is not satisfiedTryBots-Pass
Inspect html for hidden footers to help with email filtering. To unsubscribe visit settings. DiffyGerrit
Gerrit-MessageType: newchange
Gerrit-Project: go
Gerrit-Branch: master
Gerrit-Change-Id: If798b2e07f63bb4c49d71b9046b1b45db86034ee
Gerrit-Change-Number: 737140
Gerrit-PatchSet: 1
Gerrit-Owner: Michael Podtserkovskii <mich...@meta.com>
unsatisfied_requirement
satisfied_requirement
open
diffy
Reply all
Reply to author
Forward
0 new messages