Bug 162585 - g++ generates bad assembly with -masm=intel -fPIC
g++ generates bad assembly with -masm=intel -fPIC
Status: CLOSED ERRATA
Product: Fedora
Classification: Fedora
Component: gcc (Show other bugs)
3
i386 Linux
medium Severity medium
: ---
: ---
Assigned To: Jakub Jelinek
:
Depends On:
Blocks: 164810
  Show dependency treegraph
 
Reported: 2005-07-06 11:48 EDT by Carlo Wood
Modified: 2007-11-30 17:11 EST (History)
1 user (show)

See Also:
Fixed In Version: 3.4.4-2
Doc Type: Bug Fix
Doc Text:
Story Points: ---
Clone Of:
Environment:
Last Closed: 2005-09-05 04:48:43 EDT
Type: ---
Regression: ---
Mount Type: ---
Documentation: ---
CRM:
Verified Versions:
Category: ---
oVirt Team: ---
RHEL 7.3 requirements from Atomic Host:
Cloudforms Team: ---


Attachments (Terms of Use)

  None (edit)
Description Carlo Wood 2005-07-06 11:48:53 EDT
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 1 Jakub Jelinek 2005-07-06 12:50:03 EDT
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.
http://gcc.gnu.org/ml/gcc-patches/2005-07/msg00362.html
Comment 2 Jakub Jelinek 2005-07-10 16:37:19 EDT
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 10:10:12 EDT
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.