diff options
| author | Russ Cox <rsc@golang.org> | 2013-02-26 22:38:14 -0500 |
|---|---|---|
| committer | Russ Cox <rsc@golang.org> | 2013-02-26 22:38:14 -0500 |
| commit | c8dcaeb25deddac52cfca6ae6882ce94780582d3 (patch) | |
| tree | d12f5b99253e3e8a8f1606afebc8d5908470da88 /src/cmd/ld/lib.c | |
| parent | 15cce227c78ac2b499e9ad3c49ccb67d2f870169 (diff) | |
| download | go-c8dcaeb25deddac52cfca6ae6882ce94780582d3.tar.xz | |
cmd/ld, runtime: adjust symbol table representation
This CL changes the encoding used for the Go symbol table,
stored in the binary and used at run time. It does not change
any of the semantics or structure: the bits are just packed
a little differently.
The comment at the top of runtime/symtab.c describes the new format.
Compared to the Go 1.0 format, the main changes are:
* Store symbol addresses as full-pointer-sized host-endian values.
(For 6g, this means addresses are 64-bit little-endian.)
* Store other values (frame sizes and so on) varint-encoded.
The second change more than compensates for the first:
for the godoc binary on OS X/amd64, the new symbol table
is 8% smaller than the old symbol table (1,425,668 down from 1,546,276).
This is a required step for allowing the host linker (gcc) to write
the final Go binary, since it will have to fill in the symbol address slots
(so the slots must be host-endian) and on 64-bit systems it may
choose addresses above 4 GB.
R=golang-dev, iant
CC=golang-dev
https://golang.org/cl/7403054
Diffstat (limited to 'src/cmd/ld/lib.c')
| -rw-r--r-- | src/cmd/ld/lib.c | 34 |
1 files changed, 28 insertions, 6 deletions
diff --git a/src/cmd/ld/lib.c b/src/cmd/ld/lib.c index 4f0b87466b..26fa4f2ac7 100644 --- a/src/cmd/ld/lib.c +++ b/src/cmd/ld/lib.c @@ -1564,6 +1564,7 @@ genasmsym(void (*put)(Sym*, char*, int, vlong, vlong, int, Sym*)) { Auto *a; Sym *s; + int32 off; // These symbols won't show up in the first loop below because we // skip STEXT symbols. Normal STEXT symbols are emitted by walking textp. @@ -1627,16 +1628,37 @@ genasmsym(void (*put)(Sym*, char*, int, vlong, vlong, int, Sym*)) put(s, s->name, 'T', s->value, s->size, s->version, s->gotype); /* frame, locals, args, auto and param after */ - put(nil, ".frame", 'm', s->text->to.offset+PtrSize, 0, 0, 0); + put(nil, ".frame", 'm', (uint32)s->text->to.offset+PtrSize, 0, 0, 0); put(nil, ".locals", 'm', s->locals, 0, 0, 0); put(nil, ".args", 'm', s->args, 0, 0, 0); - for(a=s->autom; a; a=a->link) - if(a->type == D_AUTO) - put(nil, a->asym->name, 'a', -a->aoffset, 0, 0, a->gotype); - else + for(a=s->autom; a; a=a->link) { + // Emit a or p according to actual offset, even if label is wrong. + // This avoids negative offsets, which cannot be encoded. + if(a->type != D_AUTO && a->type != D_PARAM) + continue; + + // compute offset relative to FP if(a->type == D_PARAM) - put(nil, a->asym->name, 'p', a->aoffset, 0, 0, a->gotype); + off = a->aoffset; + else + off = a->aoffset - PtrSize; + + // FP + if(off >= 0) { + put(nil, a->asym->name, 'p', off, 0, 0, a->gotype); + continue; + } + + // SP + if(off <= -PtrSize) { + put(nil, a->asym->name, 'a', -(off+PtrSize), 0, 0, a->gotype); + continue; + } + + // Otherwise, off is addressing the saved program counter. + // Something underhanded is going on. Say nothing. + } } if(debug['v'] || debug['n']) Bprint(&bso, "symsize = %ud\n", symsize); |
