mirror of
https://github.com/golang/go
synced 2024-11-19 14:54:43 -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);
|
put(nil, a->asym->name, 'p', a->aoffset, 0, 0, a->gotype);
|
||||||
}
|
}
|
||||||
if(debug['v'] || debug['n'])
|
if(debug['v'] || debug['n'])
|
||||||
Bprint(&bso, "symsize = %uld\n", symsize);
|
Bprint(&bso, "symsize = %d\n", symsize);
|
||||||
Bflush(&bso);
|
Bflush(&bso);
|
||||||
}
|
}
|
||||||
|
@ -176,7 +176,7 @@ Dconv(Fmt *fp)
|
|||||||
}
|
}
|
||||||
brk:
|
brk:
|
||||||
if(a->index != D_NONE) {
|
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);
|
strcat(str, s);
|
||||||
}
|
}
|
||||||
conv:
|
conv:
|
||||||
|
@ -473,7 +473,6 @@ loop:
|
|||||||
s = lookup(x, r);
|
s = lookup(x, r);
|
||||||
if(x != name)
|
if(x != name)
|
||||||
free(x);
|
free(x);
|
||||||
name = nil;
|
|
||||||
|
|
||||||
if(debug['S'] && r == 0)
|
if(debug['S'] && r == 0)
|
||||||
sig = 1729;
|
sig = 1729;
|
||||||
@ -703,7 +702,6 @@ loop:
|
|||||||
lastp = p;
|
lastp = p;
|
||||||
goto loop;
|
goto loop;
|
||||||
}
|
}
|
||||||
goto loop;
|
|
||||||
|
|
||||||
eof:
|
eof:
|
||||||
diag("truncated object file: %s", pn);
|
diag("truncated object file: %s", pn);
|
||||||
|
@ -414,7 +414,6 @@ dostkoff(void)
|
|||||||
autoffset = 0;
|
autoffset = 0;
|
||||||
|
|
||||||
q = P;
|
q = P;
|
||||||
q1 = P;
|
|
||||||
if(pmorestack != P)
|
if(pmorestack != P)
|
||||||
if(!(p->from.scale & NOSPLIT)) {
|
if(!(p->from.scale & NOSPLIT)) {
|
||||||
p = appendp(p); // load g into CX
|
p = appendp(p); // load g into CX
|
||||||
|
@ -89,7 +89,7 @@ span1(Sym *s)
|
|||||||
*bp++ = v;
|
*bp++ = v;
|
||||||
*bp++ = v>>8;
|
*bp++ = v>>8;
|
||||||
*bp++ = v>>16;
|
*bp++ = v>>16;
|
||||||
*bp++ = v>>24;
|
*bp = v>>24;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
p->comefrom = P;
|
p->comefrom = P;
|
||||||
@ -1319,7 +1319,7 @@ asmins(Prog *p)
|
|||||||
andptr = and;
|
andptr = and;
|
||||||
doasm(p);
|
doasm(p);
|
||||||
if(andptr > and+sizeof and) {
|
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();
|
errorexit();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -482,13 +482,13 @@ codeblk(int32 addr, int32 size)
|
|||||||
q = sym->p;
|
q = sym->p;
|
||||||
|
|
||||||
while(n >= 16) {
|
while(n >= 16) {
|
||||||
Bprint(&bso, "%.6ux\t%-20.16I\n", addr, q);
|
Bprint(&bso, "%.6ux\t%-20.16I\n", addr, q);
|
||||||
addr += 16;
|
addr += 16;
|
||||||
q += 16;
|
q += 16;
|
||||||
n -= 16;
|
n -= 16;
|
||||||
}
|
}
|
||||||
if(n > 0)
|
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;
|
addr += n;
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
@ -502,7 +502,7 @@ codeblk(int32 addr, int32 size)
|
|||||||
Bprint(&bso, "%.6ux\t", p->pc);
|
Bprint(&bso, "%.6ux\t", p->pc);
|
||||||
q = sym->p + p->pc - sym->value;
|
q = sym->p + p->pc - sym->value;
|
||||||
n = epc - p->pc;
|
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;
|
addr += n;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -543,7 +543,7 @@ datblk(int32 addr, int32 size)
|
|||||||
Bprint(&bso, "%-20s %.8ux| 00 ...\n", "(pre-pad)", addr);
|
Bprint(&bso, "%-20s %.8ux| 00 ...\n", "(pre-pad)", addr);
|
||||||
addr = sym->value;
|
addr = sym->value;
|
||||||
}
|
}
|
||||||
Bprint(&bso, "%-20s %.8ux|", sym->name, addr);
|
Bprint(&bso, "%-20s %.8ux|", sym->name, (uint)addr);
|
||||||
p = sym->p;
|
p = sym->p;
|
||||||
ep = p + sym->np;
|
ep = p + sym->np;
|
||||||
while(p < ep)
|
while(p < ep)
|
||||||
@ -555,8 +555,8 @@ datblk(int32 addr, int32 size)
|
|||||||
}
|
}
|
||||||
|
|
||||||
if(addr < eaddr)
|
if(addr < eaddr)
|
||||||
Bprint(&bso, "%-20s %.8ux| 00 ...\n", "(post-pad)", addr);
|
Bprint(&bso, "%-20s %.8ux| 00 ...\n", "(post-pad)", (uint)addr);
|
||||||
Bprint(&bso, "%-20s %.8ux|\n", "", eaddr);
|
Bprint(&bso, "%-20s %.8ux|\n", "", (uint)eaddr);
|
||||||
}
|
}
|
||||||
|
|
||||||
void
|
void
|
||||||
@ -808,9 +808,9 @@ dodata(void)
|
|||||||
t = rnd(t, PtrSize);
|
t = rnd(t, PtrSize);
|
||||||
else if(t > 2)
|
else if(t > 2)
|
||||||
t = rnd(t, 4);
|
t = rnd(t, 4);
|
||||||
if(t & 1)
|
if(t & 1) {
|
||||||
;
|
;
|
||||||
else if(t & 2)
|
} else if(t & 2)
|
||||||
datsize = rnd(datsize, 2);
|
datsize = rnd(datsize, 2);
|
||||||
else if(t & 4)
|
else if(t & 4)
|
||||||
datsize = rnd(datsize, 4);
|
datsize = rnd(datsize, 4);
|
||||||
@ -834,9 +834,9 @@ dodata(void)
|
|||||||
t = rnd(t, PtrSize);
|
t = rnd(t, PtrSize);
|
||||||
else if(t > 2)
|
else if(t > 2)
|
||||||
t = rnd(t, 4);
|
t = rnd(t, 4);
|
||||||
if(t & 1)
|
if(t & 1) {
|
||||||
;
|
;
|
||||||
else if(t & 2)
|
} else if(t & 2)
|
||||||
datsize = rnd(datsize, 2);
|
datsize = rnd(datsize, 2);
|
||||||
else if(t & 4)
|
else if(t & 4)
|
||||||
datsize = rnd(datsize, 4);
|
datsize = rnd(datsize, 4);
|
||||||
|
@ -1822,7 +1822,7 @@ flushunit(DWDie *dwinfo, vlong pc, vlong unitstart, int32 header_length)
|
|||||||
seek(cout, unitstart, 0);
|
seek(cout, unitstart, 0);
|
||||||
LPUT(here - unitstart - sizeof(int32)); // unit_length
|
LPUT(here - unitstart - sizeof(int32)); // unit_length
|
||||||
WPUT(3); // dwarf version
|
WPUT(3); // dwarf version
|
||||||
LPUT(header_length); // header lenght starting here
|
LPUT(header_length); // header length starting here
|
||||||
cflush();
|
cflush();
|
||||||
seek(cout, here, 0);
|
seek(cout, here, 0);
|
||||||
}
|
}
|
||||||
|
@ -328,15 +328,16 @@ ldelf(Biobuf *f, char *pkg, int64 len, char *pn)
|
|||||||
Reloc *r, *rp;
|
Reloc *r, *rp;
|
||||||
Sym *s;
|
Sym *s;
|
||||||
|
|
||||||
|
USED(pkg);
|
||||||
if(debug['v'])
|
if(debug['v'])
|
||||||
Bprint(&bso, "%5.2f ldelf %s\n", cputime(), pn);
|
Bprint(&bso, "%5.2f ldelf %s\n", cputime(), pn);
|
||||||
|
|
||||||
version++;
|
version++;
|
||||||
base = Boffset(f);
|
base = Boffset(f);
|
||||||
|
|
||||||
if(Bread(f, &hdrbuf, sizeof hdrbuf) != sizeof hdrbuf)
|
if(Bread(f, hdrbuf, sizeof hdrbuf) != sizeof hdrbuf)
|
||||||
goto bad;
|
goto bad;
|
||||||
hdr = (ElfHdrBytes*)&hdrbuf;
|
hdr = (ElfHdrBytes*)hdrbuf;
|
||||||
if(memcmp(hdr->ident, ElfMagic, 4) != 0)
|
if(memcmp(hdr->ident, ElfMagic, 4) != 0)
|
||||||
goto bad;
|
goto bad;
|
||||||
switch(hdr->ident[5]) {
|
switch(hdr->ident[5]) {
|
||||||
@ -518,7 +519,7 @@ ldelf(Biobuf *f, char *pkg, int64 len, char *pn)
|
|||||||
name = smprint("%s(%s)", pn, sect->name);
|
name = smprint("%s(%s)", pn, sect->name);
|
||||||
s = lookup(name, version);
|
s = lookup(name, version);
|
||||||
free(name);
|
free(name);
|
||||||
switch(sect->flags&(ElfSectFlagAlloc|ElfSectFlagWrite|ElfSectFlagExec)) {
|
switch((int)sect->flags&(ElfSectFlagAlloc|ElfSectFlagWrite|ElfSectFlagExec)) {
|
||||||
default:
|
default:
|
||||||
werrstr("unexpected flags for ELF section %s", sect->name);
|
werrstr("unexpected flags for ELF section %s", sect->name);
|
||||||
goto bad;
|
goto bad;
|
||||||
|
@ -440,6 +440,7 @@ ldmacho(Biobuf *f, char *pkg, int64 len, char *pn)
|
|||||||
Reloc *r, *rp;
|
Reloc *r, *rp;
|
||||||
char *name;
|
char *name;
|
||||||
|
|
||||||
|
USED(pkg);
|
||||||
version++;
|
version++;
|
||||||
base = Boffset(f);
|
base = Boffset(f);
|
||||||
if(Bread(f, hdr, sizeof hdr) != sizeof hdr)
|
if(Bread(f, hdr, sizeof hdr) != sizeof hdr)
|
||||||
|
@ -125,10 +125,13 @@ ldpe(Biobuf *f, char *pkg, int64 len, char *pn)
|
|||||||
Sym *s;
|
Sym *s;
|
||||||
Reloc *r, *rp;
|
Reloc *r, *rp;
|
||||||
PeSym *sym;
|
PeSym *sym;
|
||||||
|
|
||||||
|
USED(len);
|
||||||
|
USED(pkg);
|
||||||
if(debug['v'])
|
if(debug['v'])
|
||||||
Bprint(&bso, "%5.2f ldpe %s\n", cputime(), pn);
|
Bprint(&bso, "%5.2f ldpe %s\n", cputime(), pn);
|
||||||
|
|
||||||
|
sect = nil;
|
||||||
version++;
|
version++;
|
||||||
base = Boffset(f);
|
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);
|
diag("%s: %s sectnum <0!", pn, s->name, sym->sectnum);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if(sect == nil)
|
||||||
|
return;
|
||||||
s->sub = sect->sym->sub;
|
s->sub = sect->sym->sub;
|
||||||
sect->sym->sub = s;
|
sect->sym->sub = s;
|
||||||
s->type = sect->sym->type | SSUB;
|
s->type = sect->sym->type | SSUB;
|
||||||
@ -366,7 +371,6 @@ readsym(PeObj *obj, int i, PeSym **y)
|
|||||||
|
|
||||||
sym = &obj->pesym[i];
|
sym = &obj->pesym[i];
|
||||||
*y = sym;
|
*y = sym;
|
||||||
s = nil;
|
|
||||||
|
|
||||||
name = sym->name;
|
name = sym->name;
|
||||||
if(sym->sclass == IMAGE_SYM_CLASS_STATIC && sym->value == 0) // section
|
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))
|
if(s != nil && s->type == 0 && !(sym->sclass == IMAGE_SYM_CLASS_STATIC && sym->value == 0))
|
||||||
s->type = SXREF;
|
s->type = SXREF;
|
||||||
if(strncmp(sym->name, "__imp__", 6) == 0)
|
if(strncmp(sym->name, "__imp__", 7) == 0)
|
||||||
s->got = -2; // flag for __imp__
|
s->got = -2; // flag for __imp__
|
||||||
sym->sym = s;
|
sym->sym = s;
|
||||||
|
|
||||||
|
@ -5,8 +5,6 @@
|
|||||||
// PE (Portable Executable) file writing
|
// PE (Portable Executable) file writing
|
||||||
// http://www.microsoft.com/whdc/system/platform/firmware/PECOFF.mspx
|
// http://www.microsoft.com/whdc/system/platform/firmware/PECOFF.mspx
|
||||||
|
|
||||||
#include <time.h>
|
|
||||||
|
|
||||||
#include "l.h"
|
#include "l.h"
|
||||||
#include "../ld/lib.h"
|
#include "../ld/lib.h"
|
||||||
#include "../ld/pe.h"
|
#include "../ld/pe.h"
|
||||||
@ -150,7 +148,7 @@ pewrite(void)
|
|||||||
ewrite(cout, &oh64, sizeof oh64);
|
ewrite(cout, &oh64, sizeof oh64);
|
||||||
else
|
else
|
||||||
ewrite(cout, &oh, sizeof oh);
|
ewrite(cout, &oh, sizeof oh);
|
||||||
ewrite(cout, &sh, nsect * sizeof sh[0]);
|
ewrite(cout, sh, nsect * sizeof sh[0]);
|
||||||
}
|
}
|
||||||
|
|
||||||
static void
|
static void
|
||||||
@ -175,7 +173,7 @@ initdynimport(void)
|
|||||||
Sym *s, *dynamic;
|
Sym *s, *dynamic;
|
||||||
|
|
||||||
dr = nil;
|
dr = nil;
|
||||||
|
m = nil;
|
||||||
for(s = allsym; s != S; s = s->allsym) {
|
for(s = allsym; s != S; s = s->allsym) {
|
||||||
if(!s->reachable || !s->dynimpname || s->dynexport)
|
if(!s->reachable || !s->dynimpname || s->dynexport)
|
||||||
continue;
|
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;
|
int bind, type, shndx, off;
|
||||||
|
|
||||||
|
USED(go);
|
||||||
switch(t) {
|
switch(t) {
|
||||||
default:
|
default:
|
||||||
return;
|
return;
|
||||||
@ -127,6 +128,10 @@ putplan9sym(Sym *x, char *s, int t, vlong addr, vlong size, int ver, Sym *go)
|
|||||||
{
|
{
|
||||||
int i;
|
int i;
|
||||||
|
|
||||||
|
USED(go);
|
||||||
|
USED(ver);
|
||||||
|
USED(size);
|
||||||
|
USED(x);
|
||||||
switch(t) {
|
switch(t) {
|
||||||
case 'T':
|
case 'T':
|
||||||
case 'L':
|
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;
|
int i, f, l;
|
||||||
Reloc *rel;
|
Reloc *rel;
|
||||||
|
|
||||||
|
USED(size);
|
||||||
if(t == 'f')
|
if(t == 'f')
|
||||||
name++;
|
name++;
|
||||||
l = 4;
|
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);
|
||||||
scput(0);
|
scput(0);
|
||||||
i++;
|
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
for(i=0; name[i]; i++)
|
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;
|
return;
|
||||||
}
|
}
|
||||||
if(ver)
|
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
|
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