From 3430c08632759d3d7e4eabdca09e9c8f42e3d2ba Mon Sep 17 00:00:00 2001 From: Mark Janes Date: Fri, 12 Sep 2014 16:16:38 -0700 Subject: [PATCH] Add glaze-find-libegl programs. To preparation for supporting EGL interposition, add 32 and 64 bit variants of glaze-find-libegl. glaze-find-libegl is analogous to the existing glaze-find-libgl, and has identical usage/function. --- .gitignore | 2 ++ Makefile | 12 +++++-- glaze-find-libegl.c | 78 +++++++++++++++++++++++++++++++++++++++++++++ 3 files changed, 90 insertions(+), 2 deletions(-) create mode 100644 glaze-find-libegl.c diff --git a/.gitignore b/.gitignore index 96bf551..1df48df 100644 --- a/.gitignore +++ b/.gitignore @@ -4,6 +4,8 @@ glaze.pc glaze-32.pc glaze-find-libgl-32 glaze-find-libgl-64 +glaze-find-libegl-32 +glaze-find-libegl-64 lib libglaze.so* libglaze-32.so* diff --git a/Makefile b/Makefile index bcc2629..0ce4486 100644 --- a/Makefile +++ b/Makefile @@ -35,13 +35,13 @@ SPECS = specs/gl.def specs/glx.def ifeq ($(COMPILER_SUPPORTS_32),Yes) TARGETS += $(LIBGLAZE_32_LIBNAME) TARGETS += $(LIB32_DIR)/libGL.so.1 -TARGETS += glaze-find-libgl-32 +TARGETS += glaze-find-libgl-32 glaze-find-libegl-32 endif ifeq ($(COMPILER_SUPPORTS_64),Yes) TARGETS += $(LIBGLAZE_LIBNAME) TARGETS += $(LIB64_DIR)/libGL.so.1 -TARGETS += glaze-find-libgl-64 +TARGETS += glaze-find-libgl-64 glaze-find-libegl-64 endif all: $(TARGETS) @@ -74,6 +74,12 @@ glaze-find-libgl-32: glaze-find-libgl.c glaze-find-libgl-64: glaze-find-libgl.c $(CC) $(GLAZE_CFLAGS) -m64 -fPIC -ldl -o $@ $< +glaze-find-libegl-32: glaze-find-libegl.c + $(CC) $(GLAZE_CFLAGS) -m32 -fPIC -ldl -o $@ $< + +glaze-find-libegl-64: glaze-find-libegl.c + $(CC) $(GLAZE_CFLAGS) -m64 -fPIC -ldl -o $@ $< + .PHONY: install install: all mkdir -p $(DESTDIR)$(INCLUDEDIR)/glaze @@ -90,6 +96,7 @@ ifeq ($(COMPILER_SUPPORTS_32),Yes) ln -sf $(LIBGLAZE_32_LIBNAME) $(DESTDIR)$(LIBDIR)/$(LIBGLAZE_32_LINKER_NAME) install glaze-32.pc $(DESTDIR)$(LIBDIR)/pkgconfig install -m0755 glaze-find-libgl-32 $(DESTDIR)$(BINDIR) + install -m0755 glaze-find-libegl-32 $(DESTDIR)$(BINDIR) endif ifeq ($(COMPILER_SUPPORTS_64),Yes) mkdir -p $(DESTDIR)$(LIBDIR)/glaze/$(LIB64_DIR) @@ -100,6 +107,7 @@ ifeq ($(COMPILER_SUPPORTS_64),Yes) ln -sf $(LIBGLAZE_LIBNAME) $(DESTDIR)$(LIBDIR)/$(LIBGLAZE_LINKER_NAME) install glaze.pc $(DESTDIR)$(LIBDIR)/pkgconfig install -m0755 glaze-find-libgl-64 $(DESTDIR)$(BINDIR) + install -m0755 glaze-find-libegl-64 $(DESTDIR)$(BINDIR) endif clean: diff --git a/glaze-find-libegl.c b/glaze-find-libegl.c new file mode 100644 index 0000000..cbe1a1e --- /dev/null +++ b/glaze-find-libegl.c @@ -0,0 +1,78 @@ +/* Copyright © 2014, Intel Corporation + * + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to deal + * in the Software without restriction, including without limitation the rights + * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + * copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in + * all copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN + * THE SOFTWARE. + */ + +#define _GNU_SOURCE +#include + +#include + +/* The purpose of this program is very simple. It dynamically loads + * libEGL.so.1 and then prints out the filename of the file which was + * loaded. + * + * We use this in Glaze in order to determine the libEGL.so.1 library + * that would be loaded if it weren't for us messing around with + * LD_LIBRARY_PATH causing Glaze's libEGL.so.1 to be loaded instead. + * + * Using a program like this allows us to directly inspect what the + * dynamic loader actually does. This is much more reliable than + * trying to recreate its search-path logic which would requrie at + * least: + * + * * Parsing LD_LIBRARY_PATH + * + * * Correctly interpreting $LIB within LD_LIBRARY_PATH + * + * * Knowing the canonical name for the current architecture for + * *$LIB + * + * * Parsing /etc/ld.so.conf entries + * + * * etc. etc. + */ +int +main (void) +{ + Dl_info info; + void *handle; + void *function; + + handle = dlopen ("libEGL.so.1", RTLD_NOW); + if (handle == NULL) { + fprintf (stderr, "glaze-find-libegl: Failed to dlopen libEGL.so.1\n"); + return 1; + } + + function = dlsym (handle, "eglSwapBuffers"); + if (function == NULL) { + fprintf (stderr, "glaze-find-libegl: Failed to dlsym eglSwapBuffers\n"); + return 1; + } + + if (dladdr (function, &info) == 0) { + fprintf (stderr, "glaze-find-libegl: Failed to dladdr eglSwapBuffers\n"); + return 1; + } + + printf ("%s\n", info.dli_fname); + + return 0; +} -- 2.43.0