]> Cypherpunks repositories - gostls13.git/commitdiff
8l: more fixes for Plan 9
authorLucio De Re <lucio.dere@gmail.com>
Tue, 21 Jun 2011 16:14:32 +0000 (12:14 -0400)
committerRuss Cox <rsc@golang.org>
Tue, 21 Jun 2011 16:14:32 +0000 (12:14 -0400)
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

12 files changed:
src/cmd/8l/asm.c
src/cmd/8l/list.c
src/cmd/8l/obj.c
src/cmd/8l/pass.c
src/cmd/8l/span.c
src/cmd/ld/data.c
src/cmd/ld/dwarf.c
src/cmd/ld/ldelf.c
src/cmd/ld/ldmacho.c
src/cmd/ld/ldpe.c
src/cmd/ld/pe.c
src/cmd/ld/symtab.c

index aa44b07dbdfbf2be2bca2e57339cc84cd02fd05e..a9a720af1493ac3887fe33ae2ba5954d15f78746 100644 (file)
@@ -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);
 }
index 4e199d7675b770859dca77aef560dc38eb660307..31ae023468d031c3de8da1856215fe89d57bf86f 100644 (file)
@@ -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:
index 7fd0dafaedb2a6270cceece30c8c74825afc06a7..ce7b59518241a6682ac539a01912bd79257b7443 100644 (file)
@@ -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);
index 72ae043d6416fe3c4334207739d471872c54bfbb..2e0990c5a8751e40a9ec0776bd3329b914e91be3 100644 (file)
@@ -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
index 66a843b2357686de1c069e12ee6639b1646ee0f2..a4cba125763ca1a34a24ae84ca5d939f7f094851 100644 (file)
@@ -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();
        }
 }
index 140712b2981cd44cfc3c72fa1be1e698d3ffe8f4..9d9cd109b8353143984e45514fb10ace28709805 100644 (file)
@@ -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);
index 50b42183e89b3762d4dd1c8f94d7c4bf7fd92971..1c10dc796792777c30f0817e56f8bf9166228b65 100644 (file)
@@ -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);
        }
index d61020e4992cffef52df5426c914edd7ad1aae77..8334e988e4b01adaca304231ecd73ea96c1d9eb6 100644 (file)
@@ -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;
index bbb21d51ae8815fce3f5c149efaab4a7433b03b7..abbc3b3cdb3eaa6a1ee4c1b58194171dcab976d8 100644 (file)
@@ -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)
index 288186e88c3ac446ff4dc56aef0969a75f9a5a8c..98c866feebd4169933ca69effd953b2f0bb717aa 100644 (file)
@@ -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;
 
index 91e15d343cc7d7a79e5b857206036b6b90a18f76..9ac0a50d89e65209af3f2f53bffb4c8e2b73cc41 100644 (file)
@@ -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;
index e3093b2aac5081946023e0e434a8fb74b863c455..c66eca1485ce362742c14917240536eee3172812 100644 (file)
@@ -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 : "");
        }
 }