From: Rob Pike Date: Tue, 3 Feb 2015 18:41:16 +0000 (-0800) Subject: [dev.cc] asm: fix handling of statics (data<>) and symbols X-Git-Tag: go1.5beta1~1915^2~83 X-Git-Url: http://www.git.cypherpunks.su/?a=commitdiff_plain;h=eeebcd9db30219d41ddb8a17d2bba3e72c894dd5;p=gostls13.git [dev.cc] asm: fix handling of statics (data<>) and symbols 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 --- diff --git a/src/cmd/asm/internal/asm/asm.go b/src/cmd/asm/internal/asm/asm.go index e17c1daa87..ae4f6afffc 100644 --- a/src/cmd/asm/internal/asm/asm.go +++ b/src/cmd/asm/internal/asm/asm.go @@ -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, } diff --git a/src/cmd/asm/internal/lex/input.go b/src/cmd/asm/internal/lex/input.go index 19a50f4fd0..4c8abafc23 100644 --- a/src/cmd/asm/internal/lex/input.go +++ b/src/cmd/asm/internal/lex/input.go @@ -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) } diff --git a/src/cmd/asm/internal/lex/lex.go b/src/cmd/asm/internal/lex/lex.go index b4b0a8c304..bf45ae7071 100644 --- a/src/cmd/asm/internal/lex/lex.go +++ b/src/cmd/asm/internal/lex/lex.go @@ -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} }