]> Cypherpunks repositories - gostls13.git/commitdiff
go/build: allow $ in cgo LDFLAGS
authorRuss Cox <rsc@golang.org>
Tue, 10 Sep 2013 16:47:43 +0000 (12:47 -0400)
committerRuss Cox <rsc@golang.org>
Tue, 10 Sep 2013 16:47:43 +0000 (12:47 -0400)
Fixes #6038.

R=iant
CC=golang-dev
https://golang.org/cl/13649043

src/cmd/go/test.bash
src/pkg/go/build/build.go

index 847a3e10a1c0d9d6816320b4ec27aca751b315ee..1a3adb89685af5afdab604ec2a638e03f39759bd 100755 (executable)
@@ -483,6 +483,25 @@ fi
 rm -rf $d
 unset GOPATH
 
+TEST 'cgo handles -Wl,$ORIGIN'
+d=$(TMPDIR=/var/tmp mktemp -d -t testgoXXX)
+export GOPATH=$d
+mkdir -p $d/src/origin
+echo '
+package origin
+// #cgo LDFLAGS: -Wl,-rpath -Wl,$ORIGIN
+// void f(void) {}
+import "C"
+
+func f() { C.f() }
+' >$d/src/origin/origin.go
+if ! ./testgo build origin; then
+       echo build failed
+       ok=false
+fi
+rm -rf $d
+unset GOPATH
+
 # clean up
 if $started; then stop; fi
 rm -rf testdata/bin testdata/bin1
index 043351a950ec452942d62895cb40a1b3275219e6..1b62c3da8984a478a5410aefb45bdd5a86902967 100644 (file)
@@ -920,7 +920,7 @@ func (ctxt *Context) saveCgo(filename string, di *Package, cg *ast.CommentGroup)
                        return fmt.Errorf("%s: invalid #cgo line: %s", filename, orig)
                }
                for _, arg := range args {
-                       if !safeName(arg) {
+                       if !safeCgoName(arg) {
                                return fmt.Errorf("%s: malformed #cgo argument: %s", filename, arg)
                        }
                }
@@ -943,9 +943,12 @@ func (ctxt *Context) saveCgo(filename string, di *Package, cg *ast.CommentGroup)
        return nil
 }
 
-var safeBytes = []byte("+-.,/0123456789=ABCDEFGHIJKLMNOPQRSTUVWXYZ_abcdefghijklmnopqrstuvwxyz:")
+// NOTE: $ is not safe for the shell, but it is allowed here because of linker options like -Wl,$ORIGIN.
+// We never pass these arguments to a shell (just to programs we construct argv for), so this should be okay.
+// See golang.org/issue/6038.
+var safeBytes = []byte("+-.,/0123456789=ABCDEFGHIJKLMNOPQRSTUVWXYZ_abcdefghijklmnopqrstuvwxyz:$")
 
-func safeName(s string) bool {
+func safeCgoName(s string) bool {
        if s == "" {
                return false
        }