Skip to content

Commit 6dd1901

Browse files
committed
fix panic
1 parent 556d029 commit 6dd1901

File tree

1 file changed

+28
-2
lines changed

1 file changed

+28
-2
lines changed

src/cmd/internal/obj/sym.go

Lines changed: 28 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -348,8 +348,34 @@ func (ctxt *Link) NumberSyms() {
348348
}
349349
pkg := rs.Pkg
350350
if rs.ContentAddressable() {
351-
// for now, only support content-addressable symbols that are always locally defined.
352-
panic("hashed refs unsupported for now")
351+
// Content-addressable symbols must be locally defined. If a ref shows up
352+
// without being indexed, treat it as a local definition so it can be
353+
// emitted in this object (hashed refs are still unsupported).
354+
if rs.Pkg != "" && rs.Pkg != "\"\"" && rs.Pkg != ctxt.Pkgpath {
355+
panic("hashed refs unsupported for now")
356+
}
357+
if rs.Indexed() {
358+
return
359+
}
360+
if rs.Size <= 8 && len(rs.R) == 0 && contentHashSection(rs) == 0 {
361+
rs.PkgIdx = goobj.PkgIdxHashed64
362+
rs.SymIdx = hashed64idx
363+
if hashed64idx != int32(len(ctxt.hashed64defs)) {
364+
panic("bad index")
365+
}
366+
ctxt.hashed64defs = append(ctxt.hashed64defs, rs)
367+
hashed64idx++
368+
} else {
369+
rs.PkgIdx = goobj.PkgIdxHashed
370+
rs.SymIdx = hashedidx
371+
if hashedidx != int32(len(ctxt.hasheddefs)) {
372+
panic("bad index")
373+
}
374+
ctxt.hasheddefs = append(ctxt.hasheddefs, rs)
375+
hashedidx++
376+
}
377+
rs.Set(AttrIndexed, true)
378+
return
353379
}
354380
if pkg == "" || pkg == "\"\"" || pkg == "_" || !rs.Indexed() {
355381
rs.PkgIdx = goobj.PkgIdxNone

0 commit comments

Comments
 (0)