/usr/src/gcc-6/debian/patches/cmd-go-combine-gccgo-s-ld-and-ldShared-methods.diff is in gcc-6-source 6.4.0-17ubuntu1.
This file is owned by root:root, with mode 0o644.
The actual contents of the file can be viewed below.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 | # DP: cmd/go: combine gccgo's ld() and ldShared() methods
From 7fc382a2a201960826ed72413983685ac942c64c Mon Sep 17 00:00:00 2001
From: Michael Hudson-Doyle <michael.hudson@canonical.com>
Date: Tue, 31 May 2016 20:48:42 +1200
Subject: [PATCH] cmd/go: combine gccgo's ld() and ldShared() methods
This fixes handling of cgo flags and makes sure packages that are only
implicitly included in the shared library are passed to the link.
Fixes #15885
Change-Id: I1e8a72b5314261973ca903c78834700fb113dde9
---
src/cmd/go/build.go | 63 ++++++++++++++++++++++++-----------------------------
1 file changed, 29 insertions(+), 34 deletions(-)
Index: b/src/libgo/go/cmd/go/build.go
===================================================================
--- a/src/libgo/go/cmd/go/build.go
+++ b/src/libgo/go/cmd/go/build.go
@@ -2629,7 +2629,7 @@ func (gccgoToolchain) pack(b *builder, p
return b.run(p.Dir, p.ImportPath, nil, "ar", "rc", mkAbs(objDir, afile), absOfiles)
}
-func (tools gccgoToolchain) ld(b *builder, root *action, out string, allactions []*action, mainpkg string, ofiles []string) error {
+func (tools gccgoToolchain) link(b *builder, root *action, out string, allactions []*action, mainpkg string, ofiles []string, buildmode, desc string) error {
// gccgo needs explicit linking with all package dependencies,
// and all LDFLAGS from cgo dependencies.
apackagePathsSeen := make(map[string]bool)
@@ -2638,8 +2638,12 @@ func (tools gccgoToolchain) ld(b *builde
ldflags := b.gccArchArgs()
cgoldflags := []string{}
usesCgo := false
- cxx := len(root.p.CXXFiles) > 0 || len(root.p.SwigCXXFiles) > 0
- objc := len(root.p.MFiles) > 0
+ cxx := false
+ objc := false
+ if root.p != nil {
+ cxx = len(root.p.CXXFiles) > 0 || len(root.p.SwigCXXFiles) > 0
+ objc = len(root.p.MFiles) > 0
+ }
readCgoFlags := func(flagsFile string) error {
flags, err := ioutil.ReadFile(flagsFile)
@@ -2686,11 +2690,11 @@ func (tools gccgoToolchain) ld(b *builde
}
newarchive := newa.Name()
- err = b.run(b.work, root.p.ImportPath, nil, "ar", "x", newarchive, "_cgo_flags")
+ err = b.run(b.work, desc, nil, "ar", "x", newarchive, "_cgo_flags")
if err != nil {
return "", err
}
- err = b.run(".", root.p.ImportPath, nil, "ar", "d", newarchive, "_cgo_flags")
+ err = b.run(".", desc, nil, "ar", "d", newarchive, "_cgo_flags")
if err != nil {
return "", err
}
@@ -2793,7 +2797,9 @@ func (tools gccgoToolchain) ld(b *builde
ldflags = append(ldflags, cgoldflags...)
ldflags = append(ldflags, envList("CGO_LDFLAGS", "")...)
- ldflags = append(ldflags, root.p.CgoLDFLAGS...)
+ if root.p != nil {
+ ldflags = append(ldflags, root.p.CgoLDFLAGS...)
+ }
ldflags = stringList("-Wl,-(", ldflags, "-Wl,-)")
@@ -2808,7 +2814,7 @@ func (tools gccgoToolchain) ld(b *builde
}
var realOut string
- switch ldBuildmode {
+ switch buildmode {
case "exe":
if usesCgo && goos == "linux" {
ldflags = append(ldflags, "-Wl,-E")
@@ -2843,12 +2849,14 @@ func (tools gccgoToolchain) ld(b *builde
case "c-shared":
ldflags = append(ldflags, "-shared", "-nostdlib", "-Wl,--whole-archive", "-lgolibbegin", "-Wl,--no-whole-archive", "-lgo", "-lgcc_s", "-lgcc", "-lc", "-lgcc")
+ case "shared":
+ ldflags = append(ldflags, "-zdefs", "-shared", "-nostdlib", "-lgo", "-lgcc_s", "-lgcc", "-lc")
default:
- fatalf("-buildmode=%s not supported for gccgo", ldBuildmode)
+ fatalf("-buildmode=%s not supported for gccgo", buildmode)
}
- switch ldBuildmode {
+ switch buildmode {
case "exe", "c-shared":
if cxx {
ldflags = append(ldflags, "-lstdc++")
@@ -2858,41 +2866,27 @@ func (tools gccgoToolchain) ld(b *builde
}
}
- if err := b.run(".", root.p.ImportPath, nil, tools.linker(), "-o", out, ofiles, ldflags, buildGccgoflags); err != nil {
+ if err := b.run(".", desc, nil, tools.linker(), "-o", out, ofiles, ldflags, buildGccgoflags); err != nil {
return err
}
- switch ldBuildmode {
+ switch buildmode {
case "c-archive":
- if err := b.run(".", root.p.ImportPath, nil, "ar", "rc", realOut, out); err != nil {
+ if err := b.run(".", desc, nil, "ar", "rc", realOut, out); err != nil {
return err
}
}
return nil
}
+func (tools gccgoToolchain) ld(b *builder, root *action, out string, allactions []*action, mainpkg string, ofiles []string) error {
+ return tools.link(b, root, out, allactions, mainpkg, ofiles, ldBuildmode, root.p.ImportPath)
+}
+
func (tools gccgoToolchain) ldShared(b *builder, toplevelactions []*action, out string, allactions []*action) error {
- args := []string{"-o", out, "-shared", "-nostdlib", "-zdefs", "-Wl,--whole-archive"}
- for _, a := range toplevelactions {
- args = append(args, a.target)
- }
- args = append(args, "-Wl,--no-whole-archive", "-shared", "-nostdlib", "-lgo", "-lgcc_s", "-lgcc", "-lc")
- shlibs := []string{}
- for _, a := range allactions {
- if strings.HasSuffix(a.target, ".so") {
- shlibs = append(shlibs, a.target)
- }
- }
- for _, shlib := range shlibs {
- args = append(
- args,
- "-L"+filepath.Dir(shlib),
- "-Wl,-rpath="+filepath.Dir(shlib),
- "-l"+strings.TrimSuffix(
- strings.TrimPrefix(filepath.Base(shlib), "lib"),
- ".so"))
- }
- return b.run(".", out, nil, tools.linker(), args, buildGccgoflags)
+ fakeRoot := &action{}
+ fakeRoot.deps = toplevelactions
+ return tools.link(b, fakeRoot, out, allactions, "", []string{}, "shared", out)
}
func (tools gccgoToolchain) cc(b *builder, p *Package, objdir, ofile, cfile string) error {
|