Commit 7f417d8d authored by Lucio De Re's avatar Lucio De Re Committed by Russ Cox

libmach: fix for Plan 9 build

R=rsc
CC=golang-dev
https://golang.org/cl/5316059
parent 17e493a2
...@@ -307,7 +307,7 @@ gsymoff(char *buf, int n, long v, int space) ...@@ -307,7 +307,7 @@ gsymoff(char *buf, int n, long v, int space)
if (!delta) if (!delta)
return snprint(buf, n, "%s", s.name); return snprint(buf, n, "%s", s.name);
if (s.type != 't' && s.type != 'T') 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 else
return snprint(buf, n, "#%lux", v); return snprint(buf, n, "#%lux", v);
} }
......
...@@ -125,7 +125,7 @@ i386excep(Map *map, Rgetter rget) ...@@ -125,7 +125,7 @@ i386excep(Map *map, Rgetter rget)
if (memcmp(buf, machdata->bpinst, machdata->bpsize) == 0) if (memcmp(buf, machdata->bpinst, machdata->bpsize) == 0)
return "breakpoint"; return "breakpoint";
} }
snprint(buf, sizeof(buf), "exception %ld", c); snprint(buf, sizeof(buf), "exception %d", c);
return buf; return buf;
} else } else
return excname[c]; return excname[c];
...@@ -1971,7 +1971,7 @@ plocal(Instr *ip) ...@@ -1971,7 +1971,7 @@ plocal(Instr *ip)
offset = ip->disp; offset = ip->disp;
if (!findsym(ip->addr, CTEXT, &s) || !findlocal(&s, FRAMENAME, &s)) { if (!findsym(ip->addr, CTEXT, &s) || !findlocal(&s, FRAMENAME, &s)) {
bprint(ip, "%lux(SP)", offset); bprint(ip, "%ux(SP)", offset);
return; return;
} }
...@@ -1987,7 +1987,7 @@ plocal(Instr *ip) ...@@ -1987,7 +1987,7 @@ plocal(Instr *ip)
bprint(ip, "%s+", s.name); bprint(ip, "%s+", s.name);
else else
offset = ip->disp; offset = ip->disp;
bprint(ip, "%lux%s", offset, reg); bprint(ip, "%ux%s", offset, reg);
} }
static int static int
...@@ -2061,7 +2061,7 @@ immediate(Instr *ip, vlong val) ...@@ -2061,7 +2061,7 @@ immediate(Instr *ip, vlong val)
w = -w; w = -w;
if (issymref(ip, &s, w, val)) { if (issymref(ip, &s, w, val)) {
if (w) if (w)
bprint(ip, "%s+%#lux(SB)", s.name, w); bprint(ip, "%s+%#ux(SB)", s.name, w);
else else
bprint(ip, "%s(SB)", s.name); bprint(ip, "%s(SB)", s.name);
return; return;
...@@ -2104,7 +2104,7 @@ pea(Instr *ip) ...@@ -2104,7 +2104,7 @@ pea(Instr *ip)
if (ip->base < 0) if (ip->base < 0)
immediate(ip, ip->disp); immediate(ip, ip->disp);
else { else {
bprint(ip, "%lux", ip->disp); bprint(ip, "%ux", ip->disp);
if(ip->rip) if(ip->rip)
bprint(ip, "(RIP)"); bprint(ip, "(RIP)");
bprint(ip,"(%s%s)", ANAME(ip), reg[ip->rex&REXB? ip->base+8: ip->base]); bprint(ip,"(%s%s)", ANAME(ip), reg[ip->rex&REXB? ip->base+8: ip->base]);
...@@ -2197,7 +2197,7 @@ prinstr(Instr *ip, char *fmt) ...@@ -2197,7 +2197,7 @@ prinstr(Instr *ip, char *fmt)
bprint(ip, "CBW"); bprint(ip, "CBW");
break; break;
case 'd': case 'd':
bprint(ip,"%ux:%lux",ip->seg,ip->disp); bprint(ip,"%ux:%ux", ip->seg, ip->disp);
break; break;
case 'm': case 'm':
if (ip->mod == 3 && ip->osize != 'B') { if (ip->mod == 3 && ip->osize != 'B') {
......
...@@ -677,7 +677,7 @@ elf64dotout(int fd, Fhdr *fp, ExecHdr *hp) ...@@ -677,7 +677,7 @@ elf64dotout(int fd, Fhdr *fp, ExecHdr *hp)
uint32 (*swal)(uint32); uint32 (*swal)(uint32);
ushort (*swab)(ushort); ushort (*swab)(ushort);
Ehdr64 *ep; Ehdr64 *ep;
Phdr64 *ph; Phdr64 *ph, *pph;
Shdr64 *sh; Shdr64 *sh;
int i, it, id, is, phsz, shsz; int i, it, id, is, phsz, shsz;
...@@ -797,7 +797,8 @@ elf64dotout(int fd, Fhdr *fp, ExecHdr *hp) ...@@ -797,7 +797,8 @@ elf64dotout(int fd, Fhdr *fp, ExecHdr *hp)
} }
settext(fp, ep->elfentry, ph[it].vaddr, ph[it].memsz, ph[it].offset); 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) if(is != -1)
setsym(fp, ph[is].offset, ph[is].filesz, 0, 0, 0, ph[is].memsz); setsym(fp, ph[is].offset, ph[is].filesz, 0, 0, 0, ph[is].memsz);
else if(sh != 0){ else if(sh != 0){
...@@ -1049,7 +1050,6 @@ machdotout(int fd, Fhdr *fp, ExecHdr *hp) ...@@ -1049,7 +1050,6 @@ machdotout(int fd, Fhdr *fp, ExecHdr *hp)
mp->sizeofcmds = swal(mp->sizeofcmds); mp->sizeofcmds = swal(mp->sizeofcmds);
mp->flags = swal(mp->flags); mp->flags = swal(mp->flags);
mp->reserved = swal(mp->reserved); mp->reserved = swal(mp->reserved);
hdrsize = 0;
switch(mp->magic) { switch(mp->magic) {
case 0xFEEDFACE: // 32-bit mach case 0xFEEDFACE: // 32-bit mach
...@@ -1104,7 +1104,9 @@ machdotout(int fd, Fhdr *fp, ExecHdr *hp) ...@@ -1104,7 +1104,9 @@ machdotout(int fd, Fhdr *fp, ExecHdr *hp)
datava = 0; datava = 0;
symtab = 0; symtab = 0;
pclntab = 0; pclntab = 0;
textsize = datasize = bsssize = 0; textsize = 0;
datasize = 0;
bsssize = 0;
for (i = 0; i < mp->ncmds; i++) { for (i = 0; i < mp->ncmds; i++) {
MachCmd *c; MachCmd *c;
...@@ -1379,7 +1381,8 @@ pedotout(int fd, Fhdr *fp, ExecHdr *hp) ...@@ -1379,7 +1381,8 @@ pedotout(int fd, Fhdr *fp, ExecHdr *hp)
} }
seek(fd, start+sizeof(magic)+sizeof(fh)+leswab(fh.SizeOfOptionalHeader), 0); 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; i<leswab(fh.NumberOfSections); i++) { for (i=0; i<leswab(fh.NumberOfSections); i++) {
if (readn(fd, &sh, sizeof(sh)) != sizeof(sh)) { if (readn(fd, &sh, sizeof(sh)) != sizeof(sh)) {
werrstr("could not read Section Header %d", i+1); werrstr("could not read Section Header %d", i+1);
...@@ -1398,7 +1401,7 @@ pedotout(int fd, Fhdr *fp, ExecHdr *hp) ...@@ -1398,7 +1401,7 @@ pedotout(int fd, Fhdr *fp, ExecHdr *hp)
seek(fd, leswal(fh.PointerToSymbolTable), 0); seek(fd, leswal(fh.PointerToSymbolTable), 0);
symtab = esymtab = 0; symtab = esymtab = 0;
for (i=0; i<leswal(fh.NumberOfSymbols); i++) { for (i=0; i<leswal(fh.NumberOfSymbols); i++) {
if (readn(fd, &sym, sizeof(sym)) != sizeof(sym)) { if (readn(fd, sym, sizeof(sym)) != sizeof(sym)) {
werrstr("crippled COFF symbol %d", i); werrstr("crippled COFF symbol %d", i);
return 0; return 0;
} }
...@@ -1452,7 +1455,6 @@ setsym(Fhdr *fp, vlong symoff, int32 symsz, vlong sppcoff, int32 sppcsz, vlong l ...@@ -1452,7 +1455,6 @@ setsym(Fhdr *fp, vlong symoff, int32 symsz, vlong sppcoff, int32 sppcsz, vlong l
fp->lnpcsz = lnpcsz; fp->lnpcsz = lnpcsz;
} }
static uvlong static uvlong
_round(uvlong a, uint32 b) _round(uvlong a, uint32 b)
{ {
......
...@@ -113,7 +113,7 @@ symoff(char *buf, int n, uvlong v, int space) ...@@ -113,7 +113,7 @@ symoff(char *buf, int n, uvlong v, int space)
if (s.type != 't' && s.type != 'T' && delta >= 4096) if (s.type != 't' && s.type != 'T' && delta >= 4096)
return snprint(buf, n, "%llux", v); return snprint(buf, n, "%llux", v);
else if (delta) else if (delta)
return snprint(buf, n, "%s+%#lux", s.name, delta); return snprint(buf, n, "%s+%#ux", s.name, delta);
else else
return snprint(buf, n, "%s", s.name); return snprint(buf, n, "%s", s.name);
} }
...@@ -139,7 +139,7 @@ fpformat(Map *map, Reglist *rp, char *buf, int n, int modif) ...@@ -139,7 +139,7 @@ fpformat(Map *map, Reglist *rp, char *buf, int n, int modif)
case 'X': case 'X':
if (get4(map, rp->roffs, &r) < 0) if (get4(map, rp->roffs, &r) < 0)
return -1; return -1;
snprint(buf, n, "%lux", r); snprint(buf, n, "%ux", r);
break; break;
case 'F': /* first reg of double reg pair */ case 'F': /* first reg of double reg pair */
if (modif == 'F') if (modif == 'F')
...@@ -219,12 +219,12 @@ ieeedftos(char *buf, int n, uint32 h, uint32 l) ...@@ -219,12 +219,12 @@ ieeedftos(char *buf, int n, uint32 h, uint32 l)
return snprint(buf, n, "0."); return snprint(buf, n, "0.");
exp = (h>>20) & ((1L<<11)-1L); exp = (h>>20) & ((1L<<11)-1L);
if(exp == 0) 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(exp == ((1L<<11)-1L)){
if(l==0 && (h&((1L<<20)-1L)) == 0) if(l==0 && (h&((1L<<20)-1L)) == 0)
return snprint(buf, n, "Inf"); return snprint(buf, n, "Inf");
else 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; exp -= (1L<<10) - 2L;
fr = l & ((1L<<16)-1L); fr = l & ((1L<<16)-1L);
...@@ -256,7 +256,7 @@ ieeesftos(char *buf, int n, uint32 h) ...@@ -256,7 +256,7 @@ ieeesftos(char *buf, int n, uint32 h)
return snprint(buf, n, "0."); return snprint(buf, n, "0.");
exp = (h>>23) & ((1L<<8)-1L); exp = (h>>23) & ((1L<<8)-1L);
if(exp == 0) if(exp == 0)
return snprint(buf, n, "DeN(%.8lux)", h); return snprint(buf, n, "DeN(%.8ux)", h);
if(exp == ((1L<<8)-1L)){ if(exp == ((1L<<8)-1L)){
if((h&((1L<<23)-1L)) == 0) if((h&((1L<<23)-1L)) == 0)
return snprint(buf, n, "Inf"); return snprint(buf, n, "Inf");
......
...@@ -124,7 +124,7 @@ syminit(int fd, Fhdr *fp) ...@@ -124,7 +124,7 @@ syminit(int fd, Fhdr *fp)
/* minimum symbol record size = 4+1+2 bytes */ /* minimum symbol record size = 4+1+2 bytes */
symbols = malloc((fp->symsz/(4+1+2)+1)*sizeof(Sym)); symbols = malloc((fp->symsz/(4+1+2)+1)*sizeof(Sym));
if(symbols == 0) { if(symbols == 0) {
werrstr("can't malloc %ld bytes", fp->symsz); werrstr("can't malloc %d bytes", fp->symsz);
return -1; return -1;
} }
Binit(&b, fd, OREAD); Binit(&b, fd, OREAD);
...@@ -203,11 +203,11 @@ syminit(int fd, Fhdr *fp) ...@@ -203,11 +203,11 @@ syminit(int fd, Fhdr *fp)
} }
} }
if (debug) 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 */ if (fp->sppcsz) { /* pc-sp offset table */
spoff = (uchar *)malloc(fp->sppcsz); spoff = (uchar *)malloc(fp->sppcsz);
if(spoff == 0) { if(spoff == 0) {
werrstr("can't malloc %ld bytes", fp->sppcsz); werrstr("can't malloc %d bytes", fp->sppcsz);
return -1; return -1;
} }
Bseek(&b, fp->sppcoff, 0); Bseek(&b, fp->sppcoff, 0);
...@@ -220,7 +220,7 @@ syminit(int fd, Fhdr *fp) ...@@ -220,7 +220,7 @@ syminit(int fd, Fhdr *fp)
if (fp->lnpcsz) { /* pc-line number table */ if (fp->lnpcsz) { /* pc-line number table */
pcline = (uchar *)malloc(fp->lnpcsz); pcline = (uchar *)malloc(fp->lnpcsz);
if(pcline == 0) { if(pcline == 0) {
werrstr("can't malloc %ld bytes", fp->lnpcsz); werrstr("can't malloc %d bytes", fp->lnpcsz);
return -1; return -1;
} }
Bseek(&b, fp->lnpcoff, 0); Bseek(&b, fp->lnpcoff, 0);
...@@ -280,12 +280,12 @@ decodename(Biobuf *bp, Sym *p) ...@@ -280,12 +280,12 @@ decodename(Biobuf *bp, Sym *p)
n = Bseek(bp, 0, 1)-o; n = Bseek(bp, 0, 1)-o;
p->name = malloc(n); p->name = malloc(n);
if(p->name == 0) { if(p->name == 0) {
werrstr("can't malloc %ld bytes", n); werrstr("can't malloc %d bytes", n);
return -1; return -1;
} }
Bseek(bp, -n, 1); Bseek(bp, -n, 1);
if(Bread(bp, p->name, n) != n) { 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; return -1;
} }
} else { } else {
...@@ -297,7 +297,7 @@ decodename(Biobuf *bp, Sym *p) ...@@ -297,7 +297,7 @@ decodename(Biobuf *bp, Sym *p)
n = Blinelen(bp); n = Blinelen(bp);
p->name = malloc(n); p->name = malloc(n);
if(p->name == 0) { if(p->name == 0) {
werrstr("can't malloc %ld bytes", n); werrstr("can't malloc %d bytes", n);
return -1; return -1;
} }
strcpy(p->name, cp); strcpy(p->name, cp);
...@@ -913,7 +913,7 @@ file2pc(char *file, int32 line) ...@@ -913,7 +913,7 @@ file2pc(char *file, int32 line)
break; break;
free(name); free(name);
if(i >= nfiles) { 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; return ~0;
} }
start = fp->addr; /* first text addr this file */ start = fp->addr; /* first text addr this file */
...@@ -926,10 +926,10 @@ file2pc(char *file, int32 line) ...@@ -926,10 +926,10 @@ file2pc(char *file, int32 line)
* run the state machine to locate the pc closest to that value. * run the state machine to locate the pc closest to that value.
*/ */
if(debug) 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); pc = line2addr(line, start, end);
if(pc == ~0) { if(pc == ~0) {
werrstr("line %ld not in file %s", line, file); werrstr("line %d not in file %s", line, file);
return ~0; return ~0;
} }
return pc; return pc;
...@@ -1146,7 +1146,7 @@ fline(char *str, int n, int32 line, Hist *base, Hist **ret) ...@@ -1146,7 +1146,7 @@ fline(char *str, int n, int32 line, Hist *base, Hist **ret)
else { else {
k = fileelem(fnames, (uchar*)start->name, str, n); k = fileelem(fnames, (uchar*)start->name, str, n);
if(k+8 < n) if(k+8 < n)
sprint(str+k, ":%ld", line); sprint(str+k, ":%d", line);
} }
/**********Remove comments for complete back-trace of include sequence /**********Remove comments for complete back-trace of include sequence
* if(start != base) { * if(start != base) {
...@@ -1404,7 +1404,7 @@ printhist(char *msg, Hist *hp, int count) ...@@ -1404,7 +1404,7 @@ printhist(char *msg, Hist *hp, int count)
while(hp->name) { while(hp->name) {
if(count && ++i > count) if(count && ++i > count)
break; 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); hp->line, hp->line, hp->offset, hp->offset);
for(cp = (uchar *)hp->name+1; (*cp<<8)|cp[1]; cp += 2) { for(cp = (uchar *)hp->name+1; (*cp<<8)|cp[1]; cp += 2) {
if (cp != (uchar *)hp->name+1) if (cp != (uchar *)hp->name+1)
......
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