aboutsummaryrefslogtreecommitdiff
path: root/src/cmd/ld/lib.c
diff options
context:
space:
mode:
authorIan Lance Taylor <iant@golang.org>2013-04-12 13:21:17 -0700
committerIan Lance Taylor <iant@golang.org>2013-04-12 13:21:17 -0700
commit696901204f2e7a5180ed4beb4046fbfea05841b2 (patch)
treead5132e700bdb90a56eb093c4aee514e607cde1a /src/cmd/ld/lib.c
parent813590b145448decb4de52e12ce522fe9c16f9a7 (diff)
downloadgo-696901204f2e7a5180ed4beb4046fbfea05841b2.tar.xz
cmd/ld: always do external link for -linkmode=external
There are tests in run.bash for -linkmode=external. Fixes #5238. R=golang-dev, bradfitz, remyoudompheng, r CC=golang-dev https://golang.org/cl/8716044
Diffstat (limited to 'src/cmd/ld/lib.c')
-rw-r--r--src/cmd/ld/lib.c32
1 files changed, 23 insertions, 9 deletions
diff --git a/src/cmd/ld/lib.c b/src/cmd/ld/lib.c
index d22c0870f6..47339d4e53 100644
--- a/src/cmd/ld/lib.c
+++ b/src/cmd/ld/lib.c
@@ -45,6 +45,10 @@ int nlibdir = 0;
static int maxlibdir = 0;
static int cout = -1;
+// Set if we see an object compiled by the host compiler that is not
+// from a package that is known to support internal linking mode.
+static int externalobj = 0;
+
static void hostlinksetup(void);
char* goroot;
@@ -295,6 +299,19 @@ loadlib(void)
loadinternal("math");
if(flag_race)
loadinternal("runtime/race");
+ if(linkmode == LinkExternal) {
+ // This indicates a user requested -linkmode=external.
+ // The startup code uses an import of runtime/cgo to decide
+ // whether to initialize the TLS. So give it one. This could
+ // be handled differently but it's an unusual case.
+ loadinternal("runtime/cgo");
+ // Pretend that we really imported the package.
+ // This will do no harm if we did in fact import it.
+ s = lookup("go.importpath.runtime/cgo.", 0);
+ s->type = SDATA;
+ s->dupok = 1;
+ s->reachable = 1;
+ }
for(i=0; i<libraryp; i++) {
if(debug['v'])
@@ -303,14 +320,11 @@ loadlib(void)
objfile(library[i].file, library[i].pkg);
}
- if(linkmode == LinkExternal && !iscgo)
- linkmode = LinkInternal;
-
- // If we got this far in automatic mode, there were no
- // cgo uses that suggest we need external mode.
- // Switch to internal.
if(linkmode == LinkAuto) {
- linkmode = LinkInternal;
+ if(iscgo && externalobj)
+ linkmode = LinkExternal;
+ else
+ linkmode = LinkInternal;
}
if(linkmode == LinkInternal) {
@@ -532,8 +546,8 @@ ldhostobj(void (*ld)(Biobuf*, char*, int64, char*), Biobuf *f, char *pkg, int64
}
}
- if(!isinternal && linkmode == LinkAuto)
- linkmode = LinkExternal;
+ if(!isinternal)
+ externalobj = 1;
if(nhostobj >= mhostobj) {
if(mhostobj == 0)