Note: This is a beta release of Red Hat Bugzilla 5.0. The data contained within is a snapshot of the live data so any changes you make will not be reflected in the production Bugzilla. Also email is disabled so feel free to test any aspect of the site that you want. File any problems you find or give feedback here.
Bug 162585 - g++ generates bad assembly with -masm=intel -fPIC
Summary: g++ generates bad assembly with -masm=intel -fPIC
Alias: None
Product: Fedora
Classification: Fedora
Component: gcc
Version: 3
Hardware: i386
OS: Linux
Target Milestone: ---
Assignee: Jakub Jelinek
QA Contact:
Depends On:
Blocks: 164810
TreeView+ depends on / blocked
Reported: 2005-07-06 15:48 UTC by Carlo Wood
Modified: 2007-11-30 22:11 UTC (History)
1 user (show)

Fixed In Version: 3.4.4-2
Doc Type: Bug Fix
Doc Text:
Clone Of:
Last Closed: 2005-09-05 08:48:43 UTC

Attachments (Terms of Use)

Description Carlo Wood 2005-07-06 15:48:53 UTC
From Bugzilla Helper:
User-Agent: Mozilla/5.0 (X11; U; Linux i686; en-US; rv:1.7.6) Gecko/20050323 Firefox/1.0.2 Fedora/1.0.2-1.3.1

Description of problem:
g++ -masm=intel -fPIC -g -Wall -S
g++-3.4.3 -masm=intel -fPIC -g -Wall main.s -c
g++-3.4.3 -o testcase main.o
Segmentation fault

Same when using g++ instead of g++-3.4.3 for the final steps.
Plain g++-3.4.3 -masm=intel -fPIC -g -Wall -S generates
correct assembly.

The problem is:

~/c++/g++.bugs/bug23>grep -B3 OFFSET main.s | head -n 4
        call    .L4
        pop     %ebx
        add     %ebx, _GLOBAL_OFFSET_TABLE_+(.-.L4)

This is broken, it results in assembly without offset,
trying to access low memory addresses.

Correct is:
        call    __i686.get_pc_thunk.bx
        add     %ebx, OFFSET FLAT:_GLOBAL_OFFSET_TABLE_

which is generated by plain g++-3.4.3, or if you must,

        call    .L4
        pop     %ebx
        add     %ebx, OFFSET _GLOBAL_OFFSET_TABLE_+(.-.L4)

In other words: 'OFFSET' is missing.

For example:
        call    .L4
        pop     %ebx
        add     %ebx, _GLOBAL_OFFSET_TABLE_+(.-.L4)

The test case source is as follows:

struct A { virtual ~A() { } };
int main() { A a; }

Carlo Wood


Version-Release number of selected component (if applicable):

How reproducible:

Steps to Reproduce:
1. Create a test case file '' with the following contents:

struct A { virtual ~A() { } };
int main() { A a; }

2. Compile it into an assembly file 'main.s' using both
   -masm=intel and -fPIC

g++ -masm=intel -fPIC -g -Wall -S

3. Examine the how the PIC pointer (ebx) is calculated:

add     %ebx, _GLOBAL_OFFSET_TABLE_+(.-.L4)

4. Note that the keyword OFFSET is missing.

Actual Results:  I am getting tired of repeating myself.

Expected Results:  The OFFSET should have been there, see 'description'.

Additional info:

I discussed this in detail with the gcc developers,
I am involved with g++ myself too (plain, not redhats version).
I wish you guys didn't make changes to the compiler :/

Comment 1 Jakub Jelinek 2005-07-06 16:50:03 UTC
Yes, this is a bug, though in no way specific to the Red Hat GCC branches.
The only difference is that the compiler you built yourself probably has a
different default for -mtune= if none is specified nor -march= is not used.

Comment 2 Jakub Jelinek 2005-07-10 20:37:19 UTC
Fixed for rawhide in gcc-4.0.1-1 (and the fix comitted to 3.4/4.0 GCC branches
and CVS HEAD).

Comment 4 Jakub Jelinek 2005-07-25 14:10:12 UTC
Should be fixed in gcc-3.4.4-2{,.fc3}.

Note You need to log in before you can comment on or make changes to this bug.