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

Add compatibility tests with nasm #156

Closed
postmodern opened this issue Mar 6, 2025 · 2 comments
Closed

Add compatibility tests with nasm #156

postmodern opened this issue Mar 6, 2025 · 2 comments
Labels
tests Tests x86-64 x86-64 architecture x86 x86
Milestone

Comments

@postmodern
Copy link
Member

Add specs that test whether Program#assemble can output the same bytes as nasm would given the same ASM syntax. This should catch any remaining edge-cases in X86::Encoder and X86_64::Encoder with respect to exotic features, such as:

  • SIB memory addressing
  • RIP-relative offsets (ex: _label[rip])
  • relative jumps
  • jumping to a register
  • EVEX encoding
    • vector register operands
    • {k}/{k}{z} write masks
    • scalar-to-vector memory broadcasting
    • {er}/{sae}
@postmodern postmodern added tests Tests x86 x86 x86-64 x86-64 architecture labels Mar 6, 2025
@postmodern postmodern added this to the 1.0.0 milestone Mar 6, 2025
@postmodern
Copy link
Member Author

It appears that nasm does not support certain instruction names that ronin-asm supports, which are from Opcodes:

BITS 32
section .text
_start:
	aor	[ecx],	ecx
/tmp/ronin-asm-x86-20250318-77905-vmet9i.s:4: error: parser: instruction expected

nasm also appears to have odd implicit operand casting rules that require you omit the BYTE/WORD/DWORD/QWORD size specifier for single operand instructions:

BITS 32
section .text
_start:
	clflush	BYTE [ecx]
/tmp/ronin-asm-x86-20250318-77905-w14n51.s:4: error: mismatch in operand sizes

Also noticing slight differences in byte encoding of instructions:

  2) Ronin::ASM::X86::Instructions::ADD#encode when given operands of types mem32, imm8 is expected to eq "\x80\x01A"
     Failure/Error: expect(output.string).to eq(nasm(subject))
     
       expected: "\x80\x01A"
            got: "\x83\x01A"
     
       (compared using ==)
     # ./spec/x86/instructions/add_spec.rb:415:in `block (4 levels) in <top (required)>'

@postmodern
Copy link
Member Author

Going to skip this due to nasm's encoded instructions being slightly different from our encoded instructions.

@postmodern postmodern closed this as not planned Won't fix, can't repro, duplicate, stale Mar 26, 2025
@github-project-automation github-project-automation bot moved this from In Progress to Done in ronin-asm refactor Mar 26, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
tests Tests x86-64 x86-64 architecture x86 x86
Projects
Status: Done
Development

No branches or pull requests

1 participant