author | Shawn Walker-Salas <shawn.walker@oracle.com> |
Thu, 21 Jan 2016 09:20:59 -0800 | |
changeset 5331 | 9c955076ffe3 |
permissions | -rw-r--r-- |
5331
9c955076ffe3
PSARC/2015/203 Google Go version 1.5
Shawn Walker-Salas <shawn.walker@oracle.com>
parents:
diff
changeset
|
1 |
commit dc6df1b07093ffa0568a581251e8ddd38f707ed6 |
9c955076ffe3
PSARC/2015/203 Google Go version 1.5
Shawn Walker-Salas <shawn.walker@oracle.com>
parents:
diff
changeset
|
2 |
Author: Shawn Walker-Salas <[email protected]> |
9c955076ffe3
PSARC/2015/203 Google Go version 1.5
Shawn Walker-Salas <shawn.walker@oracle.com>
parents:
diff
changeset
|
3 |
Date: Thu Sep 17 15:47:20 2015 -0700 |
9c955076ffe3
PSARC/2015/203 Google Go version 1.5
Shawn Walker-Salas <shawn.walker@oracle.com>
parents:
diff
changeset
|
4 |
|
9c955076ffe3
PSARC/2015/203 Google Go version 1.5
Shawn Walker-Salas <shawn.walker@oracle.com>
parents:
diff
changeset
|
5 |
cmd/go: elide -rpath when not applicable and used via LDFLAGS |
9c955076ffe3
PSARC/2015/203 Google Go version 1.5
Shawn Walker-Salas <shawn.walker@oracle.com>
parents:
diff
changeset
|
6 |
|
9c955076ffe3
PSARC/2015/203 Google Go version 1.5
Shawn Walker-Salas <shawn.walker@oracle.com>
parents:
diff
changeset
|
7 |
Some linker flags should only be applied when performing the final |
9c955076ffe3
PSARC/2015/203 Google Go version 1.5
Shawn Walker-Salas <shawn.walker@oracle.com>
parents:
diff
changeset
|
8 |
linking step for a shared library or executable, etc. In other |
9c955076ffe3
PSARC/2015/203 Google Go version 1.5
Shawn Walker-Salas <shawn.walker@oracle.com>
parents:
diff
changeset
|
9 |
contexts, they're either invalid, or meaningless to apply (so should |
9c955076ffe3
PSARC/2015/203 Google Go version 1.5
Shawn Walker-Salas <shawn.walker@oracle.com>
parents:
diff
changeset
|
10 |
not be specified). |
9c955076ffe3
PSARC/2015/203 Google Go version 1.5
Shawn Walker-Salas <shawn.walker@oracle.com>
parents:
diff
changeset
|
11 |
|
9c955076ffe3
PSARC/2015/203 Google Go version 1.5
Shawn Walker-Salas <shawn.walker@oracle.com>
parents:
diff
changeset
|
12 |
When an external linker is used (either directly by Go or by the |
9c955076ffe3
PSARC/2015/203 Google Go version 1.5
Shawn Walker-Salas <shawn.walker@oracle.com>
parents:
diff
changeset
|
13 |
compiler driver used by cgo), -rpath and -rpath-link should only be |
9c955076ffe3
PSARC/2015/203 Google Go version 1.5
Shawn Walker-Salas <shawn.walker@oracle.com>
parents:
diff
changeset
|
14 |
specified in the final linking step. On platforms such as Solaris, |
9c955076ffe3
PSARC/2015/203 Google Go version 1.5
Shawn Walker-Salas <shawn.walker@oracle.com>
parents:
diff
changeset
|
15 |
ld(1) will reject its use in any other scenario (such as when linking |
9c955076ffe3
PSARC/2015/203 Google Go version 1.5
Shawn Walker-Salas <shawn.walker@oracle.com>
parents:
diff
changeset
|
16 |
relocatable objects). |
9c955076ffe3
PSARC/2015/203 Google Go version 1.5
Shawn Walker-Salas <shawn.walker@oracle.com>
parents:
diff
changeset
|
17 |
|
9c955076ffe3
PSARC/2015/203 Google Go version 1.5
Shawn Walker-Salas <shawn.walker@oracle.com>
parents:
diff
changeset
|
18 |
This change is necessary because Go does not currently offer a way to |
9c955076ffe3
PSARC/2015/203 Google Go version 1.5
Shawn Walker-Salas <shawn.walker@oracle.com>
parents:
diff
changeset
|
19 |
specify LDFLAGS based on when they should be applied. |
9c955076ffe3
PSARC/2015/203 Google Go version 1.5
Shawn Walker-Salas <shawn.walker@oracle.com>
parents:
diff
changeset
|
20 |
|
9c955076ffe3
PSARC/2015/203 Google Go version 1.5
Shawn Walker-Salas <shawn.walker@oracle.com>
parents:
diff
changeset
|
21 |
Fixes #12115 |
9c955076ffe3
PSARC/2015/203 Google Go version 1.5
Shawn Walker-Salas <shawn.walker@oracle.com>
parents:
diff
changeset
|
22 |
|
9c955076ffe3
PSARC/2015/203 Google Go version 1.5
Shawn Walker-Salas <shawn.walker@oracle.com>
parents:
diff
changeset
|
23 |
Change-Id: If35a18d8eee8ec7ddcca2d4ccd41ab6ffcf93b41 |
9c955076ffe3
PSARC/2015/203 Google Go version 1.5
Shawn Walker-Salas <shawn.walker@oracle.com>
parents:
diff
changeset
|
24 |
Reviewed-on: https://go-review.googlesource.com/14674 |
9c955076ffe3
PSARC/2015/203 Google Go version 1.5
Shawn Walker-Salas <shawn.walker@oracle.com>
parents:
diff
changeset
|
25 |
Reviewed-by: Minux Ma <[email protected]> |
9c955076ffe3
PSARC/2015/203 Google Go version 1.5
Shawn Walker-Salas <shawn.walker@oracle.com>
parents:
diff
changeset
|
26 |
Run-TryBot: Minux Ma <[email protected]> |
9c955076ffe3
PSARC/2015/203 Google Go version 1.5
Shawn Walker-Salas <shawn.walker@oracle.com>
parents:
diff
changeset
|
27 |
TryBot-Result: Gobot Gobot <[email protected]> |
9c955076ffe3
PSARC/2015/203 Google Go version 1.5
Shawn Walker-Salas <shawn.walker@oracle.com>
parents:
diff
changeset
|
28 |
Reviewed-by: Ian Lance Taylor <[email protected]> |
9c955076ffe3
PSARC/2015/203 Google Go version 1.5
Shawn Walker-Salas <shawn.walker@oracle.com>
parents:
diff
changeset
|
29 |
|
9c955076ffe3
PSARC/2015/203 Google Go version 1.5
Shawn Walker-Salas <shawn.walker@oracle.com>
parents:
diff
changeset
|
30 |
diff --git a/src/cmd/go/build.go b/src/cmd/go/build.go |
9c955076ffe3
PSARC/2015/203 Google Go version 1.5
Shawn Walker-Salas <shawn.walker@oracle.com>
parents:
diff
changeset
|
31 |
index df74338..0c2bc5f 100644 |
9c955076ffe3
PSARC/2015/203 Google Go version 1.5
Shawn Walker-Salas <shawn.walker@oracle.com>
parents:
diff
changeset
|
32 |
--- a/src/cmd/go/build.go |
9c955076ffe3
PSARC/2015/203 Google Go version 1.5
Shawn Walker-Salas <shawn.walker@oracle.com>
parents:
diff
changeset
|
33 |
+++ b/src/cmd/go/build.go |
9c955076ffe3
PSARC/2015/203 Google Go version 1.5
Shawn Walker-Salas <shawn.walker@oracle.com>
parents:
diff
changeset
|
34 |
@@ -2943,7 +2943,9 @@ func (b *builder) cgo(p *Package, cgoExe, obj string, pcCFLAGS, pcLDFLAGS, cgofi |
9c955076ffe3
PSARC/2015/203 Google Go version 1.5
Shawn Walker-Salas <shawn.walker@oracle.com>
parents:
diff
changeset
|
35 |
var linkobj []string |
9c955076ffe3
PSARC/2015/203 Google Go version 1.5
Shawn Walker-Salas <shawn.walker@oracle.com>
parents:
diff
changeset
|
36 |
|
9c955076ffe3
PSARC/2015/203 Google Go version 1.5
Shawn Walker-Salas <shawn.walker@oracle.com>
parents:
diff
changeset
|
37 |
var bareLDFLAGS []string |
9c955076ffe3
PSARC/2015/203 Google Go version 1.5
Shawn Walker-Salas <shawn.walker@oracle.com>
parents:
diff
changeset
|
38 |
- // filter out -lsomelib, -l somelib, *.{so,dll,dylib}, and (on Darwin) -framework X |
9c955076ffe3
PSARC/2015/203 Google Go version 1.5
Shawn Walker-Salas <shawn.walker@oracle.com>
parents:
diff
changeset
|
39 |
+ // When linking relocatable objects, various flags need to be |
9c955076ffe3
PSARC/2015/203 Google Go version 1.5
Shawn Walker-Salas <shawn.walker@oracle.com>
parents:
diff
changeset
|
40 |
+ // filtered out as they are inapplicable and can cause some linkers |
9c955076ffe3
PSARC/2015/203 Google Go version 1.5
Shawn Walker-Salas <shawn.walker@oracle.com>
parents:
diff
changeset
|
41 |
+ // to fail. |
9c955076ffe3
PSARC/2015/203 Google Go version 1.5
Shawn Walker-Salas <shawn.walker@oracle.com>
parents:
diff
changeset
|
42 |
for i := 0; i < len(cgoLDFLAGS); i++ { |
9c955076ffe3
PSARC/2015/203 Google Go version 1.5
Shawn Walker-Salas <shawn.walker@oracle.com>
parents:
diff
changeset
|
43 |
f := cgoLDFLAGS[i] |
9c955076ffe3
PSARC/2015/203 Google Go version 1.5
Shawn Walker-Salas <shawn.walker@oracle.com>
parents:
diff
changeset
|
44 |
switch { |
9c955076ffe3
PSARC/2015/203 Google Go version 1.5
Shawn Walker-Salas <shawn.walker@oracle.com>
parents:
diff
changeset
|
45 |
@@ -2959,7 +2961,6 @@ func (b *builder) cgo(p *Package, cgoExe, obj string, pcCFLAGS, pcLDFLAGS, cgofi |
9c955076ffe3
PSARC/2015/203 Google Go version 1.5
Shawn Walker-Salas <shawn.walker@oracle.com>
parents:
diff
changeset
|
46 |
case strings.HasSuffix(f, ".dylib"), |
9c955076ffe3
PSARC/2015/203 Google Go version 1.5
Shawn Walker-Salas <shawn.walker@oracle.com>
parents:
diff
changeset
|
47 |
strings.HasSuffix(f, ".so"), |
9c955076ffe3
PSARC/2015/203 Google Go version 1.5
Shawn Walker-Salas <shawn.walker@oracle.com>
parents:
diff
changeset
|
48 |
strings.HasSuffix(f, ".dll"): |
9c955076ffe3
PSARC/2015/203 Google Go version 1.5
Shawn Walker-Salas <shawn.walker@oracle.com>
parents:
diff
changeset
|
49 |
- continue |
9c955076ffe3
PSARC/2015/203 Google Go version 1.5
Shawn Walker-Salas <shawn.walker@oracle.com>
parents:
diff
changeset
|
50 |
// Remove any -fsanitize=foo flags. |
9c955076ffe3
PSARC/2015/203 Google Go version 1.5
Shawn Walker-Salas <shawn.walker@oracle.com>
parents:
diff
changeset
|
51 |
// Otherwise the compiler driver thinks that we are doing final link |
9c955076ffe3
PSARC/2015/203 Google Go version 1.5
Shawn Walker-Salas <shawn.walker@oracle.com>
parents:
diff
changeset
|
52 |
// and links sanitizer runtime into the object file. But we are not doing |
9c955076ffe3
PSARC/2015/203 Google Go version 1.5
Shawn Walker-Salas <shawn.walker@oracle.com>
parents:
diff
changeset
|
53 |
@@ -2968,6 +2969,16 @@ func (b *builder) cgo(p *Package, cgoExe, obj string, pcCFLAGS, pcLDFLAGS, cgofi |
9c955076ffe3
PSARC/2015/203 Google Go version 1.5
Shawn Walker-Salas <shawn.walker@oracle.com>
parents:
diff
changeset
|
54 |
// See issue 8788 for details. |
9c955076ffe3
PSARC/2015/203 Google Go version 1.5
Shawn Walker-Salas <shawn.walker@oracle.com>
parents:
diff
changeset
|
55 |
case strings.HasPrefix(f, "-fsanitize="): |
9c955076ffe3
PSARC/2015/203 Google Go version 1.5
Shawn Walker-Salas <shawn.walker@oracle.com>
parents:
diff
changeset
|
56 |
continue |
9c955076ffe3
PSARC/2015/203 Google Go version 1.5
Shawn Walker-Salas <shawn.walker@oracle.com>
parents:
diff
changeset
|
57 |
+ // runpath flags not applicable unless building a shared |
9c955076ffe3
PSARC/2015/203 Google Go version 1.5
Shawn Walker-Salas <shawn.walker@oracle.com>
parents:
diff
changeset
|
58 |
+ // object or executable; see issue 12115 for details. This |
9c955076ffe3
PSARC/2015/203 Google Go version 1.5
Shawn Walker-Salas <shawn.walker@oracle.com>
parents:
diff
changeset
|
59 |
+ // is necessary as Go currently does not offer a way to |
9c955076ffe3
PSARC/2015/203 Google Go version 1.5
Shawn Walker-Salas <shawn.walker@oracle.com>
parents:
diff
changeset
|
60 |
+ // specify the set of LDFLAGS that only apply to shared |
9c955076ffe3
PSARC/2015/203 Google Go version 1.5
Shawn Walker-Salas <shawn.walker@oracle.com>
parents:
diff
changeset
|
61 |
+ // objects. |
9c955076ffe3
PSARC/2015/203 Google Go version 1.5
Shawn Walker-Salas <shawn.walker@oracle.com>
parents:
diff
changeset
|
62 |
+ case strings.HasPrefix(f, "-Wl,-rpath"): |
9c955076ffe3
PSARC/2015/203 Google Go version 1.5
Shawn Walker-Salas <shawn.walker@oracle.com>
parents:
diff
changeset
|
63 |
+ if f == "-Wl,-rpath" || f == "-Wl,-rpath-link" { |
9c955076ffe3
PSARC/2015/203 Google Go version 1.5
Shawn Walker-Salas <shawn.walker@oracle.com>
parents:
diff
changeset
|
64 |
+ // Skip following argument to -rpath* too. |
9c955076ffe3
PSARC/2015/203 Google Go version 1.5
Shawn Walker-Salas <shawn.walker@oracle.com>
parents:
diff
changeset
|
65 |
+ i++ |
9c955076ffe3
PSARC/2015/203 Google Go version 1.5
Shawn Walker-Salas <shawn.walker@oracle.com>
parents:
diff
changeset
|
66 |
+ } |
9c955076ffe3
PSARC/2015/203 Google Go version 1.5
Shawn Walker-Salas <shawn.walker@oracle.com>
parents:
diff
changeset
|
67 |
default: |
9c955076ffe3
PSARC/2015/203 Google Go version 1.5
Shawn Walker-Salas <shawn.walker@oracle.com>
parents:
diff
changeset
|
68 |
bareLDFLAGS = append(bareLDFLAGS, f) |
9c955076ffe3
PSARC/2015/203 Google Go version 1.5
Shawn Walker-Salas <shawn.walker@oracle.com>
parents:
diff
changeset
|
69 |
} |