]> Cypherpunks repositories - gostls13.git/commitdiff
cmd/internal/obj: refactor ATEXT symbol initialization
authorJosh Bleecher Snyder <josharian@gmail.com>
Mon, 10 Apr 2017 23:57:06 +0000 (16:57 -0700)
committerJosh Bleecher Snyder <josharian@gmail.com>
Tue, 11 Apr 2017 02:56:56 +0000 (02:56 +0000)
This makes the core Flushplist loop clearer.

We may also want to move the Sym initialization
much earlier in the compiler (see discussion on
CL 40254), for which this paves the way.

While we're here, eliminate package log in favor of ctxt.Diag.

Passes toolstash-check -all.

Updates #15756

Change-Id: Ieaf848d196764a5aa82578b689af7bc6638c385a
Reviewed-on: https://go-review.googlesource.com/40313
Run-TryBot: Josh Bleecher Snyder <josharian@gmail.com>
TryBot-Result: Gobot Gobot <gobot@golang.org>
Reviewed-by: Michael Hudson-Doyle <michael.hudson@canonical.com>
src/cmd/asm/internal/asm/asm.go
src/cmd/compile/internal/gc/gsubr.go
src/cmd/internal/obj/plist.go

index e83cd7286d2168bbe4f1d75f93f3e0b633cafb9e..0e31677a3f617def58eda42a0de84b0a742136ea 100644 (file)
@@ -176,6 +176,7 @@ func (p *Parser) asmText(word string, operands [][]lex.Token) {
                },
        }
        prog.To.Val = int32(argSize)
+       p.ctxt.InitTextSym(prog)
 
        p.append(prog, "", true)
 }
index b22828f2e54026519a9ea8791873f389dd2ca7b4..2c628a521fc2023edd09331874482df54b54b99b 100644 (file)
@@ -185,6 +185,8 @@ func (pp *Progs) settext(fn *Node) {
                }
        }
 
+       Ctxt.InitTextSym(ptxt)
+
        pp.Text = ptxt
 }
 
index b79b39de8de12833f0228c09d5850af28c24ca00..6614f7d74ef0d95d0a4f9bb3dd502a31419fddc4 100644 (file)
@@ -6,7 +6,6 @@ package obj
 
 import (
        "fmt"
-       "log"
        "strings"
 )
 
@@ -42,33 +41,9 @@ func Flushplist(ctxt *Link, plist *Plist, newprog ProgAlloc) {
                        if s == nil {
                                // func _() { }
                                curtext = nil
-
                                continue
                        }
-                       if s.FuncInfo == nil {
-                               s.FuncInfo = new(FuncInfo)
-                       }
-
-                       if s.Text != nil {
-                               log.Fatalf("duplicate TEXT for %s", s.Name)
-                       }
-                       if s.OnList() {
-                               log.Fatalf("symbol %s listed multiple times", s.Name)
-                       }
-                       s.Set(AttrOnList, true)
                        text = append(text, s)
-                       flag := int(p.From3Offset())
-                       if flag&DUPOK != 0 {
-                               s.Set(AttrDuplicateOK, true)
-                       }
-                       if flag&NOSPLIT != 0 {
-                               s.Set(AttrNoSplit, true)
-                       }
-                       if flag&REFLECTMETHOD != 0 {
-                               s.Set(AttrReflectMethod, true)
-                       }
-                       s.Type = STEXT
-                       s.Text = p
                        etext = p
                        curtext = s
                        continue
@@ -137,13 +112,47 @@ func Flushplist(ctxt *Link, plist *Plist, newprog ProgAlloc) {
        ctxt.Text = append(ctxt.Text, text...)
 }
 
+func (ctxt *Link) InitTextSym(p *Prog) {
+       if p.As != ATEXT {
+               ctxt.Diag("InitTextSym non-ATEXT: %v", p)
+       }
+       s := p.From.Sym
+       if s == nil {
+               // func _() { }
+               return
+       }
+       if s.FuncInfo != nil {
+               ctxt.Diag("InitTextSym double init for %s", s.Name)
+       }
+       s.FuncInfo = new(FuncInfo)
+       if s.Text != nil {
+               ctxt.Diag("duplicate TEXT for %s", s.Name)
+       }
+       if s.OnList() {
+               ctxt.Diag("symbol %s listed multiple times", s.Name)
+       }
+       s.Set(AttrOnList, true)
+       flag := int(p.From3Offset())
+       if flag&DUPOK != 0 {
+               s.Set(AttrDuplicateOK, true)
+       }
+       if flag&NOSPLIT != 0 {
+               s.Set(AttrNoSplit, true)
+       }
+       if flag&REFLECTMETHOD != 0 {
+               s.Set(AttrReflectMethod, true)
+       }
+       s.Type = STEXT
+       s.Text = p
+}
+
 func (ctxt *Link) Globl(s *LSym, size int64, flag int) {
        if s.SeenGlobl() {
                fmt.Printf("duplicate %v\n", s)
        }
        s.Set(AttrSeenGlobl, true)
        if s.OnList() {
-               log.Fatalf("symbol %s listed multiple times", s.Name)
+               ctxt.Diag("symbol %s listed multiple times", s.Name)
        }
        s.Set(AttrOnList, true)
        ctxt.Data = append(ctxt.Data, s)