Skip to content

cmd/internal/obj: -trimpath help text is misleading #13616

@binarycrusader

Description

@binarycrusader

Tested with Go 1.5.2.

The -trimpath option is documented as follows:

$ go tool asm -help 2>&1|grep -A1 trimpath
  -trimpath string
        remove prefix from recorded source file paths
...
$ go tool compile -help|grep -A1 trimpath
  -trimpath prefix
        remove prefix from recorded source file paths

However, it would appear that it mistakenly removes the leading '/' from the resulting path:

$ export PROTO_DIR=/builds/go-proto-area
$ cd $(PROTO_DIR)/usr/lib/gocode/1.5/src/golang.org/x/crypto/blowfish
$ go install -asmflags -trimpath=$PROTO_DIR -gcflags -trimpath=$PROTO_DIR
$ strings ../../../../../pkg/solaris_amd64/golang.org/x/crypto/blowfish.a | grep 'lib\/'
xusr/lib/gocode/1.5/src/golang.org/x/crypto/blowfish/block.go
xusr/lib/gocode/1.5/src/golang.org/x/crypto/blowfish/block.go
...

If I add a terminating slash, then it fails to trim entirely:

$ export PROTO_DIR=/builds/go-proto-area/
$ cd $(PROTO_DIR)/usr/lib/gocode/1.5/src/golang.org/x/crypto/blowfish
$ go install -asmflags -trimpath=$PROTO_DIR -gcflags -trimpath=$PROTO_DIR
$ strings ../../../../../pkg/solaris_amd64/golang.org/x/crypto/blowfish.a | grep 'lib\/'
/builds/go-proto-area/usr/lib/gocode/1.5/src/golang.org/x/crypto/blowfish/block.go
/builds/go-proto-area/usr/lib/gocode/1.5/src/golang.org/x/crypto/blowfish/block.go
...

This appears to be due to a off-by-one error (or bad assumption) made in src/cmd/internal/obj/obj.go in setFile():

        // Remove leading TrimPathPrefix, or else rewrite $GOROOT to $GOROOT_FINAL.
        if h.TrimPathPrefix != "" && hasPathPrefix(abs, h.TrimPathPrefix) {
                if abs == h.TrimPathPrefix {
                        abs = ""
                } else {
                        abs = abs[len(h.TrimPathPrefix)+1:]
                }

Metadata

Metadata

Assignees

No one assigned

    Labels

    DocumentationIssues describing a change to documentation.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

    No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions