diff options
| author | Russ Cox <rsc@golang.org> | 2013-01-31 14:11:32 -0800 |
|---|---|---|
| committer | Russ Cox <rsc@golang.org> | 2013-01-31 14:11:32 -0800 |
| commit | 0cb0f6d0902aff683de5535565e923c45f8d5a8a (patch) | |
| tree | 03e93da3601b89db9d4de1e6b7cdcb706e04d9e4 /src/cmd/8l | |
| parent | 739aa6b1ba6f643a37370d569c5f67827f5c370c (diff) | |
| download | go-0cb0f6d0902aff683de5535565e923c45f8d5a8a.tar.xz | |
cmd/ld: support for linking with host linker
A step toward a fix for issue 4069.
To allow linking with arbitrary host object files, add a linker mode
that can generate a host object file instead of an executable.
Then the host linker can be invoked to generate the final executable.
This CL adds a new -hostobj flag that instructs the linker to write
a host object file instead of an executable.
That is, this works:
go tool 6g x.go
go tool 6l -hostobj -o x.o x.6
ld -e _rt0_amd64_linux x.o
./a.out
as does:
go tool 8g x.go
go tool 8l -hostld ignored -o x.o x.8
ld -m elf_i386 -e _rt0_386_linux x.o
./a.out
Because 5l was never updated to use the standard relocation scheme,
it will take more work to get this working on ARM.
This is a checkpoint of the basic functionality. It does not work
with cgo yet, and cgo is the main reason for the change.
The command-line interface will likely change too.
The gc linker has other information that needs to be returned to
the caller for use when invoking the host linker besides the single
object file.
R=iant, iant
CC=golang-dev
https://golang.org/cl/7060044
Diffstat (limited to 'src/cmd/8l')
| -rw-r--r-- | src/cmd/8l/asm.c | 32 | ||||
| -rw-r--r-- | src/cmd/8l/obj.c | 10 |
2 files changed, 42 insertions, 0 deletions
diff --git a/src/cmd/8l/asm.c b/src/cmd/8l/asm.c index 2cdf4ff2ab..76ebdb9135 100644 --- a/src/cmd/8l/asm.c +++ b/src/cmd/8l/asm.c @@ -266,6 +266,35 @@ adddynrel(Sym *s, Reloc *r) diag("unsupported relocation for dynamic symbol %s (type=%d stype=%d)", targ->name, r->type, targ->type); } +int +elfreloc1(Reloc *r, vlong off, int32 elfsym, vlong add) +{ + USED(add); // written to obj file by ../ld/data.c's reloc + + LPUT(off); + + switch(r->type) { + default: + return -1; + + case D_ADDR: + if(r->siz == 4) + LPUT(R_386_32 | elfsym<<8); + else + return -1; + break; + + case D_PCREL: + if(r->siz == 4) + LPUT(R_386_PC32 | elfsym<<8); + else + return -1; + break; + } + + return 0; +} + void elfsetupplt(void) { @@ -633,6 +662,9 @@ asmb(void) if(debug['v']) Bprint(&bso, "%5.2f dwarf\n", cputime()); dwarfemitdebugsections(); + + if(isobj) + elfemitreloc(); } break; case Hplan9x32: diff --git a/src/cmd/8l/obj.c b/src/cmd/8l/obj.c index 74820e6334..c334a81f60 100644 --- a/src/cmd/8l/obj.c +++ b/src/cmd/8l/obj.c @@ -114,6 +114,7 @@ main(int argc, char *argv[]) flagcount("d", "disable dynamic executable", &debug['d']); flagcount("f", "ignore version mismatch", &debug['f']); flagcount("g", "disable go package data checks", &debug['g']); + flagcount("hostobj", "generate host object file", &hostobj); flagstr("k", "sym: set field tracking symbol", &tracksym); flagstr("o", "outfile: set output file", &outfile); flagcount("p", "insert profiling code", &debug['p']); @@ -135,6 +136,15 @@ main(int argc, char *argv[]) if(HEADTYPE == -1) HEADTYPE = headtype(goos); + if(isobj) { + switch(HEADTYPE) { + default: + sysfatal("cannot use -hostobj with -H %s", headstr(HEADTYPE)); + case Hlinux: + break; + } + } + if(outfile == nil) { if(HEADTYPE == Hwindows) outfile = "8.out.exe"; |
