Volume XXII, number 280Wednesday, October 7, 2026Latest message 2 hours ago

The Git List

News and archive of git@vger.kernel.org, since April 2005

patchMakefile: drop duplicate %.a from link recipes

18 messages between May 31, 2026 and Jun 22, 2026, from Harald Nordgren via GitGitGadget, Junio C Hamano, Harald Nordgren, D. Ben Knoble, Patrick Steinhardt, Paolo Bonzini.

Plain Markdown or JSON for tools and agents. Diffs are folded; open one to read it.

Harald Nordgren via GitGitGadgetMay 31, 2026, 23:16 UTC on lore
From: Harald Nordgren <haraldnordgren@gmail.com>

Three link recipes list archive files twice on the link line: once via $(filter %.a,$^) and again through $(LIBS), which expands to $(filter-out %.o,$(GITLIBS)) $(EXTLIBS). On macOS the linker warns about the duplicates:

  ld: warning: ignoring duplicate libraries: 'libgit.a', 'target/release/libgitcore.a'

Drop the redundant filter from the test-helper, fuzz-program, and unit-test recipes so they match the pattern used by other link recipes in the file.

Signed-off-by: Harald Nordgren <haraldnordgren@gmail.com>
---
    Makefile: drop duplicate %.a from test-helper link rule
Published-As: https://github.com/gitgitgadget/git/releases/tag/pr-git-2314%2FHaraldNordgren%2Fmakefile-test-helper-dedup-libs-v1
Fetch-It-Via: git fetch https://github.com/gitgitgadget/git pr-git-2314/HaraldNordgren/makefile-test-helper-dedup-libs-v1
Pull-Request: https://github.com/git/git/pull/2314
 Makefile | 6 +++---
 1 file changed, 3 insertions(+), 3 deletions(-)
Show changes to Makefile +3 −3
diff --git a/Makefile b/Makefile
index b31ecb0756..309d1d1e74 100644
--- a/Makefile
+++ b/Makefile
@@ -3392,7 +3392,7 @@ perf: all
 t/helper/test-tool$X: $(patsubst %,t/helper/%,$(TEST_BUILTINS_OBJS)) $(UNIT_TEST_DIR)/test-lib.o
 
 t/helper/test-%$X: t/helper/test-%.o GIT-LDFLAGS $(GITLIBS)
-	$(QUIET_LINK)$(CC) $(ALL_CFLAGS) -o $@ $(ALL_LDFLAGS) $(filter %.o,$^) $(filter %.a,$^) $(LIBS)
+	$(QUIET_LINK)$(CC) $(ALL_CFLAGS) -o $@ $(ALL_LDFLAGS) $(filter %.o,$^) $(LIBS)
 
 check-sha1:: t/helper/test-tool$X
 	t/helper/test-sha1.sh
@@ -4015,13 +4015,13 @@ fuzz-all: $(FUZZ_PROGRAMS)
 $(FUZZ_PROGRAMS): %: %.o oss-fuzz/dummy-cmd-main.o $(GITLIBS) GIT-LDFLAGS
 	$(QUIET_LINK)$(FUZZ_CXX) $(FUZZ_CXXFLAGS) -o $@ $(ALL_LDFLAGS) \
 		-Wl,--allow-multiple-definition \
-		$(filter %.o,$^) $(filter %.a,$^) $(LIBS) $(LIB_FUZZING_ENGINE)
+		$(filter %.o,$^) $(LIBS) $(LIB_FUZZING_ENGINE)
 
 $(UNIT_TEST_PROGS): $(UNIT_TEST_BIN)/%$X: $(UNIT_TEST_DIR)/%.o $(UNIT_TEST_OBJS) \
 	$(GITLIBS) GIT-LDFLAGS
 	$(call mkdir_p_parent_template)
 	$(QUIET_LINK)$(CC) $(ALL_CFLAGS) -o $@ $(ALL_LDFLAGS) \
-		$(filter %.o,$^) $(filter %.a,$^) $(LIBS)
+		$(filter %.o,$^) $(LIBS)
 
 GIT-TEST-SUITES: FORCE
 	@FLAGS='$(CLAR_TEST_SUITES)'; \

base-commit: 1666c1265231b0bc5f613fbbf3f0a9896cdef76e
-- 
gitgitgadget
Junio C HamanoJun 4, 2026, 00:33 UTC in reply to Harald Nordgren via GitGitGadget on lore

Re: [PATCH] Makefile: drop duplicate %.a from link recipes

"Harald Nordgren via GitGitGadget" <gitgitgadget@gmail.com> writes:
>  t/helper/test-%$X: t/helper/test-%.o GIT-LDFLAGS $(GITLIBS)
> -	$(QUIET_LINK)$(CC) $(ALL_CFLAGS) -o $@ $(ALL_LDFLAGS) $(filter %.o,$^) $(filter %.a,$^) $(LIBS)
> +	$(QUIET_LINK)$(CC) $(ALL_CFLAGS) -o $@ $(ALL_LDFLAGS) $(filter %.o,$^) $(LIBS)

I think the reason why the pattern to use only the .o files among the prerequisites and then use only the .a files among the same prerequisites (both filters $^) is used here is to make sure that the linker sees object files first before library archives, so that by the time its left-to-right scan sees the first library archive, all the missing symbols in the object files are known. The above change depends on LIBS being a strict superset of all the library archive files ($GITLIBS in the current code, but that can be updated in the future) listed as prerequisites for the rule, but there is nothing to guarantee that, so it looks brittle.

Exact same comment applies to the other two rules touched by this patch.
Harald NordgrenJun 4, 2026, 07:06 UTC in reply to Junio C Hamano on lore

Re: [PATCH] Makefile: drop duplicate %.a from link recipes

On Thu, Jun 4, 2026 at 2:33 AM Junio C Hamano <gitster@pobox.com> wrote:
Show 19 quoted lines
>
> "Harald Nordgren via GitGitGadget" <gitgitgadget@gmail.com> writes:
>
> >  t/helper/test-%$X: t/helper/test-%.o GIT-LDFLAGS $(GITLIBS)
> > -     $(QUIET_LINK)$(CC) $(ALL_CFLAGS) -o $@ $(ALL_LDFLAGS) $(filter %.o,$^) $(filter %.a,$^) $(LIBS)
> > +     $(QUIET_LINK)$(CC) $(ALL_CFLAGS) -o $@ $(ALL_LDFLAGS) $(filter %.o,$^) $(LIBS)
>
> I think the reason why the pattern to use only the .o files among
> the prerequisites and then use only the .a files among the same
> prerequisites (both filters $^) is used here is to make sure that the
> linker sees object files first before library archives, so that by
> the time its left-to-right scan sees the first library archive, all
> the missing symbols in the object files are known.  The above change
> depends on LIBS being a strict superset of all the library archive
> files ($GITLIBS in the current code, but that can be updated in the
> future) listed as prerequisites for the rule, but there is nothing to
> guarantee that, so it looks brittle.
>
> Exact same comment applies to the other two rules touched by this patch.

Hmm, there are other constructs like this that rely on $(LIBS) being a superset of the archives, so the three rules changed here align with the trend rather than introduce a new trend.

Not saying we shouldn't find a way to handle the overall brittleness.
Harald
Harald NordgrenJun 4, 2026, 07:15 UTC in reply to Harald Nordgren on lore

Re: [PATCH] Makefile: drop duplicate %.a from link recipes

Maybe we can do this to get around the brittleness for all ~10 places:

``` -LIBS = $(filter-out %.o, $(GITLIBS)) $(EXTLIBS) +LIBS = $(filter %.a,$^) $(filter-out $(filter %.a,$^),$(filter-out %.o,$(GITLIBS)) $(EXTLIBS))

 BASIC_CFLAGS += $(COMPAT_CFLAGS)
 LIB_OBJS += $(COMPAT_OBJS)
Show changes to diff +3 −3
@@ -3392,7 +3395,7 @@ perf: all
 t/helper/test-tool$X: $(patsubst %,t/helper/%,$(TEST_BUILTINS_OBJS))
$(UNIT_TEST_DIR)/test-lib.o

 t/helper/test-%$X: t/helper/test-%.o GIT-LDFLAGS $(GITLIBS)
- $(QUIET_LINK)$(CC) $(ALL_CFLAGS) -o $@ $(ALL_LDFLAGS) $(filter
%.o,$^) $(filter %.a,$^) $(LIBS)
+ $(QUIET_LINK)$(CC) $(ALL_CFLAGS) -o $@ $(ALL_LDFLAGS) $(filter %.o,$^) $(LIBS)

 check-sha1:: t/helper/test-tool$X
  t/helper/test-sha1.sh
@@ -4015,13 +4018,13 @@ fuzz-all: $(FUZZ_PROGRAMS)
 $(FUZZ_PROGRAMS): %: %.o oss-fuzz/dummy-cmd-main.o $(GITLIBS) GIT-LDFLAGS
  $(QUIET_LINK)$(FUZZ_CXX) $(FUZZ_CXXFLAGS) -o $@ $(ALL_LDFLAGS) \
  -Wl,--allow-multiple-definition \
- $(filter %.o,$^) $(filter %.a,$^) $(LIBS) $(LIB_FUZZING_ENGINE)
+ $(filter %.o,$^) $(LIBS) $(LIB_FUZZING_ENGINE)

 $(UNIT_TEST_PROGS): $(UNIT_TEST_BIN)/%$X: $(UNIT_TEST_DIR)/%.o
$(UNIT_TEST_OBJS) \
  $(GITLIBS) GIT-LDFLAGS
  $(call mkdir_p_parent_template)
  $(QUIET_LINK)$(CC) $(ALL_CFLAGS) -o $@ $(ALL_LDFLAGS) \
- $(filter %.o,$^) $(filter %.a,$^) $(LIBS)
+ $(filter %.o,$^) $(LIBS)

 GIT-TEST-SUITES: FORCE
  @FLAGS='$(CLAR_TEST_SUITES)'; \
```


Harald

On Thu, Jun 4, 2026 at 9:06 AM Harald Nordgren <haraldnordgren@gmail.com> wrote:
>
> On Thu, Jun 4, 2026 at 2:33 AM Junio C Hamano <gitster@pobox.com> wrote:
> >
> > "Harald Nordgren via GitGitGadget" <gitgitgadget@gmail.com> writes:
> >
> > >  t/helper/test-%$X: t/helper/test-%.o GIT-LDFLAGS $(GITLIBS)
> > > -     $(QUIET_LINK)$(CC) $(ALL_CFLAGS) -o $@ $(ALL_LDFLAGS) $(filter %.o,$^) $(filter %.a,$^) $(LIBS)
> > > +     $(QUIET_LINK)$(CC) $(ALL_CFLAGS) -o $@ $(ALL_LDFLAGS) $(filter %.o,$^) $(LIBS)
> >
> > I think the reason why the pattern to use only the .o files among
> > the prerequisites and then use only the .a files among the same
> > prerequisites (both filters $^) is used here is to make sure that the
> > linker sees object files first before library archives, so that by
> > the time its left-to-right scan sees the first library archive, all
> > the missing symbols in the object files are known.  The above change
> > depends on LIBS being a strict superset of all the library archive
> > files ($GITLIBS in the current code, but that can be updated in the
> > future) listed as prerequisites for the rule, but there is nothing to
> > guarantee that, so it looks brittle.
> >
> > Exact same comment applies to the other two rules touched by this patch.
>
> Hmm, there are other constructs like this that rely on $(LIBS) being a
> superset of the archives, so the three rules changed here align with
> the trend rather than introduce a new trend.
>
> Not saying we shouldn't find a way to handle the overall brittleness.
>
>
> Harald
Harald Nordgren via GitGitGadgetJun 4, 2026, 22:03 UTC in reply to Harald Nordgren via GitGitGadget on lore

[PATCH v2] Makefile: dedup archives in $(LIBS) so link recipes don't repeat them

From: Harald Nordgren <haraldnordgren@gmail.com>

A handful of link recipes listed archive files twice: once explicitly via $(filter %.a,$^) and again implicitly through $(LIBS), which expanded to $(filter-out %.o,$(GITLIBS)) $(EXTLIBS). On macOS the linker warned about the duplicates:

  ld: warning: ignoring duplicate libraries: 'libgit.a', 'target/release/libgitcore.a'

Redefine $(LIBS) to list archive prerequisites from $^ first, then the rest of the library list with those archives filtered out so each appears only once.

Signed-off-by: Harald Nordgren <haraldnordgren@gmail.com>
---
    Makefile: drop duplicate %.a from test-helper link rule
    
    Redefine $(LIBS) to list archive prerequisites from $^ first, then the
    rest of the library list to avoid brittleness in the future.
Published-As: https://github.com/gitgitgadget/git/releases/tag/pr-git-2314%2FHaraldNordgren%2Fmakefile-test-helper-dedup-libs-v2
Fetch-It-Via: git fetch https://github.com/gitgitgadget/git pr-git-2314/HaraldNordgren/makefile-test-helper-dedup-libs-v2
Pull-Request: https://github.com/git/git/pull/2314
Range-diff vs v1:
 1:  f6166450b0 ! 1:  0ef442ea05 Makefile: drop duplicate %.a from link recipes
     @@ Metadata
      Author: Harald Nordgren <haraldnordgren@gmail.com>
      
       ## Commit message ##
     -    Makefile: drop duplicate %.a from link recipes
     +    Makefile: dedup archives in $(LIBS) so link recipes don't repeat them
      
     -    Three link recipes list archive files twice on the link line: once
     -    via $(filter %.a,$^) and again through $(LIBS), which expands to
     -    $(filter-out %.o,$(GITLIBS)) $(EXTLIBS). On macOS the linker warns
     -    about the duplicates:
     +    A handful of link recipes listed archive files twice: once explicitly
     +    via $(filter %.a,$^) and again implicitly through $(LIBS), which
     +    expanded to $(filter-out %.o,$(GITLIBS)) $(EXTLIBS). On macOS the
     +    linker warned about the duplicates:
      
            ld: warning: ignoring duplicate libraries: 'libgit.a', 'target/release/libgitcore.a'
      
     -    Drop the redundant filter from the test-helper, fuzz-program, and
     -    unit-test recipes so they match the pattern used by other link
     -    recipes in the file.
     +    Redefine $(LIBS) to list archive prerequisites from $^ first, then
     +    the rest of the library list with those archives filtered out so each
     +    appears only once.
      
          Signed-off-by: Harald Nordgren <haraldnordgren@gmail.com>
      
       ## Makefile ##
     +@@ Makefile: endif
     + #
     + # where we use it as a dependency. Since we also pull object files
     + # from the dependency list, that would make each entry appear twice.
     +-LIBS = $(filter-out %.o, $(GITLIBS)) $(EXTLIBS)
     ++# Archives from $^ come first, then the rest with those archives
     ++# filtered out so each appears only once.
     ++LIBS = $(filter %.a,$^) $(filter-out $(filter %.a,$^),$(filter-out %.o,$(GITLIBS)) $(EXTLIBS))
     + 
     + BASIC_CFLAGS += $(COMPAT_CFLAGS)
     + LIB_OBJS += $(COMPAT_OBJS)
      @@ Makefile: perf: all
       t/helper/test-tool$X: $(patsubst %,t/helper/%,$(TEST_BUILTINS_OBJS)) $(UNIT_TEST_DIR)/test-lib.o
       
 Makefile | 10 ++++++----
 1 file changed, 6 insertions(+), 4 deletions(-)
Show changes to Makefile +6 −4
diff --git a/Makefile b/Makefile
index b31ecb0756..a828a66f28 100644
--- a/Makefile
+++ b/Makefile
@@ -2503,7 +2503,9 @@ endif
 #
 # where we use it as a dependency. Since we also pull object files
 # from the dependency list, that would make each entry appear twice.
-LIBS = $(filter-out %.o, $(GITLIBS)) $(EXTLIBS)
+# Archives from $^ come first, then the rest with those archives
+# filtered out so each appears only once.
+LIBS = $(filter %.a,$^) $(filter-out $(filter %.a,$^),$(filter-out %.o,$(GITLIBS)) $(EXTLIBS))
 
 BASIC_CFLAGS += $(COMPAT_CFLAGS)
 LIB_OBJS += $(COMPAT_OBJS)
@@ -3392,7 +3394,7 @@ perf: all
 t/helper/test-tool$X: $(patsubst %,t/helper/%,$(TEST_BUILTINS_OBJS)) $(UNIT_TEST_DIR)/test-lib.o
 
 t/helper/test-%$X: t/helper/test-%.o GIT-LDFLAGS $(GITLIBS)
-	$(QUIET_LINK)$(CC) $(ALL_CFLAGS) -o $@ $(ALL_LDFLAGS) $(filter %.o,$^) $(filter %.a,$^) $(LIBS)
+	$(QUIET_LINK)$(CC) $(ALL_CFLAGS) -o $@ $(ALL_LDFLAGS) $(filter %.o,$^) $(LIBS)
 
 check-sha1:: t/helper/test-tool$X
 	t/helper/test-sha1.sh
@@ -4015,13 +4017,13 @@ fuzz-all: $(FUZZ_PROGRAMS)
 $(FUZZ_PROGRAMS): %: %.o oss-fuzz/dummy-cmd-main.o $(GITLIBS) GIT-LDFLAGS
 	$(QUIET_LINK)$(FUZZ_CXX) $(FUZZ_CXXFLAGS) -o $@ $(ALL_LDFLAGS) \
 		-Wl,--allow-multiple-definition \
-		$(filter %.o,$^) $(filter %.a,$^) $(LIBS) $(LIB_FUZZING_ENGINE)
+		$(filter %.o,$^) $(LIBS) $(LIB_FUZZING_ENGINE)
 
 $(UNIT_TEST_PROGS): $(UNIT_TEST_BIN)/%$X: $(UNIT_TEST_DIR)/%.o $(UNIT_TEST_OBJS) \
 	$(GITLIBS) GIT-LDFLAGS
 	$(call mkdir_p_parent_template)
 	$(QUIET_LINK)$(CC) $(ALL_CFLAGS) -o $@ $(ALL_LDFLAGS) \
-		$(filter %.o,$^) $(filter %.a,$^) $(LIBS)
+		$(filter %.o,$^) $(LIBS)
 
 GIT-TEST-SUITES: FORCE
 	@FLAGS='$(CLAR_TEST_SUITES)'; \

base-commit: 9ac3f193c05c2237e2b14ebaa1149e9fc8a1abe0
-- 
gitgitgadget
Harald NordgrenJun 10, 2026, 13:24 UTC in reply to Harald Nordgren via GitGitGadget on lore

Re: [PATCH v2] Makefile: dedup archives in $(LIBS) so link recipes don't repeat them

Hi Johannes!
Maybe this could be interesting for you to look at too.
Harald

On Fri, Jun 5, 2026 at 12:03 AM Harald Nordgren via GitGitGadget <gitgitgadget@gmail.com> wrote:

Show 119 quoted lines
>
> From: Harald Nordgren <haraldnordgren@gmail.com>
>
> A handful of link recipes listed archive files twice: once explicitly
> via $(filter %.a,$^) and again implicitly through $(LIBS), which
> expanded to $(filter-out %.o,$(GITLIBS)) $(EXTLIBS). On macOS the
> linker warned about the duplicates:
>
>   ld: warning: ignoring duplicate libraries: 'libgit.a', 'target/release/libgitcore.a'
>
> Redefine $(LIBS) to list archive prerequisites from $^ first, then
> the rest of the library list with those archives filtered out so each
> appears only once.
>
> Signed-off-by: Harald Nordgren <haraldnordgren@gmail.com>
> ---
>     Makefile: drop duplicate %.a from test-helper link rule
>
>     Redefine $(LIBS) to list archive prerequisites from $^ first, then the
>     rest of the library list to avoid brittleness in the future.
>
> Published-As: https://github.com/gitgitgadget/git/releases/tag/pr-git-2314%2FHaraldNordgren%2Fmakefile-test-helper-dedup-libs-v2
> Fetch-It-Via: git fetch https://github.com/gitgitgadget/git pr-git-2314/HaraldNordgren/makefile-test-helper-dedup-libs-v2
> Pull-Request: https://github.com/git/git/pull/2314
>
> Range-diff vs v1:
>
>  1:  f6166450b0 ! 1:  0ef442ea05 Makefile: drop duplicate %.a from link recipes
>      @@ Metadata
>       Author: Harald Nordgren <haraldnordgren@gmail.com>
>
>        ## Commit message ##
>      -    Makefile: drop duplicate %.a from link recipes
>      +    Makefile: dedup archives in $(LIBS) so link recipes don't repeat them
>
>      -    Three link recipes list archive files twice on the link line: once
>      -    via $(filter %.a,$^) and again through $(LIBS), which expands to
>      -    $(filter-out %.o,$(GITLIBS)) $(EXTLIBS). On macOS the linker warns
>      -    about the duplicates:
>      +    A handful of link recipes listed archive files twice: once explicitly
>      +    via $(filter %.a,$^) and again implicitly through $(LIBS), which
>      +    expanded to $(filter-out %.o,$(GITLIBS)) $(EXTLIBS). On macOS the
>      +    linker warned about the duplicates:
>
>             ld: warning: ignoring duplicate libraries: 'libgit.a', 'target/release/libgitcore.a'
>
>      -    Drop the redundant filter from the test-helper, fuzz-program, and
>      -    unit-test recipes so they match the pattern used by other link
>      -    recipes in the file.
>      +    Redefine $(LIBS) to list archive prerequisites from $^ first, then
>      +    the rest of the library list with those archives filtered out so each
>      +    appears only once.
>
>           Signed-off-by: Harald Nordgren <haraldnordgren@gmail.com>
>
>        ## Makefile ##
>      +@@ Makefile: endif
>      + #
>      + # where we use it as a dependency. Since we also pull object files
>      + # from the dependency list, that would make each entry appear twice.
>      +-LIBS = $(filter-out %.o, $(GITLIBS)) $(EXTLIBS)
>      ++# Archives from $^ come first, then the rest with those archives
>      ++# filtered out so each appears only once.
>      ++LIBS = $(filter %.a,$^) $(filter-out $(filter %.a,$^),$(filter-out %.o,$(GITLIBS)) $(EXTLIBS))
>      +
>      + BASIC_CFLAGS += $(COMPAT_CFLAGS)
>      + LIB_OBJS += $(COMPAT_OBJS)
>       @@ Makefile: perf: all
>        t/helper/test-tool$X: $(patsubst %,t/helper/%,$(TEST_BUILTINS_OBJS)) $(UNIT_TEST_DIR)/test-lib.o
>
>
>
>  Makefile | 10 ++++++----
>  1 file changed, 6 insertions(+), 4 deletions(-)
>
> diff --git a/Makefile b/Makefile
> index b31ecb0756..a828a66f28 100644
> --- a/Makefile
> +++ b/Makefile
> @@ -2503,7 +2503,9 @@ endif
>  #
>  # where we use it as a dependency. Since we also pull object files
>  # from the dependency list, that would make each entry appear twice.
> -LIBS = $(filter-out %.o, $(GITLIBS)) $(EXTLIBS)
> +# Archives from $^ come first, then the rest with those archives
> +# filtered out so each appears only once.
> +LIBS = $(filter %.a,$^) $(filter-out $(filter %.a,$^),$(filter-out %.o,$(GITLIBS)) $(EXTLIBS))
>
>  BASIC_CFLAGS += $(COMPAT_CFLAGS)
>  LIB_OBJS += $(COMPAT_OBJS)
> @@ -3392,7 +3394,7 @@ perf: all
>  t/helper/test-tool$X: $(patsubst %,t/helper/%,$(TEST_BUILTINS_OBJS)) $(UNIT_TEST_DIR)/test-lib.o
>
>  t/helper/test-%$X: t/helper/test-%.o GIT-LDFLAGS $(GITLIBS)
> -       $(QUIET_LINK)$(CC) $(ALL_CFLAGS) -o $@ $(ALL_LDFLAGS) $(filter %.o,$^) $(filter %.a,$^) $(LIBS)
> +       $(QUIET_LINK)$(CC) $(ALL_CFLAGS) -o $@ $(ALL_LDFLAGS) $(filter %.o,$^) $(LIBS)
>
>  check-sha1:: t/helper/test-tool$X
>         t/helper/test-sha1.sh
> @@ -4015,13 +4017,13 @@ fuzz-all: $(FUZZ_PROGRAMS)
>  $(FUZZ_PROGRAMS): %: %.o oss-fuzz/dummy-cmd-main.o $(GITLIBS) GIT-LDFLAGS
>         $(QUIET_LINK)$(FUZZ_CXX) $(FUZZ_CXXFLAGS) -o $@ $(ALL_LDFLAGS) \
>                 -Wl,--allow-multiple-definition \
> -               $(filter %.o,$^) $(filter %.a,$^) $(LIBS) $(LIB_FUZZING_ENGINE)
> +               $(filter %.o,$^) $(LIBS) $(LIB_FUZZING_ENGINE)
>
>  $(UNIT_TEST_PROGS): $(UNIT_TEST_BIN)/%$X: $(UNIT_TEST_DIR)/%.o $(UNIT_TEST_OBJS) \
>         $(GITLIBS) GIT-LDFLAGS
>         $(call mkdir_p_parent_template)
>         $(QUIET_LINK)$(CC) $(ALL_CFLAGS) -o $@ $(ALL_LDFLAGS) \
> -               $(filter %.o,$^) $(filter %.a,$^) $(LIBS)
> +               $(filter %.o,$^) $(LIBS)
>
>  GIT-TEST-SUITES: FORCE
>         @FLAGS='$(CLAR_TEST_SUITES)'; \
>
> base-commit: 9ac3f193c05c2237e2b14ebaa1149e9fc8a1abe0
> --
> gitgitgadget
Harald NordgrenJun 19, 2026, 08:00 UTC in reply to Harald Nordgren via GitGitGadget on lore

Re: [PATCH v2] Makefile: dedup archives in $(LIBS) so link recipes don't repeat them

Hi!

I think this would be quite nice to fix for all the macOS developers (I don't know how many we have who are active on this list), but when running repeated tests it does take up some space on the terminal:

```` ❯ git rebase --keep-base -x 'make -s && cd t && prove -j8 t345?-history*.sh && echo'

Executing: make -s && cd t && prove -j8 t345?-history*.sh && echo
GIT_VERSION=2.55.0.rc1.20.g1e31474ef6
ld: warning: ignoring duplicate libraries: 'libgit.a',
'target/release/libgitcore.a'
ld: warning: ignoring duplicate libraries: 'libgit.a',
'target/release/libgitcore.a'
t3450-history.sh ......... ok
t3453-history-fixup.sh ... ok
t3451-history-reword.sh .. ok
t3452-history-split.sh ... ok
All tests successful.
Files=4, Tests=69,  7 wallclock secs ( 0.02 usr  0.01 sys +  4.14 cusr
 5.39 csys =  9.56 CPU)
Result: PASS
Executing: make -s && cd t && prove -j8 t345?-history*.sh && echo
GIT_VERSION=2.55.0.rc1.21.g498da64046
ld: warning: ignoring duplicate libraries: 'libgit.a',
'target/release/libgitcore.a'
ld: warning: ignoring duplicate libraries: 'libgit.a',
'target/release/libgitcore.a'
t3450-history.sh ......... ok
t3453-history-fixup.sh ... ok
t3451-history-reword.sh .. ok
t3452-history-split.sh ... ok
All tests successful.
Files=4, Tests=69,  7 wallclock secs ( 0.02 usr  0.01 sys +  4.16 cusr
 5.41 csys =  9.60 CPU)
Result: PASS
Executing: make -s && cd t && prove -j8 t345?-history*.sh && echo
GIT_VERSION=2.55.0.rc1.22.g0050368e96
ld: warning: ignoring duplicate libraries: 'libgit.a',
'target/release/libgitcore.a'
ld: warning: ignoring duplicate libraries: 'libgit.a',
'target/release/libgitcore.a'
t3450-history.sh ......... ok
t3455-history-squash.sh .. ok
t3453-history-fixup.sh ... ok
t3451-history-reword.sh .. ok
t3452-history-split.sh ... ok
All tests successful.
Files=5, Tests=86,  7 wallclock secs ( 0.03 usr  0.01 sys +  4.89 cusr
 6.36 csys = 11.29 CPU)
Result: PASS
Executing: make -s && cd t && prove -j8 t345?-history*.sh && echo
GIT_VERSION=2.55.0.rc1.23.gb86b93bda1
ld: warning: ignoring duplicate libraries: 'libgit.a',
'target/release/libgitcore.a'
ld: warning: ignoring duplicate libraries: 'libgit.a',
'target/release/libgitcore.a'
t3450-history.sh ......... ok
t3455-history-squash.sh .. ok
t3453-history-fixup.sh ... ok
t3451-history-reword.sh .. ok
t3452-history-split.sh ... ok
All tests successful.
Files=5, Tests=88,  7 wallclock secs ( 0.03 usr  0.01 sys +  5.01 cusr
 6.54 csys = 11.59 CPU)
Result: PASS

Successfully rebased and updated refs/heads/rebase-fixup-fold. ```

Harald

On Fri, Jun 5, 2026 at 12:03 AM Harald Nordgren via GitGitGadget <gitgitgadget@gmail.com> wrote:

Show 119 quoted lines
>
> From: Harald Nordgren <haraldnordgren@gmail.com>
>
> A handful of link recipes listed archive files twice: once explicitly
> via $(filter %.a,$^) and again implicitly through $(LIBS), which
> expanded to $(filter-out %.o,$(GITLIBS)) $(EXTLIBS). On macOS the
> linker warned about the duplicates:
>
>   ld: warning: ignoring duplicate libraries: 'libgit.a', 'target/release/libgitcore.a'
>
> Redefine $(LIBS) to list archive prerequisites from $^ first, then
> the rest of the library list with those archives filtered out so each
> appears only once.
>
> Signed-off-by: Harald Nordgren <haraldnordgren@gmail.com>
> ---
>     Makefile: drop duplicate %.a from test-helper link rule
>
>     Redefine $(LIBS) to list archive prerequisites from $^ first, then the
>     rest of the library list to avoid brittleness in the future.
>
> Published-As: https://github.com/gitgitgadget/git/releases/tag/pr-git-2314%2FHaraldNordgren%2Fmakefile-test-helper-dedup-libs-v2
> Fetch-It-Via: git fetch https://github.com/gitgitgadget/git pr-git-2314/HaraldNordgren/makefile-test-helper-dedup-libs-v2
> Pull-Request: https://github.com/git/git/pull/2314
>
> Range-diff vs v1:
>
>  1:  f6166450b0 ! 1:  0ef442ea05 Makefile: drop duplicate %.a from link recipes
>      @@ Metadata
>       Author: Harald Nordgren <haraldnordgren@gmail.com>
>
>        ## Commit message ##
>      -    Makefile: drop duplicate %.a from link recipes
>      +    Makefile: dedup archives in $(LIBS) so link recipes don't repeat them
>
>      -    Three link recipes list archive files twice on the link line: once
>      -    via $(filter %.a,$^) and again through $(LIBS), which expands to
>      -    $(filter-out %.o,$(GITLIBS)) $(EXTLIBS). On macOS the linker warns
>      -    about the duplicates:
>      +    A handful of link recipes listed archive files twice: once explicitly
>      +    via $(filter %.a,$^) and again implicitly through $(LIBS), which
>      +    expanded to $(filter-out %.o,$(GITLIBS)) $(EXTLIBS). On macOS the
>      +    linker warned about the duplicates:
>
>             ld: warning: ignoring duplicate libraries: 'libgit.a', 'target/release/libgitcore.a'
>
>      -    Drop the redundant filter from the test-helper, fuzz-program, and
>      -    unit-test recipes so they match the pattern used by other link
>      -    recipes in the file.
>      +    Redefine $(LIBS) to list archive prerequisites from $^ first, then
>      +    the rest of the library list with those archives filtered out so each
>      +    appears only once.
>
>           Signed-off-by: Harald Nordgren <haraldnordgren@gmail.com>
>
>        ## Makefile ##
>      +@@ Makefile: endif
>      + #
>      + # where we use it as a dependency. Since we also pull object files
>      + # from the dependency list, that would make each entry appear twice.
>      +-LIBS = $(filter-out %.o, $(GITLIBS)) $(EXTLIBS)
>      ++# Archives from $^ come first, then the rest with those archives
>      ++# filtered out so each appears only once.
>      ++LIBS = $(filter %.a,$^) $(filter-out $(filter %.a,$^),$(filter-out %.o,$(GITLIBS)) $(EXTLIBS))
>      +
>      + BASIC_CFLAGS += $(COMPAT_CFLAGS)
>      + LIB_OBJS += $(COMPAT_OBJS)
>       @@ Makefile: perf: all
>        t/helper/test-tool$X: $(patsubst %,t/helper/%,$(TEST_BUILTINS_OBJS)) $(UNIT_TEST_DIR)/test-lib.o
>
>
>
>  Makefile | 10 ++++++----
>  1 file changed, 6 insertions(+), 4 deletions(-)
>
> diff --git a/Makefile b/Makefile
> index b31ecb0756..a828a66f28 100644
> --- a/Makefile
> +++ b/Makefile
> @@ -2503,7 +2503,9 @@ endif
>  #
>  # where we use it as a dependency. Since we also pull object files
>  # from the dependency list, that would make each entry appear twice.
> -LIBS = $(filter-out %.o, $(GITLIBS)) $(EXTLIBS)
> +# Archives from $^ come first, then the rest with those archives
> +# filtered out so each appears only once.
> +LIBS = $(filter %.a,$^) $(filter-out $(filter %.a,$^),$(filter-out %.o,$(GITLIBS)) $(EXTLIBS))
>
>  BASIC_CFLAGS += $(COMPAT_CFLAGS)
>  LIB_OBJS += $(COMPAT_OBJS)
> @@ -3392,7 +3394,7 @@ perf: all
>  t/helper/test-tool$X: $(patsubst %,t/helper/%,$(TEST_BUILTINS_OBJS)) $(UNIT_TEST_DIR)/test-lib.o
>
>  t/helper/test-%$X: t/helper/test-%.o GIT-LDFLAGS $(GITLIBS)
> -       $(QUIET_LINK)$(CC) $(ALL_CFLAGS) -o $@ $(ALL_LDFLAGS) $(filter %.o,$^) $(filter %.a,$^) $(LIBS)
> +       $(QUIET_LINK)$(CC) $(ALL_CFLAGS) -o $@ $(ALL_LDFLAGS) $(filter %.o,$^) $(LIBS)
>
>  check-sha1:: t/helper/test-tool$X
>         t/helper/test-sha1.sh
> @@ -4015,13 +4017,13 @@ fuzz-all: $(FUZZ_PROGRAMS)
>  $(FUZZ_PROGRAMS): %: %.o oss-fuzz/dummy-cmd-main.o $(GITLIBS) GIT-LDFLAGS
>         $(QUIET_LINK)$(FUZZ_CXX) $(FUZZ_CXXFLAGS) -o $@ $(ALL_LDFLAGS) \
>                 -Wl,--allow-multiple-definition \
> -               $(filter %.o,$^) $(filter %.a,$^) $(LIBS) $(LIB_FUZZING_ENGINE)
> +               $(filter %.o,$^) $(LIBS) $(LIB_FUZZING_ENGINE)
>
>  $(UNIT_TEST_PROGS): $(UNIT_TEST_BIN)/%$X: $(UNIT_TEST_DIR)/%.o $(UNIT_TEST_OBJS) \
>         $(GITLIBS) GIT-LDFLAGS
>         $(call mkdir_p_parent_template)
>         $(QUIET_LINK)$(CC) $(ALL_CFLAGS) -o $@ $(ALL_LDFLAGS) \
> -               $(filter %.o,$^) $(filter %.a,$^) $(LIBS)
> +               $(filter %.o,$^) $(LIBS)
>
>  GIT-TEST-SUITES: FORCE
>         @FLAGS='$(CLAR_TEST_SUITES)'; \
>
> base-commit: 9ac3f193c05c2237e2b14ebaa1149e9fc8a1abe0
> --
> gitgitgadget
Junio C HamanoJun 19, 2026, 15:41 UTC in reply to Harald Nordgren on lore

Re: [PATCH v2] Makefile: dedup archives in $(LIBS) so link recipes don't repeat them

Harald Nordgren <haraldnordgren@gmail.com> writes:
Show 14 quoted lines
> I think this would be quite nice to fix for all the macOS developers
> (I don't know how many we have who are active on this list), but when
> running repeated tests it does take up some space on the terminal:
>
> ````
> ❯ git rebase --keep-base -x 'make -s && cd t && prove -j8
> t345?-history*.sh && echo'
>
> Executing: make -s && cd t && prove -j8 t345?-history*.sh && echo
> GIT_VERSION=2.55.0.rc1.20.g1e31474ef6
> ld: warning: ignoring duplicate libraries: 'libgit.a',
> 'target/release/libgitcore.a'
> ld: warning: ignoring duplicate libraries: 'libgit.a',
> 'target/release/libgitcore.a'

While I am very sympathetic that it may be annoying, I have to wonder if that is ultimately the linker's job to accept the same library listed twice on the same command line, deside when it can ignore the second one, and *silently* ignore it.

Imagine this situation.
 - There are two library archives, libA.a has a.o in it and libB.a
   has b.o in it, respectively.
 - The object file a.o defines a symbol that b.o needs, and b.o
   defines a symbol a.o needs (i.e., mutually dependent). libA.a and
   libB.a have other symbols in them. There are valid reasons why we
   do not want to combine them into a single libAB.a.
 - Now our program X uses both libraries and we build and try to link it this way:
   $(CC) -c x.c				# this builds x.o
   $(CC) -o programX x.o libA.a libB.a  # unfortunately does not work as-is
   which fails because x.o uses symbol from libA.a that is not in
   a.o (so a.o is not linked), and then x.o also uses something in
   b.o that is picked up from libB.a.  But b.o in turn needs a.o
   that we already skipped.  One way to make it work is to tweak the
   final link phase to read like this:
   $(CC) -o programX x.o libA.a libB.a libA.a

If your linker complains because we list libA.a twice, it would be annoying.

I guess if we can assume GNU ld (e.g., gcc/clang), we can use
   $(CC) -o programX x.o -Wl,--start-group libA.a libB.a -Wl,end-group

to tell the linker that they need to be processed for circular dependencies, but listing them twice is more portable and harmless (i.e., if all the symbols are resolved by the time the linker sees the second libA.a, then it would not pick up anything extra from there) way to achieve the same thing.

So from future-proofing and portability perspective (which is another way to say maintainability we care about), I would very much prefer to see this solved at the linker level, allowing the build procedure to list the same library twice on the command line.

It seems that on the Internet various folks, including masonbuild and CMake, have heard complaints from users enough and fixed the linker by using -no_warn_duplicate_libraries option. Their approach translates to something like the following in our build environment.

 config.mak.uname | 4 ++++
 1 file changed, 4 insertions(+)
Show changes to diff +4 −0
diff --git i/config.mak.uname w/config.mak.uname
index 8719e09f66..e29eaaf3fd 100644
--- i/config.mak.uname
+++ w/config.mak.uname
@@ -149,6 +149,10 @@ ifeq ($(uname_S),Darwin)
         ifeq ($(shell test "`expr "$(uname_R)" : '\([0-9][0-9]*\)\.'`" -ge 20 && echo 1),1)
 		OPEN_RETURNS_EINTR = UnfortunatelyYes
         endif
+
+	# NEEDSWORK: do this only for XCode 15 or later
+	BASIC_LDFLAGS += -Wl,-no_warn_duplicate_libraries
+
 	NO_MEMMEM = YesPlease
 	USE_ST_TIMESPEC = YesPlease
 	HAVE_DEV_TTY = YesPlease
Harald NordgrenJun 19, 2026, 20:25 UTC in reply to Junio C Hamano on lore

Re: [PATCH v2] Makefile: dedup archives in $(LIBS) so link recipes don't repeat them

Thanks for a good lesson about linkers!

Good idea to fix it through the same LD_MAJOR_VERSION as we did for the __DATA,__common alignment, makes it a lot cleaner.

Harald
Harald Nordgren via GitGitGadgetJun 19, 2026, 20:32 UTC in reply to Harald Nordgren via GitGitGadget on lore

[PATCH v3] config.mak.uname: avoid macOS dup-library warning

From: Harald Nordgren <haraldnordgren@gmail.com>
Building on macOS with Xcode 15 or newer emits:
    ld: warning: ignoring duplicate libraries: 'libgit.a',
    'target/release/libgitcore.a'

Some link recipes list the same archive twice, which is harmless. Quiet the warning instead.

Pass -Wl,-no_warn_duplicate_libraries on Xcode 15 and newer, whose linkers added both the warning and the suppression flag (ld64-907 and dyld-1009). Earlier linkers reject the flag, so gate on the linker version. Broaden the existing -fno-common version probe to also match the "ld64-NNN" and "dyld-NNN" forms Xcode 15 reports.

Signed-off-by: Harald Nordgren <haraldnordgren@gmail.com>
---
    Makefile: drop duplicate %.a from test-helper link rule
    
    Fix warning of duplicate libraries on macOS.
    
    Changes in v3:
    
     * Suppress the warning at the linker rather than dedup the archive list
     * Pass -Wl,-no_warn_duplicate_libraries in config.mak.uname, gated on
       the linker version (reuses the probe added for -fno-common), and
       broaden the regex to match all three PROJECT:{ld64,dyld,ld}-NNN forms
     * Floor of 907 and the version forms (ld64-907, dyld-1009.5) per meson:
       https://github.com/mesonbuild/meson/blob/master/mesonbuild/linkers/linkers.py
Published-As: https://github.com/gitgitgadget/git/releases/tag/pr-git-2314%2FHaraldNordgren%2Fmakefile-test-helper-dedup-libs-v3
Fetch-It-Via: git fetch https://github.com/gitgitgadget/git pr-git-2314/HaraldNordgren/makefile-test-helper-dedup-libs-v3
Pull-Request: https://github.com/git/git/pull/2314
Range-diff vs v2:
 1:  0ef442ea05 < -:  ---------- Makefile: dedup archives in $(LIBS) so link recipes don't repeat them
 -:  ---------- > 1:  5bf560c5ad config.mak.uname: avoid macOS dup-library warning
 config.mak.uname | 11 +++++++++--
 1 file changed, 9 insertions(+), 2 deletions(-)
Show changes to config.mak.uname +9 −2
diff --git a/config.mak.uname b/config.mak.uname
index 8719e09f66..9ebd240378 100644
--- a/config.mak.uname
+++ b/config.mak.uname
@@ -173,8 +173,15 @@ ifeq ($(uname_S),Darwin)
 		NEEDS_GOOD_LIBICONV = UnfortunatelyYes
         endif
 
-	# Silence Xcode 16.3+ linker warning about __DATA,__common alignment.
-	LD_MAJOR_VERSION = $(shell ld -v 2>&1 | sed -n 's/.*PROJECT:ld-\([0-9]*\).*/\1/p')
+	# ld reports "PROJECT:{ld,ld64,dyld}-NNN", match any of the three.
+	LD_MAJOR_VERSION = $(shell ld -v 2>&1 | sed -n 's/.*PROJECT:[^ ]*-\([0-9][0-9]*\).*/\1/p')
+
+	# Silence the Xcode 15+ warning about archives listed more than once.
+        ifeq ($(shell test -n "$(LD_MAJOR_VERSION)" && test "$(LD_MAJOR_VERSION)" -ge 907 && echo 1),1)
+		BASIC_LDFLAGS += -Wl,-no_warn_duplicate_libraries
+        endif
+
+	# Silence the Xcode 16.3+ warning about __DATA,__common alignment.
         ifeq ($(shell test -n "$(LD_MAJOR_VERSION)" && test "$(LD_MAJOR_VERSION)" -ge 1167 && echo 1),1)
 		BASIC_CFLAGS += -fno-common
         endif

base-commit: 95e20213faefeb95df29277c58ac1980ab68f701
-- 
gitgitgadget
Junio C HamanoJun 19, 2026, 22:27 UTC in reply to Harald Nordgren via GitGitGadget on lore

Re: [PATCH v3] config.mak.uname: avoid macOS dup-library warning

"Harald Nordgren via GitGitGadget" <gitgitgadget@gmail.com> writes:
Show 18 quoted lines
> From: Harald Nordgren <haraldnordgren@gmail.com>
>
> Building on macOS with Xcode 15 or newer emits:
>
>     ld: warning: ignoring duplicate libraries: 'libgit.a',
>     'target/release/libgitcore.a'
>
> Some link recipes list the same archive twice, which is harmless.
> Quiet the warning instead.
>
> Pass -Wl,-no_warn_duplicate_libraries on Xcode 15 and newer, whose
> linkers added both the warning and the suppression flag (ld64-907
> and dyld-1009). Earlier linkers reject the flag, so gate on the
> linker version. Broaden the existing -fno-common version probe to
> also match the "ld64-NNN" and "dyld-NNN" forms Xcode 15 reports.
>
> Signed-off-by: Harald Nordgren <haraldnordgren@gmail.com>
> ---
Yeah, this looks like what I expected.
A few things to note.
 * Can folks with different versions of Xcode (or is 15 sufficiently
   old that practically nobody is expected to have anything older?)
   test this patch?
 * We only patch Makefile here; can folks who use meson report how
   well your build goes?
Thanks.
Show 27 quoted lines
>  config.mak.uname | 11 +++++++++--
>  1 file changed, 9 insertions(+), 2 deletions(-)
>
> diff --git a/config.mak.uname b/config.mak.uname
> index 8719e09f66..9ebd240378 100644
> --- a/config.mak.uname
> +++ b/config.mak.uname
> @@ -173,8 +173,15 @@ ifeq ($(uname_S),Darwin)
>  		NEEDS_GOOD_LIBICONV = UnfortunatelyYes
>          endif
>  
> -	# Silence Xcode 16.3+ linker warning about __DATA,__common alignment.
> -	LD_MAJOR_VERSION = $(shell ld -v 2>&1 | sed -n 's/.*PROJECT:ld-\([0-9]*\).*/\1/p')
> +	# ld reports "PROJECT:{ld,ld64,dyld}-NNN", match any of the three.
> +	LD_MAJOR_VERSION = $(shell ld -v 2>&1 | sed -n 's/.*PROJECT:[^ ]*-\([0-9][0-9]*\).*/\1/p')
> +
> +	# Silence the Xcode 15+ warning about archives listed more than once.
> +        ifeq ($(shell test -n "$(LD_MAJOR_VERSION)" && test "$(LD_MAJOR_VERSION)" -ge 907 && echo 1),1)
> +		BASIC_LDFLAGS += -Wl,-no_warn_duplicate_libraries
> +        endif
> +
> +	# Silence the Xcode 16.3+ warning about __DATA,__common alignment.
>          ifeq ($(shell test -n "$(LD_MAJOR_VERSION)" && test "$(LD_MAJOR_VERSION)" -ge 1167 && echo 1),1)
>  		BASIC_CFLAGS += -fno-common
>          endif
>
> base-commit: 95e20213faefeb95df29277c58ac1980ab68f701
D. Ben KnobleJun 20, 2026, 20:58 UTC in reply to Junio C Hamano on lore

Re: [PATCH v3] config.mak.uname: avoid macOS dup-library warning

On Fri, Jun 19, 2026 at 6:27 PM Junio C Hamano <gitster@pobox.com> wrote:
Show 34 quoted lines
>
> "Harald Nordgren via GitGitGadget" <gitgitgadget@gmail.com> writes:
>
> > From: Harald Nordgren <haraldnordgren@gmail.com>
> >
> > Building on macOS with Xcode 15 or newer emits:
> >
> >     ld: warning: ignoring duplicate libraries: 'libgit.a',
> >     'target/release/libgitcore.a'
> >
> > Some link recipes list the same archive twice, which is harmless.
> > Quiet the warning instead.
> >
> > Pass -Wl,-no_warn_duplicate_libraries on Xcode 15 and newer, whose
> > linkers added both the warning and the suppression flag (ld64-907
> > and dyld-1009). Earlier linkers reject the flag, so gate on the
> > linker version. Broaden the existing -fno-common version probe to
> > also match the "ld64-NNN" and "dyld-NNN" forms Xcode 15 reports.
> >
> > Signed-off-by: Harald Nordgren <haraldnordgren@gmail.com>
> > ---
>
> Yeah, this looks like what I expected.
>
> A few things to note.
>
>  * Can folks with different versions of Xcode (or is 15 sufficiently
>    old that practically nobody is expected to have anything older?)
>    test this patch?
>
>  * We only patch Makefile here; can folks who use meson report how
>    well your build goes?
>
> Thanks.
On one (old) machine I have available:
    $ pkgutil --pkg-info=com.apple.pkg.CLTools_Executables
    [trimmed]
    version: 14.2.0.0.1.1668646533

On said machine, I don't get the duplicate warnings on a Meson build. No issues with the patch when running make.

I think I have seen this on my other machine, which is much newer. When I get around to trying it there, I'll report back as well.

Patrick SteinhardtJun 22, 2026, 08:04 UTC in reply to Junio C Hamano on lore

Re: [PATCH v3] config.mak.uname: avoid macOS dup-library warning

On Fri, Jun 19, 2026 at 03:27:08PM -0700, Junio C Hamano wrote:
Show 30 quoted lines
> "Harald Nordgren via GitGitGadget" <gitgitgadget@gmail.com> writes:
> > From: Harald Nordgren <haraldnordgren@gmail.com>
> >
> > Building on macOS with Xcode 15 or newer emits:
> >
> >     ld: warning: ignoring duplicate libraries: 'libgit.a',
> >     'target/release/libgitcore.a'
> >
> > Some link recipes list the same archive twice, which is harmless.
> > Quiet the warning instead.
> >
> > Pass -Wl,-no_warn_duplicate_libraries on Xcode 15 and newer, whose
> > linkers added both the warning and the suppression flag (ld64-907
> > and dyld-1009). Earlier linkers reject the flag, so gate on the
> > linker version. Broaden the existing -fno-common version probe to
> > also match the "ld64-NNN" and "dyld-NNN" forms Xcode 15 reports.
> >
> > Signed-off-by: Harald Nordgren <haraldnordgren@gmail.com>
> > ---
> 
> Yeah, this looks like what I expected.
> 
> A few things to note.
> 
>  * Can folks with different versions of Xcode (or is 15 sufficiently
>    old that practically nobody is expected to have anything older?)
>    test this patch?
> 
>  * We only patch Makefile here; can folks who use meson report how
>    well your build goes?

When using Meson we also see a warning. This got partially fixed in Meson itself though via [1], where it started to disable the warning when compiling with "--fatal-warnings" so that it doesn't cause builds to break. So starting with that commit it really only is a harmless (albeit annoying) warning.

Arguably, it might make sense to unconditionally disable this warning, as it doesn't seem to add anything of value. I've Cc'd Paolo, one of the Meson maintainers.

Thanks!
Patrick
[1]: https://github.com/mesonbuild/meson/commit/17d1cc60ed8246b8e7f0786421bf1cdf5cb19254
Junio C HamanoJun 22, 2026, 12:57 UTC in reply to Patrick Steinhardt on lore

Re: [PATCH v3] config.mak.uname: avoid macOS dup-library warning

Patrick Steinhardt <ps@pks.im> writes:
Show 26 quoted lines
>> Yeah, this looks like what I expected.
>> 
>> A few things to note.
>> 
>>  * Can folks with different versions of Xcode (or is 15 sufficiently
>>    old that practically nobody is expected to have anything older?)
>>    test this patch?
>> 
>>  * We only patch Makefile here; can folks who use meson report how
>>    well your build goes?
>
> When using Meson we also see a warning. This got partially fixed in
> Meson itself though via [1], where it started to disable the warning
> when compiling with "--fatal-warnings" so that it doesn't cause builds
> to break. So starting with that commit it really only is a harmless
> (albeit annoying) warning.
>
> Arguably, it might make sense to unconditionally disable this warning,
> as it doesn't seem to add anything of value. I've Cc'd Paolo, one of the
> Meson maintainers.
>
> Thanks!
>
> Patrick
>
> [1]: https://github.com/mesonbuild/meson/commit/17d1cc60ed8246b8e7f0786421bf1cdf5cb19254

I took my inspiration for -Wl,-no-whatever from Paolo's other attempt, referenced in

    https://github.com/mesonbuild/meson/issues/15553
which is
    https://github.com/mesonbuild/meson/commit/7c901d7a8af214e31788eb6d1a1edd5b75124e66
Paolo BonziniJun 22, 2026, 13:13 UTC in reply to Junio C Hamano on lore

Re: [PATCH v3] config.mak.uname: avoid macOS dup-library warning

On 6/22/26 14:57, Junio C Hamano wrote:
Show 11 quoted lines
>> [1]:https://github.com/mesonbuild/meson/ 
>> commit/17d1cc60ed8246b8e7f0786421bf1cdf5cb19254
> I took my inspiration for -Wl,-no-whatever from Paolo's other
> attempt, referenced in
> 
>      https://github.com/mesonbuild/meson/issues/15553
> 
> which is
> 
>      https://github.com/mesonbuild/meson/ 
> commit/7c901d7a8af214e31788eb6d1a1edd5b75124e66

Yeah, it makes sense for Meson to disable it unconditionally. I wouldn't bother adding a check in meson.build though, since as Patrick mentioned it's mostly a nuisance.

Paolo
Patrick SteinhardtJun 22, 2026, 13:36 UTC in reply to Paolo Bonzini on lore

Re: [PATCH v3] config.mak.uname: avoid macOS dup-library warning

On Mon, Jun 22, 2026 at 03:13:05PM +0200, Paolo Bonzini wrote:
Show 16 quoted lines
> On 6/22/26 14:57, Junio C Hamano wrote:
> > > [1]:https://github.com/mesonbuild/meson/
> > > commit/17d1cc60ed8246b8e7f0786421bf1cdf5cb19254
> > I took my inspiration for -Wl,-no-whatever from Paolo's other
> > attempt, referenced in
> > 
> >      https://github.com/mesonbuild/meson/issues/15553
> > 
> > which is
> > 
> >      https://github.com/mesonbuild/meson/
> > commit/7c901d7a8af214e31788eb6d1a1edd5b75124e66
> 
> Yeah, it makes sense for Meson to disable it unconditionally.  I wouldn't
> bother adding a check in meson.build though, since as Patrick mentioned it's
> mostly a nuisance.

Is this something you want to implement in Meson yourself? Otherwise I'm happy to create a pull request.

Patrick
Paolo BonziniJun 22, 2026, 14:00 UTC in reply to Patrick Steinhardt on lore

Re: [PATCH v3] config.mak.uname: avoid macOS dup-library warning

On Mon, Jun 22, 2026 at 3:36 PM Patrick Steinhardt <ps@pks.im> wrote:
Show 20 quoted lines
> On Mon, Jun 22, 2026 at 03:13:05PM +0200, Paolo Bonzini wrote:
> > On 6/22/26 14:57, Junio C Hamano wrote:
> > > > [1]:https://github.com/mesonbuild/meson/
> > > > commit/17d1cc60ed8246b8e7f0786421bf1cdf5cb19254
> > > I took my inspiration for -Wl,-no-whatever from Paolo's other
> > > attempt, referenced in
> > >
> > >      https://github.com/mesonbuild/meson/issues/15553
> > >
> > > which is
> > >
> > >      https://github.com/mesonbuild/meson/
> > > commit/7c901d7a8af214e31788eb6d1a1edd5b75124e66
> >
> > Yeah, it makes sense for Meson to disable it unconditionally.  I wouldn't
> > bother adding a check in meson.build though, since as Patrick mentioned it's
> > mostly a nuisance.
>
> Is this something you want to implement in Meson yourself? Otherwise I'm
> happy to create a pull request.
Sure, please go ahead!
Paolo
D. Ben KnobleJun 22, 2026, 15:49 UTC in reply to D. Ben Knoble on lore

Re: [PATCH v3] config.mak.uname: avoid macOS dup-library warning

On Sat, Jun 20, 2026 at 4:58 PM D. Ben Knoble <ben.knoble@gmail.com> wrote:
Show 45 quoted lines
>
> On Fri, Jun 19, 2026 at 6:27 PM Junio C Hamano <gitster@pobox.com> wrote:
> >
> > "Harald Nordgren via GitGitGadget" <gitgitgadget@gmail.com> writes:
> >
> > > From: Harald Nordgren <haraldnordgren@gmail.com>
> > >
> > > Building on macOS with Xcode 15 or newer emits:
> > >
> > >     ld: warning: ignoring duplicate libraries: 'libgit.a',
> > >     'target/release/libgitcore.a'
> > >
> > > Some link recipes list the same archive twice, which is harmless.
> > > Quiet the warning instead.
> > >
> > > Pass -Wl,-no_warn_duplicate_libraries on Xcode 15 and newer, whose
> > > linkers added both the warning and the suppression flag (ld64-907
> > > and dyld-1009). Earlier linkers reject the flag, so gate on the
> > > linker version. Broaden the existing -fno-common version probe to
> > > also match the "ld64-NNN" and "dyld-NNN" forms Xcode 15 reports.
> > >
> > > Signed-off-by: Harald Nordgren <haraldnordgren@gmail.com>
> > > ---
> >
> > Yeah, this looks like what I expected.
> >
> > A few things to note.
> >
> >  * Can folks with different versions of Xcode (or is 15 sufficiently
> >    old that practically nobody is expected to have anything older?)
> >    test this patch?
> >
> >  * We only patch Makefile here; can folks who use meson report how
> >    well your build goes?
> >
> > Thanks.
>
> On one (old) machine I have available:
>
>     $ pkgutil --pkg-info=com.apple.pkg.CLTools_Executables
>     [trimmed]
>     version: 14.2.0.0.1.1668646533
>
> On said machine, I don't get the duplicate warnings on a Meson build.
> No issues with the patch when running make.
That old machine has "ld -v":
    @(#)PROGRAM:ld  PROJECT:ld64-711
    BUILD 21:57:11 Nov 17 2021
    [trimmed]
    LTO support using: LLVM version 13.0.0, (clang-1300.0.29.30)
(static support for 27, runtime is 27)
    TAPI support using: Apple TAPI version 13.0.0 (tapi-1300.0.6.5)
> I think I have seen this on my other machine, which is much newer.
> When I get around to trying it there, I'll report back as well.
Here's those results:
    $ pkgutil --pkg-info=com.apple.pkg.CLTools_Executables
    [trimmed]
    version: 26.1.0.0.1.1761104275
sans patch:
- Meson: duplicate warning
- Make: duplicate warning
w/ patch:
- Meson: (unchanged, obviously)
- Make: no duplicate warning

Under Meson + Ninja the warning I get is (status line may not be helpful given parallelism)

    [705/708] Linking target t/helper/test-tool
    ld: warning: ignoring duplicate libraries: '-lexpat', '-liconv',
'-lresolv', '-lz'
That's in addition to a dozen or so
    ld: warning: reducing alignment of section __DATA,__common from
0x8000 to 0x4000 because it exceeds segment maximum alignment
Under Make I get (surrounding info may not be helpful given parallelism)
        LINK git
    ld: warning: ignoring duplicate libraries: 'libgit.a',
'target/release/libgitcore.a'
        MKDIR -p t/unit-tests/bin
        LINK git-sh-i18n--envsubst
        LINK t/helper/test-tool
        LINK git-remote-http
    ld: warning: ignoring duplicate libraries: 'libgit.a',
'target/release/libgitcore.a'
(No alignment warnings this time.)
Linker version (ld -v) on this machine:
    @(#)PROGRAM:ld PROJECT:ld-1230.1
    BUILD 16:18:08 Oct 17 2025
    [trimmed]
    LTO support using: LLVM version 17.0.0 (static support for 29,
runtime is 29)
    TAPI support using: Apple TAPI version 17.0.0 (tapi-1700.3.8)
-- 
D. Ben Knoble

Back to recent threads