From 7aae87b5dff6128c46fc7fb2ccd1eae2c6fa11ba Mon Sep 17 00:00:00 2001 From: Mark Wielaard Date: Thu, 3 Nov 2022 23:08:50 +0100 Subject: [PATCH] Check -DXXH_INLINE_ALL works, otherwise link against libxxhash Because we don't have a real configure script this does a Makefile shell trick trying to compile with XXH_INLINE_ALL defined when including xxhash.h. If that fails (like on oldstable debian) it doesn't add -DXXH_INLINE_ALL=1 to CFLAGS and does add -lxxhash to LIBS. --- Makefile | 13 ++++++++++++- dwz.c | 14 ++++++++------ 2 files changed, 20 insertions(+), 7 deletions(-) diff --git a/Makefile b/Makefile index 591a0f6..8b7cf76 100644 --- a/Makefile +++ b/Makefile @@ -8,7 +8,15 @@ CFLAGS = -O2 -g DWZ_VERSION := $(shell cat $(srcdir)/VERSION) CFLAGS_VERSION = -DDWZ_VERSION='"$(DWZ_VERSION)"' CFLAGS_COPYRIGHT = $(shell cat $(srcdir)/COPYRIGHT_YEARS) -CFLAGS_COMMON = -Wall -W -D_FILE_OFFSET_BITS=64 -DXXH_INLINE_ALL=1 +CFLAGS_COMMON = -Wall -W -D_FILE_OFFSET_BITS=64 +XXH_PROG = "\#define XXH_INLINE_ALL 1\n\#include \n" +XXH_INLINE_ALL_WORKS = $(shell printf $(XXH_PROG) \ + | $(CC) -xc -c - -o /dev/null 2>/dev/null \ + && echo -n 1) +ifeq "$(XXH_INLINE_ALL_WORKS)" "1" + CFLAGS_COMMON += -DXXH_INLINE_ALL=1 +endif + override CFLAGS += $(CFLAGS_COMMON) $(CFLAGS_VERSION) $(CFLAGS_COPYRIGHT) prefix = /usr @@ -18,6 +26,9 @@ datarootdir = $(prefix)/share mandir = $(datarootdir)/man OBJECTS = args.o dwz.o hashtab.o pool.o sha1.o dwarfnames.o LIBS=-lelf +ifneq "$(XXH_INLINE_ALL_WORKS)" "1" +LIBS += -lxxhash +endif dwz: $(OBJECTS) $(CC) $(LDFLAGS) -o $@ $^ $(LIBS) args.o: native.o diff --git a/dwz.c b/dwz.c index 51c5dd6..3bc6038 100644 --- a/dwz.c +++ b/dwz.c @@ -114,20 +114,20 @@ # define NT_GNU_BUILD_ID 3 #endif -/* xxHash state object. */ -static XXH64_state_t state; +/* xxHash state object. Init in main. */ +static XXH64_state_t *state; /* Clear xxHash state to zero. */ -#define hash_init_state() XXH64_reset(&state, 0) +#define hash_init_state() XXH64_reset(state, 0) /* Update hash STATE with VALUE. */ -#define hash_update_state_object(value) XXH64_update(&state, &value, sizeof value) +#define hash_update_state_object(value) XXH64_update(state, &value, sizeof value) /* Update hash STATE with OBJECT that has a provided SIZE. */ -#define hash_update_state(object, size) XXH64_update(&state, object, size) +#define hash_update_state(object, size) XXH64_update(state, object, size) /* Get digest once we are done with a state. */ -#define hash_digest() XXH64_digest(&state) +#define hash_digest() XXH64_digest(state) /* Shorthand for hashing something with an intrinsic size. */ #define hash(IN,LEN) XXH64(IN, LEN, 0) @@ -16834,6 +16834,8 @@ main (int argc, char *argv[]) int nr_files; char **files; + state = XXH64_createState (); + if (elf_version (EV_CURRENT) == EV_NONE) error (1, 0, "library out of date"); -- 2.30.2