From: Mike Frysinger <vapier@gentoo.org>
To: newlib@sourceware.org
Subject: [PATCH v2] newlib: libm: workaround ar duplicate member behavior
Date: Mon, 21 Feb 2022 19:21:14 -0500 [thread overview]
Message-ID: <20220222002114.10214-1-vapier@gentoo.org> (raw)
In-Reply-To: <20220221204327.2945-1-vapier@gentoo.org>
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)_$(<F)))
$(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) $@
+
if HAVE_MULTISUBDIR
$(BUILD_MULTISUBDIR):
$(MKDIR_P) $@
diff --git a/newlib/Makefile.in b/newlib/Makefile.in
index 2b60ef1ca96c..cc7afc70451b 100644
--- a/newlib/Makefile.in
+++ b/newlib/Makefile.in
@@ -1361,6 +1361,19 @@ toollib_LIBRARIES = libm.a \
@HAVE_MULTISUBDIR_TRUE@BUILD_MULTISUBDIR = $(builddir)$(MULTISUBDIR)
toollib_DATA = $(CRT0) $(CRT1)
+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,
@@ -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
next prev parent reply other threads:[~2022-02-22 0:21 UTC|newest]
Thread overview: 25+ messages / expand[flat|nested] mbox.gz Atom feed top
2022-02-12 20:34 [PATCH] newlib: libm: merge build up a directory Mike Frysinger
2022-02-16 8:50 ` [HEADSUP] " Corinna Vinschen
2022-02-16 9:40 ` Sebastian Huber
2022-02-16 10:48 ` Corinna Vinschen
2022-02-17 4:38 ` Mike Frysinger
2022-02-17 4:42 ` [PATCH v2] " Mike Frysinger
2022-02-17 12:08 ` Corinna Vinschen
2022-02-21 11:20 ` Corinna Vinschen
2022-02-21 18:00 ` Mike Frysinger
2022-02-21 18:04 ` Jon Turney
2022-02-21 18:30 ` Mike Frysinger
2022-02-21 19:12 ` Jon Turney
2022-02-21 19:24 ` Corinna Vinschen
2022-02-21 20:30 ` Mike Frysinger
2022-02-21 20:31 ` Mike Frysinger
2022-02-21 18:28 ` Mike Frysinger
2022-02-21 20:43 ` [PATCH] newlib: libm: workaround ar duplicate member behavior Mike Frysinger
2022-02-21 20:51 ` Joel Sherrill
2022-02-21 22:12 ` Mike Frysinger
2022-02-21 22:14 ` Joel Sherrill
2022-02-22 0:21 ` Mike Frysinger [this message]
2022-02-22 11:31 ` [PATCH v2] " Corinna Vinschen
2022-02-22 12:34 ` Jon Turney
2022-02-22 17:17 ` Mike Frysinger
2022-02-23 8:56 ` Corinna Vinschen
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=20220222002114.10214-1-vapier@gentoo.org \
--to=vapier@gentoo.org \
--cc=newlib@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).