Subject: .bc files build dependency issues.

From: "Anton A. Melnikov" <[email-masked]>
Date: Mon, 30 Mar 2026 10:28:30 +0300

Hi!

While the original discussion was about a specific commit
ecaf7c5df and related fix in 16492df7 for 16+
and its effects  [1], i would like to point out that
a similar behavior can be observed
on earlier stable branches (REL_14/15_STABLE) as well.

Using a pre-built source tree and the following reproduction
that is slightly modified version from [2] which suggests
that this is a known pattern for exposing the issue:

cd src/backend/parser
rm -rf .deps/ gram.c scan.c *.o *.bc gram.h
make parser.bc

result in:

$ make parser.bc
/usr/lib/llvm-16/bin/clang -Wno-ignored-attributes -fno-strict-aliasing -fwrapv -fexcess-precision=standard -Xclang
-no-opaque-pointers -Wno-unused-command-line-argument -Wno-compound-token-split-by-macro -Wno-deprecated-non-prototype
-O2  -I. -I. -I../../../src/include -D_GNU_SOURCE  -I/usr/include/libxml2 -I/usr/local/include -flto=thin -emit-llvm
-c -o parser.bc parser.c
In file included from parser.c:25:
../../../src/include/parser/gramparse.h:29:10: fatal error: 'parser/gram.h' file not found
#include "parser/gram.h"
          ^~~~~~~~~~~~~~~
1 error generated.
make: *** [../../../src/Makefile.global:1084: parser.bc] Error 1

Since this can be reproduced reliably on REL_14/15, it seems worth asking
whether fix for .bc files (or something equivalent) should also be
backpatched to lower branches, instead of only applying to newer ones.

Also as a possible improvement perhaps make the fix less strictly?
I.e. replace each .bc file's dependency on all .o files
with a more weak dependency just on all source .c files.
Namely use:

$(patsubst %.o,%.bc, $(OBJS)): $(patsubst %.o,%.c, $(OBJS))

instead of:

$(patsubst %.o,%.bc, $(OBJS)): $(OBJS)

This might still preserve correct build ordering while reducing
unnecessary coupling between targets. As a result make will
run faster during parallel builds since it won't wait
for absolutely all the object files to be created.

For example, rebuilding parser.bc would then require only
a single compiler call in src/backend/parser instead of many.
Please, see the attached bc-depends-on-c.txt and
bc-depends-on-o.txt for details.

Best regards,

-- 
Anton A. Melnikov
Postgres Professional: http://www.postgrespro.com
The Russian Postgres Company

[1] https://www.postgresql.org/message-id/flat/E1oYJbR-000FbR-LP%40gemulon.postgresql.org
[2] https://www.postgresql.org/message-id/20220915045007.zvlrqqicbttzpgi3%40awork3.anarazel.de

---

From: Andres Freund <[email-masked]>
Date: Mon, 30 Mar 2026 08:39:23 -0400

Hi,

> rm -rf .deps/ gram.c scan.c *.o *.bc gram.h

IOW, if you do something that intentionally breaks things, things break.

> ../../../src/include/parser/gramparse.h:29:10: fatal error: 'parser/gram.h' file not found

This seems like a complete non-issue to me. What is the actual problem here?
You intentionally removed dependency information. You intentionally removed
part of the generated files, but not all of them.

> unnecessary coupling between targets.

It'd also be broken if one of the source files is built from c++, for example.

> As a result make will run faster during parallel builds since it won't wait

The other file also needs to be built. The .bc->.o dependency will actually
often prevent redundant error messages.

Greetings,

Andres Freund