Skip to content

Add static build & add -Bsymbolic for loadable extension#402

Open
YuweiXiao wants to merge 4 commits intoduckdb:mainfrom
relytcloud:static-build
Open

Add static build & add -Bsymbolic for loadable extension#402
YuweiXiao wants to merge 4 commits intoduckdb:mainfrom
relytcloud:static-build

Conversation

@YuweiXiao
Copy link

Changes:

  • Add static build
  • Add -Bsymbolic for loadable extension build

When postgres_scanner is loaded inside a PostgreSQL backend (e.g., via pg_duckdb), the connection to postgres may fail with:

libpq is incorrectly linked to backend functions

The cause: postgres_scanner statically compiles libpq with -DFRONTEND=1, so function in libpq, i.e., pg_link_canary_is_frontend(), would validate if it is running under FRONTEND during connection startup. However, on ELF systems, the dynamic linker resolves the function symbol to the PostgreSQL backend's version, which is not FRONTEND, leading to connection failure.

By adding -Bsymbolic, we enforce postgres_scanner to bind internal symbol references within the extension.

@YuweiXiao
Copy link
Author

this PR shall solve #366

@staticlibs
Copy link
Collaborator

Hi, thanks for the PR! I'll close and reopen it to run the CI.

On the contents of the PR - I wonder whether we need to pass the C_STANDARD 99 to the static extension target too?

@staticlibs staticlibs closed this Mar 3, 2026
@staticlibs staticlibs reopened this Mar 3, 2026
@staticlibs
Copy link
Collaborator

Despite passing on CI the build fails on newer GCC with the following:

Building C object extension/postgres_scanner/CMakeFiles/postgres_scanner_extension.dir/postgres/src/common/base64.c.o
In file included from duckdb-postgres/postgres/src/include/postgres_fe.h:25,
                 from duckdb-postgres/postgres/src/common/base64.c:18:
duckdb-postgres/postgres/src/include/c.h:419:23: error: ‘bool’ cannot be defined via ‘typedef’
  419 | typedef unsigned char bool;
      |                       ^~~~
duckdb-postgres/postgres/src/include/c.h:419:23: note: ‘bool’ is a keyword with ‘-std=c23’ onwards

Suggested fix:

diff --git a/CMakeLists.txt b/CMakeLists.txt
index 61f141e..68fc2f5 100644
--- a/CMakeLists.txt
+++ b/CMakeLists.txt
@@ -217,6 +217,7 @@ if(NOT WIN32 AND NOT APPLE)
 endif()
 
 target_link_libraries(${LOADABLE_EXTENSION_NAME} ${OPENSSL_LIBRARIES})
+set_property(TARGET ${EXTENSION_NAME} PROPERTY C_STANDARD 99)
 set_property(TARGET ${LOADABLE_EXTENSION_NAME} PROPERTY C_STANDARD 99)
 
 if(WIN32

@YuweiXiao
Copy link
Author

@staticlibs Hi Alex, thanks for the review. Comment addressed.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants