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

Re: [PATCH] Makefile: remove archives before manipulating them with 'ar'

From
Ævar Arnfjörð Bjarmason <avarab@gmail.com>
Date
Sep 1, 2021, 17:06 UTC
Message-ID
<87o89cusqj.fsf@evledraar.gmail.com>
In-Reply-To
<xmqqk0khxaup.fsf@gitster.g>
On Thu, Aug 19 2021, Junio C Hamano wrote:
Show 47 quoted lines
> SZEDER Gábor <szeder.dev@gmail.com> writes:
>
>> The rules creating the $(LIB_FILE) and $(XDIFF_LIB) archives used to
>> be:
>>
>>   $(QUIET_AR)$(RM) $@ && $(AR) $(ARFLAGS) $@ $^
>>
>> until commit 7b76d6bf22 (Makefile: add and use the ".DELETE_ON_ERROR"
>> flag, 2021-06-29) removed the '$(RM) $@' part, claiming that "we can
>> rely on the "c" (create) being present in ARFLAGS", and (I presume)
>> assuming that it means that the named archive is created from scratch.
>>
>> Unfortunately, that's not what the 'c' flag does, it merely "Suppress
>> the diagnostic message that is written to standard error by default
>> when the archive is created" [1].  Consequently, all object files that
>> are already present in an existing archive and are not replaced will
>> remain there.  This leads to linker errors in back-to-back builds of
>> different revisions without a 'make clean' between them if source
>> files going into these archives are renamed in between:
>>
>>   # The last commit renaming files that go into 'libgit.a':
>>   # bc62692757 (hash-lookup: rename from sha1-lookup, 2020-12-31)
>>   #  sha1-lookup.c => hash-lookup.c | 14 +++++++-------
>>   #  sha1-lookup.h => hash-lookup.h | 12 ++++++------
>>   $ git checkout bc62692757^
>>   HEAD is now at 7a7d992d0d sha1-lookup: rename `sha1_pos()` as `hash_pos()`
>>   $ make
>>   [...]
>>   $ git checkout 7b76d6bf22
>>   HEAD is now at 7b76d6bf22 Makefile: add and use the ".DELETE_ON_ERROR" flag
>>   $ make
>>   [...]
>>       AR libgit.a
>>       LINK git
>>   /usr/bin/ld: libgit.a(hash-lookup.o): in function `bsearch_hash':
>>   /home/szeder/src/git/hash-lookup.c:105: multiple definition of `bsearch_hash'; libgit.a(sha1-lookup.o):/home/szeder/src/git/sha1-lookup.c:105: first defined here
>>   collect2: error: ld returned 1 exit status
>>   make: *** [Makefile:2213: git] Error 1
>>
>> Restore the original make rules to first remove $(LIB_FILE) and
>> $(XDIFF_LIB) and then create them from scratch to avoid these build
>> errors.
>
> Thanks.  I think I've seen a similar breakage around hook.o but
> didn't dig into it.
>
> Will queue.

Thanks both, and sorry for the late reply. This is in "next" already and scheduled for "master", but FWIW this looks good to me.

The breakage with hook.o happens when you build "seen", and then "master". Since master..seen contains a change that moves find_hook() between files we'll get an error like:

    multiple definition of `find_hook';
    libgit.a(hook.o):/home/avar/g/git/hook.c:97: first defined here
Previous: Junio C Hamano
Message 35 of 35 in “Makefile: add and use the ".DELETE_ON_ERROR" flag”
  1. Makefile: add and use the ".DELETE_ON_ERROR" flagÆvar Arnfjörð Bjarmason, Jun 22, 2021
  2. Taylor BlauJun 22, 2021
  3. Ævar Arnfjörð BjarmasonJun 22, 2021
  4. Jeff KingJun 22, 2021
  5. Ævar Arnfjörð BjarmasonJun 23, 2021
  6. Jeff KingJun 23, 2021
  7. Ævar Arnfjörð BjarmasonJun 24, 2021
  8. Jeff KingJun 24, 2021
  9. Ævar Arnfjörð BjarmasonJun 25, 2021
  10. Jeff KingJun 29, 2021
  11. Junio C HamanoJun 29, 2021
  12. Ævar Arnfjörð BjarmasonJun 29, 2021
  13. Junio C HamanoJun 29, 2021
  14. Jeff KingJun 30, 2021
  15. Felipe ContrerasJul 1, 2021
  16. Ævar Arnfjörð BjarmasonJul 1, 2021
  17. Felipe ContrerasJul 3, 2021
  18. Ævar Arnfjörð BjarmasonJul 3, 2021
  19. Felipe ContrerasJul 3, 2021
  20. Felipe ContrerasJun 23, 2021
  21. Felipe ContrerasJun 23, 2021
  22. Felipe ContrerasJun 23, 2021
  23. Ævar Arnfjörð BjarmasonJun 23, 2021
  24. Felipe ContrerasJun 23, 2021
  25. Ævar Arnfjörð BjarmasonJun 29, 2021
  26. Felipe ContrerasJul 1, 2021
  27. Felipe ContrerasJun 23, 2021
  28. Ævar Arnfjörð BjarmasonJun 23, 2021
  29. Felipe ContrerasJun 23, 2021
  30. Ævar Arnfjörð BjarmasonJun 29, 2021
  31. Felipe ContrerasJul 1, 2021
  32. Makefile: add and use the ".DELETE_ON_ERROR" flagÆvar Arnfjörð Bjarmason, Jun 29, 2021
  33. Makefile: remove archives before manipulating them with 'ar'SZEDER Gábor, Aug 18, 2021
  34. Junio C HamanoAug 19, 2021
  35. Ævar Arnfjörð BjarmasonSep 1, 2021

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.