From 620fd9cb7ec257534330cfca7d28f6a737d87d16 Mon Sep 17 00:00:00 2001 From: Wolfgang Frisch Date: Tue, 18 Feb 2025 10:07:28 +0100 Subject: [PATCH] extensions/Makefile: eliminate race condition Building extensions with parallel jobs could lead to a race condition when creating and using the temporary `.constructor` file. This resulted in unpredictable build outcomes and unreproducible builds. This commit removes the temporary file entirely, resolving the race condition and ensuring consistent builds. --- extensions/Makefile | 9 +++------ 1 file changed, 3 insertions(+), 6 deletions(-) diff --git a/extensions/Makefile b/extensions/Makefile index a6080734..e4c68c38 100644 --- a/extensions/Makefile +++ b/extensions/Makefile @@ -36,16 +36,13 @@ $(CONTRIB_SO): %.so: %.c defs.h @if [ -f $*.mk ]; then \ $(MAKE) -f $*.mk; \ else \ - grep '((constructor))' $*.c > .constructor; \ - if [ -s .constructor ]; then \ + grep -q '((constructor))' $*.c && { \ echo "gcc -Wall -g -shared -rdynamic -o $@ $*.c -fPIC -D$(TARGET) $(TARGET_CFLAGS) $(GDB_FLAGS)"; \ gcc -Wall -g -shared -rdynamic -o $@ $*.c -fPIC -D$(TARGET) $(TARGET_CFLAGS) $(GDB_FLAGS); \ - fi; \ - if [ ! -s .constructor ]; then \ + } || { \ echo "gcc -Wall -g -nostartfiles -shared -rdynamic -o $@ $*.c -fPIC -D$(TARGET) $(TARGET_CFLAGS) $(GDB_FLAGS)"; \ gcc -Wall -g -nostartfiles -shared -rdynamic -o $@ $*.c -fPIC -D$(TARGET) $(TARGET_CFLAGS) $(GDB_FLAGS); \ - fi; \ - rm -f .constructor; \ + }; \ fi clean: