]> Cypherpunks repositories - gostls13.git/commitdiff
cmd/link: Replace fmt.Sprintf with filepath.Join
authorChristopher Nelson <nadiasvertex@gmail.com>
Thu, 31 Mar 2016 20:22:54 +0000 (16:22 -0400)
committerBrad Fitzpatrick <bradfitz@golang.org>
Thu, 31 Mar 2016 22:32:28 +0000 (22:32 +0000)
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/21369
Reviewed-by: Brad Fitzpatrick <bradfitz@golang.org>
src/cmd/link/internal/ld/lib.go

index 5ec5c98290c3d1d96d5ba6266666411575b8059f..fcaa8a026aa638d87a5ecd3e3587610f50de8e7b 100644 (file)
@@ -401,7 +401,7 @@ func libinit() {
                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()
        f, err := os.OpenFile(outfile, os.O_WRONLY|os.O_CREATE|os.O_TRUNC, 0775)
@@ -464,7 +464,7 @@ func loadinternal(name string) {
        found := 0
        for i := 0; i < len(Ctxt.Libdir); i++ {
                if Linkshared {
-                       shlibname := fmt.Sprintf("%s/%s.shlibname", Ctxt.Libdir[i], name)
+                       shlibname := filepath.Join(Ctxt.Libdir[i], name+".shlibname")
                        if Debug['v'] != 0 {
                                fmt.Fprintf(&Bso, "searching for %s.a in %s\n", name, shlibname)
                        }
@@ -474,7 +474,7 @@ func loadinternal(name string) {
                                break
                        }
                }
-               pname := fmt.Sprintf("%s/%s.a", Ctxt.Libdir[i], name)
+               pname := filepath.Join(Ctxt.Libdir[i], name+".a")
                if Debug['v'] != 0 {
                        fmt.Fprintf(&Bso, "searching for %s.a in %s\n", name, pname)
                }
@@ -957,7 +957,7 @@ func hostlinksetup() {
        coutbuf.f.Close()
        mayberemoveoutfile()
 
-       p := fmt.Sprintf("%s/go.o", tmpdir)
+       p := filepath.Join(tmpdir, "go.o")
        var err error
        f, err := os.OpenFile(p, os.O_WRONLY|os.O_CREATE|os.O_TRUNC, 0775)
        if err != nil {
@@ -975,7 +975,7 @@ func hostobjCopy() (paths []string) {
        sema := make(chan struct{}, runtime.NumCPU()) // limit open file descriptors
        for i, h := range hostobj {
                h := h
-               dst := fmt.Sprintf("%s/%06d.o", tmpdir, i)
+               dst := filepath.Join(tmpdir, fmt.Sprintf("%06d.o", i))
                paths = append(paths, dst)
 
                wg.Add(1)
@@ -1021,7 +1021,7 @@ func archive() {
 
        mayberemoveoutfile()
        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()...)
 
        if Debug['v'] != 0 {
@@ -1134,7 +1134,7 @@ func hostlink() {
                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()...)
 
        if Linkshared {
@@ -1212,7 +1212,7 @@ func hostlink() {
        if Debug['s'] == 0 && debug_s == 0 && HEADTYPE == obj.Hdarwin {
                // Skip combining dwarf on arm.
                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 {
                                Ctxt.Cursym = nil
                                Exitf("%s: running dsymutil failed: %v\n%s", os.Args[0], err, out)