x86 code generation bug

Adam J. Richter adam@yggdrasil.com
Tue Sep 7 21:52: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-, 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.

Adam J. Richter     __     ______________   4880 Stevens Creek Blvd, Suite 104
adam@yggdrasil.com     \ /                  San Jose, California 95129-1034
+1 408 261-6630         | g g d r a s i l   United States of America
fax +1 408 261-6631      "Free Software For The Rest Of Us."
-----------------------------CUT HERE-----------------------------------
#include <unistd.h>
main(int argc, char**argv) {
	int (*foo)(int) = 134513652; /* Adjust this number to be the address
					of exit(), which this program prints. */
	printf("The address of exit is %d.\n", (int) exit);
	return (*foo)(7);

More information about the Gcc-bugs mailing list