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

Re: [PATCH v2 4/4] Makefile: precompile "git-compat-util.h"

From
SZEDER Gábor <szeder.dev@gmail.com>
Date
Oct 3, 2026, 19:00 UTC
Message-ID
<asFQxeh+IUGrlu6W@szeder.dev>
In-Reply-To
<20260915060952.569535-5-szeder.dev@gmail.com>
On Tue, Sep 15, 2026 at 08:09:52AM +0200, SZEDER Gábor wrote:
Show 8 quoted lines
>     - The precompiled header should not change what actually gets
>       compiled.  Therefore, use the precompiled header only when
>       compiling source files that start with including
>       "git-compat-util.h" (directly or indirectly, e.g. via
>       "builtin.h"), or its inclusion is only preceeded by #define
>       directives that don't influence "git-compat-util.h" between its
>       include guards [2] (currently DISABLE_SIGN_COMPARE_WARNINGS,
>       USE_THE_REPOSITORY_VARIABLE or GIT_TEST_PROGRESS_ONLY). [3]

Well, it turns out the precompiled header does change what gets compiled, and it causes a visible behavior difference, though I think it's really minor.

The crux of the issue is that without the precompiled header the compiler processes "git-compat-util.h", but with it, for some reason, it processes "./git-compat-util.h".

This is visible when expanding __FILE__ in "git-compat-util.h", e.g. in the assert macro in regexec_buf(). When the assertion is triggered, e.g. with this diff:

diff --git a/common-main.c b/common-main.c
index 6b7ab077b0..dd2a90c849 100644
--- a/common-main.c
+++ b/common-main.c
@@ -5,6 +5,9 @@ int main(int argc, const char **argv)
 {
 	int result;
 
+	/* Intentionally bogus regexec_buf() call to trigger its assert() */
+	regexec_buf(NULL, NULL, 0, 0, NULL, 0);
+
 	init_git(argv);
 	result = cmd_main(argc, argv);
 
Then without the precompiled header we get:

  $ ./git
  git: git-compat-util.h:1002: regexec_buf: Assertion `nmatch > 0 && pmatch' failed.
  Aborted (core dumped)

But with the precompiled header:

  $ ./git
  git: ./git-compat-util.h:1002: regexec_buf: Assertion `nmatch > 0 && pmatch' failed.
  Aborted (core dumped)

Similar could happen when the ALLOC_GROW_BY() macro is invoked with
bogus parameters to trigger a BUG().

(Sidenote: While this assert does prevent us from invoking regexec()
with nonsense, the source file name and line number in the resulting
error message are not as useful as they could be, it would be better
to show the caller's filename and line number.)

Since in "git-compat-util.h" __FILE__ is only expanded in error
messages that should basically never happen (BUG() and assert()), I
think this is acceptable.


BTW, this is also visible in compiler error messages:

diff --git a/git-compat-util.h b/git-compat-util.h
index a0f901ce79..00c1f26911 100644
--- a/git-compat-util.h
+++ b/git-compat-util.h
@@ -1,6 +1,8 @@
 #ifndef GIT_COMPAT_UTIL_H
 #define GIT_COMPAT_UTIL_H
 
+trigger_compiler_error
+
 #if __STDC_VERSION__ - 0 < 199901L
 /*
  * Git is in a testing period for mandatory C99 support in the compiler.  If

Without precompiled header:

      CC daemon.o
  In file included from daemon.c:3:
  git-compat-util.h:4:23: error: expected ‘;’ before ‘typedef’
      4 | trigger_compiler_error
        |                       ^
        |                       ;

With precompiled header:

      CC tools/precompiled.h.gch
  In file included from tools/precompiled.h:1:
  ./git-compat-util.h:4:23: error: expected ‘;’ before ‘typedef’
      4 | trigger_compiler_error
        |                       ^
        |                       ;
Previous: SZEDER Gábor
Message 15 of 15 in “make: precompile "git-compat-util.h"”
  1. 0/4 make: precompile "git-compat-util.h"SZEDER Gábor, Sep 9, 2026
  2. 1/4 Makefile: remove XDIFF_OBJS initializationSZEDER Gábor, Sep 9, 2026
  3. 2/4 cmake: remove any "$(*_OBJS)" variables when parsing Makefile for sourcesSZEDER Gábor, Sep 9, 2026
  4. 3/4 Makefile: reintroduce REFTABLE_OBJSSZEDER Gábor, Sep 9, 2026
  5. Junio C HamanoSep 9, 2026
  6. 4/4 Makefile: precompile "git-compat-util.h"SZEDER Gábor, Sep 9, 2026
  7. SZEDER GáborSep 9, 2026
  8. 0/4 make: precompile "git-compat-util.h"SZEDER Gábor, Sep 15, 2026
  9. 1/4 Makefile: remove XDIFF_OBJS initializationSZEDER Gábor, Sep 15, 2026
  10. 2/4 cmake: remove any "$(*_OBJS)" variables when parsing Makefile for sourcesSZEDER Gábor, Sep 15, 2026
  11. 3/4 Makefile: reintroduce REFTABLE_OBJSSZEDER Gábor, Sep 15, 2026
  12. 4/4 Makefile: precompile "git-compat-util.h"SZEDER Gábor, Sep 15, 2026
  13. Jeff KingSep 24, 2026
  14. SZEDER GáborSep 25, 2026
  15. SZEDER GáborOct 3, 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.