Skip to content

cmd/go: -trimpath option fails if it contains whitespace #33223

Closed
@djdv

Description

@djdv

What version of Go are you using (go version)?

$ go version
go version go1.12.7 windows/amd64

Does this issue reproduce with the latest release?

Yes

What operating system and processor architecture are you using (go env)?

go env Output
$ go env
set GOARCH=amd64
set GOBIN=
set GOCACHE=C:\Users\Dominic Della Valle\AppData\Local\go-build
set GOEXE=.exe
set GOFLAGS=
set GOHOSTARCH=amd64
set GOHOSTOS=windows
set GOOS=windows
set GOPATH=C:\Users\Dominic Della Valle\Projects\Go
set GOPROXY=
set GORACE=
set GOROOT=c:\go
set GOTMPDIR=
set GOTOOLDIR=c:\go\pkg\tool\windows_amd64
set GCCGO=gccgo
set CC=gcc
set CXX=g++
set CGO_ENABLED=1
set GOMOD=
set CGO_CFLAGS=-g -O2
set CGO_CPPFLAGS=
set CGO_CXXFLAGS=-g -O2
set CGO_FFLAGS=-g -O2
set CGO_LDFLAGS=-g -O2
set PKG_CONFIG=pkg-config
set GOGCCFLAGS=-m64 -mthreads -fmessage-length=0 -fdebug-prefix-map=C:\Users\DOMINI~1\AppData\Local\Temp\go-build550192770=/tmp/go-build -gno-record-gcc-switches

What did you do?

Tried stripping path prefix during build with a path containing whitespace on Windows.
C:\Users\Dominic Della Valle\Projects\Go\src\local\hello>go build -asmflags=all=-trimpath="C:\Users\Dominic Della Valle\Projects\Go\src\local\hello" -gcflags=all=-trimpath="C:\Users\Dominic Della Valle\Projects\Go\src\local\hello"

What did you expect to see?

Successful build.

What did you see instead?

C:\Users\Dominic Della Valle\Projects\Go\src\local\hello>go build -asmflags=all=-trimpath="C:\Users\Dominic Della Valle\Projects\Go\src\local\hello" -gcflags=all=-trimpath="C:\Users\Dominic Della Valle\Projects\Go\src\local\hello"
# unicode/utf8
Della:0: open Della: The system cannot find the file specified.
# runtime/internal/sys
Della:0: open Della: The system cannot find the file specified.
# internal/race
Della:0: open Della: The system cannot find the file specified.
# errors
Della:0: open Della: The system cannot find the file specified.
# unicode/utf16
Della:0: open Della: The system cannot find the file specified.
# unicode
Della:0: open Della: The system cannot find the file specified.
# internal/syscall/windows/sysdll
Della:0: open Della: The system cannot find the file specified.
# math/bits
Della:0: open Della: The system cannot find the file specified.
# sync/atomic
usage: asm [options] file.s ...
Flags:
  -D value
        predefined symbol with optional simple value -D=identifier=value; can be set multiple times
  -I value
        include directory; can be set multiple times
  -S    print assembly and machine code
  -V    print version and exit
  -debug
        dump instructions as they are parsed
  -dynlink
        support references to Go symbols defined in other shared libraries
  -e    no limit on number of errors reported
  -gensymabis
        write symbol ABI information to output file, don't assemble
  -o string
        output file; default foo.o for /a/b/c/foo.s as first argument
  -shared
        generate code that can be linked into a shared library
  -trimpath string
        remove prefix from recorded source file paths
# internal/cpu
usage: asm [options] file.s ...
Flags:
  -D value
        predefined symbol with optional simple value -D=identifier=value; can be set multiple times
  -I value
        include directory; can be set multiple times
  -S    print assembly and machine code
  -V    print version and exit
  -debug
        dump instructions as they are parsed
  -dynlink
        support references to Go symbols defined in other shared libraries
  -e    no limit on number of errors reported
  -gensymabis
        write symbol ABI information to output file, don't assemble
  -o string
        output file; default foo.o for /a/b/c/foo.s as first argument
  -shared
        generate code that can be linked into a shared library
  -trimpath string
        remove prefix from recorded source file paths
# runtime/internal/atomic
usage: asm [options] file.s ...
Flags:
  -D value
        predefined symbol with optional simple value -D=identifier=value; can be set multiple times
  -I value
        include directory; can be set multiple times
  -S    print assembly and machine code
  -V    print version and exit
  -debug
        dump instructions as they are parsed
  -dynlink
        support references to Go symbols defined in other shared libraries
  -e    no limit on number of errors reported
  -gensymabis
        write symbol ABI information to output file, don't assemble
  -o string
        output file; default foo.o for /a/b/c/foo.s as first argument
  -shared
        generate code that can be linked into a shared library
  -trimpath string
        remove prefix from recorded source file paths

Moving the package to a path that doesn't contain whitespace, and changing the trimpath argument to match, results in a successful build with stripped paths.

It seems like it's trying to pass the words after the space, as arguments to the assembler/compiler.

contents of hello/main.go is just hello world:

package main

import "fmt"

func main() {
	fmt.Println("Hello")
}

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions