obj.Flagint64("T", "set text segment `address`", &INITTEXT)
obj.Flagfn0("V", "print version and exit", doversion)
obj.Flagcount("W", "disassemble input", &Debug['W'])
- obj.Flagfn1("X", "set the value of a string variable; the next two arguments are its name and value", addstrdata1)
+ obj.Flagfn1("X", "add string value `definition` of the form importpath.name=value", addstrdata1)
obj.Flagcount("Z", "clear stack frame on entry", &Debug['Z'])
obj.Flagcount("a", "disassemble output", &Debug['a'])
obj.Flagstr("buildid", "record `id` as Go toolchain build id", &buildid)
obj.Flagcount("v", "print link trace", &Debug['v'])
obj.Flagcount("w", "disable DWARF generation", &Debug['w'])
- // Clumsy hack to preserve old behavior of -X taking two arguments.
+ obj.Flagstr("cpuprofile", "write cpu profile to `file`", &cpuprofile)
+ obj.Flagstr("memprofile", "write memory profile to `file`", &memprofile)
+ obj.Flagint64("memprofilerate", "set runtime.MemProfileRate to `rate`", &memprofilerate)
+
+ // Clumsy hack to preserve old two-argument -X name val syntax for old scripts.
+ // Rewrite that syntax into new syntax -X name=val.
+ // TODO(rsc): Delete this hack in Go 1.6 or later.
+ var args []string
for i := 0; i < len(os.Args); i++ {
arg := os.Args[i]
- if (arg == "--X" || arg == "-X") && i+2 < len(os.Args) {
- os.Args[i+2] = "-X=VALUE:" + os.Args[i+2]
+ if (arg == "-X" || arg == "--X") && i+2 < len(os.Args) && !strings.Contains(os.Args[i+1], "=") {
+ fmt.Fprintf(os.Stderr, "link: warning: option %s %s %s may not work in future releases; use %s %s=%s\n",
+ arg, os.Args[i+1], os.Args[i+2],
+ arg, os.Args[i+1], os.Args[i+2])
+ args = append(args, arg)
+ args = append(args, os.Args[i+1]+"="+os.Args[i+2])
i += 2
- } else if (strings.HasPrefix(arg, "--X=") || strings.HasPrefix(arg, "-X=")) && i+1 < len(os.Args) {
- os.Args[i+1] = "-X=VALUE:" + os.Args[i+1]
+ continue
+ }
+ if (strings.HasPrefix(arg, "-X=") || strings.HasPrefix(arg, "--X=")) && i+1 < len(os.Args) && strings.Count(arg, "=") == 1 {
+ fmt.Fprintf(os.Stderr, "link: warning: option %s %s may not work in future releases; use %s=%s\n",
+ arg, os.Args[i+1],
+ arg, os.Args[i+1])
+ args = append(args, arg+"="+os.Args[i+1])
i++
+ continue
}
+ args = append(args, arg)
}
- obj.Flagstr("cpuprofile", "write cpu profile to `file`", &cpuprofile)
- obj.Flagstr("memprofile", "write memory profile to `file`", &memprofile)
- obj.Flagint64("memprofilerate", "set runtime.MemProfileRate to `rate`", &memprofilerate)
+ os.Args = args
+
obj.Flagparse(usage)
+
startProfile()
Ctxt.Bso = &Bso
Ctxt.Debugvlog = int32(Debug['v'])
package main
import (
+ "bytes"
"fmt"
"os"
"os/exec"
)
func main() {
+ test(" ") // old deprecated syntax
+ test("=") // new syntax
+}
+
+func test(sep string) {
// 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()
+ cmd := exec.Command("go", "run", "-ldflags=-X main.tbd"+sep+"hello -X main.overwrite"+sep+"trumped -X main.nosuchsymbol"+sep+"neverseen", "linkx.go")
+ var out, errbuf bytes.Buffer
+ cmd.Stdout = &out
+ cmd.Stderr = &errbuf
+ err := cmd.Run()
if err != nil {
- fmt.Println(string(out))
+ fmt.Println(errbuf.String())
+ fmt.Println(out.String())
fmt.Println(err)
os.Exit(1)
}
want := "hello\ntrumped\n"
- got := string(out)
+ got := out.String()
if got != want {
fmt.Printf("got %q want %q\n", got, want)
os.Exit(1)