|
From: | Michael Matz |
Subject: | Re: [Tinycc-devel] lcall invalid hex code |
Date: | Tue, 3 May 2016 00:42:43 +0200 (CEST) |
User-agent: | Alpine 2.20 (LSU 67 2015-01-07) |
Hi, On Mon, 2 May 2016, Sergey Korshunoff wrote:
fix the "bug #39341: TCC emits wrong opcode for XCHG" .... #include <stdio.h> int main() { int i = 0x16789; printf("Number: %x\n", i); __asm__ __volatile__ ("xchg %%ah, %%al;" : "=a" (i) : "0" (i)); printf("Reversed: %x\n", i); } // The asm instruction is 0x94 which is xchg %eax,%esp (according to objdump // and ollydbg). This leads to an immediate segfault! // The correct opcode would be 0x86 0xE0.. A bug description: a byte code ops must be declared _before_ a word codes in i386-asm.h and x86_64-asm.h
Not really. It does work-around the above problem, but at the expense of not using the one-byte opcode 0x90+reg anymore, even if possible. Generally the opcode in i386-asm.h are sorted by some sort of preference (e.g. first the one-byte opcodes for nops, then the more capable two-byte opcodes for general xchg). Something isn't right in the i386-asm.c opcode parser/selector. It should reject the first ("xchgw") alternative if presented with byte-registers. I'll take a look.
Ciao, Michael.
[Prev in Thread] | Current Thread | [Next in Thread] |