From 70ad4845083be77d95d64116e2de67c95a6a649b Mon Sep 17 00:00:00 2001 From: Christoph Reiter Date: Wed, 1 Aug 2018 18:54:01 +0200 Subject: [PATCH] gresource-tool: fix build in case libelf is available on Windows. Fixes #1466 The gresource code uses libelf if available but that also depends on mmap but isn't guarded with HAVE_MMAP. This can make the build fail under MSYS2 where a mingw version of libelf exists but there is no mmap. Instead of guarting the libelf code with HAVE_LIBELF add a new macro named USE_LIBELF which is only defined if libelf and mmap support are available. Also install the mingw libelf version for CI so we catch similar errors in the future. --- .gitlab-ci/test-msys2.sh | 3 ++- gio/gresource-tool.c | 23 +++++++++++++++-------- 2 files changed, 17 insertions(+), 9 deletions(-) diff --git a/.gitlab-ci/test-msys2.sh b/.gitlab-ci/test-msys2.sh index d8891e35b..48e18e92c 100755 --- a/.gitlab-ci/test-msys2.sh +++ b/.gitlab-ci/test-msys2.sh @@ -21,7 +21,8 @@ pacman --noconfirm -S --needed \ mingw-w64-$MSYS2_ARCH-python3 \ mingw-w64-$MSYS2_ARCH-python3-pip \ mingw-w64-$MSYS2_ARCH-toolchain \ - mingw-w64-$MSYS2_ARCH-zlib + mingw-w64-$MSYS2_ARCH-zlib \ + mingw-w64-$MSYS2_ARCH-libelf curl -O -J -L "https://github.com/linux-test-project/lcov/releases/download/v1.13/lcov-1.13.tar.gz" echo "44972c878482cc06a05fe78eaa3645cbfcbad6634615c3309858b207965d8a23 lcov-1.13.tar.gz" | sha256sum -c diff --git a/gio/gresource-tool.c b/gio/gresource-tool.c index b25eebf3d..d1de02631 100644 --- a/gio/gresource-tool.c +++ b/gio/gresource-tool.c @@ -31,6 +31,9 @@ #ifdef HAVE_LIBELF #include #include +#endif + +#ifdef HAVE_MMAP #include #endif @@ -42,6 +45,10 @@ #include "glib/glib-private.h" #endif +#if defined(HAVE_LIBELF) && defined(HAVE_MMAP) +#define USE_LIBELF +#endif + /* GResource functions {{{1 */ static GResource * get_resource (const gchar *file) @@ -133,7 +140,7 @@ extract_resource (GResource *resource, /* Elf functions {{{1 */ -#ifdef HAVE_LIBELF +#ifdef USE_LIBELF static Elf * get_elf (const gchar *file, @@ -353,7 +360,7 @@ print_section_name (GElf_Shdr *shdr, return TRUE; } -#endif /* HAVE_LIBELF */ +#endif /* USE_LIBELF */ /* Toplevel commands {{{1 */ @@ -365,7 +372,7 @@ cmd_sections (const gchar *file, { GResource *resource; -#ifdef HAVE_LIBELF +#ifdef USE_LIBELF Elf *elf; gint fd; @@ -388,7 +395,7 @@ cmd_sections (const gchar *file, else { g_printerr ("Don't know how to handle %s\n", file); -#ifndef HAVE_LIBELF +#ifndef USE_LIBELF g_printerr ("gresource is built without elf support\n"); #endif } @@ -402,7 +409,7 @@ cmd_list (const gchar *file, { GResource *resource; -#ifdef HAVE_LIBELF +#ifdef USE_LIBELF Elf *elf; int fd; @@ -424,7 +431,7 @@ cmd_list (const gchar *file, else { g_printerr ("Don't know how to handle %s\n", file); -#ifndef HAVE_LIBELF +#ifndef USE_LIBELF g_printerr ("gresource is built without elf support\n"); #endif } @@ -438,7 +445,7 @@ cmd_extract (const gchar *file, { GResource *resource; -#ifdef HAVE_LIBELF +#ifdef USE_LIBELF Elf *elf; int fd; @@ -461,7 +468,7 @@ cmd_extract (const gchar *file, else { g_printerr ("Don't know how to handle %s\n", file); -#ifndef HAVE_LIBELF +#ifndef USE_LIBELF g_printerr ("gresource is built without elf support\n"); #endif }