Skip to content

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

@minux

Description

@minux
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

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions