Skip to content

Commit

Permalink
gresource-tool: fix build in case libelf is available on Windows. Fix…
Browse files Browse the repository at this point in the history
…es #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.
  • Loading branch information
lazka committed Aug 1, 2018
1 parent 83a4cab commit 70ad484
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 9 deletions.
3 changes: 2 additions & 1 deletion .gitlab-ci/test-msys2.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
23 changes: 15 additions & 8 deletions gio/gresource-tool.c
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,9 @@
#ifdef HAVE_LIBELF
#include <libelf.h>
#include <gelf.h>
#endif

#ifdef HAVE_MMAP
#include <sys/mman.h>
#endif

Expand All @@ -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)
Expand Down Expand Up @@ -133,7 +140,7 @@ extract_resource (GResource *resource,

/* Elf functions {{{1 */

#ifdef HAVE_LIBELF
#ifdef USE_LIBELF

static Elf *
get_elf (const gchar *file,
Expand Down Expand Up @@ -353,7 +360,7 @@ print_section_name (GElf_Shdr *shdr,
return TRUE;
}

#endif /* HAVE_LIBELF */
#endif /* USE_LIBELF */

/* Toplevel commands {{{1 */

Expand All @@ -365,7 +372,7 @@ cmd_sections (const gchar *file,
{
GResource *resource;

#ifdef HAVE_LIBELF
#ifdef USE_LIBELF

Elf *elf;
gint fd;
Expand All @@ -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
}
Expand All @@ -402,7 +409,7 @@ cmd_list (const gchar *file,
{
GResource *resource;

#ifdef HAVE_LIBELF
#ifdef USE_LIBELF
Elf *elf;
int fd;

Expand All @@ -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
}
Expand All @@ -438,7 +445,7 @@ cmd_extract (const gchar *file,
{
GResource *resource;

#ifdef HAVE_LIBELF
#ifdef USE_LIBELF

Elf *elf;
int fd;
Expand All @@ -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
}
Expand Down

0 comments on commit 70ad484

Please sign in to comment.