Commit 49580db1 authored by Rob Pike's avatar Rob Pike

asm: give error message for unadorned symbol reference

On amd64, the program

TEXT    foo0(SB),7,$-8
    ADDQ R520, R1
    RET

used to trigger this error because R520 was being passed through to obj:

asm: doasm: notfound ft=23 tt=23 00000 (x.s:2)	ADDQ	0, 0 23 23

Now it gets this one, as it is indeed a parse error:

x.s:2: illegal addressing mode for symbol R520

This couldn't be fixed until #12632 had been fixed for arm64.

Fixes #12470.

Change-Id: I19830c4ae9337887b93f85d9a239e2b89dbb2219
Reviewed-on: https://go-review.googlesource.com/14691Reviewed-by: 's avatarAram Hăvărneanu <aram@mgk.ro>
parent 8bd222f0
...@@ -38,6 +38,7 @@ type Parser struct { ...@@ -38,6 +38,7 @@ type Parser struct {
firstProg *obj.Prog firstProg *obj.Prog
lastProg *obj.Prog lastProg *obj.Prog
dataAddr map[string]int64 // Most recent address for DATA for this symbol. dataAddr map[string]int64 // Most recent address for DATA for this symbol.
isJump bool // Instruction being assembled is a jump.
errorWriter io.Writer errorWriter io.Writer
} }
...@@ -197,15 +198,15 @@ func (p *Parser) line() bool { ...@@ -197,15 +198,15 @@ func (p *Parser) line() bool {
func (p *Parser) instruction(op int, word, cond string, operands [][]lex.Token) { func (p *Parser) instruction(op int, word, cond string, operands [][]lex.Token) {
p.addr = p.addr[0:0] p.addr = p.addr[0:0]
isJump := p.arch.IsJump(word) p.isJump = p.arch.IsJump(word)
for _, op := range operands { for _, op := range operands {
addr := p.address(op) addr := p.address(op)
if !isJump && addr.Reg < 0 { // Jumps refer to PC, a pseudo. if !p.isJump && addr.Reg < 0 { // Jumps refer to PC, a pseudo.
p.errorf("illegal use of pseudo-register in %s", word) p.errorf("illegal use of pseudo-register in %s", word)
} }
p.addr = append(p.addr, addr) p.addr = append(p.addr, addr)
} }
if isJump { if p.isJump {
p.asmJump(op, cond, p.addr) p.asmJump(op, cond, p.addr)
return return
} }
...@@ -575,12 +576,14 @@ func (p *Parser) symbolReference(a *obj.Addr, name string, prefix rune) { ...@@ -575,12 +576,14 @@ func (p *Parser) symbolReference(a *obj.Addr, name string, prefix rune) {
} }
a.Sym = obj.Linklookup(p.ctxt, name, isStatic) a.Sym = obj.Linklookup(p.ctxt, name, isStatic)
if p.peek() == scanner.EOF { if p.peek() == scanner.EOF {
if prefix != 0 { if prefix == 0 && p.isJump {
p.errorf("illegal addressing mode for symbol %s", name) // Symbols without prefix or suffix are jump labels.
return
} }
p.errorf("illegal or missing addressing mode for symbol %s", name)
return return
} }
// Expect (SB) or (FP), (PC), (SB), or (SP) // Expect (SB), (FP), (PC), or (SP)
p.get('(') p.get('(')
reg := p.get(scanner.Ident).String() reg := p.get(scanner.Ident).String()
p.get(')') p.get(')')
......
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