]> Cypherpunks repositories - gostls13.git/commitdiff
6l: eliminate dead code, not just the symbols
authorRuss Cox <rsc@golang.org>
Tue, 5 May 2009 19:43:00 +0000 (12:43 -0700)
committerRuss Cox <rsc@golang.org>
Tue, 5 May 2009 19:43:00 +0000 (12:43 -0700)
editing the firstp list was ineffective,
because follow rebuilds it from the textp list.

the symbols for dead code were being dropped
from the binary but the code was all still there.

text for fmt.Printf("hello, world\n") drops
from 143945 to 128650.

R=r,ken
DELTA=22  (20 added, 0 deleted, 2 changed)
OCL=28255
CL=28290

src/cmd/6l/span.c
src/cmd/ld/go.c

index 97d4910e2539fbb10925476338417ad06e51a83f..18b659adc82b46d94db5e77bc68971bdedb839d6 100644 (file)
@@ -238,7 +238,7 @@ asmsym(void)
                                continue;
                        }
 
-       for(p=textp; p!=P; p=p->pcond) {
+       for(p = textp; p != P; p = p->pcond) {
                s = p->from.sym;
 
                /* filenames first */
index c481ba02ad78efcdae391bfc71b1736ae3604734..d10d89b1228a1f24f2bc123c3cb0de839043fc5a 100644 (file)
@@ -103,11 +103,12 @@ ldpkg(Biobuf *f, int64 len, char *filename)
                fprint(2, "6l: too much pkg data in %s\n", filename);
                return;
        }
-       data = mal(len);
+       data = mal(len+1);
        if(Bread(f, data, len) != len) {
                fprint(2, "6l: short pkg read %s\n", filename);
                return;
        }
+       data[len] = '\0';
 
        // first \n$$ marks beginning of exports - skip rest of line
        p0 = strstr(data, "\n$$");
@@ -554,6 +555,16 @@ sweeplist(Prog **first, Prog **last)
                                if(debug['v'] > 1)
                                        Bprint(&bso, "discard %s\n", p->from.sym->name);
                                p->from.sym->type = Sxxx;
+                               break;
+                       }
+                       if(p->as == ATEXT) {
+                               // keeping this function; link into textp list
+                               if(etextp == P)
+                                       textp = p;
+                               else
+                                       etextp->pcond = p;
+                               etextp = p;
+                               etextp->pcond = P;
                        }
                        break;
                }
@@ -603,6 +614,15 @@ deadcode(void)
        for(i=0; i<nelem(morename); i++)
                mark(lookup(morename[i], 0));
 
+       // remove dead code.
+       // sweeplist will rebuild the list of functions at textp
+       textp = P;
+       etextp = P;
+
+       // follow is going to redo the firstp, lastp list
+       // but update it anyway just to keep things consistent.
        sweeplist(&firstp, &lastp);
+
+       // remove dead data
        sweeplist(&datap, &edatap);
 }