Skip to content

Commit 5866eca

Browse files
Export all symbols (#445)
Fixes #404 and effectively reverts most of #81. After this lands we export: * All C API symbols * The Arrow ADBC entrypoint (`duckdb_adbc_init`) * The Python extension entrypoint (`PyInit__duckdb`) * Lots of mangled C++ symbols. This gives us better stacktraces again. | | Release build | Release wheel | Debug Build | | -- | ------------- | --------------- | ------------ | | **Size before** | 39.6 MB | 14 MB | 166 MB | | **Size after** | 44.6 MB | 15 MB | 183 MB |
2 parents f12a2bb + 21c351b commit 5866eca

2 files changed

Lines changed: 10 additions & 42 deletions

File tree

CMakeLists.txt

Lines changed: 5 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -57,6 +57,11 @@ target_include_directories(
5757
INTERFACE $<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}/src/duckdb_py/include>
5858
)
5959

60+
# We link duckdb_static. Without this define, duckdb.h marks C API symbols
61+
# __declspec(dllimport) on Windows, producing unresolvable __imp_* references at
62+
# link time. No-op on non-Windows.
63+
target_compile_definitions(_duckdb_dependencies INTERFACE DUCKDB_STATIC_BUILD)
64+
6065
# ────────────────────────────────────────────
6166
# Descend into the real DuckDB‑Python sources
6267
# ────────────────────────────────────────────
@@ -81,37 +86,6 @@ pybind11_add_module(
8186
target_link_libraries(_duckdb PRIVATE _duckdb_dependencies)
8287
duckdb_link_extensions(_duckdb)
8388

84-
# ────────────────────────────────────────────
85-
# Controlling symbol export
86-
#
87-
# We want to export exactly two symbols: - PyInit__duckdb: this allows CPython
88-
# to load the module - duckdb_adbc_init: the DuckDB ADBC driver
89-
#
90-
# The export of symbols on OSX and Linux is controlled by: - Visibility
91-
# annotations in the code (for this lib we use the PYBIND11_EXPORT macro) -
92-
# Telling the linker which symbols we want exported, which we do below
93-
#
94-
# For Windows, we rely on just the visbility annotations.
95-
# ────────────────────────────────────────────
96-
set_target_properties(
97-
_duckdb
98-
PROPERTIES CXX_VISIBILITY_PRESET hidden
99-
C_VISIBILITY_PRESET hidden
100-
VISIBILITY_INLINES_HIDDEN ON)
101-
102-
if(APPLE)
103-
target_link_options(
104-
_duckdb PRIVATE "LINKER:-exported_symbol,_duckdb_adbc_init"
105-
"LINKER:-exported_symbol,_PyInit__duckdb")
106-
elseif(UNIX AND NOT APPLE)
107-
target_link_options(
108-
_duckdb PRIVATE "LINKER:--export-dynamic-symbol=duckdb_adbc_init"
109-
"LINKER:--export-dynamic-symbol=PyInit__duckdb")
110-
elseif(WIN32)
111-
target_link_options(_duckdb PRIVATE "/EXPORT:duckdb_adbc_init"
112-
"/EXPORT:PyInit__duckdb")
113-
endif()
114-
11589
# ────────────────────────────────────────────
11690
# Put the object file in the correct place
11791
# ────────────────────────────────────────────

src/duckdb_py/duckdb_python.cpp

Lines changed: 5 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1051,22 +1051,16 @@ static void RegisterExpectedResultType(py::handle &m) {
10511051
}
10521052

10531053
// ######################################################################
1054-
// Symbol exports
1054+
// Force inclusion of symbols that are not referenced by any code in the
1055+
// Python module but must be present in the shared object.
10551056
//
1056-
// We want to limit the symbols we export to only the absolute minimum.
1057-
// This means we compile with -fvisibility=hidden to hide all symbols,
1058-
// and then explicitly export only the symbols we want.
1057+
// duckdb_adbc_init: entrypoint for the ADBC driver. Not called from Python
1058+
// code, but loaded by adbc_driver_manager via dlsym/GetProcAddress.
10591059
//
1060-
// Right now we export two symbols only:
1061-
// - duckdb_adbc_init: the entrypoint for our ADBC driver
1062-
// - PyInit__duckdb: the entrypoint for the python extension
1063-
//
1064-
// All symbols that need exporting must be added to both the list below
1065-
// AND to CMakeLists.txt.
1060+
// Without this, the linker may strip these as dead code.
10661061
extern "C" {
10671062
PYBIND11_EXPORT void *_force_symbol_inclusion() {
10681063
static void *symbols[] = {
1069-
// Add functions to export here
10701064
(void *)&duckdb_adbc_init,
10711065
};
10721066
return symbols;

0 commit comments

Comments
 (0)