From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mx2.suse.de (mx2.suse.de [195.135.220.15]) by sourceware.org (Postfix) with ESMTPS id 0E2E7399C00B for ; Fri, 9 Apr 2021 15:14:56 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.3.2 sourceware.org 0E2E7399C00B Authentication-Results: sourceware.org; dmarc=none (p=none dis=none) header.from=suse.de Authentication-Results: sourceware.org; spf=pass smtp.mailfrom=tdevries@suse.de X-Virus-Scanned: by amavisd-new at test-mx.suse.de Received: from relay2.suse.de (unknown [195.135.221.27]) by mx2.suse.de (Postfix) with ESMTP id 2BF92AD4A; Fri, 9 Apr 2021 15:14:55 +0000 (UTC) Date: Fri, 9 Apr 2021 17:14:48 +0200 From: Tom de Vries To: dwz@sourceware.org, jakub@redhat.com, mark@klomp.org Subject: [committed] Eliminate sed usage in building dwz-for-test Message-ID: <20210409151446.GA21593@delia> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline User-Agent: Mutt/1.10.1 (2018-07-13) X-Spam-Status: No, score=-12.2 required=5.0 tests=BAYES_00, GIT_PATCH_0, KAM_DMARC_STATUS, RCVD_IN_MSPIKE_H3, RCVD_IN_MSPIKE_WL, SPF_HELO_NONE, SPF_PASS, TXREP autolearn=ham autolearn_force=no version=3.4.2 X-Spam-Checker-Version: SpamAssassin 3.4.2 (2018-09-13) on server2.sourceware.org X-BeenThere: dwz@sourceware.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Dwz mailing list List-Unsubscribe: , List-Archive: List-Help: List-Subscribe: , X-List-Received-Date: Fri, 09 Apr 2021 15:14:57 -0000 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 * 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