symisc / PH7

An Embedded Implementation of PHP (C Library)
http://ph7.symisc.net
Other
494 stars 68 forks source link

SIGSEGV on ubuntu 12.04 LTS with gcc -O flags #2

Closed nareshv closed 10 years ago

nareshv commented 10 years ago

while trying the official docs example. experienced the following error.

Steps to reproduce:

cat /etc/issue
Ubuntu 12.04.4 LTS \n \l
wget http://www.symisc.net/downloads/ph7-amalgamation-2001004.zip
unzip ph7-amalgamation-2001004.zip
wget http://www.symisc.net/downloads/ph7_intro.c
gcc -W -Wall -O6 -o ph7_test ph7_intro.c ph7.c

./ph7_test 
Segmentation fault (core dumped)

Strace below

execve("./ph7_test", ["./ph7_test"], [/* 51 vars */]) = 0
brk(0)                                  = 0x10b7000
access("/etc/ld.so.nohwcap", F_OK)      = -1 ENOENT (No such file or directory)
mmap(NULL, 8192, PROT_READ|PROT_WRITE, MAP_PRIVATE|MAP_ANONYMOUS, -1, 0) = 0x7fc2dc292000
access("/etc/ld.so.preload", R_OK)      = -1 ENOENT (No such file or directory)
open("/etc/ld.so.cache", O_RDONLY|O_CLOEXEC) = 3
fstat(3, {st_mode=S_IFREG|0644, st_size=107616, ...}) = 0
mmap(NULL, 107616, PROT_READ, MAP_PRIVATE, 3, 0) = 0x7fc2dc277000
close(3)                                = 0
access("/etc/ld.so.nohwcap", F_OK)      = -1 ENOENT (No such file or directory)
open("/lib/x86_64-linux-gnu/libc.so.6", O_RDONLY|O_CLOEXEC) = 3
read(3, "\177ELF\2\1\1\0\0\0\0\0\0\0\0\0\3\0>\0\1\0\0\0\200\30\2\0\0\0\0\0"..., 832) = 832
fstat(3, {st_mode=S_IFREG|0755, st_size=1815224, ...}) = 0
mmap(NULL, 3929304, PROT_READ|PROT_EXEC, MAP_PRIVATE|MAP_DENYWRITE, 3, 0) = 0x7fc2dbcb2000
mprotect(0x7fc2dbe67000, 2097152, PROT_NONE) = 0
mmap(0x7fc2dc067000, 24576, PROT_READ|PROT_WRITE, MAP_PRIVATE|MAP_FIXED|MAP_DENYWRITE, 3, 0x1b5000) = 0x7fc2dc067000
mmap(0x7fc2dc06d000, 17624, PROT_READ|PROT_WRITE, MAP_PRIVATE|MAP_FIXED|MAP_ANONYMOUS, -1, 0) = 0x7fc2dc06d000
close(3)                                = 0
mmap(NULL, 4096, PROT_READ|PROT_WRITE, MAP_PRIVATE|MAP_ANONYMOUS, -1, 0) = 0x7fc2dc276000
mmap(NULL, 4096, PROT_READ|PROT_WRITE, MAP_PRIVATE|MAP_ANONYMOUS, -1, 0) = 0x7fc2dc275000
mmap(NULL, 4096, PROT_READ|PROT_WRITE, MAP_PRIVATE|MAP_ANONYMOUS, -1, 0) = 0x7fc2dc274000
arch_prctl(ARCH_SET_FS, 0x7fc2dc275700) = 0
mprotect(0x7fc2dc067000, 16384, PROT_READ) = 0
mprotect(0x681000, 4096, PROT_READ)     = 0
mprotect(0x7fc2dc294000, 4096, PROT_READ) = 0
munmap(0x7fc2dc277000, 107616)          = 0
brk(0)                                  = 0x10b7000
brk(0x10e0000)                          = 0x10e0000
open("/dev/urandom", O_RDONLY)          = 3
read(3, ".\256\345\242\352\210?\233V\312+%\334R\16n\306F\370v\2\36@7E\355\245\2762bP\37"..., 256) = 256
brk(0x1105000)                          = 0x1105000
brk(0x1102000)                          = 0x1102000
brk(0x1124000)                          = 0x1124000
--- SIGSEGV (Segmentation fault) @ 0 (0) ---
+++ killed by SIGSEGV (core dumped) +++
Segmentation fault (core dumped)

gcc version

gcc --version
gcc (Ubuntu/Linaro 4.6.3-1ubuntu5) 4.6.3
Copyright (C) 2011 Free Software Foundation, Inc.
This is free software; see the source for copying conditions.  There is NO
warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.

Works when -O1, -O2 flags are used. Fails when -O3 or higher are used.

maybe update docs or something if its trivial.

symisc commented 10 years ago

The problem seems to be a compiler optimization issue in a 64-bit platform. Anyway, I have to investigate it with my Ubuntu laptop.

grepwood commented 10 years ago

Compiled with GCC 4.8.2 on Gentoo for amd64. It works alright with -O6