public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
* [Bug rtl-optimization/34716] New: application segfaults when compiled with -O2, but works well with -O1
@ 2008-01-08 19:29 aleksey dot shipilev at gmail dot com
2008-01-08 19:36 ` [Bug rtl-optimization/34716] " aleksey dot shipilev at gmail dot com
` (5 more replies)
0 siblings, 6 replies; 9+ messages in thread
From: aleksey dot shipilev at gmail dot com @ 2008-01-08 19:29 UTC (permalink / raw)
To: gcc-bugs
When building application (namely, powertweak) with gcc 4.1.2 using -02,
application experiences segfault during startup. When building in the same
configuration but using -O1, all works fine.
Attached microtest (test.c) which resembles the problem:
# gcc test.c && ./a.out
before: output=bff74f74, buf=bff74d74
after: output=bff74f74, buf=bff74d74
sizeof(buf)=512
result=0
# gcc -O1 test.c && ./a.out
before: output=bff0b700, buf=bff0b500
after: output=bff0b700, buf=bff0b500
sizeof(buf)=512
result=0
# gcc -O2 test.c && ./a.out
before: output=bfd004fc, buf=bfd002fc
after: output=bfd004fc, buf=bfd002fc
sizeof(buf)=512
result=0
Segmentation fault <-------
If I try to hunt down the differences between -O1 and -O2 as described at
http://gcc.gnu.org/onlinedocs/gcc-4.1.2/gcc/Optimize-Options.html:
# gcc -O1 -fthread-jumps -fcrossjumping -foptimize-sibling-calls
-fcse-follow-jumps -fcse-skip-blocks -fgcse -fgcse-lm
-fexpensive-optimizations -fstrength-reduce -frerun-cse-after-loop
-frerun-loop-opt -fcaller-saves -fpeephole2 -fschedule-insns -fschedule-insns2
-fsched-interblock -fsched-spec -fregmove -fstrict-aliasing
-fdelete-null-pointer-checks -freorder-blocks -freorder-functions
-falign-functions -falign-jumps -falign-loops -falign-labels -ftree-vrp
-ftree-pre test.c && ./a.out
before: output=bfd4ed60, buf=bfd4eb60
after: output=bfd4ed60, buf=bfd4eb60
sizeof(buf)=512
result=0
All is OK, so I have failed to find guilty optimization.
Moreover, when I try to disable all optimizations described at
http://gcc.gnu.org/onlinedocs/gcc-4.1.2/gcc/Option-Summary.html under
"Optimization options":
# gcc -O2 -fno-align-functions -fno-align-jumps -fno-align-labels
-fno-align-loops -fno-sched-stalled-insns -fno-bounds-check
-fno-branch-probabilities -fno-profile-values -fno-vpt
-fno-branch-target-load-optimize -fno-branch-target-load-optimize2
-fno-btr-bb-exclusive -fno-caller-saves -fno-cprop-registers
-fno-cse-follow-jumps -fno-cse-skip-blocks -fno-cx-limited-range
-fno-data-sections -fno-delete-null-pointer-checks -fno-early-inlining
-fno-expensive-optimizations -fno-fast-math -fno-float-store -fno-force-addr
-fno-function-sections -fno-gcse -fno-gcse-lm -fno-gcse-sm -fno-gcse-las
-fno-gcse-after-reload -fno-loop-optimize -fno-crossjumping -fno-if-conversion
-fno-if-conversion2 -fno-inline-functions -fno-inline-functions-called-once
-fno-keep-inline-functions -fno-keep-static-consts -fno-merge-constants
-fno-merge-all-constants -fno-modulo-sched -fno-branch-count-reg -fno-defer-pop
-fno-loop-optimize2 -fno-move-loop-invariants -fno-function-cse
-fno-guess-branch-probability -fno-inline -fno-math-errno -fno-peephole
-fno-peephole2 -fno-unsafe-math-optimizations -fno-unsafe-loop-optimizations
-fno-finite-math-only -fno-trapping-math -fno-zero-initialized-in-bss
-fno-omit-frame-pointer -fno-optimize-register-move
-fno-optimize-sibling-calls -fno-prefetch-loop-arrays -fno-profile-generate
-fno-profile-use -fno-regmove -fno-rename-registers -fno-reorder-blocks
-fno-reorder-blocks-and-partition -fno-reorder-functions
-fno-rerun-cse-after-loop -fno-rerun-loop-opt -fno-rounding-math
-fno-schedule-insns -fno-schedule-insns2 -fno-sched-interblock
-fno-sched-spec -fno-sched-spec-load -fno-sched-spec-load-dangerous
-fno-sched2-use-superblocks -fno-sched2-use-traces
-fno-reschedule-modulo-scheduled-loops -fno-signaling-nans
-fno-single-precision-constant -fno-stack-protector -fno-strength-reduce
-fno-strict-aliasing -fno-tracer -fno-thread-jumps -fno-unroll-all-loops
-fno-unroll-loops -fno-peel-loops -fno-split-ivs-in-unroller
-fno-unswitch-loops -fno-variable-expansion-in-unroller -fno-tree-pre
-fno-tree-ccp -fno-tree-dce -fno-tree-loop-optimize -fno-tree-loop-linear
-fno-tree-loop-im -fno-tree-loop-ivcanon -fno-ivopts -fno-tree-dominator-opts
-fno-tree-dse -fno-tree-copyrename -fno-tree-sink -fno-tree-ch -fno-tree-sra
-fno-tree-ter -fno-tree-lrs -fno-tree-fre -fno-tree-vectorize
-fno-tree-vect-loop-version -fno-tree-salias -fno-web -fno-tree-copy-prop
-fno-tree-store-ccp -fno-tree-store-copy-prop -fno-whole-program test.c &&
./a.out
before: output=bfca84ac, buf=bfca82ac
after: output=bfca84ac, buf=bfca82ac
sizeof(buf)=512
result=0
Segmentation fault <-------
Still, I have segmentation fault, but all optimization seem to be disabled.
There is easy workaround though (not to compile with -O2), but I believe this
issue worth fixing.
--
Summary: application segfaults when compiled with -O2, but works
well with -O1
Product: gcc
Version: 4.1.2
Status: UNCONFIRMED
Severity: normal
Priority: P3
Component: rtl-optimization
AssignedTo: unassigned at gcc dot gnu dot org
ReportedBy: aleksey dot shipilev at gmail dot com
GCC build triplet: i686-pc-linux-gnu
GCC host triplet: i686-pc-linux-gnu
GCC target triplet: i686-pc-linux-gnu
http://gcc.gnu.org/bugzilla/show_bug.cgi?id=34716
^ permalink raw reply [flat|nested] 9+ messages in thread
* [Bug rtl-optimization/34716] application segfaults when compiled with -O2, but works well with -O1
2008-01-08 19:29 [Bug rtl-optimization/34716] New: application segfaults when compiled with -O2, but works well with -O1 aleksey dot shipilev at gmail dot com
@ 2008-01-08 19:36 ` aleksey dot shipilev at gmail dot com
2008-01-08 19:58 ` pinskia at gcc dot gnu dot org
` (4 subsequent siblings)
5 siblings, 0 replies; 9+ messages in thread
From: aleksey dot shipilev at gmail dot com @ 2008-01-08 19:36 UTC (permalink / raw)
To: gcc-bugs
------- Comment #1 from aleksey dot shipilev at gmail dot com 2008-01-08 19:07 -------
Created an attachment (id=14901)
--> (http://gcc.gnu.org/bugzilla/attachment.cgi?id=14901&action=view)
test used in issue
This test was derived from powertweak code, which segfaults.
--
http://gcc.gnu.org/bugzilla/show_bug.cgi?id=34716
^ permalink raw reply [flat|nested] 9+ messages in thread
* [Bug rtl-optimization/34716] application segfaults when compiled with -O2, but works well with -O1
2008-01-08 19:29 [Bug rtl-optimization/34716] New: application segfaults when compiled with -O2, but works well with -O1 aleksey dot shipilev at gmail dot com
2008-01-08 19:36 ` [Bug rtl-optimization/34716] " aleksey dot shipilev at gmail dot com
@ 2008-01-08 19:58 ` pinskia at gcc dot gnu dot org
2008-01-08 20:07 ` aleksey dot shipilev at gmail dot com
` (3 subsequent siblings)
5 siblings, 0 replies; 9+ messages in thread
From: pinskia at gcc dot gnu dot org @ 2008-01-08 19:58 UTC (permalink / raw)
To: gcc-bugs
------- Comment #2 from pinskia at gcc dot gnu dot org 2008-01-08 19:35 -------
I always get:
before: output=bfda12b4, buf=bfda10b4
after: output=bfda12b4, buf=bfda10b4
sizeof(buf)=512
result=-1
I really don't think this is a GCC bug.
--
http://gcc.gnu.org/bugzilla/show_bug.cgi?id=34716
^ permalink raw reply [flat|nested] 9+ messages in thread
* [Bug rtl-optimization/34716] application segfaults when compiled with -O2, but works well with -O1
2008-01-08 19:29 [Bug rtl-optimization/34716] New: application segfaults when compiled with -O2, but works well with -O1 aleksey dot shipilev at gmail dot com
2008-01-08 19:36 ` [Bug rtl-optimization/34716] " aleksey dot shipilev at gmail dot com
2008-01-08 19:58 ` pinskia at gcc dot gnu dot org
@ 2008-01-08 20:07 ` aleksey dot shipilev at gmail dot com
2008-01-08 21:21 ` aleksey dot shipilev at gmail dot com
` (2 subsequent siblings)
5 siblings, 0 replies; 9+ messages in thread
From: aleksey dot shipilev at gmail dot com @ 2008-01-08 20:07 UTC (permalink / raw)
To: gcc-bugs
------- Comment #3 from aleksey dot shipilev at gmail dot com 2008-01-08 19:47 -------
Sorry, Andrew, but result=-1 shows that ioctl failed to read enough data from
the device (maybe your device does not support SMART?). I tried to get rid of
any of such hardware-specific code, but can't eliminate that ioctl(). Sorry
again.
I still think that this is GCC bug, since compiler generates correct code in
mode A and fails to do that in mode B. It's weird again that A + (B-A) != B, so
it looks like general problem.
--
http://gcc.gnu.org/bugzilla/show_bug.cgi?id=34716
^ permalink raw reply [flat|nested] 9+ messages in thread
* [Bug rtl-optimization/34716] application segfaults when compiled with -O2, but works well with -O1
2008-01-08 19:29 [Bug rtl-optimization/34716] New: application segfaults when compiled with -O2, but works well with -O1 aleksey dot shipilev at gmail dot com
` (2 preceding siblings ...)
2008-01-08 20:07 ` aleksey dot shipilev at gmail dot com
@ 2008-01-08 21:21 ` aleksey dot shipilev at gmail dot com
2008-01-08 21:22 ` pinskia at gcc dot gnu dot org
2008-01-08 21:23 ` aleksey dot shipilev at gmail dot com
5 siblings, 0 replies; 9+ messages in thread
From: aleksey dot shipilev at gmail dot com @ 2008-01-08 21:21 UTC (permalink / raw)
To: gcc-bugs
------- Comment #4 from aleksey dot shipilev at gmail dot com 2008-01-08 20:06 -------
Created an attachment (id=14905)
--> (http://gcc.gnu.org/bugzilla/attachment.cgi?id=14905&action=view)
Updated test
One should get the read from device working. If the test prints "FAILED" that
mean issue might be not reproduced later in the code.
--
aleksey dot shipilev at gmail dot com changed:
What |Removed |Added
----------------------------------------------------------------------------
Attachment #14901|0 |1
is obsolete| |
http://gcc.gnu.org/bugzilla/show_bug.cgi?id=34716
^ permalink raw reply [flat|nested] 9+ messages in thread
* [Bug rtl-optimization/34716] application segfaults when compiled with -O2, but works well with -O1
2008-01-08 19:29 [Bug rtl-optimization/34716] New: application segfaults when compiled with -O2, but works well with -O1 aleksey dot shipilev at gmail dot com
` (3 preceding siblings ...)
2008-01-08 21:21 ` aleksey dot shipilev at gmail dot com
@ 2008-01-08 21:22 ` pinskia at gcc dot gnu dot org
2008-01-08 21:23 ` aleksey dot shipilev at gmail dot com
5 siblings, 0 replies; 9+ messages in thread
From: pinskia at gcc dot gnu dot org @ 2008-01-08 21:22 UTC (permalink / raw)
To: gcc-bugs
------- Comment #5 from pinskia at gcc dot gnu dot org 2008-01-08 20:24 -------
Can you run your program under gdb and then give the backtrace?
Are you sure that the ioctl does not keep around the buffer so when you return
from main, the buffer becomes invalid?
--
http://gcc.gnu.org/bugzilla/show_bug.cgi?id=34716
^ permalink raw reply [flat|nested] 9+ messages in thread
* [Bug rtl-optimization/34716] application segfaults when compiled with -O2, but works well with -O1
2008-01-08 19:29 [Bug rtl-optimization/34716] New: application segfaults when compiled with -O2, but works well with -O1 aleksey dot shipilev at gmail dot com
` (4 preceding siblings ...)
2008-01-08 21:22 ` pinskia at gcc dot gnu dot org
@ 2008-01-08 21:23 ` aleksey dot shipilev at gmail dot com
5 siblings, 0 replies; 9+ messages in thread
From: aleksey dot shipilev at gmail dot com @ 2008-01-08 21:23 UTC (permalink / raw)
To: gcc-bugs
------- Comment #6 from aleksey dot shipilev at gmail dot com 2008-01-08 20:37 -------
Here you go, Andrew.
# gdb ./a.out
GNU gdb 6.7.1
(gdb) set disassembly-flavor intel
(gdb) run
Starting program: ~/src/gcc-b/a.out
before: output=bffa911c, buf=bffa8f1c
after: output=bffa911c, buf=bffa8f1c
sizeof(buf)=512
result=0
OK on reading from device
Program received signal SIGSEGV, Segmentation fault.
0x08048571 in main () at test2.c:39
39 }
(gdb) disassemble
Dump of assembler code for function main:
0x08048480 <main+0>: lea ecx,[esp+0x4]
0x08048484 <main+4>: and esp,0xfffffff0
0x08048487 <main+7>: push DWORD PTR [ecx-0x4]
0x0804848a <main+10>: push ebp
0x0804848b <main+11>: mov ebp,esp
0x0804848d <main+13>: sub esp,0x238
0x08048493 <main+19>: mov DWORD PTR [ebp-0xc],ebx
0x08048496 <main+22>: xor ebx,ebx
0x08048498 <main+24>: mov DWORD PTR [ebp-0x10],ecx
0x0804849b <main+27>: mov DWORD PTR [ebp-0x8],esi
0x0804849e <main+30>: mov DWORD PTR [ebp-0x4],edi
0x080484a1 <main+33>: lea edi,[ebp-0x1c]
0x080484a4 <main+36>: mov BYTE PTR [ebp-0x14],0xb0
0x080484a8 <main+40>: mov BYTE PTR [ebp-0x13],0x1
0x080484ac <main+44>: mov BYTE PTR [ebp-0x12],0xd1
0x080484b0 <main+48>: mov BYTE PTR [ebp-0x11],0x1
0x080484b4 <main+52>: mov DWORD PTR [esp+0x4],ebx
0x080484b8 <main+56>: lea ebx,[ebp-0x21c]
0x080484be <main+62>: mov DWORD PTR [esp],0x804867c
0x080484c5 <main+69>: call 0x804836c <open@plt>
0x080484ca <main+74>: mov DWORD PTR [ebp-0x224],eax
0x080484d0 <main+80>: mov DWORD PTR [esp+0x8],ebx
0x080484d4 <main+84>: mov DWORD PTR [esp+0x4],edi
0x080484d8 <main+88>: mov DWORD PTR [esp],0x8048685
0x080484df <main+95>: call 0x80483ac <printf@plt>
0x080484e4 <main+100>: mov ecx,0x31f
0x080484e9 <main+105>: lea eax,[ebp-0x14]
0x080484ec <main+108>: mov DWORD PTR [esp+0x4],ecx
0x080484f0 <main+112>: mov DWORD PTR [esp+0xc],ebx
0x080484f4 <main+116>: mov DWORD PTR [esp+0x8],eax
0x080484f8 <main+120>: mov eax,DWORD PTR [ebp-0x224]
0x080484fe <main+126>: mov DWORD PTR [esp],eax
0x08048501 <main+129>: call 0x804839c <ioctl@plt>
0x08048506 <main+134>: mov DWORD PTR [esp+0x8],ebx
0x0804850a <main+138>: mov DWORD PTR [esp+0x4],edi
0x0804850e <main+142>: mov DWORD PTR [esp],0x80486a0
0x08048515 <main+149>: mov esi,eax
0x08048517 <main+151>: call 0x80483ac <printf@plt>
0x0804851c <main+156>: mov edx,0x200
0x08048521 <main+161>: mov DWORD PTR [esp+0x4],edx
0x08048525 <main+165>: mov DWORD PTR [esp],0x80486bb
0x0804852c <main+172>: call 0x80483ac <printf@plt>
0x08048531 <main+177>: mov DWORD PTR [esp+0x4],esi
0x08048535 <main+181>: mov DWORD PTR [esp],0x80486cb
0x0804853c <main+188>: call 0x80483ac <printf@plt>
0x08048541 <main+193>: test esi,esi
0x08048543 <main+195>: je 0x8048572 <main+242>
0x08048545 <main+197>: mov eax,0x804867c
0x0804854a <main+202>: mov DWORD PTR [esp+0x4],eax
0x0804854e <main+206>: mov DWORD PTR [esp],0x80486f0
0x08048555 <main+213>: call 0x80483ac <printf@plt>
0x0804855a <main+218>: mov eax,0x1
0x0804855f <main+223>: mov ecx,DWORD PTR [ebp-0x10]
0x08048562 <main+226>: mov ebx,DWORD PTR [ebp-0xc]
0x08048565 <main+229>: mov esi,DWORD PTR [ebp-0x8]
0x08048568 <main+232>: mov edi,DWORD PTR [ebp-0x4]
0x0804856b <main+235>: mov esp,ebp
0x0804856d <main+237>: pop ebp
0x0804856e <main+238>: lea esp,[ecx-0x4]
0x08048571 <main+241>: ret
0x08048572 <main+242>: mov DWORD PTR [esp],0x80486d6
0x08048579 <main+249>: call 0x80483cc <puts@plt>
0x0804857e <main+254>: mov eax,DWORD PTR [ebp-0x21c]
0x08048584 <main+260>: mov DWORD PTR [ebp-0x1c],eax
0x08048587 <main+263>: mov eax,DWORD PTR [ebp-0x218]
0x0804858d <main+269>: mov DWORD PTR [ebp-0x18],eax
0x08048590 <main+272>: mov eax,DWORD PTR [ebp-0x224]
0x08048596 <main+278>: mov DWORD PTR [esp],eax
0x08048599 <main+281>: call 0x80483bc <close@plt>
0x0804859e <main+286>: xor eax,eax
0x080485a0 <main+288>: jmp 0x804855f <main+223>
End of assembler dump.
(gdb) bt
#0 0x08048571 in main () at test2.c:39
(gdb) info registers
eax 0x0 0
ecx 0x33010010 855703568
edx 0xbffa8f1c -1074098404
ebx 0x0 0
esp 0x3301000c 0x3301000c
ebp 0x0 0x0
esi 0x0 0
edi 0x19030000 419627008
eip 0x8048571 0x8048571 <main+241>
eflags 0x210246 [ PF ZF IF RF ID ]
cs 0x73 115
ss 0x7b 123
ds 0x7b 123
es 0x7b 123
fs 0x0 0
gs 0x33 51
(gdb)
--
http://gcc.gnu.org/bugzilla/show_bug.cgi?id=34716
^ permalink raw reply [flat|nested] 9+ messages in thread
* [Bug rtl-optimization/34716] application segfaults when compiled with -O2, but works well with -O1
[not found] <bug-34716-4@http.gcc.gnu.org/bugzilla/>
2014-08-04 10:43 ` ktietz at gcc dot gnu.org
@ 2014-08-04 10:44 ` ktietz at gcc dot gnu.org
1 sibling, 0 replies; 9+ messages in thread
From: ktietz at gcc dot gnu.org @ 2014-08-04 10:44 UTC (permalink / raw)
To: gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=34716
--- Comment #8 from Kai Tietz <ktietz at gcc dot gnu.org> ---
(In reply to Kai Tietz from comment #7)
> As 5.1 is now already for some time no more in maintenance it would be
> interesting to learn if that problem is still there for more current version
> (4.9, 4.8) gcc.
Of course I mean 4.1
^ permalink raw reply [flat|nested] 9+ messages in thread
* [Bug rtl-optimization/34716] application segfaults when compiled with -O2, but works well with -O1
[not found] <bug-34716-4@http.gcc.gnu.org/bugzilla/>
@ 2014-08-04 10:43 ` ktietz at gcc dot gnu.org
2014-08-04 10:44 ` ktietz at gcc dot gnu.org
1 sibling, 0 replies; 9+ messages in thread
From: ktietz at gcc dot gnu.org @ 2014-08-04 10:43 UTC (permalink / raw)
To: gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=34716
Kai Tietz <ktietz at gcc dot gnu.org> changed:
What |Removed |Added
----------------------------------------------------------------------------
Status|UNCONFIRMED |WAITING
Last reconfirmed| |2014-08-04
CC| |ktietz at gcc dot gnu.org
Ever confirmed|0 |1
--- Comment #7 from Kai Tietz <ktietz at gcc dot gnu.org> ---
As 5.1 is now already for some time no more in maintenance it would be
interesting to learn if that problem is still there for more current version
(4.9, 4.8) gcc.
^ permalink raw reply [flat|nested] 9+ messages in thread
end of thread, other threads:[~2014-08-04 10:44 UTC | newest]
Thread overview: 9+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2008-01-08 19:29 [Bug rtl-optimization/34716] New: application segfaults when compiled with -O2, but works well with -O1 aleksey dot shipilev at gmail dot com
2008-01-08 19:36 ` [Bug rtl-optimization/34716] " aleksey dot shipilev at gmail dot com
2008-01-08 19:58 ` pinskia at gcc dot gnu dot org
2008-01-08 20:07 ` aleksey dot shipilev at gmail dot com
2008-01-08 21:21 ` aleksey dot shipilev at gmail dot com
2008-01-08 21:22 ` pinskia at gcc dot gnu dot org
2008-01-08 21:23 ` aleksey dot shipilev at gmail dot com
[not found] <bug-34716-4@http.gcc.gnu.org/bugzilla/>
2014-08-04 10:43 ` ktietz at gcc dot gnu.org
2014-08-04 10:44 ` ktietz at gcc dot gnu.org
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).