This is the mail archive of the
gcc-bugs@gcc.gnu.org
mailing list for the GCC project.
[Bug c/42764] New: Bad exit code in interrupt functions using local vars and calling a function, when compiled without optimization
- From: "pvh dot pf at t-online dot de" <gcc-bugzilla at gcc dot gnu dot org>
- To: gcc-bugs at gcc dot gnu dot org
- Date: 16 Jan 2010 07:08:00 -0000
- Subject: [Bug c/42764] New: Bad exit code in interrupt functions using local vars and calling a function, when compiled without optimization
- Reply-to: gcc-bugzilla at gcc dot gnu dot org
Problem:
When compiling WITHOUT OPTIMIZATION, the code
generated for INTERRUPT FUNCTIONS using LOCAL VARS
and CALLING A FUNCTION will corrupt the stack.
This bug persists at least since GCC-3.3.4.
How-To-Repeat:
This is the C-code:
~~~~~~~~~~~~~~~~~~~~~~~~~~~~
extern void function(void);
void __attribute__((interrupt)) VECT_INTBAD(void) {
int x, y, z;
x=1;
y=2;
z=3;
function();
}
~~~~~~~~~~~~~~~~~~~~~~~~~~~~
Compiled with
v850e-unknown-elf-gcc -mv850e -mdisable-callt -fverbose-asm -nostartfiles
-nodefaultlibs -nostdlib -Wa,-a,-aln=bad_code.ASM
-o bad_code.o -c bad_code.c -save-temps
will generate:
~~~~~~~~~~~~~~~~~~~~~~~~~~~~
28 _VECT_INTBAD:
29 0000 501A add -16, sp
30 0002 63570D00 st.w r10, 12[sp]
31 0006 63F70100 st.w ep, 0[sp]
32 000a 63270500 st.w gp, 4[sp]
33 000e 630F0900 st.w r1, 8[sp]
34 0012 40F60000 movhi hi(__ep), r0, ep
35 0016 3EF60000 movea lo(__ep), ep, ep
36 001a 40260000 movhi hi(__gp), r0, gp
37 001e 24260000 movea lo(__gp), gp, gp
38 0022 031E88FF addi -120, sp, sp
39 0026 63FF7500 st.w r31, 116[sp]
40 002a 63177100 st.w r2, 112[sp]
41 002e 63276D00 st.w gp, 108[sp]
42 0032 63376900 st.w r6, 104[sp]
43 0036 633F6500 st.w r7, 100[sp]
44 003a 63476100 st.w r8, 96[sp]
45 003e 634F5D00 st.w r9, 92[sp]
46 0042 635F5900 st.w r11, 88[sp]
47 0046 63675500 st.w r12, 84[sp]
48 004a 636F5100 st.w r13, 80[sp]
49 004e 63774D00 st.w r14, 76[sp]
50 0052 637F4900 st.w r15, 72[sp]
51 0056 63874500 st.w r16, 68[sp]
52 005a 638F4100 st.w r17, 64[sp]
53 005e 63973D00 st.w r18, 60[sp]
54 0062 639F3900 st.w r19, 56[sp]
55 0066 63A73500 st.w r20, 52[sp]
56 006a 63AF3100 st.w r21, 48[sp]
57 006e 63B72D00 st.w r22, 44[sp]
58 0072 63BF2900 st.w r23, 40[sp]
59 0076 63C72500 st.w r24, 36[sp]
60 007a 63CF2100 st.w r25, 32[sp]
61 007e 63D71D00 st.w r26, 28[sp]
62 0082 63DF1900 st.w r27, 24[sp]
63 0086 63E71500 st.w r28, 20[sp]
64 008a 63EF1100 st.w r29, 16[sp]
65 008e 541A add -12,sp #,
66 0090 03E8 mov sp,r29 #,
67 0092 0152 mov 1,r10 #, tmp39
68 0094 7D571100 st.w r10,16[r29] # x, tmp39
69 0098 0252 mov 2,r10 #, tmp40
70 009a 7D571500 st.w r10,20[r29] # y, tmp40
71 009e 0352 mov 3,r10 #, tmp41
72 00a0 7D571900 st.w r10,24[r29] # z, tmp41
73 00a4 2A060000 mov hilo(_function),r10 #, tmp42
73 0000
74 00aa 80FF0400 jarl .+4,r31 ; add 4,r31 ; jmp r10 # tmp42
74 44FA6A00
75 00b2 1D18 mov r29,sp #,
76 00b4 23FF7500 ld.w 116[sp], r31
77 00b8 23177100 ld.w 112[sp], r2
78 00bc 23276D00 ld.w 108[sp], gp
79 00c0 23376900 ld.w 104[sp], r6
80 00c4 233F6500 ld.w 100[sp], r7
81 00c8 23476100 ld.w 96[sp], r8
82 00cc 234F5D00 ld.w 92[sp], r9
83 00d0 235F5900 ld.w 88[sp], r11
84 00d4 23675500 ld.w 84[sp], r12
85 00d8 236F5100 ld.w 80[sp], r13
86 00dc 23774D00 ld.w 76[sp], r14
87 00e0 237F4900 ld.w 72[sp], r15
88 00e4 23874500 ld.w 68[sp], r16
89 00e8 238F4100 ld.w 64[sp], r17
90 00ec 23973D00 ld.w 60[sp], r18
91 00f0 239F3900 ld.w 56[sp], r19
92 00f4 23A73500 ld.w 52[sp], r20
93 00f8 23AF3100 ld.w 48[sp], r21
94 00fc 23B72D00 ld.w 44[sp], r22
95 0100 23BF2900 ld.w 40[sp], r23
96 0104 23C72500 ld.w 36[sp], r24
97 0108 23CF2100 ld.w 32[sp], r25
98 010c 23D71D00 ld.w 28[sp], r26
99 0110 23DF1900 ld.w 24[sp], r27
100 0114 23E71500 ld.w 20[sp], r28
101 0118 23EF1100 ld.w 16[sp], r29
102 011c 031E7800 addi 120, sp, sp
103 0120 23F70100 ld.w 0[sp], ep
104 0124 23270500 ld.w 4[sp], gp
105 0128 230F0900 ld.w 8[sp], r1
106 012c 23570D00 ld.w 12[sp], r10
107 0130 031E1000 addi 16, sp, sp
108 0134 E0074001 reti
109 .size _VECT_INTBAD, .-_VECT_INTBAD
110 .ident "GCC: (GNU) 4.4.2"
~~~~~~~~~~~~~~~~~~~~~~~~~~~~
Stack adjustment (in the functions epilogue code) is missing.
Between listing lines 75 und 76:
75
xx yyyy zzzz add 12,sp #,
76
Related to line 65:
65 008e 541A add -12,sp #,
Environment:
gcc-4.4.2 compiled on debian lenny stable i686
Cross-compiling for v850e-unknown-elf
Configuration options for building GCC:
../gcc-4.4.2/configure
--target=v850e-unknown-elf
--prefix=/usr/local/nec
--disable-libssp
--enable-languages="c"
--disable-nls
Thanks,
Paul
--
Summary: Bad exit code in interrupt functions using local vars
and calling a function, when compiled without
optimization
Product: gcc
Version: 4.4.2
Status: UNCONFIRMED
Severity: normal
Priority: P3
Component: c
AssignedTo: unassigned at gcc dot gnu dot org
ReportedBy: pvh dot pf at t-online dot de
GCC host triplet: i686-pc-linux-gnu
GCC target triplet: v850-unknown-elf
http://gcc.gnu.org/bugzilla/show_bug.cgi?id=42764