]> Cypherpunks repositories - gostls13.git/commitdiff
cmd/link/internal/ld: exclude only real container symbols from symtab
authorKeith Randall <khr@golang.org>
Sat, 27 Jun 2015 19:57:06 +0000 (12:57 -0700)
committerKeith Randall <khr@golang.org>
Mon, 29 Jun 2015 02:54:09 +0000 (02:54 +0000)
It looks like the test for whether symbols contain subsymbols is wrong.
In particular, symbols in C libraries are mistakenly considered container
symbols.

Fix the test so only symbols which actually have a subsymbol
are excluded from the symtab.  When linking cgo programs the list
of containers is small, something like:

container _/home/khr/sandbox/symtab/misc/cgo/test(.text)<74>
container _/home/khr/sandbox/symtab/misc/cgo/test/issue8828(.text)<75>
container _/home/khr/sandbox/symtab/misc/cgo/test/issue9026(.text)<76>
container runtime/cgo(.text)<77>

I'm not sure this is the right fix.  In particular I can't reproduce
the original problem.  Anyone have a repro they can try and see if
this fix works?

Fixes #10747
Fixes #11396

Change-Id: Id8b016389d33348b4a791fdcba0f9db8ae71ebf3
Reviewed-on: https://go-review.googlesource.com/11652
Reviewed-by: Russ Cox <rsc@golang.org>
src/cmd/internal/obj/link.go
src/cmd/link/internal/ld/pcln.go

index a6ade0f20d9770b92e72e135d42cd3258df675c8..24de6ef698b7f1c431e1e77761ae9dfdbac645bf 100644 (file)
@@ -365,9 +365,10 @@ const (
        SCONST
        SDYNIMPORT
        SHOSTOBJ
-       SSUB    = 1 << 8
-       SMASK   = SSUB - 1
-       SHIDDEN = 1 << 9
+       SSUB       = 1 << 8
+       SMASK      = SSUB - 1
+       SHIDDEN    = 1 << 9
+       SCONTAINER = 1 << 10 // has a sub-symbol
 )
 
 type Reloc struct {
index be2568d3b9dc6a01ea0d3e30e0d3e2a6fe50ec9a..56d813bfde7f9f616f7748f471095d8070cc8baa 100644 (file)
@@ -191,7 +191,7 @@ func renumberfiles(ctxt *Link, files []*LSym, d *Pcdata) {
 func container(s *LSym) int {
        // We want to generate func table entries only for the "lowest level" symbols,
        // not containers of subsymbols.
-       if s != nil && s.Sub != nil {
+       if s != nil && s.Type&obj.SCONTAINER != 0 {
                return 1
        }
        return 0
@@ -223,6 +223,13 @@ func pclntab() {
        //      offset to file table [4 bytes]
        nfunc := int32(0)
 
+       // Find container symbols, mark them with SCONTAINER
+       for Ctxt.Cursym = Ctxt.Textp; Ctxt.Cursym != nil; Ctxt.Cursym = Ctxt.Cursym.Next {
+               if Ctxt.Cursym.Outer != nil {
+                       Ctxt.Cursym.Outer.Type |= obj.SCONTAINER
+               }
+       }
+
        for Ctxt.Cursym = Ctxt.Textp; Ctxt.Cursym != nil; Ctxt.Cursym = Ctxt.Cursym.Next {
                if container(Ctxt.Cursym) == 0 {
                        nfunc++