From 7f417d8d6679fa0d6e8fdfee232a043706a414a0 Mon Sep 17 00:00:00 2001 From: Lucio De Re Date: Fri, 18 Nov 2011 23:11:50 -0500 Subject: [PATCH] libmach: fix for Plan 9 build R=rsc CC=golang-dev https://golang.org/cl/5316059 --- src/libmach/5db.c | 2 +- src/libmach/8db.c | 12 ++++++------ src/libmach/executable.c | 16 +++++++++------- src/libmach/machdata.c | 10 +++++----- src/libmach/sym.c | 24 ++++++++++++------------ 5 files changed, 33 insertions(+), 31 deletions(-) diff --git a/src/libmach/5db.c b/src/libmach/5db.c index aea391edfc..ae71dd90dc 100644 --- a/src/libmach/5db.c +++ b/src/libmach/5db.c @@ -307,7 +307,7 @@ gsymoff(char *buf, int n, long v, int space) if (!delta) return snprint(buf, n, "%s", s.name); if (s.type != 't' && s.type != 'T') - return snprint(buf, n, "%s+%lux", s.name, v-s.value); + return snprint(buf, n, "%s+%llux", s.name, v-s.value); else return snprint(buf, n, "#%lux", v); } diff --git a/src/libmach/8db.c b/src/libmach/8db.c index 5b3de69a51..a5d147a8e2 100644 --- a/src/libmach/8db.c +++ b/src/libmach/8db.c @@ -125,7 +125,7 @@ i386excep(Map *map, Rgetter rget) if (memcmp(buf, machdata->bpinst, machdata->bpsize) == 0) return "breakpoint"; } - snprint(buf, sizeof(buf), "exception %ld", c); + snprint(buf, sizeof(buf), "exception %d", c); return buf; } else return excname[c]; @@ -1971,7 +1971,7 @@ plocal(Instr *ip) offset = ip->disp; if (!findsym(ip->addr, CTEXT, &s) || !findlocal(&s, FRAMENAME, &s)) { - bprint(ip, "%lux(SP)", offset); + bprint(ip, "%ux(SP)", offset); return; } @@ -1987,7 +1987,7 @@ plocal(Instr *ip) bprint(ip, "%s+", s.name); else offset = ip->disp; - bprint(ip, "%lux%s", offset, reg); + bprint(ip, "%ux%s", offset, reg); } static int @@ -2061,7 +2061,7 @@ immediate(Instr *ip, vlong val) w = -w; if (issymref(ip, &s, w, val)) { if (w) - bprint(ip, "%s+%#lux(SB)", s.name, w); + bprint(ip, "%s+%#ux(SB)", s.name, w); else bprint(ip, "%s(SB)", s.name); return; @@ -2104,7 +2104,7 @@ pea(Instr *ip) if (ip->base < 0) immediate(ip, ip->disp); else { - bprint(ip, "%lux", ip->disp); + bprint(ip, "%ux", ip->disp); if(ip->rip) bprint(ip, "(RIP)"); bprint(ip,"(%s%s)", ANAME(ip), reg[ip->rex&REXB? ip->base+8: ip->base]); @@ -2197,7 +2197,7 @@ prinstr(Instr *ip, char *fmt) bprint(ip, "CBW"); break; case 'd': - bprint(ip,"%ux:%lux",ip->seg,ip->disp); + bprint(ip,"%ux:%ux", ip->seg, ip->disp); break; case 'm': if (ip->mod == 3 && ip->osize != 'B') { diff --git a/src/libmach/executable.c b/src/libmach/executable.c index 9d45323021..3db3e7da4d 100644 --- a/src/libmach/executable.c +++ b/src/libmach/executable.c @@ -677,7 +677,7 @@ elf64dotout(int fd, Fhdr *fp, ExecHdr *hp) uint32 (*swal)(uint32); ushort (*swab)(ushort); Ehdr64 *ep; - Phdr64 *ph; + Phdr64 *ph, *pph; Shdr64 *sh; int i, it, id, is, phsz, shsz; @@ -797,7 +797,8 @@ elf64dotout(int fd, Fhdr *fp, ExecHdr *hp) } settext(fp, ep->elfentry, ph[it].vaddr, ph[it].memsz, ph[it].offset); - setdata(fp, ph[id].vaddr, ph[id].filesz, ph[id].offset, ph[id].memsz - ph[id].filesz); + pph = ph + id; + setdata(fp, pph->vaddr, pph->filesz, pph->offset, pph->memsz - pph->filesz); if(is != -1) setsym(fp, ph[is].offset, ph[is].filesz, 0, 0, 0, ph[is].memsz); else if(sh != 0){ @@ -1049,7 +1050,6 @@ machdotout(int fd, Fhdr *fp, ExecHdr *hp) mp->sizeofcmds = swal(mp->sizeofcmds); mp->flags = swal(mp->flags); mp->reserved = swal(mp->reserved); - hdrsize = 0; switch(mp->magic) { case 0xFEEDFACE: // 32-bit mach @@ -1104,7 +1104,9 @@ machdotout(int fd, Fhdr *fp, ExecHdr *hp) datava = 0; symtab = 0; pclntab = 0; - textsize = datasize = bsssize = 0; + textsize = 0; + datasize = 0; + bsssize = 0; for (i = 0; i < mp->ncmds; i++) { MachCmd *c; @@ -1379,7 +1381,8 @@ pedotout(int fd, Fhdr *fp, ExecHdr *hp) } seek(fd, start+sizeof(magic)+sizeof(fh)+leswab(fh.SizeOfOptionalHeader), 0); - fp->txtaddr = fp->dataddr = 0; + fp->txtaddr = 0; + fp->dataddr = 0; for (i=0; ilnpcsz = lnpcsz; } - static uvlong _round(uvlong a, uint32 b) { diff --git a/src/libmach/machdata.c b/src/libmach/machdata.c index 425a921794..66c19f9537 100644 --- a/src/libmach/machdata.c +++ b/src/libmach/machdata.c @@ -113,7 +113,7 @@ symoff(char *buf, int n, uvlong v, int space) if (s.type != 't' && s.type != 'T' && delta >= 4096) return snprint(buf, n, "%llux", v); else if (delta) - return snprint(buf, n, "%s+%#lux", s.name, delta); + return snprint(buf, n, "%s+%#ux", s.name, delta); else return snprint(buf, n, "%s", s.name); } @@ -139,7 +139,7 @@ fpformat(Map *map, Reglist *rp, char *buf, int n, int modif) case 'X': if (get4(map, rp->roffs, &r) < 0) return -1; - snprint(buf, n, "%lux", r); + snprint(buf, n, "%ux", r); break; case 'F': /* first reg of double reg pair */ if (modif == 'F') @@ -219,12 +219,12 @@ ieeedftos(char *buf, int n, uint32 h, uint32 l) return snprint(buf, n, "0."); exp = (h>>20) & ((1L<<11)-1L); if(exp == 0) - return snprint(buf, n, "DeN(%.8lux%.8lux)", h, l); + return snprint(buf, n, "DeN(%.8ux%.8ux)", h, l); if(exp == ((1L<<11)-1L)){ if(l==0 && (h&((1L<<20)-1L)) == 0) return snprint(buf, n, "Inf"); else - return snprint(buf, n, "NaN(%.8lux%.8lux)", h&((1L<<20)-1L), l); + return snprint(buf, n, "NaN(%.8ux%.8ux)", h&((1<<20)-1), l); } exp -= (1L<<10) - 2L; fr = l & ((1L<<16)-1L); @@ -256,7 +256,7 @@ ieeesftos(char *buf, int n, uint32 h) return snprint(buf, n, "0."); exp = (h>>23) & ((1L<<8)-1L); if(exp == 0) - return snprint(buf, n, "DeN(%.8lux)", h); + return snprint(buf, n, "DeN(%.8ux)", h); if(exp == ((1L<<8)-1L)){ if((h&((1L<<23)-1L)) == 0) return snprint(buf, n, "Inf"); diff --git a/src/libmach/sym.c b/src/libmach/sym.c index 5e4fdd8673..1512d7a4fe 100644 --- a/src/libmach/sym.c +++ b/src/libmach/sym.c @@ -124,7 +124,7 @@ syminit(int fd, Fhdr *fp) /* minimum symbol record size = 4+1+2 bytes */ symbols = malloc((fp->symsz/(4+1+2)+1)*sizeof(Sym)); if(symbols == 0) { - werrstr("can't malloc %ld bytes", fp->symsz); + werrstr("can't malloc %d bytes", fp->symsz); return -1; } Binit(&b, fd, OREAD); @@ -203,11 +203,11 @@ syminit(int fd, Fhdr *fp) } } if (debug) - print("NG: %ld NT: %d NF: %d\n", nglob, ntxt, fmaxi); + print("NG: %d NT: %d NF: %d\n", nglob, ntxt, fmaxi); if (fp->sppcsz) { /* pc-sp offset table */ spoff = (uchar *)malloc(fp->sppcsz); if(spoff == 0) { - werrstr("can't malloc %ld bytes", fp->sppcsz); + werrstr("can't malloc %d bytes", fp->sppcsz); return -1; } Bseek(&b, fp->sppcoff, 0); @@ -220,7 +220,7 @@ syminit(int fd, Fhdr *fp) if (fp->lnpcsz) { /* pc-line number table */ pcline = (uchar *)malloc(fp->lnpcsz); if(pcline == 0) { - werrstr("can't malloc %ld bytes", fp->lnpcsz); + werrstr("can't malloc %d bytes", fp->lnpcsz); return -1; } Bseek(&b, fp->lnpcoff, 0); @@ -280,12 +280,12 @@ decodename(Biobuf *bp, Sym *p) n = Bseek(bp, 0, 1)-o; p->name = malloc(n); if(p->name == 0) { - werrstr("can't malloc %ld bytes", n); + werrstr("can't malloc %d bytes", n); return -1; } Bseek(bp, -n, 1); if(Bread(bp, p->name, n) != n) { - werrstr("can't read %ld bytes of symbol name", n); + werrstr("can't read %d bytes of symbol name", n); return -1; } } else { @@ -297,7 +297,7 @@ decodename(Biobuf *bp, Sym *p) n = Blinelen(bp); p->name = malloc(n); if(p->name == 0) { - werrstr("can't malloc %ld bytes", n); + werrstr("can't malloc %d bytes", n); return -1; } strcpy(p->name, cp); @@ -913,7 +913,7 @@ file2pc(char *file, int32 line) break; free(name); if(i >= nfiles) { - werrstr("line %ld in file %s not found", line, file); + werrstr("line %d in file %s not found", line, file); return ~0; } start = fp->addr; /* first text addr this file */ @@ -926,10 +926,10 @@ file2pc(char *file, int32 line) * run the state machine to locate the pc closest to that value. */ if(debug) - print("find pc for %ld - between: %llux and %llux\n", line, start, end); + print("find pc for %d - between: %llux and %llux\n", line, start, end); pc = line2addr(line, start, end); if(pc == ~0) { - werrstr("line %ld not in file %s", line, file); + werrstr("line %d not in file %s", line, file); return ~0; } return pc; @@ -1146,7 +1146,7 @@ fline(char *str, int n, int32 line, Hist *base, Hist **ret) else { k = fileelem(fnames, (uchar*)start->name, str, n); if(k+8 < n) - sprint(str+k, ":%ld", line); + sprint(str+k, ":%d", line); } /**********Remove comments for complete back-trace of include sequence * if(start != base) { @@ -1404,7 +1404,7 @@ printhist(char *msg, Hist *hp, int count) while(hp->name) { if(count && ++i > count) break; - print("%s Line: %lx (%ld) Offset: %lx (%ld) Name: ", msg, + print("%s Line: %x (%d) Offset: %x (%d) Name: ", msg, hp->line, hp->line, hp->offset, hp->offset); for(cp = (uchar *)hp->name+1; (*cp<<8)|cp[1]; cp += 2) { if (cp != (uchar *)hp->name+1)