summary |
shortlog |
log |
commit | commitdiff |
tree
raw |
patch |
inline | side by side (from parent 1:
fded9f2)
The dependency is onerous since it requires the user of Glaze to have
both a 32-bit and 64-bit development version of libelf available, (and
also have a toolchain ready to find either one as appropriate).
Meanwhile, the only thing we were doing with libelf was determining
whether the current library targets a 32-bit or a 64-bit
architecture. But we are compiling this code twice, once for each
architecture. So it is actually quite simple to just conditionally
compile in the value we want.
$(LIB64_DIR)/libGL.so.1: glaze-gl.c glapi.def
mkdir -p $(LIB64_DIR)
$(LIB64_DIR)/libGL.so.1: glaze-gl.c glapi.def
mkdir -p $(LIB64_DIR)
- $(CC) $(GLAZE_CFLAGS) -m64 -fPIC -shared -Wl,-Bsymbolic -lelf -o $@ $<
+ $(CC) $(GLAZE_CFLAGS) -DGLAZE_BITS=64 -m64 -fPIC -shared -Wl,-Bsymbolic -o $@ $<
$(LIB32_DIR)/libGL.so.1: glaze-gl.c specs/gl.def
mkdir -p $(LIB32_DIR)
$(LIB32_DIR)/libGL.so.1: glaze-gl.c specs/gl.def
mkdir -p $(LIB32_DIR)
- $(CC) $(GLAZE_CFLAGS) -m32 -fPIC -shared -Wl,-Bsymbolic -lelf -o $@ $<
+ $(CC) $(GLAZE_CFLAGS) -DGLAZE_BITS=32 -m32 -fPIC -shared -Wl,-Bsymbolic -o $@ $<
glaze-find-libgl-32: glaze-find-libgl.c
$(CC) $(GLAZE_CFLAGS) -m32 -fPIC -ldl -o $@ $<
glaze-find-libgl-32: glaze-find-libgl.c
$(CC) $(GLAZE_CFLAGS) -m32 -fPIC -ldl -o $@ $<
#include <string.h>
#include <fcntl.h>
#include <string.h>
#include <fcntl.h>
void *libgl_handle;
void *wrapper_handle;
void *libgl_handle;
void *wrapper_handle;
-/* Is the given elf program 32 or 64 bit?
- *
- * Note: This function returns -1 if 'filename' cannot
- * be opened as a valid ELF file.
- */
-static int
-elf_bits (const char *filename)
-{
- Elf *elf;
- GElf_Ehdr ehdr;
- int fd, class;
-
- fd = open (filename, O_RDONLY, 0);
- if (fd < 0)
- return -1;
-
- if (elf_version (EV_CURRENT ) == EV_NONE)
- return -1;
-
- elf = elf_begin (fd, ELF_C_READ, NULL);
- if (elf == NULL)
- return -1;
-
- if (elf_kind (elf) != ELF_K_ELF)
- return -1;
-
- if (gelf_getehdr (elf, &ehdr) == NULL)
- return -1;
-
- class = gelf_getclass (elf);
-
- switch (class) {
- case ELFCLASS32:
- return 32;
- case ELFCLASS64:
- return 64;
- default:
- return -1;
- }
-}
-
static void
open_libgl_handle (void)
{
static void
open_libgl_handle (void)
{
libgl_path = getenv ("GLAZE_LIBGL");
if (libgl_path == NULL) {
libgl_path = getenv ("GLAZE_LIBGL");
if (libgl_path == NULL) {
- Dl_info info;
- int bits;
-
- if (dladdr (open_libgl_handle, &info) == 0) {
- fprintf (stderr, "Internal error: Failed to lookup filename of glaze library with dladdr.\n");
- exit (1);
- }
-
- bits = elf_bits (info.dli_fname);
- if (bits == 32)
- libgl_path = getenv ("GLAZE_LIBGL_32_AUTO");
- if (bits == 64)
- libgl_path = getenv ("GLAZE_LIBGL_64_AUTO");
+#if GLAZE_BITS == 32
+ libgl_path = getenv ("GLAZE_LIBGL_32_AUTO");
+#elif GLAZE_BITS == 64
+ libgl_path = getenv ("GLAZE_LIBGL_64_AUTO");
+#endif
if (libgl_path == NULL) {
fprintf (stderr,
if (libgl_path == NULL) {
fprintf (stderr,