Commit 9182c364 authored by Ian Lance Taylor's avatar Ian Lance Taylor

cmd/ld: add -extld and -extldflags options

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
parent df9f4f14
...@@ -114,6 +114,8 @@ main(int argc, char *argv[]) ...@@ -114,6 +114,8 @@ main(int argc, char *argv[])
flagcount("a", "disassemble output", &debug['a']); flagcount("a", "disassemble output", &debug['a']);
flagcount("c", "dump call graph", &debug['c']); flagcount("c", "dump call graph", &debug['c']);
flagcount("d", "disable dynamic executable", &debug['d']); 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("f", "ignore version mismatch", &debug['f']);
flagcount("g", "disable go package data checks", &debug['g']); flagcount("g", "disable go package data checks", &debug['g']);
flagstr("k", "sym: set field tracking symbol", &tracksym); flagstr("k", "sym: set field tracking symbol", &tracksym);
......
...@@ -107,6 +107,8 @@ main(int argc, char *argv[]) ...@@ -107,6 +107,8 @@ main(int argc, char *argv[])
flagcount("a", "disassemble output", &debug['a']); flagcount("a", "disassemble output", &debug['a']);
flagcount("c", "dump call graph", &debug['c']); flagcount("c", "dump call graph", &debug['c']);
flagcount("d", "disable dynamic executable", &debug['d']); 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("f", "ignore version mismatch", &debug['f']);
flagcount("g", "disable go package data checks", &debug['g']); flagcount("g", "disable go package data checks", &debug['g']);
flagfn1("linkmode", "mode: set link mode (internal, external, auto)", setlinkmode); flagfn1("linkmode", "mode: set link mode (internal, external, auto)", setlinkmode);
......
...@@ -113,6 +113,8 @@ main(int argc, char *argv[]) ...@@ -113,6 +113,8 @@ main(int argc, char *argv[])
flagcount("a", "disassemble output", &debug['a']); flagcount("a", "disassemble output", &debug['a']);
flagcount("c", "dump call graph", &debug['c']); flagcount("c", "dump call graph", &debug['c']);
flagcount("d", "disable dynamic executable", &debug['d']); 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("f", "ignore version mismatch", &debug['f']);
flagcount("g", "disable go package data checks", &debug['g']); flagcount("g", "disable go package data checks", &debug['g']);
flagfn1("linkmode", "mode: set link mode (internal, external, auto)", setlinkmode); flagfn1("linkmode", "mode: set link mode (internal, external, auto)", setlinkmode);
......
...@@ -71,5 +71,22 @@ Options new in this version: ...@@ -71,5 +71,22 @@ Options new in this version:
NOTE: it only eliminates false positives caused by other function NOTE: it only eliminates false positives caused by other function
calls, not false positives caused by dead temporaries stored in calls, not false positives caused by dead temporaries stored in
the current function call. 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 package main
...@@ -609,7 +609,7 @@ void ...@@ -609,7 +609,7 @@ void
hostlink(void) hostlink(void)
{ {
char *p, **argv; char *p, **argv;
int i, w, n, argc, len; int c, i, w, n, argc, len;
Hostobj *h; Hostobj *h;
Biobuf *f; Biobuf *f;
static char buf[64<<10]; static char buf[64<<10];
...@@ -617,11 +617,22 @@ hostlink(void) ...@@ -617,11 +617,22 @@ hostlink(void)
if(linkmode != LinkExternal || nerrors > 0) if(linkmode != LinkExternal || nerrors > 0)
return; 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; argc = 0;
// TODO: Add command-line flag to override gcc path and specify additional leading options. if(extld == nil)
// TODO: Add command-line flag to specify additional trailing options. extld = "gcc";
argv[argc++] = "gcc"; argv[argc++] = extld;
switch(thechar){ switch(thechar){
case '8': case '8':
argv[argc++] = "-m32"; argv[argc++] = "-m32";
...@@ -679,6 +690,17 @@ hostlink(void) ...@@ -679,6 +690,17 @@ hostlink(void)
argv[argc++] = smprint("%s/go.o", tmpdir); argv[argc++] = smprint("%s/go.o", tmpdir);
for(i=0; i<nldflag; i++) for(i=0; i<nldflag; i++)
argv[argc++] = ldflag[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; argv[argc] = nil;
quotefmtinstall(); quotefmtinstall();
......
...@@ -157,6 +157,8 @@ EXTERN int flag_shared; ...@@ -157,6 +157,8 @@ EXTERN int flag_shared;
EXTERN char* tracksym; EXTERN char* tracksym;
EXTERN char* interpreter; EXTERN char* interpreter;
EXTERN char* tmpdir; EXTERN char* tmpdir;
EXTERN char* extld;
EXTERN char* extldflags;
enum enum
{ {
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment