This is the mail archive of the gcc-bugs@gcc.gnu.org mailing list for the GCC project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

[Bug c/26687] New: gcc -O1 -fno-pic generates bad code that references uninitialized r31


Overview Description:
  gcc 3.3 or gcc 4.0 on Apple's OSX 10.4 generates bad code that references r31
when called with -O1 -fno-pic.  If you use -O0 or do not use -fno-pic the
problem.

Steps to Reproduce:
run gcc -O1 -fno-pic -c or gcc-4.0 -O1 -fno-pic -c on:

void broken(double *ret, int num)
{
  ret[0] = num ? 0.1 : 0.0;
}

Actual Results:
Compile this source file with "gcc-4.0 -c -O1 -fno-pic".
View the object file with "otool -lrtvdI -s __TEXT __literal8":

[...]
Relocation information (__TEXT,__text) 8 entries
address  pcrel length extern type    scattered symbolnum/value
00000014 False long   n/a    LO16    True      0x00000030
         False long   False  PAIR    False     half = 0x0000
00000010 False long   n/a    HA16    True      0x00000030
         False long   False  PAIR    False     half = 0x0034
0000000c False long   False  LO16    False     2 (__TEXT,__literal8)
         False long   False  PAIR    False     half = 0x0000
00000008 False long   False  HA16    False     2 (__TEXT,__literal8)
         False long   False  PAIR    False     half = 0x0030
(__TEXT,__text) section
_broken:
00000000        cmpwi   cr7,r4,0x0
00000004        beq+    cr7,0x1c
00000008        lis     r2,0x0
0000000c        lwz     r9,0x30(r2)
00000010        addis   r10,r31,0x0
00000014        lwz     r10,0x34(r10)
00000018        b       0x24
0000001c        li      r9,0x0
00000020        li      r10,0x0
00000024        stw     r9,0x0(r3)
00000028        stw     r10,0x4(r3)
0000002c        blr
Contents of (__TEXT,__literal8) section
00000030  0x3fb99999 0x9999999a (1.0000000000000001e-01)

Observe that "r31" is being used without being initialized.

Expected Results:
It should not reference r31 unless it has initialized it...
And if you compile this source file with "gcc-4.0 -c -O1".
View the object file with "otool -lrtvdI -s __TEXT __literal8":
[...]
Relocation information (__TEXT,__text) 8 entries
address  pcrel length extern type    scattered symbolnum/value
00000024 False long   n/a    LO16DIF True   0x00000040
         False long   n/a    PAIR    True   0x00000008 other_half = 0x0000
00000020 False long   n/a    HA16DIF True   0x00000040
         False long   n/a    PAIR    True   0x00000008 other_half = 0x003c
0000001c False long   n/a    LO16DIF True   0x00000040
         False long   n/a    PAIR    True   0x00000008 other_half = 0x0000
00000018 False long   n/a    HA16DIF True   0x00000040
         False long   n/a    PAIR    True   0x00000008 other_half = 0x0038
(__TEXT,__text) section
_broken:
00000000        mfspr   r0,lr
00000004        bcl     20,31,0x8
00000008        mfspr   r8,lr
0000000c        mtspr   lr,r0
00000010        cmpwi   cr7,r4,0x0
00000014        beq+    cr7,0x2c
00000018        addis   r2,r8,0x0
0000001c        lwz     r9,0x38(r2)
00000020        addis   r10,r8,0x0
00000024        lwz     r10,0x3c(r10)
00000028        b       0x34
0000002c        li      r9,0x0
00000030        li      r10,0x0
00000034        stw     r9,0x0(r3)
00000038        stw     r10,0x4(r3)
0000003c        blr
Contents of (__TEXT,__literal8) section
00000040  0x3fb99999 0x9999999a (1.0000000000000001e-01)
Observe that the code seems reasonable.


-- 
           Summary: gcc -O1 -fno-pic generates bad code that references
                    uninitialized r31
           Product: gcc
           Version: 4.0.0
            Status: UNCONFIRMED
          Severity: major
          Priority: P3
         Component: c
        AssignedTo: unassigned at gcc dot gnu dot org
        ReportedBy: bardwell at curl dot com
  GCC host triplet: gcc version 4.0.0 20041026 (Apple Computer, Inc. build
                    4061), OS
GCC target triplet: gcc version 4.0.0 20041026 (Apple Computer, Inc. build
                    4061), OS


http://gcc.gnu.org/bugzilla/show_bug.cgi?id=26687


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]