From 5ad394510bb36aaebd5bb054a5bf4730f666947b Mon Sep 17 00:00:00 2001 From: Mike Frysinger Date: Mon, 21 Feb 2022 15:42:18 -0500 Subject: newlib: libm: workaround ar duplicate member behavior 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. --- newlib/Makefile.am | 28 ++++++++++++++++++++++++++++ 1 file changed, 28 insertions(+) (limited to 'newlib/Makefile.am') diff --git a/newlib/Makefile.am b/newlib/Makefile.am index 8025695..1a5123f 100644 --- a/newlib/Makefile.am +++ b/newlib/Makefile.am @@ -85,6 +85,25 @@ 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. The algorithm here: +## - Generates the set of unique objects based on the basename. +## - Favors objects later in the list (since machine objects come last). +## - Outputs object list in same order as input for reproducibility. +## 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. @@ -122,8 +141,17 @@ libm_a_SOURCES = libm_a_CFLAGS = $(AM_CFLAGS) $(libm_a_CFLAGS_$(subst /,_,$(@D))) $(libm_a_CFLAGS_$(subst /,_,$(@D)_$(