问题
I am porting Quake 2's inline Win32 assembly to GAS. I started out by taking the inline assembly and then placing it into it's own ASM file. Fixed any issues, then started porting to GAS. I do know that the src/dst is reversed in AT&T vs Intel syntax (including floating point registers for some math operations) and a few other small gotchas, but when I got this compiling fine I noticed that the code was not working as intended. I looked over it carefully for hours with a compare utility and reading assembly manuals and finally tried "objdump -dwrC > out.txt" on the GAS and MASM versions. What I noticed was strange.
All of the code looked to be generated the same except in the MASM version there is an "fsubp st(1), st(0)" line and in GAS it was "fsubrp st(1), st(0)". This is strange because the actually assembly code in MASM and GAS both used fsubrp. Changing it to fsubp allowed the particle drawing code to work as intended.
Why is this happening?
Steps taken: Verifying src/dst line by line with compare utilities, reading x87 assembly manuals including tutorials and GCC ASM manual for any quirks.
Code snippet: Original MASM code:
fsubrp st(1), st(0)
GAS code:
fsubrp %st(0), %st(1)
MASM code according to objdump:
fsubp %st(0), st(1)
GAS code according to objdump:
fsubrp %st(0), st(1)
Expected results: I expected subrp to be generated in the objdump of the MASM file not fsubp.
回答1:
This is a known bug with gas which unfortunately cannot be fixed; reversed vs. non-reversed mnemonics for x87 non-commutative floating point instructions with register operands (like fdiv
vs. fdivr
) is the wrong way round. As compilers expect the order to be this way, this bug is here to stay.
See the AT&T Syntax bugs section of the GAS manual; this syntax design bug originated with AT&T's UnixWare assembler, and GAS chose to copy that syntax for compatibility.
It also affects objdump
in AT&T mode.
回答2:
I figured this out. Thanks to Peter Cordes, I did run with -Mintel on MASM and GAS versions. The opcodes were wrong like he stated. For some reason with GAS if you have and fsubp followed by and fsubrp you have to reverse that. Once this was done, it was generating the right opcodes. Not sure if this an ultra-obscure issue.
来源:https://stackoverflow.com/questions/56210264/objdump-swapping-fsubrp-to-fsubp-on-compiled-assembly