From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from gnu.wildebeest.org (gnu.wildebeest.org [45.83.234.184]) by sourceware.org (Postfix) with ESMTPS id 9FC69385840B for ; Thu, 3 Nov 2022 22:11:34 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.1 sourceware.org 9FC69385840B Authentication-Results: sourceware.org; dmarc=none (p=none dis=none) header.from=klomp.org Authentication-Results: sourceware.org; spf=pass smtp.mailfrom=klomp.org Received: from reform (deer0x07.wildebeest.org [172.31.17.137]) (using TLSv1.2 with cipher ADH-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by gnu.wildebeest.org (Postfix) with ESMTPSA id 66340309FA85 for ; Thu, 3 Nov 2022 23:11:32 +0100 (CET) Received: by reform (Postfix, from userid 1000) id 8AEFF2E8028B; Thu, 3 Nov 2022 23:11:31 +0100 (CET) Date: Thu, 3 Nov 2022 23:11:31 +0100 From: Mark Wielaard To: dwz@sourceware.org Subject: Re: [PATCH] Check -DXXH_INLINE_ALL works, otherwise link against libxxhash Message-ID: References: <20221103162838.31402-1-mark@klomp.org> MIME-Version: 1.0 Content-Type: multipart/mixed; boundary="vhuUZiPNa9t1RS/8" Content-Disposition: inline In-Reply-To: <20221103162838.31402-1-mark@klomp.org> X-Spam-Status: No, score=-3039.0 required=5.0 tests=BAYES_00,GIT_PATCH_0,JMQ_SPF_NEUTRAL,KAM_DMARC_STATUS,SPF_HELO_NONE,SPF_PASS,TXREP autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on server2.sourceware.org List-Id: --vhuUZiPNa9t1RS/8 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline On Thu, Nov 03, 2022 at 05:28:38PM +0100, Mark Wielaard wrote: > 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. After testing a bit more on different systems I pushed this variant which does the string escaping slightly different. Cheers, Mark --vhuUZiPNa9t1RS/8 Content-Type: text/x-diff; charset=us-ascii Content-Disposition: attachment; filename="0001-Check-DXXH_INLINE_ALL-works-otherwise-link-against-l.patch" >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 --vhuUZiPNa9t1RS/8--