1
0
mirror of https://github.com/MariaDB/server.git synced 2025-08-08 11:22:35 +03:00

MDEV-22214 mariadbd.exe calls function mysqld.exe, and crashes

Stop linking plugins to the server executable on Windows.
Instead, extract whole server functionality into a large DLL, called
server.dll. Link both plugins, and small server "stub" exe to it.

This eliminates plugin dependency on the name of the server executable.
It also reduces the size of the packages (since tiny mysqld.exe
and mariadbd.exe are now both linked to one big DLL)

Also, simplify the functionality of exporing all symbols from selected
static libraries. Rely on WINDOWS_EXPORT_ALL_SYMBOLS, rather than old
self-backed solution.

fix compile error

replace GetProcAddress(GetModuleHandle(NULL), "variable_name")
for server exported data with actual variable names.

Runtime loading was never required,was error prone
, since symbols could be missing at runtime, and now it actually failed,
because we do not export symbols from executable anymore, but from a shared
library

This did require a MYSQL_PLUGIN_IMPORT decoration for the plugin,
but made the code more straightforward, and avoids missing symbols at
runtime (as mentioned before).

The audit plugin is still doing some dynamic loading, as it aims to work
cross-version. Now it won't work cross-version on Windows, as it already
uses some symbols that are *not* dynamically loaded, e.g fn_format
and those symbols now exported from server.dll , when earlier they were
exported by mysqld.exe

Windows, fixes for storage engine plugin loading
after various rebranding stuff

Create server.dll containing functionality of the whole server
make mariadbd.exe/mysqld.exe a stub that is only  calling mysqld_main()

fix build
This commit is contained in:
Vladislav Vaintroub
2020-04-10 14:09:18 +02:00
parent 38f7dbec19
commit 93efbc390d
16 changed files with 81 additions and 182 deletions

View File

@@ -276,7 +276,7 @@ static my_off_t loc_tell(File fd)
#endif /*WIN32*/
extern char server_version[];
extern MYSQL_PLUGIN_IMPORT char server_version[];
static const char *serv_ver= NULL;
static int started_mysql= 0;
static int mysql_57_started= 0;
@@ -2373,31 +2373,37 @@ typedef struct loc_system_variables
static int init_done= 0;
static void* find_sym(const char *sym)
{
#ifdef _WIN32
return GetProcAddress(GetModuleHandle("server.dll"),sym);
#else
return dlsym(RTLD_DEFAULT, sym);
#endif
}
static int server_audit_init(void *p __attribute__((unused)))
{
if (!serv_ver)
{
#ifdef _WIN32
serv_ver= (const char *) GetProcAddress(0, "server_version");
#else
serv_ver= server_version;
#endif /*_WIN32*/
serv_ver= find_sym("server_version");
}
if (!mysql_57_started)
{
const void *my_hash_init_ptr= dlsym(RTLD_DEFAULT, "_my_hash_init");
const void *my_hash_init_ptr= find_sym("_my_hash_init");
if (!my_hash_init_ptr)
{
maria_above_5= 1;
my_hash_init_ptr= dlsym(RTLD_DEFAULT, "my_hash_init2");
my_hash_init_ptr= find_sym("my_hash_init2");
}
if (!my_hash_init_ptr)
return 1;
}
if(!(int_mysql_data_home= dlsym(RTLD_DEFAULT, "mysql_data_home")))
if(!(int_mysql_data_home= find_sym("mysql_data_home")))
{
if(!(int_mysql_data_home= dlsym(RTLD_DEFAULT, "?mysql_data_home@@3PADA")))
if(!(int_mysql_data_home= find_sym("?mysql_data_home@@3PADA")))
int_mysql_data_home= &default_home;
}
@@ -2929,7 +2935,7 @@ BOOL WINAPI DllMain(HINSTANCE hinstDLL, DWORD fdwReason, LPVOID lpvReserved)
if (fdwReason != DLL_PROCESS_ATTACH)
return 1;
serv_ver= (const char *) GetProcAddress(0, "server_version");
serv_ver= server_version;
#else
void __attribute__ ((constructor)) audit_plugin_so_init(void)
{