From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from smtp.gentoo.org (mail.gentoo.org [IPv6:2001:470:ea4a:1:5054:ff:fec7:86e4]) by sourceware.org (Postfix) with ESMTP id CC4A63858C2C for ; Tue, 22 Feb 2022 00:21:15 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.1 sourceware.org CC4A63858C2C Authentication-Results: sourceware.org; dmarc=pass (p=none dis=none) header.from=gentoo.org Authentication-Results: sourceware.org; spf=pass smtp.mailfrom=gentoo.org Received: by smtp.gentoo.org (Postfix, from userid 559) id E71CF3436A7; Tue, 22 Feb 2022 00:21:14 +0000 (UTC) From: Mike Frysinger To: newlib@sourceware.org Subject: [PATCH v2] newlib: libm: workaround ar duplicate member behavior Date: Mon, 21 Feb 2022 19:21:14 -0500 Message-Id: <20220222002114.10214-1-vapier@gentoo.org> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20220221204327.2945-1-vapier@gentoo.org> References: <20220221204327.2945-1-vapier@gentoo.org> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Spam-Status: No, score=-11.6 required=5.0 tests=BAYES_00, GIT_PATCH_0, KAM_DMARC_STATUS, SPF_HELO_PASS, SPF_PASS, TXREP, T_SCC_BODY_TEXT_LINE autolearn=ham autolearn_force=no version=3.4.4 X-Spam-Checker-Version: SpamAssassin 3.4.4 (2020-01-24) on server2.sourceware.org X-BeenThere: newlib@sourceware.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Newlib mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Tue, 22 Feb 2022 00:21:17 -0000 GNU ar has undocumented behavior where it doesn't dedupe its inputs if they're all on the same command line, so we have to dedupe ourselves. --- v2 - use awk to dedupe the object list newlib/Makefile.am | 22 ++++++++++++++++++++++ newlib/Makefile.in | 24 +++++++++++++++++++----- 2 files changed, 41 insertions(+), 5 deletions(-) diff --git a/newlib/Makefile.am b/newlib/Makefile.am index 80256952da3d..116332eb2ab9 100644 --- a/newlib/Makefile.am +++ b/newlib/Makefile.am @@ -85,6 +85,22 @@ toollib_DATA = $(CRT0) $(CRT1) CLEANFILES += libg.a +## GNU ar has undocumented behavior when specifying the same name multiple times +## in a single invocation, so we have to dedupe ourselves. +## https://sourceware.org/PR28917 +AWK_UNIQUE_OBJS = $(AWK) '{ \ + for (i = NF; i > 0; --i) { \ + split($$i, parts, "/"); \ + name = parts[length(parts)]; \ + if (!(name in seen)) { \ + objs[i] = $$i; \ + seen[name] = 1; \ + } \ + } \ + for (i in objs) \ + print objs[i]; \ +}' + # The functions ldexp, frexp and modf are traditionally supplied in # both libc.a and libm.a. We build them in libm.a and copy them over, # along with some required supporting routines. @@ -124,6 +140,12 @@ libm_a_CCASFLAGS = $(AM_CCASFLAGS) $(libm_a_CCASFLAGS_$(subst /,_,$(@D))) $(libm libm_a_CPPFLAGS = $(AM_CPPFLAGS) -I$(srcdir)/libm/common $(libm_a_CPPFLAGS_$(subst /,_,$(@D))) $(libm_a_CPPFLAGS_$(subst /,_,$(@D)_$( 0; --i) { \ + split($$i, parts, "/"); \ + name = parts[length(parts)]; \ + if (!(name in seen)) { \ + objs[i] = $$i; \ + seen[name] = 1; \ + } \ + } \ + for (i in objs) \ + print objs[i]; \ +}' + # The functions ldexp, frexp and modf are traditionally supplied in # both libc.a and libm.a. We build them in libm.a and copy them over, @@ -3248,11 +3261,6 @@ libm/machine/x86_64/libm_a-fetestexcept.$(OBJEXT): \ libm/machine/x86_64/libm_a-feupdateenv.$(OBJEXT): \ libm/machine/x86_64/$(am__dirstamp) -libm.a: $(libm_a_OBJECTS) $(libm_a_DEPENDENCIES) $(EXTRA_libm_a_DEPENDENCIES) - $(AM_V_at)-rm -f libm.a - $(AM_V_AR)$(libm_a_AR) libm.a $(libm_a_OBJECTS) $(libm_a_LIBADD) - $(AM_V_at)$(RANLIB) libm.a - mostlyclean-compile: -rm -f *.$(OBJEXT) -rm -f libm/common/*.$(OBJEXT) @@ -8650,6 +8658,12 @@ libg.a: libc.a $(AM_V_GEN)ln libc.a libg.a >/dev/null 2>/dev/null || cp libc.a libg.a $(libm_a_OBJECTS): stmp-targ-include +libm.a: $(libm_a_OBJECTS) $(libm_a_DEPENDENCIES) + $(AM_V_at)rm -f $@ + $(AM_V_AR)objs=`echo $(libm_a_OBJECTS) | $(AWK_UNIQUE_OBJS)` || exit $$?; \ + $(AR) $(ARFLAGS) $@ $$objs + $(AM_V_at)$(RANLIB) $@ + @HAVE_MULTISUBDIR_TRUE@$(BUILD_MULTISUBDIR): @HAVE_MULTISUBDIR_TRUE@ $(MKDIR_P) $@ -- 2.34.1