x86 code generation bug

Martin v. Loewis martin@mira.isdn.cs.tu-berlin.de
Thu Sep 30 19:57:00 GMT 1999


> 	The following program generates bad code when compiled with
> optimization on x86 and good code when compiled without optimization.
> This is true for gcc-2.7.2.3, gcc-2.95.1, and egcs-19990907 (after
> commenting out the syntax error in gcc/configure).  I believe the
> reason is that the x86 machine description is incorrect
> for how to do a call to an absolute address.  I think that gcc thinks
> that to call address 0x12345678, it should emit "call 0x12345678",
> but this syntax generates an instruction that calls address PC+0x12345678.
> I believe gcc should generate something like "call 0x12345678-PC" (not
> exactly the correct syntax).  Probably just commenting out the
> support for calling an absolute address in the machine description
> should be sufficient to patch the problem.

Thanks for your bug report. I believe this is a known issue, and
various people have made various comments about the nature of the
problem:

a) The code you write has undefined behaviour, you cannot call an
   integer in ANSI C. Therefore, it deserves to break.

b) The generated assembler code is correct; this is a bug in the
   assembler and/or the linker. Please note that 'call literal'
   appears to be unspecified by various ABI and assembler documents;
   many assemblers totally reject them. Only gas accepts it and takes
   the argument as a relative value. Please check with the binutils
   people whether they have done anything about it already.

c) This is a genuine bug in gcc. Opinions about the seriousness of the
   bug differ.

If you want this issue resolved, it is probably best to submit a patch
that fixes it. If you need a work-around, avoid calling the literal -
call a function returning the literal instead.

Hope this helps,
Martin



More information about the Gcc-bugs mailing list