Commit c480d32f authored by Cherry Zhang's avatar Cherry Zhang

[dev.link] cmd/link: do not put static symbols into name lookup table

Since the previous CL, we will not reference static symbols by
name. Therefore no need to put them into the name lookup table.

On Linux/ARM, in runtime/internal/atomic/sys_linux_arm.s, the
kernelcas function has a definition and a reference written in
two different forms, one with package prefix, one without. This
way, the assembler cannot know they are the same symbol, only the
linker knows. This is quite unusual, unify the names to so the
assembler can resolve it to index.

Change-Id: Ie7223097be6a3b65f3fa43ed4575da9972ef5b69
Reviewed-on: https://go-review.googlesource.com/c/go/+/201998
Run-TryBot: Cherry Zhang <cherryyz@google.com>
TryBot-Result: Gobot Gobot <gobot@golang.org>
Reviewed-by: default avatarThan McIntosh <thanm@google.com>
parent d56c8149
...@@ -147,6 +147,12 @@ func (l *Loader) AddSym(name string, ver int, i Sym, r *oReader, dupok bool, typ ...@@ -147,6 +147,12 @@ func (l *Loader) AddSym(name string, ver int, i Sym, r *oReader, dupok bool, typ
if l.extStart != 0 { if l.extStart != 0 {
panic("AddSym called after AddExtSym is called") panic("AddSym called after AddExtSym is called")
} }
if ver == r.version {
// Static symbol. Add its global index but don't
// add to name lookup table, as it cannot be
// referenced by name.
return true
}
nv := nameVer{name, ver} nv := nameVer{name, ver}
if oldi, ok := l.symsByName[nv]; ok { if oldi, ok := l.symsByName[nv]; ok {
if dupok { if dupok {
...@@ -294,7 +300,10 @@ func (l *Loader) IsDup(i Sym) bool { ...@@ -294,7 +300,10 @@ func (l *Loader) IsDup(i Sym) bool {
return false return false
} }
if osym.Name == "" { if osym.Name == "" {
return false return false // Unnamed aux symbol cannot be dup.
}
if osym.ABI == goobj2.SymABIstatic {
return false // Static symbol cannot be dup.
} }
name := strings.Replace(osym.Name, "\"\".", r.pkgprefix, -1) name := strings.Replace(osym.Name, "\"\".", r.pkgprefix, -1)
ver := abiToVer(osym.ABI, r.version) ver := abiToVer(osym.ABI, r.version)
...@@ -656,7 +665,7 @@ func loadObjSyms(l *Loader, syms *sym.Symbols, r *oReader) { ...@@ -656,7 +665,7 @@ func loadObjSyms(l *Loader, syms *sym.Symbols, r *oReader) {
continue continue
} }
ver := abiToVer(osym.ABI, r.version) ver := abiToVer(osym.ABI, r.version)
if l.symsByName[nameVer{name, ver}] != istart+Sym(i) { if osym.ABI != goobj2.SymABIstatic && l.symsByName[nameVer{name, ver}] != istart+Sym(i) {
continue continue
} }
...@@ -709,17 +718,19 @@ func loadObjFull(l *Loader, r *oReader) { ...@@ -709,17 +718,19 @@ func loadObjFull(l *Loader, r *oReader) {
} }
ver := abiToVer(osym.ABI, r.version) ver := abiToVer(osym.ABI, r.version)
dupok := osym.Dupok() dupok := osym.Dupok()
if dupsym := l.symsByName[nameVer{name, ver}]; dupsym != istart+Sym(i) { if dupok {
if dupok && l.Reachable.Has(dupsym) { if dupsym := l.symsByName[nameVer{name, ver}]; dupsym != istart+Sym(i) {
// A dupok symbol is resolved to another package. We still need if l.Reachable.Has(dupsym) {
// to record its presence in the current package, as the trampoline // A dupok symbol is resolved to another package. We still need
// pass expects packages are laid out in dependency order. // to record its presence in the current package, as the trampoline
s := l.Syms[dupsym] // pass expects packages are laid out in dependency order.
if s.Type == sym.STEXT { s := l.Syms[dupsym]
lib.DupTextSyms = append(lib.DupTextSyms, s) if s.Type == sym.STEXT {
lib.DupTextSyms = append(lib.DupTextSyms, s)
}
} }
continue
} }
continue
} }
s := l.Syms[istart+Sym(i)] s := l.Syms[istart+Sym(i)]
......
...@@ -29,9 +29,9 @@ TEXT runtime∕internal∕atomic·Cas(SB),NOSPLIT|NOFRAME,$0 ...@@ -29,9 +29,9 @@ TEXT runtime∕internal∕atomic·Cas(SB),NOSPLIT|NOFRAME,$0
CMP $7, R11 CMP $7, R11
BLT 2(PC) BLT 2(PC)
JMP ·armcas(SB) JMP ·armcas(SB)
JMP ·kernelcas<>(SB) JMP kernelcas<>(SB)
TEXT runtimeinternalatomic·kernelcas<>(SB),NOSPLIT,$0 TEXT kernelcas<>(SB),NOSPLIT,$0
MOVW ptr+0(FP), R2 MOVW ptr+0(FP), R2
// trigger potential paging fault here, // trigger potential paging fault here,
// because we don't know how to traceback through __kuser_cmpxchg // because we don't know how to traceback through __kuser_cmpxchg
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment