1
0
mirror of https://github.com/golang/go synced 2024-11-19 11:04:47 -07:00

cmd/link: tidy up rdsym

Use an early return. Check errors. Deduplicate.

Change-Id: Iabefd563b5ef82a16fab4791277630804fd09003
Reviewed-on: https://go-review.googlesource.com/20597
Run-TryBot: Josh Bleecher Snyder <josharian@gmail.com>
TryBot-Result: Gobot Gobot <gobot@golang.org>
Reviewed-by: Brad Fitzpatrick <bradfitz@golang.org>
This commit is contained in:
Josh Bleecher Snyder 2016-03-11 11:58:06 -08:00
parent de4317cbd7
commit 2ac8555d57

View File

@ -494,25 +494,31 @@ func rdsym(ctxt *Link, f *obj.Biobuf, pkg string) *LSym {
v = ctxt.Version
}
s := Linklookup(ctxt, name, v)
if v == 0 && s.Name[0] == '$' && s.Type == 0 {
if strings.HasPrefix(s.Name, "$f32.") {
x, _ := strconv.ParseUint(s.Name[5:], 16, 32)
i32 := int32(x)
s.Type = obj.SRODATA
s.Attr |= AttrLocal
Adduint32(ctxt, s, uint32(i32))
s.Attr.Set(AttrReachable, false)
} else if strings.HasPrefix(s.Name, "$f64.") || strings.HasPrefix(s.Name, "$i64.") {
x, _ := strconv.ParseUint(s.Name[5:], 16, 64)
i64 := int64(x)
s.Type = obj.SRODATA
s.Attr |= AttrLocal
Adduint64(ctxt, s, uint64(i64))
s.Attr.Set(AttrReachable, false)
}
if v != 0 {
return s
}
if v == 0 && strings.HasPrefix(s.Name, "runtime.gcbits.") {
if s.Name[0] == '$' && len(s.Name) > 5 && s.Type == 0 {
x, err := strconv.ParseUint(s.Name[5:], 16, 64)
if err != nil {
log.Panicf("failed to parse $-symbol %s: %v", s.Name, err)
}
s.Type = obj.SRODATA
s.Attr |= AttrLocal
switch s.Name[:5] {
case "$f32.":
if uint64(uint32(x)) != x {
log.Panicf("$-symbol %s too large: %d", s.Name, x)
}
Adduint32(ctxt, s, uint32(x))
case "$f64.", "$i64.":
Adduint64(ctxt, s, x)
default:
log.Panicf("unrecognized $-symbol: %s", s.Name)
}
s.Attr.Set(AttrReachable, false)
}
if strings.HasPrefix(s.Name, "runtime.gcbits.") {
s.Attr |= AttrLocal
}
return s