public inbox for dwz@sourceware.org
 help / color / mirror / Atom feed
From: Tom de Vries <tdevries@suse.de>
To: dwz@sourceware.org, jakub@redhat.com, mark@klomp.org
Subject: [committed] Eliminate sed usage in building dwz-for-test
Date: Fri, 9 Apr 2021 17:14:48 +0200	[thread overview]
Message-ID: <20210409151446.GA21593@delia> (raw)

Hi,

We started out building dwz-for-test using -U__GNUC__.  That resulted
in problems with system headers on fedora, so instead a solution using
sed was implemented.  This works well and ensures that all __GNUC__ uses
are addressed, but it makes refactoring more complicated.

Instead, use the slightly more error-prone but less cumbersome method
of replacing uses of __GNUC__ with uses of a new variable USE_GNUC,
and define USE_GNUC=0 for dwz-for-test.

Committed to trunk.

Thanks,
- Tom

Eliminate sed usage in building dwz-for-test

2021-04-09  Tom de Vries  <tdevries@suse.de>

	* Makefile: Compile dwz-for-test using -DUSE_GNUC=0.
	* dwz.c (USE_GNUC): Weakly define if __GNUC__ is defined, and
	use instead of __GNUC__.

---
 Makefile | 23 +++++++++++++----------
 dwz.c    | 16 ++++++++++++----
 2 files changed, 25 insertions(+), 14 deletions(-)

diff --git a/Makefile b/Makefile
index c3a5abe..02da6c4 100644
--- a/Makefile
+++ b/Makefile
@@ -24,7 +24,7 @@ install: dwz
 	install -D dwz $(DESTDIR)$(bindir)/dwz
 	install -D -m 644 $(srcdir)/dwz.1 $(DESTDIR)$(mandir)/man1/dwz.1
 clean:
-	rm -f $(OBJECTS) *~ core* dwz $(TEST_EXECS) $(DWZ_TEST_SOURCES) \
+	rm -f $(OBJECTS) *~ core* dwz $(TEST_EXECS) $(DWZ_TEST_OBJECTS) \
 	  dwz.log dwz.sum
 	rm -Rf testsuite-bin tmp.*
 
@@ -55,14 +55,17 @@ dw2-skip-prologue:
 py-section-script:
 	$(CC) $(TEST_SRC)/py-section-script.s -o $@ -g || touch $@
 
-DWZ_TEST_SOURCES := $(patsubst %.o,%-for-test.c,$(OBJECTS))
-
-%-for-test.c: %.c
-	sed 's/__GNUC__/NOT_DEFINED/' $< > $@
-
-dwz-for-test: $(DWZ_TEST_SOURCES)
-	$(CC) $(DWZ_TEST_SOURCES) -O2 -g $(LIBS) -o $@ $(CFLAGS_COMMON) \
-	  -DDEVEL -DDWZ_VERSION='"for-test"' -I$(srcdir) $(CFLAGS_COPYRIGHT)
+DWZ_TEST_OBJECTS := $(patsubst %.o,%-for-test.o,$(OBJECTS))
+dwz-for-test: $(DWZ_TEST_OBJECTS)
+	$(CC) $(LDFLAGS) -o $@ $^ $(LIBS)
+	rm -f $(DWZ_TEST_OBJECTS)
+$(DWZ_TEST_OBJECTS): %-for-test.o : %.c
+	$(CC) $< -o $@ -c \
+	  -DUSE_GNUC=0 -DDEVEL \
+	  -O2 -g \
+	  $(CFLAGS_COMMON) \
+	  -DDWZ_VERSION='"for-test"' \
+	  $(CFLAGS_COPYRIGHT)
 
 min:
 	$(CC) $(TEST_SRC)/min.c $(TEST_SRC)/min-2.c -o $@ -g
@@ -161,4 +164,4 @@ check check-valgrind: dwz $(TEST_EXECS)
 	export DEJAGNU=$(DEJAGNU); \
 	export PATH=$(PWD)/testsuite-bin:$$PATH; export LC_ALL=C; \
 	runtest --tool=dwz -srcdir $(srcdir)/testsuite $(RUNTESTFLAGS)
-	rm -Rf testsuite-bin $(TEST_EXECS) $(DWZ_TEST_SOURCES)
+	rm -Rf testsuite-bin $(TEST_EXECS) $(DWZ_TEST_OBJECTS)
diff --git a/dwz.c b/dwz.c
index 92b7e5d..dfae64f 100644
--- a/dwz.c
+++ b/dwz.c
@@ -44,6 +44,14 @@
 #include "sha1.h"
 #include "args.h"
 
+#ifndef USE_GNUC
+#ifdef __GNUC__
+#define USE_GNUC 1
+#else
+#define USE_GNUC 0
+#endif
+#endif
+
 #ifndef SHF_COMPRESSED
  /* Glibc elf.h contains SHF_COMPRESSED starting v2.22.  Libelf libelf.h has
     a fallback definition starting v0.166.  Define a fallback definition here
@@ -110,7 +118,7 @@
 # define NT_GNU_BUILD_ID 3
 #endif
 
-#if defined __GNUC__ && __GNUC__ >= 3
+#if USE_GNUC && __GNUC__ >= 3
 # define likely(x) __builtin_expect (!!(x), 1)
 # define unlikely(x) __builtin_expect (!!(x), 0)
 #else
@@ -118,7 +126,7 @@
 # define unlikely(x) (x)
 #endif
 
-#if defined __GNUC__
+#if USE_GNUC
 # define FORCE_INLINE __attribute__((always_inline))
 # define UNUSED __attribute__((unused))
 # define USED __attribute__((used))
@@ -1121,7 +1129,7 @@ die_cu (dw_die_ref die)
 #define die_safe_nextdup(die) \
   ((die)->die_toplevel ? (die)->die_nextdup : (dw_die_ref) NULL)
 
-#ifdef __GNUC__
+#if USE_GNUC
 # define ALIGN_STRUCT(name)
 #else
 # define ALIGN_STRUCT(name) struct align_##name { char c; struct name s; };
@@ -1186,7 +1194,7 @@ pool_destroy (void)
     }
 }
 
-#ifdef __GNUC__
+#if USE_GNUC
 # define pool_alloc(name, size) \
   (struct name *) pool_alloc_1 (__alignof__ (struct name), size)
 #else

                 reply	other threads:[~2021-04-09 15:14 UTC|newest]

Thread overview: [no followups] expand[flat|nested]  mbox.gz  Atom feed

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=20210409151446.GA21593@delia \
    --to=tdevries@suse.de \
    --cc=dwz@sourceware.org \
    --cc=jakub@redhat.com \
    --cc=mark@klomp.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).