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
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);
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);
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);
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
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];
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";
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();
EXTERN char* tracksym;
EXTERN char* interpreter;
EXTERN char* tmpdir;
+EXTERN char* extld;
+EXTERN char* extldflags;
enum
{