Skip to content

Commit 7e54aa2

Browse files
committed
cmd/link: don't mark a symbol's GoType reachable when -linkshared
In CL 231397, we stopped marking symbols' GoType reachable in general, but not when -linkshared. It was left as a TODO. This CL addresses it. The problem was that the type names are mangled in the shared library, so we need to mangle the name consistently in the executable as well (regardless of whether the symbol is reachable or not), so that the GCProg generation code can find the corresponding symbol from the shared library. Change-Id: I1040747402929a983ec581109f1681a77893682e Reviewed-on: https://go-review.googlesource.com/c/go/+/255964 Trust: Cherry Zhang <[email protected]> Run-TryBot: Cherry Zhang <[email protected]> Reviewed-by: Jeremy Faller <[email protected]> Reviewed-by: Than McIntosh <[email protected]> TryBot-Result: Go Bot <[email protected]>
1 parent d91d076 commit 7e54aa2

File tree

2 files changed

+7
-6
lines changed

2 files changed

+7
-6
lines changed

src/cmd/link/internal/ld/deadcode.go

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -174,13 +174,9 @@ func (d *deadcodePass) flood() {
174174
naux := d.ldr.NAux(symIdx)
175175
for i := 0; i < naux; i++ {
176176
a := d.ldr.Aux(symIdx, i)
177-
if a.Type() == goobj.AuxGotype && !d.ctxt.linkShared {
177+
if a.Type() == goobj.AuxGotype {
178178
// A symbol being reachable doesn't imply we need its
179179
// type descriptor. Don't mark it.
180-
// TODO: when -linkshared, the GCProg generation code
181-
// seems to need it. I'm not sure why. I think it could
182-
// just reach to the type descriptor's data without
183-
// requiring to mark it reachable.
184180
continue
185181
}
186182
d.mark(a.Sym(), symIdx)

src/cmd/link/internal/ld/lib.go

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -831,7 +831,12 @@ func (ctxt *Link) mangleTypeSym() {
831831

832832
ldr := ctxt.loader
833833
for s := loader.Sym(1); s < loader.Sym(ldr.NSym()); s++ {
834-
if !ldr.AttrReachable(s) {
834+
if !ldr.AttrReachable(s) && !ctxt.linkShared {
835+
// If -linkshared, the GCProg generation code may need to reach
836+
// out to the shared library for the type descriptor's data, even
837+
// the type descriptor itself is not actually needed at run time
838+
// (therefore not reachable). We still need to mangle its name,
839+
// so it is consistent with the one stored in the shared library.
835840
continue
836841
}
837842
name := ldr.SymName(s)

0 commit comments

Comments
 (0)