Bug 164810

Summary: g++ generates bad assembly with -masm=intel -fPIC
Product: Red Hat Enterprise Linux 4 Reporter: Elena Zannoni <ezannoni>
Component: gccAssignee: Jakub Jelinek <jakub>
Status: CLOSED ERRATA QA Contact:
Severity: medium Docs Contact:
Priority: medium    
Version: 4.0   
Target Milestone: ---   
Target Release: ---   
Hardware: i386   
OS: Linux   
Whiteboard:
Fixed In Version: RHBA-2005-677 Doc Type: Bug Fix
Doc Text:
Story Points: ---
Clone Of: Environment:
Last Closed: 2005-10-05 11:18:51 UTC Type: ---
Regression: --- Mount Type: ---
Documentation: --- CRM:
Verified Versions: Category: ---
oVirt Team: --- RHEL 7.3 requirements from Atomic Host:
Cloudforms Team: --- Target Upstream Version:
Embargoed:
Bug Depends On: 162585    
Bug Blocks: 156322    

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