mirror of https://github.com/golang/go.git
go/build: allow $ in cgo LDFLAGS
Fixes #6038. R=iant CC=golang-dev https://golang.org/cl/13649043
This commit is contained in:
parent
358ae20777
commit
c971f95c10
|
|
@ -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
|
||||
|
|
|
|||
|
|
@ -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
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in New Issue