Hi, hackers

I've run into a build issue when trying to use pg_probackup with PostgreSQL
18beta1.  After some adjustments to pg_probackup, I encountered the following
linker errors:

/usr/bin/ld: src/pg_crc.o: in function `crc32_bytea':
/home/japin/Codes/extensions/pg_probackup/src/pg_crc.c:109:(.text+0x40): 
undefined reference to `pg_detoast_datum_packed'
/usr/bin/ld: src/pg_crc.o: in function `crc32c_bytea':
/home/japin/Codes/extensions/pg_probackup/src/pg_crc.c:122:(.text+0x1a1): 
undefined reference to `pg_detoast_datum_packed'
collect2: error: ld returned 1 exit status
make: *** 
[/data/Codes/ngdb/main/build/ngdb/lib/postgresql/pgxs/src/makefiles/pgxs.mk:478:
 pg_probackup] Error 1

It appears that PostgreSQL commit 760162f introduced user-callable CRC
functions.  Since pg_probackup leverages pg_crc.c from the PostgreSQL source,
this change is leading to the "undefined reference to pg_detoast_datum_packed"
errors during the build.

To resolve this, I'm wondering about wrapping these user-callable CRC functions
with an #ifndef FRONTEND block:

#ifndef FRONTEND
... // user-callable CRC functions here
#endif

This would ensure these functions are only included in the backend compilation
and avoid linker issues when building extensions like pg_probackup.

Any thoughts or alternative suggestions would be greatly appreciated!

-- 
Regards,
Japin Li

diff --git a/src/backup.c b/src/backup.c
index 78c3512e..e23b2210 100644
--- a/src/backup.c
+++ b/src/backup.c
@@ -2513,7 +2513,11 @@ void
 process_block_change(ForkNumber forknum, RelFileNode rnode, BlockNumber blkno)
 {
 //	char	   *path;
+#if PG_VERSION_NUM < 180000
 	char	   *rel_path;
+#else
+	RelPathStr  rel_path;
+#endif
 	BlockNumber blkno_inseg;
 	int			segno;
 	pgFile	  **file_item;
@@ -2524,9 +2528,17 @@ process_block_change(ForkNumber forknum, RelFileNode rnode, BlockNumber blkno)
 
 	rel_path = relpathperm(rnode, forknum);
 	if (segno > 0)
+#if PG_VERSION_NUM < 180000
 		f.rel_path = psprintf("%s.%u", rel_path, segno);
+#else
+		f.rel_path = psprintf("%s.%u", rel_path.str, segno);
+#endif
 	else
+#if PG_VERSION_NUM < 180000
 		f.rel_path = rel_path;
+#else
+		f.rel_path = pstrdup(rel_path.str);
+#endif
 
 	f.external_dir_num = 0;
 
@@ -2554,7 +2566,9 @@ process_block_change(ForkNumber forknum, RelFileNode rnode, BlockNumber blkno)
 
 	if (segno > 0)
 		pg_free(f.rel_path);
+#if PG_VERSION_NUM < 180000
 	pg_free(rel_path);
+#endif
 
 }
 
diff --git a/src/stream.c b/src/stream.c
index 77453e99..1786b4e9 100644
--- a/src/stream.c
+++ b/src/stream.c
@@ -164,6 +164,11 @@ checkpoint_timeout(PGconn *backup_conn)
  * CreateReplicationSlot_compat() -- wrapper for CreateReplicationSlot() used in StreamLog()
  * src/bin/pg_basebackup/streamutil.c
  * CreateReplicationSlot() has different signatures on different PG versions:
+ * PG 18
+ * bool
+ * CreateReplicationSlot(PGconn *conn, const char *slot_name, const char *plugin,
+ *                                           bool is_temporary, bool is_physical, bool reserve_wal,
+ *                                           bool slot_exists_ok, bool two_phase, bool failover)
  * PG 15
  * bool
  * CreateReplicationSlot(PGconn *conn, const char *slot_name, const char *plugin,
@@ -188,7 +193,10 @@ CreateReplicationSlot_compat(PGconn *conn, const char *slot_name, const char *pl
                                           bool is_temporary, bool is_physical,
                                           bool slot_exists_ok)
 {
-#if PG_VERSION_NUM >= 150000
+#if PG_VERSION_NUM >= 180000
+	return CreateReplicationSlot(conn, slot_name, plugin, is_temporary, is_physical,
+		/* reserve_wal = */ true, slot_exists_ok, /* two_phase = */ false, /* failover = */ false);
+#elif PG_VERSION_NUM >= 150000
 	return CreateReplicationSlot(conn, slot_name, plugin, is_temporary, is_physical,
 		/* reserve_wal = */ true, slot_exists_ok, /* two_phase = */ false);
 #elif PG_VERSION_NUM >= 110000
diff --git a/src/utils/pgut.c b/src/utils/pgut.c
index 9559fa64..4980f8fd 100644
--- a/src/utils/pgut.c
+++ b/src/utils/pgut.c
@@ -54,7 +54,9 @@ static void on_before_exec(PGconn *conn, PGcancel *thread_cancel_conn);
 static void on_after_exec(PGcancel *thread_cancel_conn);
 static void on_interrupt(void);
 static void on_cleanup(void);
+#if PG_VERSION_NUM < 180000
 static pqsigfunc oldhandler = NULL;
+#endif
 
 static char ** pgut_pgfnames(const char *path, bool strict);
 static void pgut_pgfnames_cleanup(char **filenames);
@@ -819,8 +821,9 @@ on_interrupt(void)
 	if (in_password)
 	{
 		on_cleanup();
-
+#if PG_VERSION_NUM < 180000
 		pqsignal(SIGINT, oldhandler);
+#endif
 		kill(0, SIGINT);
 	}
 
@@ -1062,7 +1065,11 @@ handle_interrupt(SIGNAL_ARGS)
 static void
 init_cancel_handler(void)
 {
+#if PG_VERSION_NUM < 180000
 	oldhandler = pqsignal(SIGINT, handle_interrupt);
+#else
+	pqsignal(SIGINT, handle_interrupt);
+#endif
 	pqsignal(SIGQUIT, handle_interrupt);
 	pqsignal(SIGTERM, handle_interrupt);
 	pqsignal(SIGPIPE, handle_interrupt);

Reply via email to