libmach: fix for Plan 9 build

R=rsc
CC=golang-dev
https://golang.org/cl/5316059
diff --git a/src/libmach/5db.c b/src/libmach/5db.c
index aea391e..ae71dd9 100644
--- a/src/libmach/5db.c
+++ b/src/libmach/5db.c
@@ -307,7 +307,7 @@
 	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 5b3de69..a5d147a 100644
--- a/src/libmach/8db.c
+++ b/src/libmach/8db.c
@@ -125,7 +125,7 @@
 			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 @@
 
 	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 @@
 		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 @@
 			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 @@
 		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 @@
 				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 9d45323..3db3e7d 100644
--- a/src/libmach/executable.c
+++ b/src/libmach/executable.c
@@ -677,7 +677,7 @@
 	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 @@
 	}
 
 	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 @@
 	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 @@
 	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 @@
 	}
 
 	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++) {
 		if (readn(fd, &sh, sizeof(sh)) != sizeof(sh)) {
 			werrstr("could not read Section Header %d", i+1);
@@ -1398,7 +1401,7 @@
 	seek(fd, leswal(fh.PointerToSymbolTable), 0);
 	symtab = esymtab = 0;
 	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);
 			return 0;
 		}
@@ -1452,7 +1455,6 @@
 	fp->lnpcsz = lnpcsz;
 }
 
-
 static uvlong
 _round(uvlong a, uint32 b)
 {
diff --git a/src/libmach/machdata.c b/src/libmach/machdata.c
index 425a921..66c19f9 100644
--- a/src/libmach/machdata.c
+++ b/src/libmach/machdata.c
@@ -113,7 +113,7 @@
 	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 @@
 	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 @@
 		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 @@
 		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 5e4fdd8..1512d7a 100644
--- a/src/libmach/sym.c
+++ b/src/libmach/sym.c
@@ -124,7 +124,7 @@
 		/* 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 @@
 		}
 	}
 	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 @@
 	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 @@
 		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 @@
 		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 @@
 			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 @@
 	 * 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 @@
 	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 @@
 	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)