gbm_wrapper: Load mali library before searching the symbols

The RTLD_NEXT would not work if the gbm library was loaded with
RTLD_LOCAL.

Change-Id: I4256b52271a92e03dbcb490b1e7fabeb32be6401
Signed-off-by: Jeffy Chen <jeffy.chen@rock-chips.com>
This commit is contained in:
Jeffy Chen 2021-01-27 16:51:03 +08:00
parent 728b7bf14f
commit 6141ad6e6f
2 changed files with 45 additions and 11 deletions

View file

@ -19,6 +19,8 @@
#include <dlfcn.h>
#include <errno.h>
#include <fcntl.h>
#include <stdio.h>
#include <stdlib.h>
#include <stdbool.h>
#include <string.h>
#include <xf86drm.h>
@ -187,6 +189,30 @@ gbm_bo_unmap(struct gbm_bo *bo, void *map_data)
}
#endif
static inline void *
mali_dlsym(const char *func)
{
void *handle, *symbol;
/* The libmali should be already loaded */
handle = dlopen(LIBMALI_SO, RTLD_LAZY | RTLD_NOLOAD);
if (!handle) {
/* Should not reach here */
fprintf(stderr, "FATAL: " LIBMALI_SO " not loaded\n");
exit(-1);
}
/* Clear error */
dlerror();
symbol = dlsym(handle, func);
if (!symbol)
fprintf(stderr, "%s\n", dlerror());
dlclose(handle);
return symbol;
}
/* Wrappers for unsupported flags */
struct gbm_surface *
gbm_surface_create(struct gbm_device *gbm,
@ -195,10 +221,12 @@ gbm_surface_create(struct gbm_device *gbm,
{
struct gbm_surface *surface;
static struct gbm_surface * (*surface_create)();
static struct gbm_surface * (* surface_create) ();
if (!surface_create) {
surface_create = mali_dlsym(__func__);
if(!surface_create)
surface_create =
(struct gbm_surface *(*)()) dlsym(RTLD_NEXT, "gbm_surface_create");
return NULL;
}
surface = surface_create(gbm, width, height, format, flags);
if (surface)
@ -216,10 +244,12 @@ gbm_bo_create(struct gbm_device *gbm,
{
struct gbm_bo *bo;
static struct gbm_bo * (*bo_create)();
static struct gbm_bo * (* bo_create) ();
if (!bo_create) {
bo_create = mali_dlsym(__func__);
if(!bo_create)
bo_create =
(struct gbm_bo *(*)()) dlsym(RTLD_NEXT, "gbm_bo_create");
return NULL;
}
bo = bo_create(gbm, width, height, format, flags);
if (bo)

View file

@ -4,6 +4,8 @@ project(
meson_version : '>=0.49.0',
default_options : ['b_asneeded=false', 'b_lundef=false'])
mali_version = meson.project_version()
pkgconfig = import('pkgconfig')
if get_option('arch') != 'auto'
@ -68,7 +70,7 @@ cl_headers = {
# Package name : required symbol, wrappers, headers, package version
map = {
'mali' : ['', mali_wrappers, mali_headers, meson.project_version()],
'mali' : ['', mali_wrappers, mali_headers, mali_version],
'gbm' : ['gbm_create_device', gbm_wrappers, gbm_headers, '20.1.5'],
'egl' : ['eglCreateContext', egl_wrappers, egl_headers, '7.10'],
'glesv1_cm' : ['eglCreateContext', glesv1_wrappers, glesv1_headers, '7.10'],
@ -86,7 +88,7 @@ libmali = shared_library(
'mali',
dummy_source,
install : true,
version : meson.project_version())
version : mali_version)
# The gbm functions might be missing
gbm_check_funcs = [
@ -109,7 +111,9 @@ libgbm = []
gbm_symbol = map['gbm'][0]
if run_command('grep', '-q', gbm_symbol, default_lib).returncode() == 0
libgbm_version = gbm_wrappers['gbm']
libgbm_cflags = []
libgbm_cflags = [
'-DLIBMALI_SO="libmali.so.' + mali_version.split('.')[0] + '"',
]
libdrm_dep = dependency('libdrm', version : '>= 2.4.0')
if not libdrm_dep.found()