Bug 4051 - SIGSEGV when compiling with -march=core2 -O3 on MinGW (bt included)
Status: RESOLVED FIXED
Alias: None
Product: ioquake3
Classification: Unclassified
Component: Misc
Version: GIT MASTER
Hardware: PC Windows Vista
: P3 normal
Assignee: Zachary J. Slater
QA Contact: ioquake3 bugzilla mailing list
URL:
Depends on:
Blocks:
 
Reported: 2009-04-29 11:04 EDT by tinkah
Modified: 2009-05-02 13:08:55 EDT
2 users (show)

See Also:



Description tinkah 2009-04-29 11:04:38 EDT
This goes away if -fno-tree-vectorize is used (option included in -O3 but not -O2). Another (lesser) march may let it compile and run fine on -O3.

Gcc 4.4.0 (and 4.3.3), MinGW, Vista, Core 2 T7500.

Occurs during bsp loading.

mod Urban Terror. Occurs on most maps (e.g. in ut4_casa and ut4_turnpike, not in ut4_dressingroom).




Program received signal SIGSEGV, Segmentation fault.
R_SubdividePatchToGrid (width=3, height=3, points=0x21ef98)
    at code/renderer/tr_curve.c:411
411                                     VectorNormalize( dir );
(gdb) bt
#0  R_SubdividePatchToGrid (width=3, height=3, points=0x21ef98)
    at code/renderer/tr_curve.c:411
#1  0x0051bbf6 in ParseMesh (ds=<value optimized out>, verts=0xa183790, 
    surf=<value optimized out>) at code/renderer/tr_bsp.c:424
#2  0x0051fd34 in RE_LoadWorldMap (name=0x2397db38 "maps/ut4_casa.bsp")
    at code/renderer/tr_bsp.c:1265
#3  0x00402832 in CL_CgameSystemCalls (args=0x25635ce8)
    at code/client/cl_cgame.c:553
#4  0x0055d136 in CallAsmCall (syscallNum=36, programStack=33553764, 
    opStack=0x22a160) at code/qcommon/vm_x86.c:193
#5  0x0055d108 in AsmCall ()
#6  0x00000024 in ?? ()
#7  0x01fffd64 in ?? ()
#8  0x0022a160 in ?? ()
#9  0x00000002 in ?? ()
#10 0x2d5a5ed1 in ?? ()
#11 0x0055d0f4 in AsmCall ()
#12 0x2d5af947 in ?? ()
#13 0x0055d0f4 in AsmCall ()
#14 0x2d5a010d in ?? ()
#15 0x0055d24d in VM_CallCompiled (vm=0x1dd4670, args=0x22b1f4)
    at code/qcommon/vm_x86.c:1192
#16 0x00493c96 in VM_Call (vm=0x1dd4670, callnum=0) at code/qcommon/vm.c:771
#17 0x00401b2d in CL_InitCGame () at code/client/cl_cgame.c:748
#18 0x004204f8 in CL_DownloadsComplete () at code/client/cl_main.c:1882
#19 0x0042064c in CL_InitDownloads () at code/client/cl_main.c:2046
#20 0x00423375 in CL_ParseGamestate (msg=0x22f848)
    at code/client/cl_parse.c:532
#21 0x00423fa8 in CL_ParseServerMessage (msg=0x22f848)
    at code/client/cl_parse.c:894
#22 0x00422531 in CL_PacketEvent (from=
      {type = NA_LOOPBACK, ip = "\000\000\000", ip6 = '\0' <repeats 15 times>, p                            ort = 0, scope_id = 0}, msg=0x22f848) at code/client/cl_main.c:2486
#23 0x00443803 in Com_EventLoop () at code/qcommon/common.c:2208
#24 0x00443b3b in Com_Frame () at code/qcommon/common.c:2935
#25 0x0055cc69 in SDL_main (argc=10, argv=0x26a3010)
    at code/sys/sys_main.c:571
#26 0x00564ffb in console_main (argc=10, argv=0x26a3010)
    at ./src/main/win32/SDL_win32_main.c:217
#27 0x005651d9 in WinMain (hInst=0x400000, hPrev=0x0, 
    szCmdLine=0x2a2baf "+set fs_basepath d:/games/UrbanTerror +set fs_game q3ut4                             +set r_fullscreen 0", sw=10) at ./src/main/win32/SDL_win32_main.c:353
#28 0x00564a58 in main ()
(gdb) q
Comment 1 Zachary J. Slater 2009-04-29 14:12:24 EDT
can you reproduce the bug with baseq3?
Comment 2 Amanieu d'Antras 2009-04-29 14:47:10 EDT
A disassembly would help
Comment 3 tinkah 2009-04-29 16:42:59 EDT
on baseq3 right after /devmap in all maps I tried.


Program received signal SIGSEGV, Segmentation fault.
build_ycc_rgb_table (cinfo=<value optimized out>) at code/jpeg-6b/jdcolor.c:94
94          cconvert->Cr_r_tab[i] = (int)
(gdb) bt
#0  build_ycc_rgb_table (cinfo=<value optimized out>)
    at code/jpeg-6b/jdcolor.c:94
#1  0x0050917e in jinit_color_deconverter (cinfo=0x229738)
    at code/jpeg-6b/jdcolor.c:362
#2  0x0051132e in jinit_master_decompress (cinfo=0x229738)
    at code/jpeg-6b/jdmaster.c:367
#3  0x0050724b in jpeg_start_decompress (cinfo=0x229738)
    at code/jpeg-6b/jdapistd.c:42
#4  0x0052f42c in R_LoadJPG (filename=0xa02c00 "textures/sfx/logo512.jpg", 
    pic=0x229a3c, width=0x229a44, height=0x229a40)
    at code/renderer/tr_image_jpg.c:110
#5  0x00528b24 in R_LoadImage (name=0xa14600 "textures/sfx/logo512.tga", 
    pic=0x229a3c, width=0x229a44, height=0x229a40)
    at code/renderer/tr_image.c:906
#6  0x0052c190 in R_FindImageFile (name=0xa14600 "textures/sfx/logo512.tga", 
    mipmap=qfalse, allowPicmip=qfalse, glWrapClampMode=10497)
    at code/renderer/tr_image.c:966
#7  0x00549353 in ParseStage (stage=0xabde40, text=0x22a004)
    at code/renderer/tr_shader.c:660
#8  0x0054c9db in R_FindShader (name=0x62ff041 "menuback", lightmapIndex=-4, 
    mipRawImage=qfalse) at code/renderer/tr_shader.c:1437
#9  0x0054dd8f in RE_RegisterShaderNoMip (name=0x62ff041 "menuback")
    at code/renderer/tr_shader.c:2767
#10 0x00426353 in CL_UISystemCalls (args=0x63f8b18) at code/client/cl_ui.c:801
#11 0x0055d136 in CallAsmCall (syscallNum=20, programStack=1048404, 
    opStack=0x22a174) at code/qcommon/vm_x86.c:193
#12 0x0055d108 in AsmCall ()
#13 0x00000014 in ?? ()
#14 0x000fff54 in ?? ()
#15 0x0022a174 in ?? ()
#16 0x00000002 in ?? ()
#17 0x1c7ee3f2 in ?? ()
#18 0x0055d0f4 in AsmCall ()
#19 0x1c7aec96 in ?? ()
#20 0x0055d0f4 in AsmCall ()
#21 0x1c7900fd in ?? ()
#22 0x0055d24d in VM_CallCompiled (vm=0x1dd4598, args=0x22b204)
    at code/qcommon/vm_x86.c:1192
#23 0x00493c96 in VM_Call (vm=0x1dd4598, callnum=1) at code/qcommon/vm.c:771
#24 0x004253ea in CL_InitUI () at code/client/cl_ui.c:1123
#25 0x004204e9 in CL_DownloadsComplete () at code/client/cl_main.c:1878
#26 0x0042064c in CL_InitDownloads () at code/client/cl_main.c:2046
#27 0x00423375 in CL_ParseGamestate (msg=0x22f848)
    at code/client/cl_parse.c:532
#28 0x00423fa8 in CL_ParseServerMessage (msg=0x22f848)
    at code/client/cl_parse.c:894
#29 0x00422531 in CL_PacketEvent (from=
      {type = NA_LOOPBACK, ip = "\000\000\000", ip6 = '\0' <repeats 15 times>, port = 0, scope_id = 0}, msg=0x22f848) at code/client/cl_main.c:2486
#30 0x00443803 in Com_EventLoop () at code/qcommon/common.c:2208
#31 0x00443b3b in Com_Frame () at code/qcommon/common.c:2935
#32 0x0055cc69 in SDL_main (argc=4, argv=0x383158) at code/sys/sys_main.c:571
#33 0x00564ffb in console_main (argc=4, argv=0x383158)
    at ./src/main/win32/SDL_win32_main.c:217
#34 0x005651d9 in WinMain (hInst=0x400000, hPrev=0x0, 
    szCmdLine=0x22a2b4f "+set fs_basepath d:/games/UrbanTerror", sw=10)
    at ./src/main/win32/SDL_win32_main.c:353
#35 0x00564a58 in main ()
(gdb)
Comment 4 Ludwig Nussel 2009-04-30 11:21:24 EDT
An alignment issue I guess. run "disassemble $eip $eip+16" in gdb to see which instruction causes the segv. I tried fixing the stack alignment in the compiled vm but that makes the problem only go away on some systems. Just don't use optimizations other than the default ones if you don't know how to fix problems.
Comment 5 tinkah 2009-04-30 16:08:11 EDT
Program received signal SIGSEGV, Segmentation fault.
R_SubdividePatchToGrid (width=3, height=3, points=0x21ef98)
    at code/renderer/tr_curve.c:411
411                                     VectorNormalize( dir );
(gdb) disassemble $eip $eip+16
Dump of assembler code from 0x523217 to 0x523227:
0x00523217 <R_SubdividePatchToGrid+1463>:       movaps %xmm0,-0x2db58(%ebp)
0x0052321e <R_SubdividePatchToGrid+1470>:       flds   0x8(%ebx)
0x00523221 <R_SubdividePatchToGrid+1473>:       flds   (%ebx)
0x00523223 <R_SubdividePatchToGrid+1475>:       fadds  (%esi)
0x00523225 <R_SubdividePatchToGrid+1477>:       flds   (%edi)
End of assembler dump.
(gdb) 


and on baseq3

Program received signal SIGSEGV, Segmentation fault.
build_ycc_rgb_table (cinfo=<value optimized out>) at code/jpeg-6b/jdcolor.c:94
94          cconvert->Cr_r_tab[i] = (int)
(gdb) disassemble $eip $eip+16
Dump of assembler code from 0x50839a to 0x5083aa:
0x0050839a <build_ycc_rgb_table+2362>:  movdqa %xmm7,-0x28(%ebp)
0x0050839f <build_ycc_rgb_table+2367>:  movdqa %xmm3,%xmm6
0x005083a3 <build_ycc_rgb_table+2371>:  movdqa %xmm4,%xmm7
0x005083a7 <build_ycc_rgb_table+2375>:  psrldq $0x4,%xmm6
End of assembler dump.
(gdb)
Comment 6 Amanieu d'Antras 2009-05-01 02:46:55 EDT
See if this fixes your problem:

Index: code/qcommon/vm_x86.c
===================================================================
--- code/qcommon/vm_x86.c
+++ code/qcommon/vm_x86.c
@@ -216,12 +216,17 @@
 	"0:\n\t" // system call
 	"notl  %eax\n\t"
 	"pushl %ecx\n\t"
+	"movl  %esp, %ecx\n\t"
+	"andl  $-16, %esp\n\t"
+	"pushl %ecx\n\t"
 	"pushl %edi\n\t" // opStack
 	"pushl %esi\n\t" // programStack
 	"pushl %eax\n\t" // syscallNum
 	"call  " CMANG(CallAsmCall) "\n\t"
 	"addl  $12, %esp\n\t"
 	"popl  %ecx\n\t"
+	"movl  %ecx, %esp\n\t"
+	"popl  %ecx\n\t"
 	"addl  $4, %edi\n\t"
 	"ret\n\t"
 #if defined __ELF__
Comment 7 tinkah 2009-05-01 14:40:33 EDT
It worked.

Patch fixed it.
Comment 8 Amanieu d'Antras 2009-05-01 14:54:37 EDT
That patch is by gimhael (Matthias Bentrup). It realigns the stack to 16 bytes on syscalls, which is what gcc expects.
Comment 9 Ludwig Nussel 2009-05-02 13:08:55 EDT
(In reply to comment #8)
> That patch is by gimhael (Matthias Bentrup). It realigns the stack to 16 bytes
> on syscalls, which is what gcc expects.

Yeah, that's what I meant. Game still segfaults when compiled on openSUSE 11.0 though but doesn't on 11.1. Weird. I've commited the stack alignment fix anyways.