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;
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'])
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) {
}
}
- if(!isinternal && linkmode == LinkAuto)
- linkmode = LinkExternal;
+ if(!isinternal)
+ externalobj = 1;
if(nhostobj >= mhostobj) {
if(mhostobj == 0)