cmd/link: simplify content hashed symbol handling

Symbol's content hash used to depend on package path expansion in
symbol names, so we have special logic handling hashed symbols
when path expansion is needed. As we required -p in the compiler
the symbol names are now fully expanded. Remove that logic.

Change-Id: I888574f63ea3789455d96468a6abd500e0958230
Reviewed-on: https://go-review.googlesource.com/c/go/+/394218
Trust: Cherry Mui <cherryyz@google.com>
Reviewed-by: Than McIntosh <thanm@google.com>
Run-TryBot: Cherry Mui <cherryyz@google.com>
TryBot-Result: Gopher Robot <gobot@golang.org>
This commit is contained in:
Cherry Mui 2022-03-21 15:46:32 -04:00
parent e853464055
commit 77680a0644

View file

@ -261,8 +261,6 @@ type Loader struct {
flags uint32
hasUnknownPkgPath bool // if any Go object has unknown package path
strictDupMsgs int // number of strict-dup warning/errors, when FlagStrictDups is enabled
elfsetstring elfsetstringFunc
@ -361,7 +359,7 @@ func (l *Loader) addObj(pkg string, r *oReader) Sym {
l.start[r] = i
l.objs = append(l.objs, objIdx{r, i})
if r.NeedNameExpansion() && !r.FromAssembly() {
l.hasUnknownPkgPath = true
panic("object compiled without -p")
}
return i
}
@ -2126,16 +2124,6 @@ func (st *loadState) preloadSyms(r *oReader, kind int) {
case hashedDef:
start = uint32(r.ndef + r.nhashed64def)
end = uint32(r.ndef + r.nhashed64def + r.nhasheddef)
if l.hasUnknownPkgPath {
// The content hash depends on symbol name expansion. If any package is
// built without fully expanded names, the content hash is unreliable.
// Treat them as named symbols.
// This is rare.
// (We don't need to do this for hashed64Def case, as there the hash
// function is simply the identity function, which doesn't depend on
// name expansion.)
kind = nonPkgDef
}
case nonPkgDef:
start = uint32(r.ndef + r.nhashed64def + r.nhasheddef)
end = uint32(r.ndef + r.nhashed64def + r.nhasheddef + r.NNonpkgdef())