Commit 8677cad1 authored by Christopher Nelson's avatar Christopher Nelson Committed by Brad Fitzpatrick

cmd/link: Replace fmt.Sprintf with filepath.Join

In a number of places the code was joining filepaths explicitly with
"/", instead of using filepath.Join. This may cause problems on Windows
(or other) platforms.

This is in support of https://go-review.googlesource.com/#/c/18057

Change-Id: Ieb1334f35ddb2e125be690afcdadff8d7b0ace10
Reviewed-on: https://go-review.googlesource.com/21369Reviewed-by: 's avatarBrad Fitzpatrick <bradfitz@golang.org>
parent c27efce6
...@@ -401,7 +401,7 @@ func libinit() { ...@@ -401,7 +401,7 @@ func libinit() {
suffix = "msan" suffix = "msan"
} }
Lflag(fmt.Sprintf("%s/pkg/%s_%s%s%s", goroot, goos, goarch, suffixsep, suffix)) Lflag(filepath.Join(goroot, "pkg", fmt.Sprintf("%s_%s%s%s", goos, goarch, suffixsep, suffix)))
mayberemoveoutfile() mayberemoveoutfile()
f, err := os.OpenFile(outfile, os.O_WRONLY|os.O_CREATE|os.O_TRUNC, 0775) f, err := os.OpenFile(outfile, os.O_WRONLY|os.O_CREATE|os.O_TRUNC, 0775)
...@@ -464,7 +464,7 @@ func loadinternal(name string) { ...@@ -464,7 +464,7 @@ func loadinternal(name string) {
found := 0 found := 0
for i := 0; i < len(Ctxt.Libdir); i++ { for i := 0; i < len(Ctxt.Libdir); i++ {
if Linkshared { if Linkshared {
shlibname := fmt.Sprintf("%s/%s.shlibname", Ctxt.Libdir[i], name) shlibname := filepath.Join(Ctxt.Libdir[i], name+".shlibname")
if Debug['v'] != 0 { if Debug['v'] != 0 {
fmt.Fprintf(&Bso, "searching for %s.a in %s\n", name, shlibname) fmt.Fprintf(&Bso, "searching for %s.a in %s\n", name, shlibname)
} }
...@@ -474,7 +474,7 @@ func loadinternal(name string) { ...@@ -474,7 +474,7 @@ func loadinternal(name string) {
break break
} }
} }
pname := fmt.Sprintf("%s/%s.a", Ctxt.Libdir[i], name) pname := filepath.Join(Ctxt.Libdir[i], name+".a")
if Debug['v'] != 0 { if Debug['v'] != 0 {
fmt.Fprintf(&Bso, "searching for %s.a in %s\n", name, pname) fmt.Fprintf(&Bso, "searching for %s.a in %s\n", name, pname)
} }
...@@ -957,7 +957,7 @@ func hostlinksetup() { ...@@ -957,7 +957,7 @@ func hostlinksetup() {
coutbuf.f.Close() coutbuf.f.Close()
mayberemoveoutfile() mayberemoveoutfile()
p := fmt.Sprintf("%s/go.o", tmpdir) p := filepath.Join(tmpdir, "go.o")
var err error var err error
f, err := os.OpenFile(p, os.O_WRONLY|os.O_CREATE|os.O_TRUNC, 0775) f, err := os.OpenFile(p, os.O_WRONLY|os.O_CREATE|os.O_TRUNC, 0775)
if err != nil { if err != nil {
...@@ -975,7 +975,7 @@ func hostobjCopy() (paths []string) { ...@@ -975,7 +975,7 @@ func hostobjCopy() (paths []string) {
sema := make(chan struct{}, runtime.NumCPU()) // limit open file descriptors sema := make(chan struct{}, runtime.NumCPU()) // limit open file descriptors
for i, h := range hostobj { for i, h := range hostobj {
h := h h := h
dst := fmt.Sprintf("%s/%06d.o", tmpdir, i) dst := filepath.Join(tmpdir, fmt.Sprintf("%06d.o", i))
paths = append(paths, dst) paths = append(paths, dst)
wg.Add(1) wg.Add(1)
...@@ -1021,7 +1021,7 @@ func archive() { ...@@ -1021,7 +1021,7 @@ func archive() {
mayberemoveoutfile() mayberemoveoutfile()
argv := []string{extar, "-q", "-c", "-s", outfile} argv := []string{extar, "-q", "-c", "-s", outfile}
argv = append(argv, fmt.Sprintf("%s/go.o", tmpdir)) argv = append(argv, filepath.Join(tmpdir, "go.o"))
argv = append(argv, hostobjCopy()...) argv = append(argv, hostobjCopy()...)
if Debug['v'] != 0 { if Debug['v'] != 0 {
...@@ -1134,7 +1134,7 @@ func hostlink() { ...@@ -1134,7 +1134,7 @@ func hostlink() {
argv = append(argv, "-Qunused-arguments") argv = append(argv, "-Qunused-arguments")
} }
argv = append(argv, fmt.Sprintf("%s/go.o", tmpdir)) argv = append(argv, filepath.Join(tmpdir, "go.o"))
argv = append(argv, hostobjCopy()...) argv = append(argv, hostobjCopy()...)
if Linkshared { if Linkshared {
...@@ -1212,7 +1212,7 @@ func hostlink() { ...@@ -1212,7 +1212,7 @@ func hostlink() {
if Debug['s'] == 0 && debug_s == 0 && HEADTYPE == obj.Hdarwin { if Debug['s'] == 0 && debug_s == 0 && HEADTYPE == obj.Hdarwin {
// Skip combining dwarf on arm. // Skip combining dwarf on arm.
if Thearch.Thechar != '5' && Thearch.Thechar != '7' { if Thearch.Thechar != '5' && Thearch.Thechar != '7' {
dsym := fmt.Sprintf("%s/go.dwarf", tmpdir) dsym := filepath.Join(tmpdir, "go.dwarf")
if out, err := exec.Command("dsymutil", "-f", outfile, "-o", dsym).CombinedOutput(); err != nil { if out, err := exec.Command("dsymutil", "-f", outfile, "-o", dsym).CombinedOutput(); err != nil {
Ctxt.Cursym = nil Ctxt.Cursym = nil
Exitf("%s: running dsymutil failed: %v\n%s", os.Args[0], err, out) Exitf("%s: running dsymutil failed: %v\n%s", os.Args[0], err, out)
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment