}
}
+var strdata []*LSym
+
func addstrdata1(arg string) {
i := strings.Index(arg, "=")
if i < 0 {
// we know before entering this function.
s.Reachable = reachable
+ strdata = append(strdata, s)
+
sp.Reachable = reachable
}
+func checkstrdata() {
+ for _, s := range strdata {
+ if s.Type == obj.STEXT {
+ Diag("cannot use -X with text symbol %s", s.Name)
+ } else if s.Gotype != nil && s.Gotype.Name != "type.string" {
+ Diag("cannot use -X with non-string symbol %s", s.Name)
+ }
+ }
+}
+
func Addstring(s *LSym, str string) int64 {
if s.Type == 0 {
s.Type = obj.SNOPTRDATA
"fmt"
"os"
"os/exec"
+ "strings"
)
func main() {
fmt.Println("-X linker flag should not accept keys without values")
os.Exit(1)
}
+
+ // Issue 9621
+ cmd = exec.Command("go", "run", "-ldflags=-X main.b=false -X main.x=42", "linkx.go")
+ outx, err := cmd.CombinedOutput()
+ if err == nil {
+ fmt.Println("-X linker flag should not overwrite non-strings")
+ os.Exit(1)
+ }
+ outstr := string(outx)
+ if !strings.Contains(outstr, "main.b") {
+ fmt.Printf("-X linker flag did not diagnose overwrite of main.b\n")
+ os.Exit(1)
+ }
+ if !strings.Contains(outstr, "main.x") {
+ fmt.Printf("-X linker flag did not diagnose overwrite of main.x\n")
+ os.Exit(1)
+ }
}