public inbox for dwz@sourceware.org
 help / color / mirror / Atom feed
From: Mark Wielaard <mark@klomp.org>
To: dwz@sourceware.org
Subject: Re: [PATCH] Check -DXXH_INLINE_ALL works, otherwise link against libxxhash
Date: Thu, 3 Nov 2022 23:11:31 +0100	[thread overview]
Message-ID: <Y2Q8k2SsRW1pJuMk@wildebeest.org> (raw)
In-Reply-To: <20221103162838.31402-1-mark@klomp.org>

[-- Attachment #1: Type: text/plain, Size: 474 bytes --]

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

[-- Attachment #2: 0001-Check-DXXH_INLINE_ALL-works-otherwise-link-against-l.patch --]
[-- Type: text/x-diff, Size: 2952 bytes --]

From 7aae87b5dff6128c46fc7fb2ccd1eae2c6fa11ba Mon Sep 17 00:00:00 2001
From: Mark Wielaard <mark@klomp.org>
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 <xxhash.h>\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


      reply	other threads:[~2022-11-03 22:11 UTC|newest]

Thread overview: 2+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2022-11-03 16:28 Mark Wielaard
2022-11-03 22:11 ` Mark Wielaard [this message]

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=Y2Q8k2SsRW1pJuMk@wildebeest.org \
    --to=mark@klomp.org \
    --cc=dwz@sourceware.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).