Bug 164810 - g++ generates bad assembly with -masm=intel -fPIC
Summary: g++ generates bad assembly with -masm=intel -fPIC
Keywords:
Status: CLOSED ERRATA
Alias: None
Product: Red Hat Enterprise Linux 4
Classification: Red Hat
Component: gcc
Version: 4.0
Hardware: i386
OS: Linux
medium
medium
Target Milestone: ---
: ---
Assignee: Jakub Jelinek
QA Contact:
URL:
Whiteboard:
Depends On: 162585
Blocks: 156322
TreeView+ depends on / blocked
 
Reported: 2005-08-01 16:07 UTC by Elena Zannoni
Modified: 2007-11-30 22:07 UTC (History)
0 users

Fixed In Version: RHBA-2005-677
Doc Type: Bug Fix
Doc Text:
Clone Of:
Environment:
Last Closed: 2005-10-05 11:18:51 UTC
Target Upstream Version:
Embargoed:


Attachments (Terms of Use)


Links
System ID Private Priority Status Summary Last Updated
Red Hat Product Errata RHBA-2005:677 0 qe-ready SHIPPED_LIVE gcc bug fix update 2005-10-05 04:00:00 UTC

Description Elena Zannoni 2005-08-01 16:07:53 UTC
+++ This bug was initially created as a clone of Bug #162585 +++

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:
~/c++/g++.bugs/bug23>make
g++ -masm=intel -fPIC -g -Wall main.cc -S
g++-3.4.3 -masm=intel -fPIC -g -Wall main.s -c
g++-3.4.3 -o testcase main.o
~/c++/g++.bugs/bug23>./testcase
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 main.cc -S generates
correct assembly.

The problem is:

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

In other words: 'OFFSET' is missing.

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

The test case source is as follows:

~/c++/g++.bugs/bug23>cat main.cc
struct A { virtual ~A() { } };
int main() { A a; }

Regards,
Carlo Wood

 


Version-Release number of selected component (if applicable):
gcc-c++-3.4.3-22.fc3

How reproducible:
Always

Steps to Reproduce:
1. Create a test case file 'main.cc' 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 main.cc -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 3 Red Hat Bugzilla 2005-10-05 11:18:51 UTC
An advisory has been issued which should help the problem
described in this bug report. This report is therefore being
closed with a resolution of ERRATA. For more information
on the solution and/or where to find the updated files,
please follow the link below. You may reopen this bug report
if the solution does not work for you.

http://rhn.redhat.com/errata/RHBA-2005-677.html



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