http://gcc.gnu.org/bugzilla/show_bug.cgi?id=46275
Summary: -masm=intel -fPIC causes global offset table issues Product: gcc Version: 4.4.5 Status: UNCONFIRMED Severity: major Priority: P3 Component: c AssignedTo: unassig...@gcc.gnu.org ReportedBy: hezekiahe...@gmail.com Created attachment 22231 --> http://gcc.gnu.org/bugzilla/attachment.cgi?id=22231 Output from gcc -v -save-temps ... The combination of -masm=intel and -fPIC when producing 32-bit causes strange behaviour when dealing with globals. Specifically, it looks like calculations using the global offset table are being done incorrectly. (I'm not sure if this is because the EBX register was loaded with the wrong value or if the computations using it are somehow off.) You can reproduce the bug with a simple Hello World program. I used the following code and the command "gcc -m32 -fPIC -masm=intel -o hello hello.c": #include <stdio.h> int main() { puts("Hello, world!"); } If you run the resulting 32-bit ELF, you get an output other than "Hello, world!" (In my case, I get a single 0x02 byte and the newline added by puts.) As far as my debugging has shown, it appears that an incorrect address is computed for the "Hello, world!" global string constant. If you compile the same code either without -fPIC or without -masm=intel, the resulting executable works as expected. I originally discovered the bug on a 32-bit system with a 32-bit gcc executable, so it does not seem to be specific to running the compiler in a 64-bit environment; the 32-bit output seems to be the important part. I have attached the compiler output from a -v -save-temps run. I will attach the hello.i file shortly.