]> Cypherpunks repositories - gostls13.git/commitdiff
[dev.cc] asm: fix handling of statics (data<>) and symbols
authorRob Pike <r@golang.org>
Tue, 3 Feb 2015 18:41:16 +0000 (10:41 -0800)
committerRob Pike <r@golang.org>
Tue, 3 Feb 2015 20:43:37 +0000 (20:43 +0000)
A typo limited the number of center-dot substitutions to one. Fixed.

With these changes, plus a recent fix to 6a, the are no differences,
down to the bit level, in object code for any assembly files in std
between asm and 6a. (Runtime has not been checked yet, but I
expect no errors.)

Change-Id: I0e8045b4414223d937e7f8919c8768860554b7d5
Reviewed-on: https://go-review.googlesource.com/3820
Reviewed-by: Russ Cox <rsc@golang.org>
src/cmd/asm/internal/asm/asm.go
src/cmd/asm/internal/lex/input.go
src/cmd/asm/internal/lex/lex.go

index e17c1daa87857e53aa866f8c2bf318d2fcf6762b..ae4f6afffc1269fd9a888dc771bbf0728f7c8967 100644 (file)
@@ -39,6 +39,15 @@ func (p *Parser) symbolType(a *addr.Addr) int {
        return 0
 }
 
+// staticVersion reports whether the data's Symbol has <>, as in data<>.
+// It returns 1 for static, 0 for non-static, because that's what obj wants.
+func staticVersion(a *addr.Addr) int {
+       if a.Symbol != "" && a.IsStatic {
+               return 1
+       }
+       return 0
+}
+
 // TODO: configure the architecture
 
 // TODO: This is hacky and irregular. When obj settles down, rewrite for simplicity.
@@ -53,7 +62,6 @@ func (p *Parser) addrToAddr(a *addr.Addr) obj.Addr {
                // a<>(SB) = STATIC,NONE
                // The call to symbolType does the first column; we need to fix up Index here.
                out.Type = int16(p.symbolType(a))
-               out.Sym = obj.Linklookup(p.linkCtxt, a.Symbol, 0)
                if a.IsImmediateAddress {
                        // Index field says whether it's a static.
                        switch a.Register {
@@ -67,6 +75,7 @@ func (p *Parser) addrToAddr(a *addr.Addr) obj.Addr {
                                p.errorf("can't handle immediate address of %s not (SB)\n", a.Symbol)
                        }
                }
+               out.Sym = obj.Linklookup(p.linkCtxt, a.Symbol, staticVersion(a))
        } else if a.Has(addr.Register) {
                // TODO: SP is tricky, and this isn't good enough.
                // SP = D_SP
@@ -217,7 +226,7 @@ func (p *Parser) asmText(word string, operands [][]lex.Token) {
                From: obj.Addr{
                        Type:  int16(p.symbolType(&nameAddr)),
                        Index: uint8(p.arch.D_NONE),
-                       Sym:   obj.Linklookup(p.linkCtxt, name, 0),
+                       Sym:   obj.Linklookup(p.linkCtxt, name, staticVersion(&nameAddr)),
                        Scale: flag,
                },
                To: obj.Addr{
@@ -282,7 +291,7 @@ func (p *Parser) asmData(word string, operands [][]lex.Token) {
                From: obj.Addr{
                        Type:   int16(p.symbolType(&nameAddr)),
                        Index:  uint8(p.arch.D_NONE),
-                       Sym:    obj.Linklookup(p.linkCtxt, name, 0),
+                       Sym:    obj.Linklookup(p.linkCtxt, name, staticVersion(&nameAddr)),
                        Offset: nameAddr.Offset,
                        Scale:  scale,
                },
@@ -335,7 +344,7 @@ func (p *Parser) asmGlobl(word string, operands [][]lex.Token) {
                From: obj.Addr{
                        Type:   int16(p.symbolType(&nameAddr)),
                        Index:  uint8(p.arch.D_NONE),
-                       Sym:    obj.Linklookup(p.linkCtxt, name, 0),
+                       Sym:    obj.Linklookup(p.linkCtxt, name, staticVersion(&nameAddr)),
                        Offset: nameAddr.Offset,
                        Scale:  scale,
                },
@@ -425,7 +434,7 @@ func (p *Parser) asmFuncData(word string, operands [][]lex.Token) {
                To: obj.Addr{
                        Type:   int16(p.symbolType(&nameAddr)),
                        Index:  uint8(p.arch.D_NONE),
-                       Sym:    obj.Linklookup(p.linkCtxt, name, 0),
+                       Sym:    obj.Linklookup(p.linkCtxt, name, staticVersion(&nameAddr)),
                        Offset: value1,
                },
        }
@@ -485,7 +494,7 @@ func (p *Parser) asmJump(op int, a []addr.Addr) {
                }
                prog.To = obj.Addr{
                        Type:   int16(p.arch.D_BRANCH),
-                       Sym:    obj.Linklookup(p.linkCtxt, target.Symbol, 0),
+                       Sym:    obj.Linklookup(p.linkCtxt, target.Symbol, staticVersion(target)),
                        Index:  uint8(p.arch.D_NONE),
                        Offset: target.Offset,
                }
index 19a50f4fd094e7b952560f70ef4700dd8cdeb122..4c8abafc2392d727f3a1a89dc464eea016d4c69c 100644 (file)
@@ -422,6 +422,10 @@ func (in *Input) line() {
        if err != nil {
                in.Error("unquoting #line file name: ", err)
        }
+       tok = in.Stack.Next()
+       if tok != '\n' {
+               in.Error("unexpected token at end of #line: ", tok)
+       }
        obj.Linklinehist(linkCtxt, histLine, file, line)
        in.Stack.SetPos(line, file)
 }
index b4b0a8c3040928e93dca5cf56fbda39fcdba5e33..bf45ae70712b149d4cc0fbaea66672698785078d 100644 (file)
@@ -113,7 +113,7 @@ func Make(token ScanToken, text string) Token {
                text = `""` + text
        }
        // Substitute the substitutes for . and /.
-       text = strings.Replace(text, "\u00B7", ".", 1)
+       text = strings.Replace(text, "\u00B7", ".", -1)
        text = strings.Replace(text, "\u2215", "/", -1)
        return Token{ScanToken: token, text: text}
 }