git/list[1] front-page[2] threads[3] people[4] search[5] about
 

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

From
Harald Nordgren <haraldnordgren@gmail.com>
Date
Jun 4, 2026, 07:15 UTC
Message-ID
<CAHwyqnXScbCONOGcP1RY3Ho7t7Y3smOfOMOOVf7eNsrQRnSLJw@mail.gmail.com>
In-Reply-To
<CAHwyqnV6uh_yyO9FcUiXKfKPt15ojR3GOmRC06pW55f=KRu=Zw@mail.gmail.com>
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)
@@ -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
Previous: Harald NordgrenNext: Harald Nordgren via GitGitGadget
Message 4 of 18 in “Makefile: drop duplicate %.a from link recipes”
  1. Makefile: drop duplicate %.a from link recipesHarald Nordgren via GitGitGadget, May 31, 2026
  2. Junio C HamanoJun 4, 2026
  3. Harald NordgrenJun 4, 2026
  4. Harald NordgrenJun 4, 2026
  5. Makefile: dedup archives in $(LIBS) so link recipes don't repeat themHarald Nordgren via GitGitGadget, Jun 4, 2026
  6. Harald NordgrenJun 10, 2026
  7. Harald NordgrenJun 19, 2026
  8. Junio C HamanoJun 19, 2026
  9. Harald NordgrenJun 19, 2026
  10. config.mak.uname: avoid macOS dup-library warningHarald Nordgren via GitGitGadget, Jun 19, 2026
  11. Junio C HamanoJun 19, 2026
  12. D. Ben KnobleJun 20, 2026
  13. D. Ben KnobleJun 22, 2026
  14. Patrick SteinhardtJun 22, 2026
  15. Junio C HamanoJun 22, 2026
  16. Paolo BonziniJun 22, 2026
  17. Patrick SteinhardtJun 22, 2026
  18. Paolo BonziniJun 22, 2026

Read the whole thread, see it on lore, or plain text.

$ cat FOOTERMessages come from the public archive at lore.kernel.org/git, fetched every hour. The front page is chosen and written each morning by an AI editor and can be wrong; the threads themselves are the record. About and API. For agents: an MCP server at https://gitlist.dev/mcp, and any thread, story or person page as Markdown by adding .md to its URL (or sending Accept: text/markdown). Details in /llms.txt.