Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

cmd/cgo: ${SRCDIR} does not handle paths with % #16959

Closed
aronatkins opened this issue Sep 1, 2016 · 6 comments
Closed

cmd/cgo: ${SRCDIR} does not handle paths with % #16959

aronatkins opened this issue Sep 1, 2016 · 6 comments
Labels
FrozenDueToAge NeedsFix The path to resolution is known, but the work has not been done.
Milestone

Comments

@aronatkins
Copy link

aronatkins commented Sep 1, 2016

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

go version go1.6.3 linux/amd64
Also tested with go version go1.6.3 linux/amd64

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

GOARCH="amd64"
GOBIN=""
GOEXE=""
GOHOSTARCH="amd64"
GOHOSTOS="linux"
GOOS="linux"
GOPATH=""
GORACE=""
GOROOT="/usr/local/go"
GOTOOLDIR="/usr/local/go/pkg/tool/linux_amd64"
GO15VENDOREXPERIMENT="1"
CC="gcc"
GOGCCFLAGS="-fPIC -m64 -pthread -fmessage-length=0"
CXX="g++"
CGO_ENABLED="1"

What did you do?

mkdir a%2fb
cd a%2fb
mkdir include

Save this Go program as a%2fb/silly.go:

package main

// #cgo CFLAGS: -I"${SRCDIR}/include"
import "C"

func main() {
}

What did you expect to see?

Expected successful compilation/execution of the program.

What did you see instead?

# go run silly.go
package main: /somewhere/a%2Fb/silly.go: malformed #cgo argument: -I/somewhere/a%2Fb/include

This happens for CFLAGS and LDFLAGS on multiple architectures.

Related to #7906, #16455, #11868, which all discuss spaces in paths; there are issues with other valid path characters as well.

This path was not something I created naturally; it was a side-effect of our CI environment (Jenkins) which occasionally uses paths like foo%2Fbar if a Git branch has a name "foo/bar". It also can create paths like foo%2Fbar@2 when a second scratch directory is needed.

@aronatkins
Copy link
Author

I am able to use bind mounts as a workaround. Something like:

mkdir /simplename
mount -o bind $PWD /simplename
cd /simplename
<go commands that previously failed...>

@quentinmit
Copy link
Contributor

Have you tried "-I${SRCDIR}/include" (that is, put quotes around the entire argument?)

@quentinmit quentinmit added this to the Go1.8Maybe milestone Sep 6, 2016
@aronatkins
Copy link
Author

Behavior is the same with full argument quoting.

@aronatkins
Copy link
Author

Note: I tried full argument quoting for CFLAGS with -I but did not re-test LDFLAGS.

@quentinmit quentinmit added the NeedsFix The path to resolution is known, but the work has not been done. label Oct 10, 2016
@rsc
Copy link
Contributor

rsc commented Oct 20, 2016

The list of allowed characters for $SRCDIR is src/go/build/build.go's safeString. % is not one of them.
I am a bit wary of adding % for fear that it will lead to environment variable interpolation on Windows,
but I guess we can try it.

@rsc rsc self-assigned this Oct 20, 2016
@gopherbot
Copy link

CL https://golang.org/cl/31611 mentions this issue.

@golang golang locked and limited conversation to collaborators Oct 24, 2017
@rsc rsc removed their assignment Jun 23, 2022
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
FrozenDueToAge NeedsFix The path to resolution is known, but the work has not been done.
Projects
None yet
Development

No branches or pull requests

4 participants