We are currently migrating Bugzilla to GitHub issues.
Any changes made to the bug tracker now will be lost, so please do not post new bugs or make changes to them.
When we're done, all bug URLs will redirect to their equivalent location on the new bug tracker.

Bug 4887 - X11_XSetLocaleModifiers(NULL) called by X11_InitKeyboard caused a segmentation fault
Summary: X11_XSetLocaleModifiers(NULL) called by X11_InitKeyboard caused a segmentatio...
Status: RESOLVED INVALID
Alias: None
Product: SDL
Classification: Unclassified
Component: video (show other bugs)
Version: 2.0.10
Hardware: x86_64 Linux
: P2 major
Assignee: Ryan C. Gordon
QA Contact: Sam Lantinga
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2019-12-06 15:08 UTC by Gunwoo Gim
Modified: 2020-02-11 18:41 UTC (History)
0 users

See Also:


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description Gunwoo Gim 2019-12-06 15:08:12 UTC
Hi, I'm trying to build a game engine that is powered by SDL and vulkan, and to get some help with figuring out what caused this segmentation fault.

I simply called SDL_Init in my code and linked to a static object of SDL, Does anybody know how to find out what made this happen?


I think I have to show you the GDB output:

~[Switching to thread 5 (Thread 0x7ffff5221700 (LWP 29421))](running)
=thread-selected,id="5"
~Thread 2 "salami" received signal SIGSEGV, Segmentation fault.
~#0  0x00007ffff4739066 in _XlcResolveLocaleName () from /usr/lib/x86_64-linux-gnu/libX11.so.6
~#1  0x00007ffff473c990 in ?? () from /usr/lib/x86_64-linux-gnu/libX11.so.6
~#2  0x00007ffff473bf43 in ?? () from /usr/lib/x86_64-linux-gnu/libX11.so.6
~#3  0x00007ffff473c788 in _XlcCreateLC () from /usr/lib/x86_64-linux-gnu/libX11.so.6
~#4  0x00007ffff475c4f0 in _XlcUtf8Loader () from /usr/lib/x86_64-linux-gnu/libX11.so.6
~#5  0x00007ffff4743bbe in _XOpenLC () from /usr/lib/x86_64-linux-gnu/libX11.so.6
~#6  0x00007ffff4743d0b in _XlcCurrentLC () from /usr/lib/x86_64-linux-gnu/libX11.so.6
~#7  0x00007ffff4743d4e in XSetLocaleModifiers () from /usr/lib/x86_64-linux-gnu/libX11.so.6
~#8  0x000000000054c307 in X11_InitKeyboard (_this=_this@entry=0x7ffff0004750) at /home/dewr/Products/salami-engine/extern/sdl/src/video/x11/SDL_x11keyboard.c:293
~#9  0x00000000004cc0f1 in X11_VideoInit (_this=0x7ffff0004750) at /home/dewr/Products/salami-engine/extern/sdl/src/video/x11/SDL_x11video.c:447
~#10 0x00000000004a4d03 in SDL_VideoInit_REAL (driver_name=<optimized out>, driver_name@entry=0x0) at /home/dewr/Products/salami-engine/extern/sdl/src/video/SDL_video.c:529
~#11 0x00000000004d5287 in SDL_InitSubSystem_REAL (flags=29233) at /home/dewr/Products/salami-engine/extern/sdl/src/SDL.c:170
~#12 SDL_Init_REAL (flags=<optimized out>) at /home/dewr/Products/salami-engine/extern/sdl/src/SDL.c:255
~#13 0x0000000000404ed2 in init_sdl () at /home/dewr/Products/salami-engine/salami.c:69
~#14 jf_kickstart (ws=0x7ffff7211968) at /home/dewr/Products/salami-engine/salami.c:425
~#15 0x0000000000404e05 in launch_worker (arg=<optimized out>) at /home/dewr/Products/salami-engine/salami.c:360
~#16 0x00007ffff79b96db in start_thread (arg=0x7ffff7ff6700) at pthread_create.c:463
~#17 0x00007ffff734488f in clone () at ../sysdeps/unix/sysv/linux/x86_64/clone.S:95
~0x00007ffff4739066 in _XlcResolveLocaleName () from /usr/lib/x86_64-linux-gnu/libX11.so.6



And this is the only function call the program made in the run:
  SDL_Init(SDL_INIT_VIDEO | SDL_INIT_TIMER | SDL_INIT_AUDIO |
    SDL_INIT_HAPTIC | SDL_INIT_GAMECONTROLLER) < 0 )



libSDL2.a was built with:
  make LDFLAGS="-pthread" "CFLAGS=-O3 -g -DNDEBUG ${C_FLAGS_TARG_ARCH}"



When I tried to debug the code using GDB, the event happened here:
        char *prev_locale = setlocale(LC_ALL, NULL);
        char *prev_xmods  = X11_XSetLocaleModifiers(NULL);
  ( src/video/x11/SDL_x11keyboard.c:292 )



And this is what I captured during the follow-up in GDB:
   
B+>│0x54c2f0 <X11_InitKeyboard+1936>        xor    %esi,%esi                                                                 │
   │0x54c2f2 <X11_InitKeyboard+1938>        mov    $0x6,%edi                                                                 │
   │0x54c2f7 <X11_InitKeyboard+1943>        callq  0x4042e0 <setlocale@plt>                                                  │
   │0x54c2fc <X11_InitKeyboard+1948>        xor    %edi,%edi                                                                 │
   │0x54c2fe <X11_InitKeyboard+1950>        mov    %rax,%r14                                                                 │
   │0x54c301 <X11_InitKeyboard+1953>        callq  *0x25d801(%rip)        # 0x7a9b08 <X11_XSetLocaleModifiers>               │

┌─────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────┐
   │0x7ffff4739047 <_XlcResolveLocaleName+7>        push   %r13                                                              │
   │0x7ffff4739049 <_XlcResolveLocaleName+9>        push   %r12                                                              │
>  │0x7ffff473904b <_XlcResolveLocaleName+11>       mov    $0x1000,%esi                                                      │
   │0x7ffff4739050 <_XlcResolveLocaleName+16>       push   %rbp                                                              │
   │0x7ffff4739051 <_XlcResolveLocaleName+17>       push   %rbx                                                              │
   │0x7ffff4739052 <_XlcResolveLocaleName+18>       sub    $0x2228,%rsp                                                      │
   │0x7ffff4739059 <_XlcResolveLocaleName+25>       lea    0x210(%rsp),%rbx                                                  │
   │0x7ffff4739061 <_XlcResolveLocaleName+33>       lea    0x10(%rsp),%r12                                                   │
  >│0x7ffff4739066 <_XlcResolveLocaleName+38>       mov    %rdi,(%rsp)                                                       │
   │0x7ffff473906a <_XlcResolveLocaleName+42>       mov    %fs:0x28,%rax                                                     │
   │0x7ffff4739073 <_XlcResolveLocaleName+51>       mov    %rax,0x2218(%rsp)                                                 │
   │0x7ffff473907b <_XlcResolveLocaleName+59>       xor    %eax,%eax                                                         │
   │0x7ffff473907d <_XlcResolveLocaleName+61>       mov    %rbx,%rdi                                                         │
   │0x7ffff4739080 <_XlcResolveLocaleName+64>       callq  0x7ffff4738cf0 <xlocaledir>                                       │
   │0x7ffff4739085 <_XlcResolveLocaleName+69>       mov    %r12,%rsi                                                         │
   │0x7ffff4739088 <_XlcResolveLocaleName+72>       mov    %rbx,%rdi                                                         │
   │0x7ffff473908b <_XlcResolveLocaleName+75>       callq  0x7ffff4738c80                                                    │
   │0x7ffff4739090 <_XlcResolveLocaleName+80>       test   %eax,%eax                                                         │
   │0x7ffff4739092 <_XlcResolveLocaleName+82>       jle    0x7ffff47391f0 <_XlcResolveLocaleName+432>                        │
   │0x7ffff4739098 <_XlcResolveLocaleName+88>       sub    $0x1,%eax                                                         │
   └─────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────┘



Any commenting will be much appreciated :)

Best regards,
Gunwoo Gim
Comment 1 Gunwoo Gim 2019-12-06 15:17:34 UTC
${C_FLAGS_TARG_ARCH} was simply " -march=nocona"
Comment 2 Ryan C. Gordon 2020-01-28 16:23:39 UTC
The instruction that crashed, "mov    %rdi,(%rsp)"  (move the RDI register to the memory at the top of the stack) suggests that you ran out of stack space, if I'm reading this correctly.

(but also, try to do video things from the main thread, it only causes problems otherwise.)

--ryan.
Comment 3 Sam Lantinga 2020-02-10 18:31:23 UTC
Can you increase your thread stack size and see if that fixes it? You'll probably need to increase it by a huge amount if you're running the entire engine on it.
Comment 4 Gunwoo Gim 2020-02-11 15:41:55 UTC
Sorry for the late reply, I'm busy making money delivering foods riding a scooter in the city these days... haha, riding a motorcycle is too fun.

And thank you so much for the advice, Ryan was on the money. I increased the stack size from PTHREAD_STACK_MIN(16384) to its double and it fixed the problem :)

Can't wait to start working on my game engine and my game someday!


Best regards,
Gunwoo Gim
Comment 5 Sam Lantinga 2020-02-11 18:41:24 UTC
Have fun! :)