I just discovered that doing "make -C src/backend/storage/lmgr check" no
longer works, because commit 92daeca45df6 ("Add wait event for
pg_usleep() in perform_spin_delay()") added a requirement for
my_wait_event_info to be present at link time:

$ LC_ALL=C make -C src/backend/storage/lmgr/ s_lock_test
make: Entering directory 
'/home/alvherre/Code/pgsql-build/master/src/backend/storage/lmgr'
gcc -I. -I../../../../src/include -I/pgsql/source/master/src/include  
-D_GNU_SOURCE  -Wall -Wmissing-prototypes -Wpointer-arith 
-Wdeclaration-after-statement -Werror=vla -Wendif-labels 
-Wmissing-format-attribute -Wimplicit-fallthrough=3 -Wcast-function-type 
-Wshadow=compatible-local -Wformat-security -fno-strict-aliasing -fwrapv 
-fexcess-precision=standard -Wno-format-truncation -Wno-stringop-truncation -g 
-O2 -DS_LOCK_TEST=1 /pgsql/source/master/src/backend/storage/lmgr/s_lock.c \
         -L ../../../../src/common -lpgcommon \
        -L ../../../../src/port -lpgport -lm -o s_lock_test
/usr/bin/ld: /run/user/1000/alvherre-tmp/ccMaAvVj.o: warning: relocation 
against `my_wait_event_info' in read-only section `.text'
/usr/bin/ld: /run/user/1000/alvherre-tmp/ccMaAvVj.o: in function 
`pgstat_report_wait_start':
/pgsql/source/master/src/include/utils/wait_event.h:94: undefined reference to 
`my_wait_event_info'
/usr/bin/ld: /run/user/1000/alvherre-tmp/ccMaAvVj.o: in function 
`pgstat_report_wait_end':
/pgsql/source/master/src/include/utils/wait_event.h:107: undefined reference to 
`my_wait_event_info'
/usr/bin/ld: warning: creating DT_TEXTREL in a PIE
collect2: error: ld returned 1 exit status
make: *** [Makefile:35: s_lock_test] Error 1
make: Leaving directory 
'/home/alvherre/Code/pgsql-build/master/src/backend/storage/lmgr'


This is after I added -lm, to fix these other problems:

/home/alvherre/Code/pgsql-build/master/src/common/../../../../../../../pgsql/source/master/src/common/pg_prng.c:269:
 undefined reference to `log'
/usr/bin/ld: 
/home/alvherre/Code/pgsql-build/master/src/common/../../../../../../../pgsql/source/master/src/common/pg_prng.c:269:
 undefined reference to `sin'
/usr/bin/ld: 
/home/alvherre/Code/pgsql-build/master/src/common/../../../../../../../pgsql/source/master/src/common/pg_prng.c:269:
 undefined reference to `sqrt'


On my machine, it's enough to patch s_lock_test.c to have a local definition
for the missing symbol.  Since the file already has a test mode, it
turns out to be quite simple -- attached.


I do wonder if we want to keep this around, given that it's been more
than one year broken and nobody seems to have noticed, and the Meson
build does not support the test as a target.

-- 
Álvaro Herrera        Breisgau, Deutschland  —  https://www.EnterpriseDB.com/
 Are you not unsure you want to delete Firefox?
       [Not unsure]     [Not not unsure]    [Cancel]
                   http://smylers.hates-software.com/2008/01/03/566e45b2.html
>From 92913e4d8cdde22b03d0b32547718f5ca4170747 Mon Sep 17 00:00:00 2001
From: Alvaro Herrera <alvhe...@alvh.no-ip.org>
Date: Wed, 24 Jan 2024 12:10:27 +0100
Subject: [PATCH] fix s_lock_test compile

---
 src/backend/storage/lmgr/Makefile | 2 +-
 src/backend/storage/lmgr/s_lock.c | 5 +++++
 2 files changed, 6 insertions(+), 1 deletion(-)

diff --git a/src/backend/storage/lmgr/Makefile b/src/backend/storage/lmgr/Makefile
index 81da6ee13a..89cbb8de49 100644
--- a/src/backend/storage/lmgr/Makefile
+++ b/src/backend/storage/lmgr/Makefile
@@ -34,7 +34,7 @@ endif
 s_lock_test: s_lock.c $(top_builddir)/src/common/libpgcommon.a $(top_builddir)/src/port/libpgport.a
 	$(CC) $(CPPFLAGS) $(CFLAGS) -DS_LOCK_TEST=1 $(srcdir)/s_lock.c \
 		$(TASPATH) -L $(top_builddir)/src/common -lpgcommon \
-		-L $(top_builddir)/src/port -lpgport -o s_lock_test
+		-L $(top_builddir)/src/port -lpgport -lm -o s_lock_test
 
 # see notes in src/backend/parser/Makefile
 lwlocknames.c: lwlocknames.h
diff --git a/src/backend/storage/lmgr/s_lock.c b/src/backend/storage/lmgr/s_lock.c
index 0e5f7ab0b9..a47027eb63 100644
--- a/src/backend/storage/lmgr/s_lock.c
+++ b/src/backend/storage/lmgr/s_lock.c
@@ -61,6 +61,11 @@
 #define MIN_DELAY_USEC		1000L
 #define MAX_DELAY_USEC		1000000L
 
+#ifdef S_LOCK_TEST
+static uint32 local_my_wait_event_info;
+uint32 *my_wait_event_info = &local_my_wait_event_info;
+
+#endif
 
 slock_t		dummy_spinlock;
 
-- 
2.39.2

Reply via email to