Commit b4f3533c authored by Russ Cox's avatar Russ Cox

cmd/ld: replace -hostobj with -linkmode

Still disabled. Need to fix TLS.

R=golang-dev, minux.ma, bradfitz
CC=golang-dev
https://golang.org/cl/7783044
parent ab08eac5
...@@ -605,7 +605,7 @@ asmb(void) ...@@ -605,7 +605,7 @@ asmb(void)
Bprint(&bso, "%5.2f dwarf\n", cputime()); Bprint(&bso, "%5.2f dwarf\n", cputime());
dwarfemitdebugsections(); dwarfemitdebugsections();
if(isobj) if(linkmode == LinkExternal)
elfemitreloc(); elfemitreloc();
} }
break; break;
......
...@@ -117,6 +117,7 @@ main(int argc, char *argv[]) ...@@ -117,6 +117,7 @@ main(int argc, char *argv[])
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);
flagfn1("linkmode", "mode: set link mode (internal, external, auto)", setlinkmode);
flagcount("n", "dump symbol table", &debug['n']); flagcount("n", "dump symbol table", &debug['n']);
flagstr("o", "outfile: set output file", &outfile); flagstr("o", "outfile: set output file", &outfile);
flagcount("p", "insert profiling code", &debug['p']); flagcount("p", "insert profiling code", &debug['p']);
...@@ -135,6 +136,11 @@ main(int argc, char *argv[]) ...@@ -135,6 +136,11 @@ main(int argc, char *argv[])
if(argc != 1) if(argc != 1)
usage(); usage();
if(linkmode != Linkinternal) {
diag("only -linkmode=internal is supported");
errorexit();
}
libinit(); libinit();
if(HEADTYPE == -1) if(HEADTYPE == -1)
......
...@@ -711,7 +711,7 @@ asmb(void) ...@@ -711,7 +711,7 @@ asmb(void)
dwarfemitdebugsections(); dwarfemitdebugsections();
if(isobj) if(linkmode == LinkExternal)
elfemitreloc(); elfemitreloc();
} }
break; break;
...@@ -735,7 +735,7 @@ asmb(void) ...@@ -735,7 +735,7 @@ asmb(void)
dwarfemitdebugsections(); dwarfemitdebugsections();
break; break;
case Hdarwin: case Hdarwin:
if(isobj) if(linkmode == LinkExternal)
machoemitreloc(); machoemitreloc();
break; break;
} }
......
...@@ -109,7 +109,7 @@ main(int argc, char *argv[]) ...@@ -109,7 +109,7 @@ main(int argc, char *argv[])
flagcount("d", "disable dynamic executable", &debug['d']); flagcount("d", "disable dynamic executable", &debug['d']);
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']);
flagcount("hostobj", "generate host object file", &isobj); flagfn1("linkmode", "mode: set link mode (internal, external, auto)", setlinkmode);
flagstr("k", "sym: set field tracking symbol", &tracksym); flagstr("k", "sym: set field tracking symbol", &tracksym);
flagcount("n", "dump symbol table", &debug['n']); flagcount("n", "dump symbol table", &debug['n']);
flagstr("o", "outfile: set output file", &outfile); flagstr("o", "outfile: set output file", &outfile);
...@@ -124,10 +124,6 @@ main(int argc, char *argv[]) ...@@ -124,10 +124,6 @@ main(int argc, char *argv[])
flagcount("w", "disable DWARF generation", &debug['w']); flagcount("w", "disable DWARF generation", &debug['w']);
flagparse(&argc, &argv, usage); flagparse(&argc, &argv, usage);
// TODO: link mode flag instead of isobj
if(isobj)
linkmode = LinkExternal;
if(argc != 1) if(argc != 1)
usage(); usage();
...@@ -137,17 +133,19 @@ main(int argc, char *argv[]) ...@@ -137,17 +133,19 @@ main(int argc, char *argv[])
if(HEADTYPE == -1) if(HEADTYPE == -1)
HEADTYPE = headtype(goos); HEADTYPE = headtype(goos);
if(isobj) { switch(HEADTYPE) {
switch(HEADTYPE) { default:
default: if(linkmode == LinkAuto)
sysfatal("cannot use -hostobj with -H %s", headstr(HEADTYPE)); linkmode = LinkInternal;
case Hdarwin: if(linkmode == LinkExternal)
case Hfreebsd: sysfatal("cannot use -linkmode=external with -H %s", headstr(HEADTYPE));
case Hlinux: break;
case Hnetbsd: case Hdarwin:
case Hopenbsd: case Hfreebsd:
break; case Hlinux:
} case Hnetbsd:
case Hopenbsd:
break;
} }
if(outfile == nil) { if(outfile == nil) {
......
...@@ -671,7 +671,7 @@ asmb(void) ...@@ -671,7 +671,7 @@ asmb(void)
Bprint(&bso, "%5.2f dwarf\n", cputime()); Bprint(&bso, "%5.2f dwarf\n", cputime());
dwarfemitdebugsections(); dwarfemitdebugsections();
if(isobj) if(linkmode == LinkExternal)
elfemitreloc(); elfemitreloc();
} }
break; break;
...@@ -694,7 +694,7 @@ asmb(void) ...@@ -694,7 +694,7 @@ asmb(void)
dwarfemitdebugsections(); dwarfemitdebugsections();
break; break;
case Hdarwin: case Hdarwin:
if(isobj) if(linkmode == LinkExternal)
machoemitreloc(); machoemitreloc();
break; break;
} }
......
...@@ -115,7 +115,7 @@ main(int argc, char *argv[]) ...@@ -115,7 +115,7 @@ main(int argc, char *argv[])
flagcount("d", "disable dynamic executable", &debug['d']); flagcount("d", "disable dynamic executable", &debug['d']);
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']);
flagcount("hostobj", "generate host object file", &isobj); flagfn1("linkmode", "mode: set link mode (internal, external, auto)", setlinkmode);
flagstr("k", "sym: set field tracking symbol", &tracksym); flagstr("k", "sym: set field tracking symbol", &tracksym);
flagstr("o", "outfile: set output file", &outfile); flagstr("o", "outfile: set output file", &outfile);
flagcount("p", "insert profiling code", &debug['p']); flagcount("p", "insert profiling code", &debug['p']);
...@@ -131,10 +131,6 @@ main(int argc, char *argv[]) ...@@ -131,10 +131,6 @@ main(int argc, char *argv[])
flagparse(&argc, &argv, usage); flagparse(&argc, &argv, usage);
// TODO: link mode flag instead of isobj
if(isobj)
linkmode = LinkExternal;
if(argc != 1) if(argc != 1)
usage(); usage();
...@@ -143,17 +139,19 @@ main(int argc, char *argv[]) ...@@ -143,17 +139,19 @@ main(int argc, char *argv[])
if(HEADTYPE == -1) if(HEADTYPE == -1)
HEADTYPE = headtype(goos); HEADTYPE = headtype(goos);
if(isobj) { switch(HEADTYPE) {
switch(HEADTYPE) { default:
default: if(linkmode == LinkAuto)
sysfatal("cannot use -hostobj with -H %s", headstr(HEADTYPE)); linkmode = LinkInternal;
case Hdarwin: if(linkmode == LinkExternal)
case Hfreebsd: sysfatal("cannot use -linkmode=external with -H %s", headstr(HEADTYPE));
case Hlinux: break;
case Hnetbsd: case Hdarwin:
case Hopenbsd: case Hfreebsd:
break; case Hlinux:
} case Hnetbsd:
case Hopenbsd:
break;
} }
if(outfile == nil) { if(outfile == nil) {
......
...@@ -178,11 +178,11 @@ relocsym(Sym *s) ...@@ -178,11 +178,11 @@ relocsym(Sym *s)
switch(r->type) { switch(r->type) {
default: default:
o = 0; o = 0;
if(isobj || archreloc(r, s, &o) < 0) if(linkmode == LinkExternal || archreloc(r, s, &o) < 0)
diag("unknown reloc %d", r->type); diag("unknown reloc %d", r->type);
break; break;
case D_ADDR: case D_ADDR:
if(isobj && r->sym->type != SCONST) { if(linkmode == LinkExternal && r->sym->type != SCONST) {
r->done = 0; r->done = 0;
// set up addend for eventual relocation via outer symbol. // set up addend for eventual relocation via outer symbol.
...@@ -212,7 +212,7 @@ relocsym(Sym *s) ...@@ -212,7 +212,7 @@ relocsym(Sym *s)
break; break;
case D_PCREL: case D_PCREL:
// r->sym can be null when CALL $(constant) is transformed from absolute PC to relative PC call. // r->sym can be null when CALL $(constant) is transformed from absolute PC to relative PC call.
if(isobj && r->sym && r->sym->type != SCONST && r->sym->sect != cursym->sect) { if(linkmode == LinkExternal && r->sym && r->sym->type != SCONST && r->sym->sect != cursym->sect) {
r->done = 0; r->done = 0;
// set up addend for eventual relocation via outer symbol. // set up addend for eventual relocation via outer symbol.
...@@ -630,7 +630,7 @@ datblk(int32 addr, int32 size) ...@@ -630,7 +630,7 @@ datblk(int32 addr, int32 size)
Bprint(&bso, " %.2ux", 0); Bprint(&bso, " %.2ux", 0);
Bprint(&bso, "\n"); Bprint(&bso, "\n");
if(isobj) { if(linkmode == LinkExternal) {
for(i=0; i<sym->nr; i++) { for(i=0; i<sym->nr; i++) {
r = &sym->r[i]; r = &sym->r[i];
rsname = ""; rsname = "";
......
...@@ -758,7 +758,7 @@ elfshbits(Section *sect) ...@@ -758,7 +758,7 @@ elfshbits(Section *sect)
sh->flags |= SHF_EXECINSTR; sh->flags |= SHF_EXECINSTR;
if(sect->rwx & 2) if(sect->rwx & 2)
sh->flags |= SHF_WRITE; sh->flags |= SHF_WRITE;
if(!isobj) if(linkmode != LinkExternal)
sh->addr = sect->vaddr; sh->addr = sect->vaddr;
sh->addralign = sect->align; sh->addralign = sect->align;
sh->size = sect->len; sh->size = sect->len;
...@@ -899,7 +899,7 @@ doelf(void) ...@@ -899,7 +899,7 @@ doelf(void)
addstring(shstrtab, ".gosymtab"); addstring(shstrtab, ".gosymtab");
addstring(shstrtab, ".gopclntab"); addstring(shstrtab, ".gopclntab");
if(isobj) { if(linkmode == LinkExternal) {
debug['s'] = 0; debug['s'] = 0;
debug['d'] = 1; debug['d'] = 1;
...@@ -1131,7 +1131,7 @@ asmbelf(vlong symo) ...@@ -1131,7 +1131,7 @@ asmbelf(vlong symo)
resoff = ELFRESERVE; resoff = ELFRESERVE;
pph = nil; pph = nil;
if(isobj) { if(linkmode == LinkExternal) {
/* skip program headers */ /* skip program headers */
eh->phoff = 0; eh->phoff = 0;
eh->phentsize = 0; eh->phentsize = 0;
...@@ -1392,7 +1392,7 @@ elfobj: ...@@ -1392,7 +1392,7 @@ elfobj:
for(sect=segdata.sect; sect!=nil; sect=sect->next) for(sect=segdata.sect; sect!=nil; sect=sect->next)
elfshbits(sect); elfshbits(sect);
if(isobj) { if(linkmode == LinkExternal) {
for(sect=segtext.sect; sect!=nil; sect=sect->next) for(sect=segtext.sect; sect!=nil; sect=sect->next)
elfshreloc(sect); elfshreloc(sect);
for(sect=segdata.sect; sect!=nil; sect=sect->next) for(sect=segdata.sect; sect!=nil; sect=sect->next)
...@@ -1415,8 +1415,8 @@ elfobj: ...@@ -1415,8 +1415,8 @@ elfobj:
sh->size = elfstrsize; sh->size = elfstrsize;
sh->addralign = 1; sh->addralign = 1;
// TODO(rsc): Enable for isobj too, once we know it works. // TODO(rsc): Enable for linkmode == LinkExternal too, once we know it works.
if(!isobj) if(linkmode != LinkExternal)
dwarfaddelfheaders(); dwarfaddelfheaders();
} }
...@@ -1440,12 +1440,12 @@ elfobj: ...@@ -1440,12 +1440,12 @@ elfobj:
if(flag_shared) if(flag_shared)
eh->type = ET_DYN; eh->type = ET_DYN;
else if(isobj) else if(linkmode == LinkExternal)
eh->type = ET_REL; eh->type = ET_REL;
else else
eh->type = ET_EXEC; eh->type = ET_EXEC;
if(!isobj) if(linkmode != LinkExternal)
eh->entry = entryvalue(); eh->entry = entryvalue();
eh->version = EV_CURRENT; eh->version = EV_CURRENT;
...@@ -1462,7 +1462,7 @@ elfobj: ...@@ -1462,7 +1462,7 @@ elfobj:
a += elfwriteshdrs(); a += elfwriteshdrs();
if(!debug['d']) if(!debug['d'])
a += elfwriteinterp(); a += elfwriteinterp();
if(!isobj) { if(linkmode != LinkExternal) {
if(HEADTYPE == Hnetbsd) if(HEADTYPE == Hnetbsd)
a += elfwritenetbsdsig(); a += elfwritenetbsdsig();
if(HEADTYPE == Hopenbsd) if(HEADTYPE == Hopenbsd)
......
...@@ -476,12 +476,10 @@ loadcgo(char *file, char *pkg, char *p, int n) ...@@ -476,12 +476,10 @@ loadcgo(char *file, char *pkg, char *p, int n)
if(strcmp(f[0], "cgo_import_static") == 0) { if(strcmp(f[0], "cgo_import_static") == 0) {
if(nf != 2) if(nf != 2)
goto err; goto err;
if(isobj) { local = f[1];
local = f[1]; s = lookup(local, 0);
s = lookup(local, 0); s->type = SHOSTOBJ;
s->type = SHOSTOBJ; s->size = 0;
s->size = 0;
}
continue; continue;
} }
...@@ -925,3 +923,18 @@ importcycles(void) ...@@ -925,3 +923,18 @@ importcycles(void)
for(p=pkgall; p; p=p->all) for(p=pkgall; p; p=p->all)
cycle(p); cycle(p);
} }
void
setlinkmode(char *arg)
{
if(strcmp(arg, "internal") == 0)
linkmode = LinkInternal;
else if(strcmp(arg, "external") == 0)
linkmode = LinkExternal;
else if(strcmp(arg, "auto") == 0)
linkmode = LinkAuto;
else {
fprint(2, "unknown link mode -linkmode %s\n", arg);
errorexit();
}
}
...@@ -170,6 +170,7 @@ EXTERN Segment segtext; ...@@ -170,6 +170,7 @@ EXTERN Segment segtext;
EXTERN Segment segdata; EXTERN Segment segdata;
EXTERN Segment segdwarf; EXTERN Segment segdwarf;
void setlinkmode(char*);
void addlib(char *src, char *obj); void addlib(char *src, char *obj);
void addlibpath(char *srcref, char *objref, char *file, char *pkg); void addlibpath(char *srcref, char *objref, char *file, char *pkg);
Section* addsection(Segment*, char*, int); Section* addsection(Segment*, char*, int);
......
...@@ -75,10 +75,11 @@ go run $GOROOT/test/run.go - . ...@@ -75,10 +75,11 @@ go run $GOROOT/test/run.go - .
[ "$CGO_ENABLED" != 1 ] || [ "$CGO_ENABLED" != 1 ] ||
(xcd ../misc/cgo/test (xcd ../misc/cgo/test
go test go test -ldflags '-linkmode=auto'
go test -ldflags '-linkmode=internal'
case "$GOHOSTOS-$GOARCH" in case "$GOHOSTOS-$GOARCH" in
darwin-386 | darwin-amd64 | freebsd-386 | freebsd-amd64 | linux-386 | linux-amd64 | netbsd-386 | netbsd-amd64 | openbsd-386 | openbsd-amd64) darwin-386 | darwin-amd64 | freebsd-386 | freebsd-amd64 | linux-386 | linux-amd64 | netbsd-386 | netbsd-amd64 | openbsd-386 | openbsd-amd64)
go test -ldflags '-w -hostobj' go test -ldflags '-linkmode=external'
esac esac
) || exit $? ) || exit $?
......
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