• David Crawshaw's avatar
    cmd/compile, etc: store method tables as offsets · 7d469179
    David Crawshaw authored
    This CL introduces the typeOff type and a lookup method of the same
    name that can turn a typeOff offset into an *rtype.
    
    In a typical Go binary (built with buildmode=exe, pie, c-archive, or
    c-shared), there is one moduledata and all typeOff values are offsets
    relative to firstmoduledata.types. This makes computing the pointer
    cheap in typical programs.
    
    With buildmode=shared (and one day, buildmode=plugin) there are
    multiple modules whose relative offset is determined at runtime.
    We identify a type in the general case by the pair of the original
    *rtype that references it and its typeOff value. We determine
    the module from the original pointer, and then use the typeOff from
    there to compute the final *rtype.
    
    To ensure there is only one *rtype representing each type, the
    runtime initializes a typemap for each module, using any identical
    type from an earlier module when resolving that offset. This means
    that types computed from an offset match the type mapped by the
    pointer dynamic relocations.
    
    A series of followup CLs will replace other *rtype values with typeOff
    (and name/*string with nameOff).
    
    For types created at runtime by reflect, type offsets are treated as
    global IDs and reference into a reflect offset map kept by the runtime.
    
    darwin/amd64:
    	cmd/go:  -57KB (0.6%)
    	jujud:  -557KB (0.8%)
    
    linux/amd64 PIE:
    	cmd/go: -361KB (3.0%)
    	jujud:  -3.5MB (4.2%)
    
    For #6853.
    
    Change-Id: Icf096fd884a0a0cb9f280f46f7a26c70a9006c96
    Reviewed-on: https://go-review.googlesource.com/21285Reviewed-by: 's avatarIan Lance Taylor <iant@golang.org>
    Run-TryBot: David Crawshaw <crawshaw@golang.org>
    TryBot-Result: Gobot Gobot <gobot@golang.org>
    7d469179
symtab.go 14.5 KB