mirror of
https://github.com/golang/go
synced 2024-11-21 21:14:47 -07:00
8l: more fixes for Plan 9
Once these changes are effected, it is possible to construct "8l" native on a (386?) Plan 9 system, albeit with assistance from modules such as mkfiles that are not (yet) included in any public patches. 8l/asm.c: . Corrected some format qualifiers. 8l/list.c: . Cast a print() argument to (int) to match the given format. It may be possible to change the format (%R), but I have not looked into it. 8l/obj.c: . Removed some unused code. 8l/span.c: . Removed unnecessary incrementation on "bp". . Corrected some format qualifiers. ld/data.c: . Corrected some format qualifiers. . Cast print argument to (int): used as field size. . Use braces to suppress warning about empty if() statements. ld/dwarf.c: . Trivial spelling mistake in comment. ld/ldelf.c: . Added USED() statements to silence warnings. . Dropped redundant address (&) operators. . corrected some format qualifiers. . Cast to (int) for switch selection variable. ld/macho.c: . Added USED() statements to silence warnings. ld/ldpe.c: . Added USED() statements to silence warnings. . More careful use of "sect" variable. . Corrected some format qualifiers. . Removed redundant assignments. . Minor fix dropped as it was submitted separately. ld/pe.c: . Dropped <time.h> which is now in <u.h>. . Dropped redundant address (&) operators. . Added a missing variable initialisation. ld/symtab.c: . Added USED() statements to silence warnings. . Removed redundant incrementation. . Corrected some format qualifiers. All the above have been tested against a (very) recent release and do not seem to trigger any regressions. All review suggestions have been incorporated. R=rsc CC=golang-dev https://golang.org/cl/4633043
This commit is contained in:
parent
b88e669a8f
commit
10b5519d3a
@ -1272,6 +1272,6 @@ genasmsym(void (*put)(Sym*, char*, int, vlong, vlong, int, Sym*))
|
||||
put(nil, a->asym->name, 'p', a->aoffset, 0, 0, a->gotype);
|
||||
}
|
||||
if(debug['v'] || debug['n'])
|
||||
Bprint(&bso, "symsize = %uld\n", symsize);
|
||||
Bprint(&bso, "symsize = %d\n", symsize);
|
||||
Bflush(&bso);
|
||||
}
|
||||
|
@ -176,7 +176,7 @@ Dconv(Fmt *fp)
|
||||
}
|
||||
brk:
|
||||
if(a->index != D_NONE) {
|
||||
sprint(s, "(%R*%d)", a->index, a->scale);
|
||||
sprint(s, "(%R*%d)", (int)a->index, a->scale);
|
||||
strcat(str, s);
|
||||
}
|
||||
conv:
|
||||
|
@ -473,7 +473,6 @@ loop:
|
||||
s = lookup(x, r);
|
||||
if(x != name)
|
||||
free(x);
|
||||
name = nil;
|
||||
|
||||
if(debug['S'] && r == 0)
|
||||
sig = 1729;
|
||||
@ -703,7 +702,6 @@ loop:
|
||||
lastp = p;
|
||||
goto loop;
|
||||
}
|
||||
goto loop;
|
||||
|
||||
eof:
|
||||
diag("truncated object file: %s", pn);
|
||||
|
@ -414,7 +414,6 @@ dostkoff(void)
|
||||
autoffset = 0;
|
||||
|
||||
q = P;
|
||||
q1 = P;
|
||||
if(pmorestack != P)
|
||||
if(!(p->from.scale & NOSPLIT)) {
|
||||
p = appendp(p); // load g into CX
|
||||
|
@ -89,7 +89,7 @@ span1(Sym *s)
|
||||
*bp++ = v;
|
||||
*bp++ = v>>8;
|
||||
*bp++ = v>>16;
|
||||
*bp++ = v>>24;
|
||||
*bp = v>>24;
|
||||
}
|
||||
}
|
||||
p->comefrom = P;
|
||||
@ -1319,7 +1319,7 @@ asmins(Prog *p)
|
||||
andptr = and;
|
||||
doasm(p);
|
||||
if(andptr > and+sizeof and) {
|
||||
print("and[] is too short - %d byte instruction\n", andptr - and);
|
||||
print("and[] is too short - %ld byte instruction\n", andptr - and);
|
||||
errorexit();
|
||||
}
|
||||
}
|
||||
|
@ -482,13 +482,13 @@ codeblk(int32 addr, int32 size)
|
||||
q = sym->p;
|
||||
|
||||
while(n >= 16) {
|
||||
Bprint(&bso, "%.6ux\t%-20.16I\n", addr, q);
|
||||
Bprint(&bso, "%.6ux\t%-20.16I\n", addr, q);
|
||||
addr += 16;
|
||||
q += 16;
|
||||
n -= 16;
|
||||
}
|
||||
if(n > 0)
|
||||
Bprint(&bso, "%.6ux\t%-20.*I\n", addr, n, q);
|
||||
Bprint(&bso, "%.6ux\t%-20.*I\n", addr, (int)n, q);
|
||||
addr += n;
|
||||
continue;
|
||||
}
|
||||
@ -502,7 +502,7 @@ codeblk(int32 addr, int32 size)
|
||||
Bprint(&bso, "%.6ux\t", p->pc);
|
||||
q = sym->p + p->pc - sym->value;
|
||||
n = epc - p->pc;
|
||||
Bprint(&bso, "%-20.*I | %P\n", n, q, p);
|
||||
Bprint(&bso, "%-20.*I | %P\n", (int)n, q, p);
|
||||
addr += n;
|
||||
}
|
||||
}
|
||||
@ -543,7 +543,7 @@ datblk(int32 addr, int32 size)
|
||||
Bprint(&bso, "%-20s %.8ux| 00 ...\n", "(pre-pad)", addr);
|
||||
addr = sym->value;
|
||||
}
|
||||
Bprint(&bso, "%-20s %.8ux|", sym->name, addr);
|
||||
Bprint(&bso, "%-20s %.8ux|", sym->name, (uint)addr);
|
||||
p = sym->p;
|
||||
ep = p + sym->np;
|
||||
while(p < ep)
|
||||
@ -555,8 +555,8 @@ datblk(int32 addr, int32 size)
|
||||
}
|
||||
|
||||
if(addr < eaddr)
|
||||
Bprint(&bso, "%-20s %.8ux| 00 ...\n", "(post-pad)", addr);
|
||||
Bprint(&bso, "%-20s %.8ux|\n", "", eaddr);
|
||||
Bprint(&bso, "%-20s %.8ux| 00 ...\n", "(post-pad)", (uint)addr);
|
||||
Bprint(&bso, "%-20s %.8ux|\n", "", (uint)eaddr);
|
||||
}
|
||||
|
||||
void
|
||||
@ -808,9 +808,9 @@ dodata(void)
|
||||
t = rnd(t, PtrSize);
|
||||
else if(t > 2)
|
||||
t = rnd(t, 4);
|
||||
if(t & 1)
|
||||
if(t & 1) {
|
||||
;
|
||||
else if(t & 2)
|
||||
} else if(t & 2)
|
||||
datsize = rnd(datsize, 2);
|
||||
else if(t & 4)
|
||||
datsize = rnd(datsize, 4);
|
||||
@ -834,9 +834,9 @@ dodata(void)
|
||||
t = rnd(t, PtrSize);
|
||||
else if(t > 2)
|
||||
t = rnd(t, 4);
|
||||
if(t & 1)
|
||||
if(t & 1) {
|
||||
;
|
||||
else if(t & 2)
|
||||
} else if(t & 2)
|
||||
datsize = rnd(datsize, 2);
|
||||
else if(t & 4)
|
||||
datsize = rnd(datsize, 4);
|
||||
|
@ -1822,7 +1822,7 @@ flushunit(DWDie *dwinfo, vlong pc, vlong unitstart, int32 header_length)
|
||||
seek(cout, unitstart, 0);
|
||||
LPUT(here - unitstart - sizeof(int32)); // unit_length
|
||||
WPUT(3); // dwarf version
|
||||
LPUT(header_length); // header lenght starting here
|
||||
LPUT(header_length); // header length starting here
|
||||
cflush();
|
||||
seek(cout, here, 0);
|
||||
}
|
||||
|
@ -328,15 +328,16 @@ ldelf(Biobuf *f, char *pkg, int64 len, char *pn)
|
||||
Reloc *r, *rp;
|
||||
Sym *s;
|
||||
|
||||
USED(pkg);
|
||||
if(debug['v'])
|
||||
Bprint(&bso, "%5.2f ldelf %s\n", cputime(), pn);
|
||||
|
||||
version++;
|
||||
base = Boffset(f);
|
||||
|
||||
if(Bread(f, &hdrbuf, sizeof hdrbuf) != sizeof hdrbuf)
|
||||
if(Bread(f, hdrbuf, sizeof hdrbuf) != sizeof hdrbuf)
|
||||
goto bad;
|
||||
hdr = (ElfHdrBytes*)&hdrbuf;
|
||||
hdr = (ElfHdrBytes*)hdrbuf;
|
||||
if(memcmp(hdr->ident, ElfMagic, 4) != 0)
|
||||
goto bad;
|
||||
switch(hdr->ident[5]) {
|
||||
@ -518,7 +519,7 @@ ldelf(Biobuf *f, char *pkg, int64 len, char *pn)
|
||||
name = smprint("%s(%s)", pn, sect->name);
|
||||
s = lookup(name, version);
|
||||
free(name);
|
||||
switch(sect->flags&(ElfSectFlagAlloc|ElfSectFlagWrite|ElfSectFlagExec)) {
|
||||
switch((int)sect->flags&(ElfSectFlagAlloc|ElfSectFlagWrite|ElfSectFlagExec)) {
|
||||
default:
|
||||
werrstr("unexpected flags for ELF section %s", sect->name);
|
||||
goto bad;
|
||||
|
@ -440,6 +440,7 @@ ldmacho(Biobuf *f, char *pkg, int64 len, char *pn)
|
||||
Reloc *r, *rp;
|
||||
char *name;
|
||||
|
||||
USED(pkg);
|
||||
version++;
|
||||
base = Boffset(f);
|
||||
if(Bread(f, hdr, sizeof hdr) != sizeof hdr)
|
||||
|
@ -125,10 +125,13 @@ ldpe(Biobuf *f, char *pkg, int64 len, char *pn)
|
||||
Sym *s;
|
||||
Reloc *r, *rp;
|
||||
PeSym *sym;
|
||||
|
||||
|
||||
USED(len);
|
||||
USED(pkg);
|
||||
if(debug['v'])
|
||||
Bprint(&bso, "%5.2f ldpe %s\n", cputime(), pn);
|
||||
|
||||
sect = nil;
|
||||
version++;
|
||||
base = Boffset(f);
|
||||
|
||||
@ -304,6 +307,8 @@ ldpe(Biobuf *f, char *pkg, int64 len, char *pn)
|
||||
diag("%s: %s sectnum <0!", pn, s->name, sym->sectnum);
|
||||
}
|
||||
|
||||
if(sect == nil)
|
||||
return;
|
||||
s->sub = sect->sym->sub;
|
||||
sect->sym->sub = s;
|
||||
s->type = sect->sym->type | SSUB;
|
||||
@ -366,7 +371,6 @@ readsym(PeObj *obj, int i, PeSym **y)
|
||||
|
||||
sym = &obj->pesym[i];
|
||||
*y = sym;
|
||||
s = nil;
|
||||
|
||||
name = sym->name;
|
||||
if(sym->sclass == IMAGE_SYM_CLASS_STATIC && sym->value == 0) // section
|
||||
@ -403,7 +407,7 @@ readsym(PeObj *obj, int i, PeSym **y)
|
||||
|
||||
if(s != nil && s->type == 0 && !(sym->sclass == IMAGE_SYM_CLASS_STATIC && sym->value == 0))
|
||||
s->type = SXREF;
|
||||
if(strncmp(sym->name, "__imp__", 6) == 0)
|
||||
if(strncmp(sym->name, "__imp__", 7) == 0)
|
||||
s->got = -2; // flag for __imp__
|
||||
sym->sym = s;
|
||||
|
||||
|
@ -5,8 +5,6 @@
|
||||
// PE (Portable Executable) file writing
|
||||
// http://www.microsoft.com/whdc/system/platform/firmware/PECOFF.mspx
|
||||
|
||||
#include <time.h>
|
||||
|
||||
#include "l.h"
|
||||
#include "../ld/lib.h"
|
||||
#include "../ld/pe.h"
|
||||
@ -150,7 +148,7 @@ pewrite(void)
|
||||
ewrite(cout, &oh64, sizeof oh64);
|
||||
else
|
||||
ewrite(cout, &oh, sizeof oh);
|
||||
ewrite(cout, &sh, nsect * sizeof sh[0]);
|
||||
ewrite(cout, sh, nsect * sizeof sh[0]);
|
||||
}
|
||||
|
||||
static void
|
||||
@ -175,7 +173,7 @@ initdynimport(void)
|
||||
Sym *s, *dynamic;
|
||||
|
||||
dr = nil;
|
||||
|
||||
m = nil;
|
||||
for(s = allsym; s != S; s = s->allsym) {
|
||||
if(!s->reachable || !s->dynimpname || s->dynexport)
|
||||
continue;
|
||||
|
@ -90,6 +90,7 @@ putelfsym(Sym *x, char *s, int t, vlong addr, vlong size, int ver, Sym *go)
|
||||
{
|
||||
int bind, type, shndx, off;
|
||||
|
||||
USED(go);
|
||||
switch(t) {
|
||||
default:
|
||||
return;
|
||||
@ -127,6 +128,10 @@ putplan9sym(Sym *x, char *s, int t, vlong addr, vlong size, int ver, Sym *go)
|
||||
{
|
||||
int i;
|
||||
|
||||
USED(go);
|
||||
USED(ver);
|
||||
USED(size);
|
||||
USED(x);
|
||||
switch(t) {
|
||||
case 'T':
|
||||
case 'L':
|
||||
@ -252,6 +257,7 @@ putsymb(Sym *s, char *name, int t, vlong v, vlong size, int ver, Sym *typ)
|
||||
int i, f, l;
|
||||
Reloc *rel;
|
||||
|
||||
USED(size);
|
||||
if(t == 'f')
|
||||
name++;
|
||||
l = 4;
|
||||
@ -280,7 +286,6 @@ putsymb(Sym *s, char *name, int t, vlong v, vlong size, int ver, Sym *typ)
|
||||
}
|
||||
scput(0);
|
||||
scput(0);
|
||||
i++;
|
||||
}
|
||||
else {
|
||||
for(i=0; name[i]; i++)
|
||||
@ -311,9 +316,9 @@ putsymb(Sym *s, char *name, int t, vlong v, vlong size, int ver, Sym *typ)
|
||||
return;
|
||||
}
|
||||
if(ver)
|
||||
Bprint(&bso, "%c %.8llux %s<%d> %s\n", t, v, s, ver, typ ? typ->name : "");
|
||||
Bprint(&bso, "%c %.8llux %s<%d> %s\n", t, v, s->name, ver, typ ? typ->name : "");
|
||||
else
|
||||
Bprint(&bso, "%c %.8llux %s %s\n", t, v, s, typ ? typ->name : "");
|
||||
Bprint(&bso, "%c %.8llux %s %s\n", t, v, s->name, typ ? typ->name : "");
|
||||
}
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user