Makefile.in
author Sam Lantinga <slouken@libsdl.org>
Thu, 13 Oct 2016 04:54:43 -0700
changeset 10530 2a3f8bc23daa
parent 10303 b326f93e1bc5
child 11206 946452867513
permissions -rw-r--r--
Fixed bug 3328 - Race condition in Wayland_VideoInit

Robert Folland

When running this little test program with SDL2 on Wayland it often crashes in SDL_Init.

From a backtrace it is apparent that there is a race condition in creating a xkb_context_ref. Sometimes it is 0x0.

By moving the relevant lines higher up in Wayland_VideoInit (in SDL2-2.0.4/src/video/wayland/SDL_waylandvideo.c:302) this seems to get fixed.

I moved the call to WAYLAND_xkb_context_new() up to before the call to WAYLAND_wl_display_connect().

Here is the test program (just a loop of init and quit), and a backtrace from gdb:

#include <cstdio>
#include <stdlib.h>
#include <SDL2/SDL.h>
#include <unistd.h>
#include <iostream>

int main(int argc, char **argv)
{
int count = atoi(argv[1]);

for (int i = 0; i < count; i++) {
std::cout << "Init " << i << std::endl;
if (SDL_Init(SDL_INIT_VIDEO) < 0) {
SDL_LogError(SDL_LOG_CATEGORY_APPLICATION,
"Couldn't initialize SDL: %s\n",
SDL_GetError());
return 1;
}
std::cout << "Quit" << std::endl;
SDL_Quit();
}
return 0;
}


Init 12
Quit
Init 13

Program received signal SIGSEGV, Segmentation fault.
xkb_context_ref (ctx=ctx@entry=0x0) at src/context.c:156
156 ctx->refcnt++;
(gdb) bt
#0 xkb_context_ref (ctx=ctx@entry=0x0) at src/context.c:156
#1 0x00007ffff5e1cd4c in xkb_keymap_new (ctx=0x0, format=XKB_KEYMAP_FORMAT_TEXT_V1, flags=flags@entry=XKB_KEYMAP_COMPILE_NO_FLAGS) at src/keymap-priv.c:65
#2 0x00007ffff5e1c6cc in xkb_keymap_new_from_buffer (ctx=<optimized out>,
buffer=0x7ffff7fd5000 "xkb_keymap {\nxkb_keycodes \"(unnamed)\" {\n\tminimum = 8;\n\tmaximum = 255;\n\t<ESC>", ' ' <repeats 16 times>, "= 9;\n\t<AE01>", ' ' <re
peats 15 times>, "= 10;\n\t<AE02>", ' ' <repeats 15 times>, "= 11;\n\t<AE03>", ' ' <repeats 15 times>, "= 12;\n\t<AE04>", ' ' <repeats 12 times>..., length=48090,
format=<optimized out>, flags=<optimized out>) at src/keymap.c:191
#3 0x00007ffff7b8ea4e in keyboard_handle_keymap (data=0x6169b0, keyboard=<optimized out>, format=<optimized out>, fd=5, size=48091)
at /home/vlab/abs/sdl2/src/SDL2-2.0.4/src/video/wayland/SDL_waylandevents.c:269
#4 0x00007ffff64501f0 in ffi_call_unix64 () from /usr/lib/libffi.so.6
#5 0x00007ffff644fc58 in ffi_call () from /usr/lib/libffi.so.6
#6 0x00007ffff665be3e in wl_closure_invoke (closure=closure@entry=0x61f000, flags=flags@entry=1, target=<optimized out>, target@entry=0x616d20,
opcode=opcode@entry=0, data=<optimized out>) at src/connection.c:949
#7 0x00007ffff6658be0 in dispatch_event (display=<optimized out>, queue=<optimized out>) at src/wayland-client.c:1274
#8 0x00007ffff6659db4 in dispatch_queue (queue=0x617398, display=0x6172d0) at src/wayland-client.c:1420
#9 wl_display_dispatch_queue_pending (display=0x6172d0, queue=0x617398) at src/wayland-client.c:1662
#10 0x00007ffff665a0cf in wl_display_roundtrip_queue (display=0x6172d0, queue=0x617398) at src/wayland-client.c:1085
#11 0x00007ffff7b8faa0 in Wayland_VideoInit (_this=<optimized out>) at /home/vlab/abs/sdl2/src/SDL2-2.0.4/src/video/wayland/SDL_waylandvideo.c:302
#12 0x00007ffff7b7aed6 in SDL_VideoInit_REAL (driver_name=<optimized out>, driver_name@entry=0x0) at /home/vlab/abs/sdl2/src/SDL2-2.0.4/src/video/SDL_video.c:513
#13 0x00007ffff7ae0ee7 in SDL_InitSubSystem_REAL (flags=16416) at /home/vlab/abs/sdl2/src/SDL2-2.0.4/src/SDL.c:173
#14 0x0000000000400b24 in main (argc=2, argv=0x7fffffffebb8) at vplay-init.cpp:13
(gdb)
     1 # Makefile to build and install the SDL library
     2 
     3 top_builddir = .
     4 srcdir  = @srcdir@
     5 objects = build
     6 gen = gen
     7 prefix = @prefix@
     8 exec_prefix = @exec_prefix@
     9 bindir	= @bindir@
    10 libdir  = @libdir@
    11 includedir = @includedir@
    12 datarootdir = @datarootdir@
    13 datadir	= @datadir@
    14 auxdir	= @ac_aux_dir@
    15 distpath = $(srcdir)/..
    16 distdir = SDL2-@SDL_VERSION@
    17 distfile = $(distdir).tar.gz
    18 
    19 @SET_MAKE@
    20 SHELL	= @SHELL@
    21 CC      = @CC@
    22 INCLUDE = @INCLUDE@
    23 CFLAGS  = @BUILD_CFLAGS@
    24 EXTRA_CFLAGS = @EXTRA_CFLAGS@
    25 LDFLAGS = @BUILD_LDFLAGS@
    26 EXTRA_LDFLAGS = @EXTRA_LDFLAGS@
    27 LIBTOOL = @LIBTOOL@
    28 INSTALL = @INSTALL@
    29 AR	= @AR@
    30 RANLIB	= @RANLIB@
    31 WINDRES	= @WINDRES@
    32 
    33 TARGET  = libSDL2.la
    34 OBJECTS = @OBJECTS@
    35 GEN_HEADERS = @GEN_HEADERS@
    36 GEN_OBJECTS = @GEN_OBJECTS@
    37 VERSION_OBJECTS = @VERSION_OBJECTS@
    38 
    39 SDLMAIN_TARGET = libSDL2main.a
    40 SDLMAIN_OBJECTS = @SDLMAIN_OBJECTS@
    41 
    42 SDLTEST_TARGET = libSDL2_test.a
    43 SDLTEST_OBJECTS = @SDLTEST_OBJECTS@
    44 
    45 WAYLAND_SCANNER = @WAYLAND_SCANNER@
    46 
    47 SRC_DIST = *.txt acinclude Android.mk autogen.sh android-project build-scripts cmake cmake_uninstall.cmake.in configure configure.in debian docs include Makefile.* sdl2-config.cmake.in sdl2-config.in sdl2.m4 sdl2.pc.in SDL2.spec.in src test VisualC.html VisualC VisualC-WinRT Xcode Xcode-iOS
    48 GEN_DIST = SDL2.spec
    49 
    50 ifneq ($V,1)
    51 RUN_CMD_AR     = @echo "  AR    " $@;
    52 RUN_CMD_CC     = @echo "  CC    " $@;
    53 RUN_CMD_CXX    = @echo "  CXX   " $@;
    54 RUN_CMD_LTLINK = @echo "  LTLINK" $@;
    55 RUN_CMD_RANLIB = @echo "  RANLIB" $@;
    56 RUN_CMD_GEN    = @echo "  GEN   " $@;
    57 LIBTOOL += --quiet
    58 endif
    59 
    60 HDRS = \
    61 	SDL.h \
    62 	SDL_assert.h \
    63 	SDL_atomic.h \
    64 	SDL_audio.h \
    65 	SDL_bits.h \
    66 	SDL_blendmode.h \
    67 	SDL_clipboard.h \
    68 	SDL_cpuinfo.h \
    69 	SDL_egl.h \
    70 	SDL_endian.h \
    71 	SDL_error.h \
    72 	SDL_events.h \
    73 	SDL_filesystem.h \
    74 	SDL_gamecontroller.h \
    75 	SDL_gesture.h \
    76 	SDL_haptic.h \
    77 	SDL_hints.h \
    78 	SDL_joystick.h \
    79 	SDL_keyboard.h \
    80 	SDL_keycode.h \
    81 	SDL_loadso.h \
    82 	SDL_log.h \
    83 	SDL_main.h \
    84 	SDL_messagebox.h \
    85 	SDL_mouse.h \
    86 	SDL_mutex.h \
    87 	SDL_name.h \
    88 	SDL_opengl.h \
    89 	SDL_opengl_glext.h \
    90 	SDL_opengles.h \
    91 	SDL_opengles2_gl2ext.h \
    92 	SDL_opengles2_gl2.h \
    93 	SDL_opengles2_gl2platform.h \
    94 	SDL_opengles2.h \
    95 	SDL_opengles2_khrplatform.h \
    96 	SDL_pixels.h \
    97 	SDL_platform.h \
    98 	SDL_power.h \
    99 	SDL_quit.h \
   100 	SDL_rect.h \
   101 	SDL_render.h \
   102 	SDL_rwops.h \
   103 	SDL_scancode.h \
   104 	SDL_shape.h \
   105 	SDL_stdinc.h \
   106 	SDL_surface.h \
   107 	SDL_system.h \
   108 	SDL_syswm.h \
   109 	SDL_thread.h \
   110 	SDL_timer.h \
   111 	SDL_touch.h \
   112 	SDL_types.h \
   113 	SDL_version.h \
   114 	SDL_video.h \
   115 	begin_code.h \
   116 	close_code.h
   117 
   118 SDLTEST_HDRS = $(shell ls $(srcdir)/include | fgrep SDL_test)
   119 
   120 LT_AGE      = @LT_AGE@
   121 LT_CURRENT  = @LT_CURRENT@
   122 LT_RELEASE  = @LT_RELEASE@
   123 LT_REVISION = @LT_REVISION@
   124 LT_LDFLAGS  = -no-undefined -rpath $(DESTDIR)$(libdir) -release $(LT_RELEASE) -version-info $(LT_CURRENT):$(LT_REVISION):$(LT_AGE)
   125 
   126 all: $(srcdir)/configure Makefile $(objects) $(objects)/$(TARGET) $(objects)/$(SDLMAIN_TARGET) $(objects)/$(SDLTEST_TARGET)
   127 
   128 $(srcdir)/configure: $(srcdir)/configure.in
   129 	@echo "Warning, configure.in is out of date"
   130 	#(cd $(srcdir) && sh autogen.sh && sh configure)
   131 	@sleep 3
   132 
   133 Makefile: $(srcdir)/Makefile.in
   134 	$(SHELL) config.status $@
   135 
   136 Makefile.in:;
   137 
   138 $(objects):
   139 	$(SHELL) $(auxdir)/mkinstalldirs $@
   140 
   141 update-revision:
   142 	$(SHELL) $(auxdir)/updaterev.sh
   143 
   144 .PHONY: all update-revision install install-bin install-hdrs install-lib install-data uninstall uninstall-bin uninstall-hdrs uninstall-lib uninstall-data clean distclean dist $(OBJECTS:.lo=.d)
   145 
   146 $(objects)/$(TARGET): $(GEN_HEADERS) $(GEN_OBJECTS) $(OBJECTS) $(VERSION_OBJECTS)
   147 	$(RUN_CMD_LTLINK)$(LIBTOOL) --tag=CC --mode=link $(CC) -o $@ $(OBJECTS) $(GEN_OBJECTS) $(VERSION_OBJECTS) $(LDFLAGS) $(EXTRA_LDFLAGS) $(LT_LDFLAGS)
   148 
   149 $(objects)/$(SDLMAIN_TARGET): $(SDLMAIN_OBJECTS)
   150 	$(RUN_CMD_AR)$(AR) cru $@ $(SDLMAIN_OBJECTS)
   151 	$(RUN_CMD_RANLIB)$(RANLIB) $@
   152 
   153 $(objects)/$(SDLTEST_TARGET): $(SDLTEST_OBJECTS)
   154 	$(RUN_CMD_AR)$(AR) cru $@ $(SDLTEST_OBJECTS)
   155 	$(RUN_CMD_RANLIB)$(RANLIB) $@
   156 
   157 install: all install-bin install-hdrs install-lib install-data
   158 install-bin:
   159 	$(SHELL) $(auxdir)/mkinstalldirs $(DESTDIR)$(bindir)
   160 	$(INSTALL) -m 755 sdl2-config $(DESTDIR)$(bindir)/sdl2-config
   161 install-hdrs: update-revision
   162 	$(SHELL) $(auxdir)/mkinstalldirs $(DESTDIR)$(includedir)/SDL2
   163 	for file in $(HDRS) $(SDLTEST_HDRS); do \
   164 	    $(INSTALL) -m 644 $(srcdir)/include/$$file $(DESTDIR)$(includedir)/SDL2/$$file; \
   165 	done
   166 	$(INSTALL) -m 644 include/SDL_config.h $(DESTDIR)$(includedir)/SDL2/SDL_config.h
   167 	if test -f include/SDL_revision.h; then \
   168 	    $(INSTALL) -m 644 include/SDL_revision.h $(DESTDIR)$(includedir)/SDL2/SDL_revision.h; \
   169 	else \
   170 	    $(INSTALL) -m 644 $(srcdir)/include/SDL_revision.h $(DESTDIR)$(includedir)/SDL2/SDL_revision.h; \
   171 	fi
   172 
   173 install-lib: $(objects) $(objects)/$(TARGET) $(objects)/$(SDLMAIN_TARGET) $(objects)/$(SDLTEST_TARGET)
   174 	$(SHELL) $(auxdir)/mkinstalldirs $(DESTDIR)$(libdir)
   175 	$(LIBTOOL) --mode=install $(INSTALL) $(objects)/$(TARGET) $(DESTDIR)$(libdir)/$(TARGET)
   176 	$(INSTALL) -m 644 $(objects)/$(SDLMAIN_TARGET) $(DESTDIR)$(libdir)/$(SDLMAIN_TARGET)
   177 	$(RANLIB) $(DESTDIR)$(libdir)/$(SDLMAIN_TARGET)
   178 	$(INSTALL) -m 644 $(objects)/$(SDLTEST_TARGET) $(DESTDIR)$(libdir)/$(SDLTEST_TARGET)
   179 	$(RANLIB) $(DESTDIR)$(libdir)/$(SDLTEST_TARGET)
   180 install-data:
   181 	$(SHELL) $(auxdir)/mkinstalldirs $(DESTDIR)$(datadir)/aclocal
   182 	$(INSTALL) -m 644 $(srcdir)/sdl2.m4 $(DESTDIR)$(datadir)/aclocal/sdl2.m4
   183 	$(SHELL) $(auxdir)/mkinstalldirs $(DESTDIR)$(libdir)/pkgconfig
   184 	$(INSTALL) -m 644 sdl2.pc $(DESTDIR)$(libdir)/pkgconfig
   185 	$(SHELL) $(auxdir)/mkinstalldirs $(DESTDIR)$(libdir)/cmake/SDL2
   186 	$(INSTALL) -m 644 sdl2-config.cmake $(DESTDIR)$(libdir)/cmake/SDL2
   187 
   188 uninstall: uninstall-bin uninstall-hdrs uninstall-lib uninstall-data
   189 uninstall-bin:
   190 	rm -f $(DESTDIR)$(bindir)/sdl2-config
   191 uninstall-hdrs:
   192 	for file in $(HDRS) $(SDLTEST_HDRS); do \
   193 	    rm -f $(DESTDIR)$(includedir)/SDL2/$$file; \
   194 	done
   195 	rm -f $(DESTDIR)$(includedir)/SDL2/SDL_config.h
   196 	rm -f $(DESTDIR)$(includedir)/SDL2/SDL_revision.h
   197 	-rmdir $(DESTDIR)$(includedir)/SDL2
   198 uninstall-lib:
   199 	$(LIBTOOL) --mode=uninstall rm -f $(DESTDIR)$(libdir)/$(TARGET)
   200 	rm -f $(DESTDIR)$(libdir)/$(SDLMAIN_TARGET)
   201 	rm -f $(DESTDIR)$(libdir)/$(SDLTEST_TARGET)
   202 uninstall-data:
   203 	rm -f $(DESTDIR)$(datadir)/aclocal/sdl2.m4
   204 	rm -f $(DESTDIR)$(libdir)/pkgconfig/sdl2.pc
   205 	rm -f $(DESTDIR)$(libdir)/cmake/SDL2/sdl2-config.cmake
   206 
   207 clean:
   208 	rm -rf $(objects)
   209 	rm -rf $(gen)
   210 	if test -f test/Makefile; then (cd test; $(MAKE) $@); fi
   211 
   212 distclean: clean
   213 	rm -f Makefile Makefile.rules sdl2-config
   214 	rm -f config.status config.cache config.log libtool
   215 	rm -rf $(srcdir)/autom4te*
   216 	find $(srcdir) \( \
   217 	    -name '*~' -o \
   218 	    -name '*.bak' -o \
   219 	    -name '*.old' -o \
   220 	    -name '*.rej' -o \
   221 	    -name '*.orig' -o \
   222 	    -name '.#*' \) \
   223 	    -exec rm -f {} \;
   224 	if test -f test/Makefile; then (cd test; $(MAKE) $@); fi
   225 
   226 dist $(distfile):
   227 	$(SHELL) $(auxdir)/mkinstalldirs $(distdir)
   228 	(cd $(srcdir); tar cf - $(SRC_DIST)) | (cd $(distdir); tar xf -)
   229 	tar cf - $(GEN_DIST) | (cd $(distdir); tar xf -)
   230 	find $(distdir) \( \
   231 	    -name '*~' -o \
   232 	    -name '*.bak' -o \
   233 	    -name '*.old' -o \
   234 	    -name '*.rej' -o \
   235 	    -name '*.orig' -o \
   236 	    -name '.#*' \) \
   237 	    -exec rm -f {} \;
   238 	if test -f $(distdir)/test/Makefile; then (cd $(distdir)/test && make distclean); fi
   239 	(cd $(distdir); build-scripts/updaterev.sh)
   240 	tar cvf - $(distdir) | gzip --best >$(distfile)
   241 	rm -rf $(distdir)
   242 
   243 rpm: $(distfile)
   244 	rpmbuild -ta $?