]> Cypherpunks repositories - gostls13.git/commitdiff
[dev.cc] cmd/ld: finalize linkmode before determining whether to import runtime/cgo
authorShenghou Ma <minux@golang.org>
Fri, 5 Dec 2014 07:22:20 +0000 (02:22 -0500)
committerShenghou Ma <minux@golang.org>
Fri, 5 Dec 2014 07:22:20 +0000 (02:22 -0500)
Frankly, I don't understand how the current code could possibly work except
when every android program is using cgo. Discovered this while working on
the iOS port.

LGTM=crawshaw, rsc
R=rsc, crawshaw
CC=golang-codereviews
https://golang.org/cl/177470043

src/cmd/ld/lib.c

index 64608d226ece43196a831abd54dc6fc295bcfb65..925274bfd34eec408a7f889216b61e55a60a574f 100644 (file)
@@ -202,7 +202,18 @@ loadlib(void)
                iscgo |= strcmp(ctxt->library[i].pkg, "runtime/cgo") == 0;
                objfile(ctxt->library[i].file, ctxt->library[i].pkg);
        }
-       
+
+       if(linkmode == LinkAuto) {
+               if(iscgo && externalobj)
+                       linkmode = LinkExternal;
+               else
+                       linkmode = LinkInternal;
+
+               // Force external linking for android.
+               if(strcmp(goos, "android") == 0)
+                       linkmode = LinkExternal;
+       }
+
        if(linkmode == LinkExternal && !iscgo) {
                // This indicates a user requested -linkmode=external.
                // The startup code uses an import of runtime/cgo to decide
@@ -229,17 +240,6 @@ loadlib(void)
                }
        }
 
-       if(linkmode == LinkAuto) {
-               if(iscgo && externalobj)
-                       linkmode = LinkExternal;
-               else
-                       linkmode = LinkInternal;
-
-               // Force external linking for android.
-               if(strcmp(goos, "android") == 0)
-                       linkmode = LinkExternal;
-       }
-
        if(linkmode == LinkInternal) {
                // Drop all the cgo_import_static declarations.
                // Turns out we won't be needing them.