This is the mail archive of the
gcc-bugs@gcc.gnu.org
mailing list for the GCC project.
[Bug c/46275] New: -masm=intel -fPIC causes global offset table issues
- From: "hezekiahehud at gmail dot com" <gcc-bugzilla at gcc dot gnu dot org>
- To: gcc-bugs at gcc dot gnu dot org
- Date: Tue, 2 Nov 2010 18:30:11 +0000
- Subject: [Bug c/46275] New: -masm=intel -fPIC causes global offset table issues
- Auto-submitted: auto-generated
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: unassigned@gcc.gnu.org
ReportedBy: hezekiahehud@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.