# How does the SDL dynamic API inject itself in statically linked code

I've been using SDL2 for development almost since it came out. Long story short, I stumbled upon the SDL dynamic API explanation. I've looked in SDL_Dynapi.c to understand how it works. I get that the jump table can be updated with function pointers to newer versions of the functions, but what I don't get is how one would actually goes about doing that dynamically.

Did I miss a function declaration, is there some specific function to call outside the application? I have no idea how an updated dynapi loads itself.

It's pretty straightforward, if not entirely well documented. Reading the source (not sure if the released version differs significantly) tells me that you must export an environment variable SDL_DYNAMIC_API with the name of the .so you want to load. That .so must contain a symbol SDL_DYNAPI_entry with signature: Sint32(SDLCALL*)(Uint32 apiver, void *table, Uint32 tablesize). If the library exists and the symbol exists, it will be loaded and the function called.
A combination of apiver (which is equal to SDL_DYNAPI_VERSION) and tablesize (roughly the number of dynamic functions) can be used to fill in the table at table. The apiver will only change if the ABI changes in a non-compatible way. The tablesize may grow, but hypothetically this is ok: it just means that the SDL library has new dynamic functions that you don't have to care about and you can safely only update the parts of table you already know about. The function should return non-zero on success and zero on failure.