mirror of
https://github.com/golang/go
synced 2024-11-18 16:34:51 -07:00
8bbd80063b
If the user provided a key but no value via -ldflag -X, another linker flag was used as the value. Placing the user's flags at the end avoids this problem. It also provides the user the opportunity to override existing linker flags. Fixes #8810. Change-Id: I96f4190713dc9a9c29142e56658446fba7fb6bc8 Reviewed-on: https://go-review.googlesource.com/2242 Reviewed-by: Minux Ma <minux@golang.org>
43 lines
885 B
Go
43 lines
885 B
Go
// +build !nacl
|
|
// run
|
|
|
|
// Copyright 2014 The Go Authors. All rights reserved.
|
|
// Use of this source code is governed by a BSD-style
|
|
// license that can be found in the LICENSE file.
|
|
|
|
// Run the linkx test.
|
|
|
|
package main
|
|
|
|
import (
|
|
"fmt"
|
|
"os"
|
|
"os/exec"
|
|
)
|
|
|
|
func main() {
|
|
// Successful run
|
|
cmd := exec.Command("go", "run", "-ldflags=-X main.tbd hello -X main.overwrite trumped -X main.nosuchsymbol neverseen", "linkx.go")
|
|
out, err := cmd.CombinedOutput()
|
|
if err != nil {
|
|
fmt.Println(string(out))
|
|
fmt.Println(err)
|
|
os.Exit(1)
|
|
}
|
|
|
|
want := "hello\ntrumped\n"
|
|
got := string(out)
|
|
if got != want {
|
|
fmt.Printf("got %q want %q\n", got, want)
|
|
os.Exit(1)
|
|
}
|
|
|
|
// Issue 8810
|
|
cmd = exec.Command("go", "run", "-ldflags=-X main.tbd", "linkx.go")
|
|
_, err = cmd.CombinedOutput()
|
|
if err == nil {
|
|
fmt.Println("-X linker flag should not accept keys without values")
|
|
os.Exit(1)
|
|
}
|
|
}
|