]> git.cworth.org Git - glaze/commitdiff
Add glaze-find-libegl programs.
authorMark Janes <mark.a.janes@intel.com>
Fri, 12 Sep 2014 23:16:38 +0000 (16:16 -0700)
committerCarl Worth <cworth@cworth.org>
Thu, 18 Dec 2014 15:04:05 +0000 (07:04 -0800)
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
Makefile
glaze-find-libegl.c [new file with mode: 0644]

index 96bf5515c013a8367d41e2246ca6be025008441d..1df48df6cdf109ad8179dcba315786cabe26196f 100644 (file)
@@ -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*
index bcc26295946192a9e20e339fe20e703793580fe7..0ce4486d002baf7c465600eed7014b81240fa9fa 100644 (file)
--- 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 (file)
index 0000000..cbe1a1e
--- /dev/null
@@ -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 <dlfcn.h>
+
+#include <stdio.h>
+
+/* 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;
+}