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
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
}
| Inspect html for hidden footers to help with email filtering. To unsubscribe visit settings. |