Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

cmd/asm: wrong error message when assembling incorrect program #12470

Closed
4ad opened this issue Sep 3, 2015 · 9 comments
Closed

cmd/asm: wrong error message when assembling incorrect program #12470

4ad opened this issue Sep 3, 2015 · 9 comments
Milestone

Comments

@4ad
Copy link
Member

4ad commented Sep 3, 2015

: iridium:tmp; cat a0.s
TEXT    foo0(SB),7,$-8
    ADD R520, R1
    RET
: iridium:tmp; GOOS=linux GOARCH=arm go tool asm -S $HOME/tmp/a0.s
asm: illegal combination 00000 (/Users/aram/tmp/a0.s:2) ADD 0, R1; SOREG NONE REG, 7 11
: iridium:tmp; GOOS=linux GOARCH=arm64 go tool asm -S $HOME/tmp/a0.s
asm: illegal combination 00000 (/Users/aram/tmp/a0.s:2) ADD 0, R1 ZOREG NONE REG, 7 11
: iridium:tmp; 
@4ad 4ad added this to the Go1.6 milestone Sep 3, 2015
@4ad
Copy link
Member Author

4ad commented Sep 3, 2015

There are two problems here, first, the operand is encoded incorrectly, which makes cmd/internal/obj/... bail out correctly, but with wrong error message.

The second problem is that the printing of the Addr is wrong as well.

@4ad 4ad changed the title cmd/asm: wrong error when assembling incorrect program cmd/asm: wrong error message when assembling incorrect program Sep 3, 2015
@minux
Copy link
Member

minux commented Sep 3, 2015

And cmd/asm seems to abort after the first call to
ctxt.Diag, making further output after "illegal combination"
unavailable from cmd/internal/obj.

I'm also hit by this problem (I added another call to ctxt.Diag
and it never comes out.)

@robpike
Copy link
Contributor

robpike commented Sep 11, 2015

This one is tricky. I was thrown by the R520, but that's being parsed as a symbol, so in amd64 terms, the error is caused by
ADDQ xxx, R1

The issue is that this is a syntax error, but is not caught as one because the operand parser has no context, and it is illegal to have a bare symbol like that except as a jump label. I made a tiny change to catch that case, and it failed on arm64 because of this obscure syntax:

CSINV CS, R1, R2, R3

here the CS is a magic word, not a register, that is parsing as TYPE_MEM. It really shouldn't be. We should fix that somehow or special-case it more precisely in the assembler - it works only by accident. If that's fixed, the fix can be made so that xxx is allowed only as a label and you get this nice error:

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

@robpike
Copy link
Contributor

robpike commented Sep 15, 2015

This has been fixed by other changes.

x.s:2: unrecognized instruction "ADD"
x.s:5: unrecognized instruction "ADD"
asm: asm: assembly of x.s failed

@robpike robpike closed this as completed Sep 15, 2015
@robpike robpike reopened this Sep 15, 2015
@robpike robpike closed this as completed Sep 15, 2015
@4ad
Copy link
Member Author

4ad commented Sep 16, 2015

I'm sorry, but this is not fixed, in fact, for many instruction the form is silently accepted creating hard to debug defects.

: iridium:tmp; cat a0.s
TEXT    foo0(SB),7,$-8
    MOVD    R520, R5
    RET
: iridium:tmp; GOOS=linux GOARCH=arm64 go tool asm -o /tmp/a.o -S /Users/aram/tmp/a0.s
foo0 t=1 dupok nosplit size=16 value=0 args=0xffffffff80000000 locals=0xfffffffffffffff8 leaf
    0x0000 00000 (/Users/aram/tmp/a0.s:1)   TEXT    foo0(SB), 7, $-8
    0x0000 00000 (/Users/aram/tmp/a0.s:2)   MOVD    0, R5
    0x0004 00004 (/Users/aram/tmp/a0.s:3)   RET (R30)
    0x0000 05 00 40 f9 c0 03 5f d6 00 00 00 00 00 00 00 00  ..@..._.........
    rel 4+0 t=8 +0
: iridium:tmp; 

@4ad 4ad reopened this Sep 16, 2015
@robpike
Copy link
Contributor

robpike commented Sep 16, 2015

The problem is about the syntax
R520
I cannot put in a fix for that until someone fixes the arm64 obj representation for condition codes. That is issue #12632. Fix that and the invalid syntax here can be rejected cleanly. I have assigned it to you to encourage progress.

P.S. Read the longer message from me above.

@4ad
Copy link
Member Author

4ad commented Sep 16, 2015

I'll fix the arm64 problem.

@gopherbot
Copy link

CL https://golang.org/cl/14680 mentions this issue.

4ad added a commit that referenced this issue Sep 17, 2015
Add CS as an alias for HS, and CC as an alias for LO, otherwise

	CSINV	CS, R1, R2, R3

was interpreted as

	CSINV	0, R1, R2, R3

Also fix the corresponding faulty test.

Fixes #12632
Updates #12470

Change-Id: I974cfc7e5ced682d4754ba09b0b102cb08a46567
Reviewed-on: https://go-review.googlesource.com/14680
Reviewed-by: Rob Pike <r@golang.org>
@gopherbot
Copy link

CL https://golang.org/cl/14691 mentions this issue.

@golang golang locked and limited conversation to collaborators Sep 22, 2016
@rsc rsc unassigned robpike Jun 23, 2022
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

No branches or pull requests

4 participants