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

x/arch/x86/x86asm: Mem.Disp is positive for negative displacements #18666

Closed
minux opened this issue Jan 15, 2017 · 4 comments
Closed

x/arch/x86/x86asm: Mem.Disp is positive for negative displacements #18666

minux opened this issue Jan 15, 2017 · 4 comments

Comments

@minux
Copy link
Member

minux commented Jan 15, 2017

package main

import "golang.org/x/arch/x86/x86asm"

func main() {
	text := []byte{0x48, 0x8d, 0x05, 0x0d, 0xea, 0xff, 0xff}
	inst, err := x86asm.Decode(text[:], 64)
	if err != nil {
		panic(err)
	}
	println(x86asm.GNUSyntax(inst))
}

The program outputs:
lea 0xffffea0d(%rip),%rax
which is obviously incorrect. The correct disassembly should be:

$ echo '0x48, 0x8d, 0x05, 0x0d, 0xea, 0xff, 0xff' | tr -d ',' | llvm-mc -disassemble
leaq	-5619(%rip), %rax

The problem is that, in the decoded arg, the Disp is int64(0xffffea0d). Whereas it should be a negative number instead as the displacement is always signed.

I haven't checked other use of Mem, but I suspect they all have this problem.

/cc @rsc

@minux minux added this to the Unreleased milestone Jan 15, 2017
@josharian
Copy link
Contributor

Possibly related: #8000

@josharian
Copy link
Contributor

If it is related, https://codereview.appspot.com/100480046/ might be of use.

@minux
Copy link
Member Author

minux commented Jan 15, 2017 via email

@minux minux closed this as completed Jan 15, 2017
@minux
Copy link
Member Author

minux commented Jan 15, 2017 via email

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

3 participants