This is the mail archive of the
gcc-prs@gcc.gnu.org
mailing list for the GCC project.
target/5474: GCC 3+ generates bad stack offset on ARM with -fpic and -msingle-pic-base
- From: mainland at apeiron dot net
- To: gcc-gnats at gcc dot gnu dot org
- Date: Wed, 23 Jan 2002 22:29:29 -0800 (PST)
- Subject: target/5474: GCC 3+ generates bad stack offset on ARM with -fpic and -msingle-pic-base
>Number: 5474
>Category: target
>Synopsis: GCC 3+ generates bad stack offset on ARM with -fpic and -msingle-pic-base
>Confidential: no
>Severity: serious
>Priority: medium
>Responsible: unassigned
>State: open
>Class: wrong-code
>Submitter-Id: net
>Arrival-Date: Wed Jan 23 22:36:01 PST 2002
>Closed-Date:
>Last-Modified:
>Originator: Geoffrey Mainland
>Release: 3.0.2
>Organization:
>Environment:
System: FreeBSD anaximander.apeiron.net 4.5-PRERELEASE FreeBSD 4.5-PRERELEASE #1: Sat Jan 5 18:42:31 PST 2002 toor@anaximander.apeiron.net:/.amd_mnt/anaximander/home01/freebsd-src/obj/.amd_mnt/anaximander/home01/freebsd-src/src/sys/APEIRON i386
host: i386-unknown-freebsd4.5
build: i386-unknown-freebsd4.5
target: arm-unknown-elf
configured with: ../../tools/gcc/configure --prefix=/home/mainland/work/handspring/arm-tools/ --target=arm-elf --enable-languages=c++ --with-gnu-as --with-gnu-ld --with-newlib --with-dwarf2 --with-cross-host --enable-multilib
>Description:
Compiling with -fpic and -msingle-pic-base can produce incorrect code. If a function uses global data the static base register will not be saved on the stack, but offsets to variables stored on the stack are still calculated as if the static base register *had* been saved on the stack.
>How-To-Repeat:
Code fragment:
static const char const_string[] = "";
char string[10];
void foo(int arg);
int bar(int* arg);
void
foo(int arg)
{
int local;
string[0] = const_string[0];
bar(&local);
}
int
bar(int* arg)
{
return *arg;
}
With -fpic only:
arm-elf-gcc -g -fpic -c test.c -o test.o
test.o: file format elf32-littlearm
Disassembly of section .text:
00000000 <foo>:
0: e1a0c00d mov ip, sp
4: e92ddc00 stmdb sp!, {sl, fp, ip, lr, pc}
8: e24cb004 sub fp, ip, #4 ; 0x4
c: e24dd008 sub sp, sp, #8 ; 0x8
10: e59fa028 ldr sl, [pc, #28] ; 40 <foo+0x40>
14: e08fa00a add sl, pc, sl
18: e50b0014 str r0, [fp, -#20]
1c: e59f3020 ldr r3, [pc, #20] ; 44 <foo+0x44>
20: e79a3003 ldr r3, [sl, r3]
24: e5d32000 ldrb r2, [r3]
28: e59f3018 ldr r3, [pc, #18] ; 48 <foo+0x48>
2c: e79a3003 ldr r3, [sl, r3]
30: e5c32000 strb r2, [r3]
34: e24b0018 sub r0, fp, #24 ; 0x18
38: ebfffffe bl 0 <foo>
3c: e91bac00 ldmdb fp, {sl, fp, sp, pc}
40: 00000024 andeq r0, r0, r4, lsr #32
...
0000004c <bar>:
4c: e1a0c00d mov ip, sp
50: e92dd800 stmdb sp!, {fp, ip, lr, pc}
54: e24cb004 sub fp, ip, #4 ; 0x4
58: e24dd004 sub sp, sp, #4 ; 0x4
5c: e50b0010 str r0, [fp, -#16]
60: e51b3010 ldr r3, [fp, -#16]
64: e5933000 ldr r3, [r3]
68: e1a00003 mov r0, r3
6c: e91ba800 ldmdb fp, {fp, sp, pc}
Disassembly of section .data:
Disassembly of section .rodata:
00000000 <const_string>:
0: 00000000 andeq r0, r0, r0
With -fpic and -msingle-pic-base:
arm-elf-gcc -g -fpic -msingle-pic-base -c test.c -o test.o
test.o: file format elf32-littlearm
Disassembly of section .text:
00000000 <foo>:
0: e1a0c00d mov ip, sp
4: e92dd800 stmdb sp!, {fp, ip, lr, pc}
8: e24cb004 sub fp, ip, #4 ; 0x4
c: e24dd008 sub sp, sp, #8 ; 0x8
10: e50b0014 str r0, [fp, -#20]
14: e59f301c ldr r3, [pc, #1c] ; 38 <foo+0x38>
18: e79a3003 ldr r3, [sl, r3]
1c: e5d32000 ldrb r2, [r3]
20: e59f3014 ldr r3, [pc, #14] ; 3c <foo+0x3c>
24: e79a3003 ldr r3, [sl, r3]
28: e5c32000 strb r2, [r3]
2c: e24b0018 sub r0, fp, #24 ; 0x18
30: ebfffffe bl 0 <foo>
34: e91ba800 ldmdb fp, {fp, sp, pc}
...
00000040 <bar>:
40: e1a0c00d mov ip, sp
44: e92dd800 stmdb sp!, {fp, ip, lr, pc}
48: e24cb004 sub fp, ip, #4 ; 0x4
4c: e24dd004 sub sp, sp, #4 ; 0x4
50: e50b0010 str r0, [fp, -#16]
54: e51b3010 ldr r3, [fp, -#16]
58: e5933000 ldr r3, [r3]
5c: e1a00003 mov r0, r3
60: e91ba800 ldmdb fp, {fp, sp, pc}
Disassembly of section .data:
Disassembly of section .rodata:
00000000 <const_string>:
0: 00000000 andeq r0, r0, r0
>Fix:
--- gcc/config/arm/arm.h.orig Thu May 24 14:03:58 2001
+++ gcc/config/arm/arm.h Wed Jan 23 19:37:42 2002
@@ -1681,7 +1681,9 @@
&& ! call_used_regs[HARD_FRAME_POINTER_REGNUM]) \
saved_hard_reg = 1, offset += 4; \
/* PIC register is a fixed reg, so call_used_regs set. */ \
- if (flag_pic && regs_ever_live[PIC_OFFSET_TABLE_REGNUM]) \
+ if (flag_pic \
+ && ! TARGET_SINGLE_PIC_BASE \
+ && regs_ever_live[PIC_OFFSET_TABLE_REGNUM]) \
saved_hard_reg = 1, offset += 4; \
for (regno = FIRST_ARM_FP_REGNUM; \
regno <= LAST_ARM_FP_REGNUM; regno++) \
>Release-Note:
>Audit-Trail:
>Unformatted: