diff options
| author | Russ Cox <rsc@golang.org> | 2015-02-24 21:40:57 -0500 |
|---|---|---|
| committer | Russ Cox <rsc@golang.org> | 2015-02-26 19:44:08 +0000 |
| commit | 26438d4d80c8c517f1d287d065ad7a967160281e (patch) | |
| tree | 326038eacf38d8fa2f8ace860a43ea8212b2fc94 /src/liblink/objfile.c | |
| parent | a5eda13d20405c659203db34f6d30942ca67fb96 (diff) | |
| download | go-26438d4d80c8c517f1d287d065ad7a967160281e.tar.xz | |
liblink: delete unused code
Liblink is still needed for the linker (for a bit longer) but mostly not.
Delete the unused parts.
Change-Id: Ie63a7c1520dee52b17425b384943cd16262d36e3
Reviewed-on: https://go-review.googlesource.com/6110
Reviewed-by: Rob Pike <r@golang.org>
Reviewed-by: Brad Fitzpatrick <bradfitz@golang.org>
Diffstat (limited to 'src/liblink/objfile.c')
| -rw-r--r-- | src/liblink/objfile.c | 428 |
1 files changed, 0 insertions, 428 deletions
diff --git a/src/liblink/objfile.c b/src/liblink/objfile.c index 99f5e97607..ab88c45550 100644 --- a/src/liblink/objfile.c +++ b/src/liblink/objfile.c @@ -105,442 +105,14 @@ #include "../cmd/ld/textflag.h" #include "../runtime/funcdata.h" -static void writesym(Link*, Biobuf*, LSym*); -static void wrint(Biobuf*, int64); -static void wrstring(Biobuf*, char*); -static void wrpath(Link *, Biobuf*, char*); -static void wrdata(Biobuf*, void*, int); -static void wrsym(Biobuf*, LSym*); -static void wrpathsym(Link *ctxt, Biobuf *b, LSym *s); - static void readsym(Link*, Biobuf*, char*, char*); static int64 rdint(Biobuf*); static char *rdstring(Biobuf*); static void rddata(Biobuf*, uchar**, int*); static LSym *rdsym(Link*, Biobuf*, char*); -void writeobjdirect(Link *ctxt, Biobuf *b); - -void writeobjgo1(Link*, char*); -void writeobjgo2(Link*, char*, int64); - extern char *outfile; -void -writeobj(Link *ctxt, Biobuf *b) -{ - vlong start; - char *env; - - // If $GOOBJ > 0, invoke the Go version of the liblink - // output routines via a subprocess. - // If $GOOBJ == 1, copy that subprocess's output to - // the actual output file. - // If $GOOBJ >= 2, generate output using the usual C version - // but then check that the subprocess wrote the same bytes. - // $GOOBJ is a temporary setting for the transition to a - // Go liblink back end. Once the C liblink back ends are deleted, - // we will hard code the GOOBJ=1 behavior. - env = getenv("GOOBJ"); - if(env == nil) - env = "0"; - if(atoi(env) == 0) { - writeobjdirect(ctxt, b); - return; - } - - Bflush(b); - start = Boffset(b); - writeobjgo1(ctxt, outfile); - if(atoi(env) > 1) { - writeobjdirect(ctxt, b); - Bflush(b); - } - writeobjgo2(ctxt, outfile, start); - Bseek(b, 0, 2); -} - -// The Go and C compilers, and the assembler, call writeobj to write -// out a Go object file. The linker does not call this; the linker -// does not write out object files. -void -writeobjdirect(Link *ctxt, Biobuf *b) -{ - int flag, found; - Hist *h; - LSym *s, *text, *etext, *curtext, *data, *edata; - Plist *pl; - Prog *p, *plink; - Auto *a; - - // Build list of symbols, and assign instructions to lists. - // Ignore ctxt->plist boundaries. There are no guarantees there, - // and the C compilers and assemblers just use one big list. - text = nil; - curtext = nil; - data = nil; - etext = nil; - edata = nil; - for(pl = ctxt->plist; pl != nil; pl = pl->link) { - for(p = pl->firstpc; p != nil; p = plink) { - if(ctxt->debugasm && ctxt->debugvlog) - print("obj: %P\n", p); - plink = p->link; - p->link = nil; - - if(p->as == AEND) - continue; - - if(p->as == ATYPE) { - // Assume each TYPE instruction describes - // a different local variable or parameter, - // so no dedup. - // Using only the TYPE instructions means - // that we discard location information about local variables - // in C and assembly functions; that information is inferred - // from ordinary references, because there are no TYPE - // instructions there. Without the type information, gdb can't - // use the locations, so we don't bother to save them. - // If something else could use them, we could arrange to - // preserve them. - if(curtext == nil) - continue; - a = emallocz(sizeof *a); - a->asym = p->from.sym; - a->aoffset = p->from.offset; - a->name = p->from.name; - a->gotype = p->from.gotype; - a->link = curtext->autom; - curtext->autom = a; - continue; - } - - if(p->as == AGLOBL) { - s = p->from.sym; - if(s->seenglobl++) - print("duplicate %P\n", p); - if(s->onlist) - sysfatal("symbol %s listed multiple times", s->name); - s->onlist = 1; - if(data == nil) - data = s; - else - edata->next = s; - s->next = nil; - s->size = p->to.offset; - if(s->type == 0 || s->type == SXREF) - s->type = SBSS; - flag = p->from3.offset; - if(flag & DUPOK) - s->dupok = 1; - if(flag & RODATA) - s->type = SRODATA; - else if(flag & NOPTR) - s->type = SNOPTRBSS; - edata = s; - continue; - } - - if(p->as == ADATA) { - savedata(ctxt, p->from.sym, p, "<input>"); - continue; - } - - if(p->as == ATEXT) { - s = p->from.sym; - if(s == nil) { - // func _() { } - curtext = nil; - continue; - } - if(s->text != nil) - sysfatal("duplicate TEXT for %s", s->name); - if(s->onlist) - sysfatal("symbol %s listed multiple times", s->name); - s->onlist = 1; - if(text == nil) - text = s; - else - etext->next = s; - etext = s; - flag = p->from3.offset; - if(flag & DUPOK) - s->dupok = 1; - if(flag & NOSPLIT) - s->nosplit = 1; - s->next = nil; - s->type = STEXT; - s->text = p; - s->etext = p; - curtext = s; - continue; - } - - if(p->as == AFUNCDATA) { - // Rewrite reference to go_args_stackmap(SB) to the Go-provided declaration information. - if(curtext == nil) // func _() {} - continue; - if(strcmp(p->to.sym->name, "go_args_stackmap") == 0) { - if(p->from.type != TYPE_CONST || p->from.offset != FUNCDATA_ArgsPointerMaps) - ctxt->diag("FUNCDATA use of go_args_stackmap(SB) without FUNCDATA_ArgsPointerMaps"); - p->to.sym = linklookup(ctxt, smprint("%s.args_stackmap", curtext->name), curtext->version); - } - } - - if(curtext == nil) - continue; - s = curtext; - s->etext->link = p; - s->etext = p; - } - } - - // Add reference to Go arguments for C or assembly functions without them. - for(s = text; s != nil; s = s->next) { - if(strncmp(s->name, "\"\".", 3) != 0) - continue; - found = 0; - for(p = s->text; p != nil; p = p->link) { - if(p->as == AFUNCDATA && p->from.type == TYPE_CONST && p->from.offset == FUNCDATA_ArgsPointerMaps) { - found = 1; - break; - } - } - if(!found) { - p = appendp(ctxt, s->text); - p->as = AFUNCDATA; - p->from.type = TYPE_CONST; - p->from.offset = FUNCDATA_ArgsPointerMaps; - p->to.type = TYPE_MEM; - p->to.name = NAME_EXTERN; - p->to.sym = linklookup(ctxt, smprint("%s.args_stackmap", s->name), s->version); - } - } - - // Turn functions into machine code images. - for(s = text; s != nil; s = s->next) { - mkfwd(s); - linkpatch(ctxt, s); - ctxt->arch->follow(ctxt, s); - ctxt->arch->preprocess(ctxt, s); - ctxt->arch->assemble(ctxt, s); - linkpcln(ctxt, s); - } - - // Emit header. - Bputc(b, 0); - Bputc(b, 0); - Bprint(b, "go13ld"); - Bputc(b, 1); // version - - // Emit autolib. - for(h = ctxt->hist; h != nil; h = h->link) - if(h->offset < 0) - wrstring(b, h->name); - wrstring(b, ""); - - // Emit symbols. - for(s = text; s != nil; s = s->next) - writesym(ctxt, b, s); - for(s = data; s != nil; s = s->next) - writesym(ctxt, b, s); - - // Emit footer. - Bputc(b, 0xff); - Bputc(b, 0xff); - Bprint(b, "go13ld"); -} - -static void -writesym(Link *ctxt, Biobuf *b, LSym *s) -{ - Reloc *r; - int i, j, c, n; - Pcln *pc; - Prog *p; - Auto *a; - char *name; - - if(ctxt->debugasm) { - Bprint(ctxt->bso, "%s ", s->name); - if(s->version) - Bprint(ctxt->bso, "v=%d ", s->version); - if(s->type) - Bprint(ctxt->bso, "t=%d ", s->type); - if(s->dupok) - Bprint(ctxt->bso, "dupok "); - if(s->cfunc) - Bprint(ctxt->bso, "cfunc "); - if(s->nosplit) - Bprint(ctxt->bso, "nosplit "); - Bprint(ctxt->bso, "size=%lld value=%lld", (vlong)s->size, (vlong)s->value); - if(s->type == STEXT) { - Bprint(ctxt->bso, " args=%#llux locals=%#llux", (uvlong)s->args, (uvlong)s->locals); - if(s->leaf) - Bprint(ctxt->bso, " leaf"); - } - Bprint(ctxt->bso, "\n"); - for(p=s->text; p != nil; p = p->link) - Bprint(ctxt->bso, "\t%#06ux %P\n", (int)p->pc, p); - for(i=0; i<s->np; ) { - Bprint(ctxt->bso, "\t%#06ux", i); - for(j=i; j<i+16 && j<s->np; j++) - Bprint(ctxt->bso, " %02ux", s->p[j]); - for(; j<i+16; j++) - Bprint(ctxt->bso, " "); - Bprint(ctxt->bso, " "); - for(j=i; j<i+16 && j<s->np; j++) { - c = s->p[j]; - if(' ' <= c && c <= 0x7e) - Bprint(ctxt->bso, "%c", c); - else - Bprint(ctxt->bso, "."); - } - Bprint(ctxt->bso, "\n"); - i += 16; - } - for(i=0; i<s->nr; i++) { - r = &s->r[i]; - name = ""; - if(r->sym != nil) - name = r->sym->name; - if(ctxt->arch->thechar == '5' || ctxt->arch->thechar == '9') - Bprint(ctxt->bso, "\trel %d+%d t=%d %s+%llux\n", (int)r->off, r->siz, r->type, name, (vlong)r->add); - else - Bprint(ctxt->bso, "\trel %d+%d t=%d %s+%lld\n", (int)r->off, r->siz, r->type, name, (vlong)r->add); - } - } - - Bputc(b, 0xfe); - wrint(b, s->type); - wrstring(b, s->name); - wrint(b, s->version); - wrint(b, s->dupok); - wrint(b, s->size); - wrsym(b, s->gotype); - wrdata(b, s->p, s->np); - - wrint(b, s->nr); - for(i=0; i<s->nr; i++) { - r = &s->r[i]; - wrint(b, r->off); - wrint(b, r->siz); - wrint(b, r->type); - wrint(b, r->add); - wrint(b, r->xadd); - wrsym(b, r->sym); - wrsym(b, r->xsym); - } - - if(s->type == STEXT) { - wrint(b, s->args); - wrint(b, s->locals); - wrint(b, s->nosplit); - wrint(b, s->leaf | s->cfunc<<1); - n = 0; - for(a = s->autom; a != nil; a = a->link) - n++; - wrint(b, n); - for(a = s->autom; a != nil; a = a->link) { - wrsym(b, a->asym); - wrint(b, a->aoffset); - if(a->name == NAME_AUTO) - wrint(b, A_AUTO); - else if(a->name == NAME_PARAM) - wrint(b, A_PARAM); - else - sysfatal("%s: invalid local variable type %d", s->name, a->name); - wrsym(b, a->gotype); - } - - pc = s->pcln; - wrdata(b, pc->pcsp.p, pc->pcsp.n); - wrdata(b, pc->pcfile.p, pc->pcfile.n); - wrdata(b, pc->pcline.p, pc->pcline.n); - wrint(b, pc->npcdata); - for(i=0; i<pc->npcdata; i++) - wrdata(b, pc->pcdata[i].p, pc->pcdata[i].n); - wrint(b, pc->nfuncdata); - for(i=0; i<pc->nfuncdata; i++) - wrsym(b, pc->funcdata[i]); - for(i=0; i<pc->nfuncdata; i++) - wrint(b, pc->funcdataoff[i]); - wrint(b, pc->nfile); - for(i=0; i<pc->nfile; i++) - wrpathsym(ctxt, b, pc->file[i]); - } -} - -static void -wrint(Biobuf *b, int64 sval) -{ - uint64 uv, v; - uchar buf[10], *p; - - uv = ((uint64)sval<<1) ^ (uint64)(int64)(sval>>63); - - p = buf; - for(v = uv; v >= 0x80; v >>= 7) - *p++ = v | 0x80; - *p++ = v; - - Bwrite(b, buf, p - buf); -} - -static void -wrstring(Biobuf *b, char *s) -{ - wrdata(b, s, strlen(s)); -} - -// wrpath writes a path just like a string, but on windows, it -// translates '\\' to '/' in the process. -static void -wrpath(Link *ctxt, Biobuf *b, char *p) -{ - int i, n; - if (!ctxt->windows || strchr(p, '\\') == nil) { - wrstring(b, p); - return; - } else { - n = strlen(p); - wrint(b, n); - for (i = 0; i < n; i++) - Bputc(b, p[i] == '\\' ? '/' : p[i]); - } -} - -static void -wrdata(Biobuf *b, void *v, int n) -{ - wrint(b, n); - Bwrite(b, v, n); -} - -static void -wrpathsym(Link *ctxt, Biobuf *b, LSym *s) -{ - if(s == nil) { - wrint(b, 0); - wrint(b, 0); - return; - } - wrpath(ctxt, b, s->name); - wrint(b, s->version); -} - -static void -wrsym(Biobuf *b, LSym *s) -{ - if(s == nil) { - wrint(b, 0); - wrint(b, 0); - return; - } - wrstring(b, s->name); - wrint(b, s->version); -} - static char startmagic[] = "\x00\x00go13ld"; static char endmagic[] = "\xff\xffgo13ld"; |
