]> Cypherpunks repositories - gostls13.git/commitdiff
cmd/ld: add -extld and -extldflags options
authorIan Lance Taylor <iant@golang.org>
Mon, 1 Apr 2013 19:56:18 +0000 (12:56 -0700)
committerIan Lance Taylor <iant@golang.org>
Mon, 1 Apr 2013 19:56:18 +0000 (12:56 -0700)
Permits specifying the linker to use, and trailing flags to
pass to that linker, when linking in external mode.  External
mode linking is used when building a package that uses cgo, as
described in the cgo docs.

Also document -linkmode and -tmpdir.

R=golang-dev, r
CC=golang-dev
https://golang.org/cl/8225043

src/cmd/5l/obj.c
src/cmd/6l/obj.c
src/cmd/8l/obj.c
src/cmd/ld/doc.go
src/cmd/ld/lib.c
src/cmd/ld/lib.h

index 72bb1fb78410eabcbe236bc93973349ba8e582d9..24e6294a84b519999c5801041ec95a70f0314df6 100644 (file)
@@ -114,6 +114,8 @@ main(int argc, char *argv[])
        flagcount("a", "disassemble output", &debug['a']);
        flagcount("c", "dump call graph", &debug['c']);
        flagcount("d", "disable dynamic executable", &debug['d']);
+       flagstr("extld", "linker to run in external mode", &extld);
+       flagstr("extldflags", "flags for external linker", &extldflags);
        flagcount("f", "ignore version mismatch", &debug['f']);
        flagcount("g", "disable go package data checks", &debug['g']);
        flagstr("k", "sym: set field tracking symbol", &tracksym);
index 4e69a8df0c11293b792f4de9f687f7e7f36a9fb0..e98f91eeb792b7402a09e466b47ba1680dd6c64c 100644 (file)
@@ -107,6 +107,8 @@ main(int argc, char *argv[])
        flagcount("a", "disassemble output", &debug['a']);
        flagcount("c", "dump call graph", &debug['c']);
        flagcount("d", "disable dynamic executable", &debug['d']);
+       flagstr("extld", "linker to run in external mode", &extld);
+       flagstr("extldflags", "flags for external linker", &extldflags);
        flagcount("f", "ignore version mismatch", &debug['f']);
        flagcount("g", "disable go package data checks", &debug['g']);
        flagfn1("linkmode", "mode: set link mode (internal, external, auto)", setlinkmode);
index d624a999ba6f3611ad7449afcebbdc1e988606ac..c819b9936845033dfdeae8061b9a4c3e12d97936 100644 (file)
@@ -113,6 +113,8 @@ main(int argc, char *argv[])
        flagcount("a", "disassemble output", &debug['a']);
        flagcount("c", "dump call graph", &debug['c']);
        flagcount("d", "disable dynamic executable", &debug['d']);
+       flagstr("extld", "linker to run in external mode", &extld);
+       flagstr("extldflags", "flags for external linker", &extldflags);
        flagcount("f", "ignore version mismatch", &debug['f']);
        flagcount("g", "disable go package data checks", &debug['g']);
        flagfn1("linkmode", "mode: set link mode (internal, external, auto)", setlinkmode);
index bad4e540f2c782ab7dd1fb7b66cca61df12947e1..874db41c9ce0bb2e7d450e038e3983f622e98bb0 100644 (file)
@@ -71,5 +71,22 @@ Options new in this version:
                NOTE: it only eliminates false positives caused by other function
                calls, not false positives caused by dead temporaries stored in
                the current function call.
+       -linkmode argument
+               Set the linkmode.  The argument must be one of
+               internal, external, or auto.  The default is auto.
+               This sets the linking mode as described in
+               ../cgo/doc.go.
+       -tmpdir dir
+               Set the location to use for any temporary files.  The
+               default is a newly created directory that is removed
+               after the linker completes.  Temporary files are only
+               used in external linking mode.
+       -extld name
+               Set the name of the external linker to use in external
+               linking mode.  The default is "gcc".
+       -extldflags flags
+               Set space-separated trailing flags to pass to the
+               external linker in external linking mode.  The default
+               is to not pass any additional trailing flags.
 */
 package main
index 541b03c7364f15b8eac4c864b189934cb391cc7b..84777b1a92b57393f0662c645dfe0d9e635023b1 100644 (file)
@@ -609,7 +609,7 @@ void
 hostlink(void)
 {
        char *p, **argv;
-       int i, w, n, argc, len;
+       int c, i, w, n, argc, len;
        Hostobj *h;
        Biobuf *f;
        static char buf[64<<10];
@@ -617,11 +617,22 @@ hostlink(void)
        if(linkmode != LinkExternal || nerrors > 0)
                return;
 
-       argv = malloc((10+nhostobj+nldflag)*sizeof argv[0]);
+       c = 0;
+       p = extldflags;
+       while(p != nil) {
+               while(*p == ' ')
+                       p++;
+               if(*p == '\0')
+                       break;
+               c++;
+               p = strchr(p + 1, ' ');
+       }
+
+       argv = malloc((10+nhostobj+nldflag+c)*sizeof argv[0]);
        argc = 0;
-       // TODO: Add command-line flag to override gcc path and specify additional leading options.
-       // TODO: Add command-line flag to specify additional trailing options.
-       argv[argc++] = "gcc";
+       if(extld == nil)
+               extld = "gcc";
+       argv[argc++] = extld;
        switch(thechar){
        case '8':
                argv[argc++] = "-m32";
@@ -679,6 +690,17 @@ hostlink(void)
        argv[argc++] = smprint("%s/go.o", tmpdir);
        for(i=0; i<nldflag; i++)
                argv[argc++] = ldflag[i];
+
+       p = extldflags;
+       while(p != nil) {
+               while(*p == ' ')
+                       *p++ = '\0';
+               if(*p == '\0')
+                       break;
+               argv[argc++] = p;
+               p = strchr(p + 1, ' ');
+       }
+
        argv[argc] = nil;
 
        quotefmtinstall();
index 614a35c529ce8522d818c051e2f3653fc23d4cd4..9bdfe95c411884f6254d3a5e8982e025d77aea41 100644 (file)
@@ -157,6 +157,8 @@ EXTERN      int flag_shared;
 EXTERN char*   tracksym;
 EXTERN char*   interpreter;
 EXTERN char*   tmpdir;
+EXTERN char*   extld;
+EXTERN char*   extldflags;
 
 enum
 {