]> Cypherpunks repositories - gostls13.git/commitdiff
5l, 6l, 8l: omit symbols for type, string, go.string
authorRuss Cox <rsc@golang.org>
Tue, 8 Mar 2011 19:14:28 +0000 (14:14 -0500)
committerRuss Cox <rsc@golang.org>
Tue, 8 Mar 2011 19:14:28 +0000 (14:14 -0500)
Much of the bulk of Go binaries is the symbol tables,
which give a name to every C string, Go string,
and reflection type symbol.  These names are not worth
much other than seeing what's where in a binary.

This CL deletes all those names from the symbol table,
instead aggregating the symbols into contiguous blocks
and giving them the names "string.*", "go.string.*", and "type.*".

Before:
$ 6nm $(which godoc.old) | sort | grep ' string\.' | tail -10
  59eda4 D string."aa87ca22be8b05378eb1c71...
  59ee08 D string."b3312fa7e23ee7e4988e056...
  59ee6c D string."func(*token.FileSet, st...
  59eed0 D string."func(io.Writer, []uint8...
  59ef34 D string."func(*tls.Config, *tls....
  59ef98 D string."func(*bool, **template....
  59effc D string."method(p *printer.print...
  59f060 D string."method(S *scanner.Scann...
  59f12c D string."func(*struct { begin in...
  59f194 D string."method(ka *tls.ecdheRSA...
$

After:
$ 6nm $(which godoc) | sort | grep ' string\.' | tail -10
  5e6a30 D string.*
$

Those names in the "Before" are truncated for the CL.
In the real binary they are the complete string, up to
a certain length, or else a unique identifier.
The same applies to the type and go.string symbols.

Removing the names cuts godoc by more than half:

-rwxr-xr-x 1 rsc rsc 9153405 2011-03-07 23:19 godoc.old
-rwxr-xr-x 1 rsc rsc 4290071 2011-03-07 23:19 godoc

For what it's worth, only 80% of what's left gets loaded
into memory; the other 20% is dwarf debugging information
only ever accessed by gdb:

-rwxr-xr-x 1 rsc rsc 3397787 2011-03-07 23:19 godoc.nodwarf

R=r, cw
CC=golang-dev
https://golang.org/cl/4245072

src/cmd/5l/asm.c
src/cmd/5l/l.h
src/cmd/6l/asm.c
src/cmd/6l/l.h
src/cmd/8l/asm.c
src/cmd/8l/l.h
src/cmd/ld/data.c
src/cmd/ld/dwarf.c
src/cmd/ld/go.c
src/cmd/ld/lib.h
src/cmd/ld/symtab.c

index af6d1dfda06150262b5d0088e1b10f9495531434..95b12a9b4961c41a651a7dd85e3511174540b1ab 100644 (file)
@@ -1978,6 +1978,8 @@ genasmsym(void (*put)(Sym*, char*, int, vlong, vlong, int, Sym*))
 
        for(h=0; h<NHASH; h++) {
                for(s=hash[h]; s!=S; s=s->hash) {
+                       if(s->hide)
+                               continue;
                        switch(s->type) {
                        case SCONST:
                        case SRODATA:
index 2e887dad7357a2281622911edc06910ad40a4765..9ce9d02c6c387b9be0a3823869053ee89bb2f6d8 100644 (file)
@@ -136,6 +136,7 @@ struct      Sym
        uchar   dynexport;
        uchar   leaf;
        uchar   stkcheck;
+       uchar   hide;
        int32   dynid;
        int32   plt;
        int32   got;
@@ -202,22 +203,6 @@ struct     Count
 
 enum
 {
-       Sxxx,
-       
-       /* order here is order in output file */
-       STEXT           = 1,
-       SRODATA,
-       SELFDATA,
-       SDATA,
-       SBSS,
-
-       SXREF,
-       SFILE,
-       SCONST,
-       SDYNIMPORT,
-
-       SSUB    = 1<<8,
-
        LFROM           = 1<<0,
        LTO             = 1<<1,
        LPOOL           = 1<<2,
index fb041d83a5562fa55e3d31e9ba1089c11e12a307..3e2fe69604e9e6d1147c73b419c4a21ad2e9347b 100644 (file)
@@ -1105,12 +1105,17 @@ genasmsym(void (*put)(Sym*, char*, int, vlong, vlong, int, Sym*))
 
        for(h=0; h<NHASH; h++) {
                for(s=hash[h]; s!=S; s=s->hash) {
+                       if(s->hide)
+                               continue;
                        switch(s->type&~SSUB) {
                        case SCONST:
                        case SRODATA:
                        case SDATA:
                        case SELFDATA:
                        case SMACHOGOT:
+                       case STYPE:
+                       case SSTRING:
+                       case SGOSTRING:
                        case SWINDOWS:
                                if(!s->reachable)
                                        continue;
index 6933d8eb19aed1de348372a8ca21abd1b9bc5dd1..139b06af8926d59303c84c9846ff66de894a8a2b 100644 (file)
@@ -132,6 +132,7 @@ struct      Sym
        uchar   dynexport;
        uchar   special;
        uchar   stkcheck;
+       uchar   hide;
        int32   dynid;
        int32   sig;
        int32   plt;
@@ -177,28 +178,6 @@ struct     Movtab
 
 enum
 {
-       Sxxx,
-       
-       /* order here is order in output file */
-       STEXT           = 1,
-       SELFDATA,
-       SMACHOPLT,
-       SRODATA,
-       SDATA,
-       SMACHOGOT,
-       SWINDOWS,
-       SBSS,
-
-       SXREF,
-       SMACHODYNSTR,
-       SMACHODYNSYM,
-       SMACHOINDIRECTPLT,
-       SMACHOINDIRECTGOT,
-       SFILE,
-       SCONST,
-       SDYNIMPORT,
-       SSUB    = 1<<8,
-
        NHASH           = 10007,
        MINSIZ          = 8,
        STRINGSZ        = 200,
index 1e760d89e540cd5c0b33c8b9d2e32d4170ed9f14..19134d4a974dc426de0f26696df1f3871a585575 100644 (file)
@@ -1158,6 +1158,8 @@ genasmsym(void (*put)(Sym*, char*, int, vlong, vlong, int, Sym*))
 
        for(h=0; h<NHASH; h++) {
                for(s=hash[h]; s!=S; s=s->hash) {
+                       if(s->hide)
+                               continue;
                        switch(s->type&~SSUB) {
                        case SCONST:
                        case SRODATA:
index e4650ee58f36193562070baae7df1097565d4b43..62f470257358d61544807fd9ed167f0c466f2afa 100644 (file)
@@ -131,6 +131,7 @@ struct      Sym
        uchar   dynexport;
        uchar   special;
        uchar   stkcheck;
+       uchar   hide;
        int32   value;
        int32   size;
        int32   sig;
@@ -168,30 +169,6 @@ struct     Optab
 
 enum
 {
-       Sxxx,
-       
-       /* order here is order in output file */
-       STEXT,
-       SELFDATA,
-       SMACHOPLT,
-       SRODATA,
-       SDATA,
-       SMACHO, /* Mach-O __nl_symbol_ptr */
-       SMACHOGOT,
-       SWINDOWS,
-       SBSS,
-
-       SXREF,
-       SMACHODYNSTR,
-       SMACHODYNSYM,
-       SMACHOINDIRECTPLT,
-       SMACHOINDIRECTGOT,
-       SFILE,
-       SCONST,
-       SDYNIMPORT,
-
-       SSUB = 1<<8,    /* sub-symbol, linked from parent via ->sub list */
-
        NHASH           = 10007,
        MINSIZ          = 4,
        STRINGSZ        = 200,
index a20b057ce59271938ac52829d3e5862811e62315..4066cd8143c527be22c6715cf7ddd2bc9608d611 100644 (file)
@@ -732,6 +732,7 @@ dodata(void)
 
        last = nil;
        datap = nil;
+
        for(h=0; h<NHASH; h++) {
                for(s=hash[h]; s!=S; s=s->hash){
                        if(!s->reachable || s->special)
@@ -786,7 +787,7 @@ dodata(void)
        s = datap;
        for(; s != nil && s->type < SDATA; s = s->next) {
                s->type = SRODATA;
-               t = rnd(s->size, 4);
+               t = rnd(s->size, PtrSize);
                s->size = t;
                s->value = datsize;
                datsize += t;
index f7c8e3834105411b3a82e8d8ffd527de22e4a001..ace38cbc5347ea3e7514c3b6a7d16bc5cfb7c385 100644 (file)
@@ -1467,7 +1467,7 @@ defdwsymb(Sym* sym, char *s, int t, vlong v, vlong size, int ver, Sym *gotype)
        if (strncmp(s, "type._.", 7) == 0)
                return;
 
-       if (strncmp(s, "type.", 5) == 0) {
+       if (strncmp(s, "type.", 5) == 0 && strcmp(s, "type.*") != 0) {
                defgotype(sym);
                return;
        }
index 3c1e230b4b68e4f5472b98c957b2cfa79a118f50..a64153ff2f97e29bd3c2124e6125d16c74a13c01 100644 (file)
@@ -662,6 +662,7 @@ deadcode(void)
                if(strncmp(s->name, "weak.", 5) == 0) {
                        s->special = 1;  // do not lay out in data segment
                        s->reachable = 1;
+                       s->hide = 1;
                }
 }
 
index adde2c9ff2a4980f82d3e6c3bea0e8543b6da8b0..fbd372b23dd7cee6fbb34f59299234cd90efb8bd 100644 (file)
 // OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
 // THE SOFTWARE.
 
-// Where symbol table data gets mapped into memory.
-#define SYMDATVA 0x99LL<<24
+enum
+{
+       Sxxx,
+       
+       /* order here is order in output file */
+       STEXT,
+       SELFDATA,
+       SMACHOPLT,
+       STYPE,
+       SSTRING,
+       SGOSTRING,
+       SRODATA,
+       SDATA,
+       SMACHO, /* Mach-O __nl_symbol_ptr */
+       SMACHOGOT,
+       SWINDOWS,
+       SBSS,
+
+       SXREF,
+       SMACHODYNSTR,
+       SMACHODYNSYM,
+       SMACHOINDIRECTPLT,
+       SMACHOINDIRECTGOT,
+       SFILE,
+       SCONST,
+       SDYNIMPORT,
+
+       SSUB = 1<<8,    /* sub-symbol, linked from parent via ->sub list */
+};
 
 typedef struct Library Library;
 struct Library
index 22777b6b5bf5a4c685227b8aa99187129147c9d7..f1d44058e001b13a1b1937850d55c49e2d48d19f 100644 (file)
@@ -340,6 +340,9 @@ putsymb(Sym *s, char *name, int t, vlong v, vlong size, int ver, Sym *typ)
 void
 symtab(void)
 {
+       int32 h;
+       Sym *s;
+
        // Define these so that they'll get put into the symbol table.
        // data.c:/^address will provide the actual values.
        xdefine("text", STEXT, 0);
@@ -351,11 +354,50 @@ symtab(void)
        xdefine("end", SBSS, 0);
        xdefine("epclntab", SRODATA, 0);
        xdefine("esymtab", SRODATA, 0);
+       
+       // pseudo-symbols to mark locations of type, string, and go string data.
+       s = lookup("type.*", 0);
+       s->type = STYPE;
+       s->size = 0;
+       s->reachable = 1;
+
+       s = lookup("string.*", 0);
+       s->type = SSTRING;
+       s->size = 0;
+       s->reachable = 1;
+
+       s = lookup("go.string.*", 0);
+       s->type = SGOSTRING;
+       s->size = 0;
+       s->reachable = 1;
 
        symt = lookup("symtab", 0);
        symt->type = SRODATA;
        symt->size = 0;
        symt->reachable = 1;
+       
+       // assign specific types so that they sort together.
+       // within a type they sort by size, so the .* symbols
+       // just defined above will be first.
+       // hide the specific symbols.
+       for(h=0; h<NHASH; h++) {
+               for(s=hash[h]; s!=S; s=s->hash){
+                       if(!s->reachable || s->special || s->type != SRODATA)
+                               continue;
+                       if(strncmp(s->name, "type.", 5) == 0) {
+                               s->type = STYPE;
+                               s->hide = 1;
+                       }
+                       if(strncmp(s->name, "string.", 7) == 0) {
+                               s->type = SSTRING;
+                               s->hide = 1;
+                       }
+                       if(strncmp(s->name, "go.string.", 10) == 0) {
+                               s->type = SGOSTRING;
+                               s->hide = 1;
+                       }
+               }
+       }
 
        genasmsym(putsymb);
 }