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 4891

Summary: Busy loop within C library when calling SDL_Init()
Product: SDL Reporter: Paul Cercueil <paul>
Component: loadsoAssignee: Sam Lantinga <slouken>
Status: RESOLVED FIXED QA Contact: Sam Lantinga <slouken>
Severity: major    
Priority: P2 CC: icculus
Version: 2.0.10   
Hardware: Other   
OS: Linux   
Attachments: Patch to fix bug 4891

Description Paul Cercueil 2019-12-08 14:41:23 UTC
Running a basic SDL2 app on a MIPS-based Buildroot system running uClibc or musl (glibc untested) results in SDL_Init() locking up and eating the CPU in the process.

From a quick GDB session on the uClibc-based system, it appears to busy-loop in _dl_find_hash() (uclibc-1.0.32/ldso/ldso/dl-hash.c).

The fact that it happens with both musl and uClibc, and only with SDL2 and no other library or app, makes me think it's a bug of SDL2.
Comment 1 Ryan C. Gordon 2019-12-08 14:54:07 UTC
This function generally means the dynamic loader is resolving symbols. If you observed this under the debugger, can you run the “bt” command and paste the output here? It’s probably going to be somewhere under a dlopen() call.

--ryan.
Comment 2 Paul Cercueil 2019-12-08 17:54:12 UTC
Unfortunately it doesn't go very far:

(gdb) bt
#0  0x77e6ab88 in _dl_find_hash () from /lib/ld-uClibc.so.0
#1  0x77e6aba4 in _dl_find_hash () from /lib/ld-uClibc.so.0
Backtrace stopped: frame did not save the PC

(and yes, I compiled SDL2 with -ggdb3 and GDB did load the symbols).
Comment 3 Paul Cercueil 2019-12-08 18:32:22 UTC
I added debug to src/loadso/dlopen/SDL_sysloadso.c.
From what I can see, it seems to hang within dlopen(), when libdrm.so.2 is opened for the *second* time.

See below:

gcw0:~ $ gdb ./testsdl2 
[...]
(gdb) r
Starting program: /media/data/local/home/testsdl2 
[New LWP 264]
SDL dlopen(libdrm.so.2)... done
SDL dlopen(libgbm.so.1)... done
SDL dlsym(drmModeFreeResources)... done
SDL dlsym(drmModeFreeFB)... done
SDL dlsym(drmModeFreeCrtc)... done
SDL dlsym(drmModeFreeConnector)... done
SDL dlsym(drmModeFreeEncoder)... done
SDL dlsym(drmModeGetResources)... done
SDL dlsym(drmModeAddFB)... done
SDL dlsym(drmModeRmFB)... done
SDL dlsym(drmModeGetFB)... done
SDL dlsym(drmModeGetCrtc)... done
SDL dlsym(drmModeSetCrtc)... done
SDL dlsym(drmModeSetCursor)... done
SDL dlsym(drmModeSetCursor2)... done
SDL dlsym(drmModeMoveCursor)... done
SDL dlsym(drmModeGetEncoder)... done
SDL dlsym(drmModeGetConnector)... done
SDL dlsym(drmHandleEvent)... done
SDL dlsym(drmModePageFlip)... done
SDL dlsym(gbm_device_get_fd)... done
SDL dlsym(gbm_device_is_format_supported)... done
SDL dlsym(gbm_device_destroy)... done
SDL dlsym(gbm_create_device)... done
SDL dlsym(gbm_bo_get_width)... done
SDL dlsym(gbm_bo_get_height)... done
SDL dlsym(gbm_bo_get_stride)... done
SDL dlsym(gbm_bo_get_handle)... done
SDL dlsym(gbm_bo_write)... done
SDL dlsym(gbm_bo_get_device)... done
SDL dlsym(gbm_bo_set_user_data)... done
SDL dlsym(gbm_bo_get_user_data)... done
SDL dlsym(gbm_bo_destroy)... done
SDL dlsym(gbm_bo_create)... done
SDL dlsym(gbm_surface_create)... done
SDL dlsym(gbm_surface_destroy)... done
SDL dlsym(gbm_surface_lock_front_buffer)... done
SDL dlsym(gbm_surface_release_buffer)... done
SDL dlopen(libdrm.so.2)...
Comment 4 Paul Cercueil 2019-12-17 22:38:53 UTC
Small update: this bug does not happen if libdrm is pre-loaded:

SDL_PRELOAD=/usr/lib/libdrm.so.2 ./testsdl2

works fine.
Comment 5 Paul Cercueil 2019-12-17 23:33:44 UTC
Created attachment 4113 [details]
Patch to fix bug 4891
Comment 6 Sam Lantinga 2019-12-20 05:48:06 UTC
Patch added, thanks!
https://hg.libsdl.org/SDL/rev/4f5bef55183c