Repository navigation
Export only the C API entrypoint from the loadable extension - #167
Closed
Robinho-MR wants to merge 1 commit into
Closed
Robinho-MR wants to merge 1 commit into
Robinho-MR wants to merge 1 commit into
Conversation
Since the move to the C API, the loadable extension exported all of its symbols, including those of avro-c and its bundled jansson (1298 on linux_arm64). On Linux a symbol defined by the host executable takes precedence over one in a dlopen-ed library, so when DuckDB runs inside Postgres (pg_duckdb), jansson's internal call to json_object() bound to Postgres' SQL function json_object(fcinfo) and crashed while parsing an Avro schema. Link the loadable extension with a version script (Linux) or an exported-symbols list (macOS) that exports only avro_init_c_api_v2.
Member
|
Superseded by duckdb/duckdb#29057 |
PeterVanHolland
pushed a commit
to PeterVanHolland/duckdb
that referenced
this pull request
Nov 19, 2026
…kdb#29057) C++ ABI loadable extensions are linked so that they export only `<name>_duckdb_cpp_init`. For C API extensions (`C_STRUCT` / `C_STRUCT_UNSTABLE`) this was still a TODO in `build_loadable_extension_directory` (`# TODO strip all symbols except the capi init`), so they exported every symbol of the libraries they bundle. The v2.0.1 avro extension, which moved to the C API, exports 1336 symbols on linux_amd64, including jansson's `json_*` functions. The v2.0.0 C++ ABI build exported 12. On Linux, a symbol that the host executable defines takes precedence over one in a `dlopen`-ed library. When DuckDB runs inside Postgres (pg_duckdb), jansson's internal call to `json_object()` binds to Postgres's exported SQL function `json_object(fcinfo)` instead. It then crashes in `pg_detoast_datum` while avro parses an Avro schema, for example on the first `iceberg_scan`. This PR exports only the C API entrypoint (`<name>_init_c_api` or `<name>_init_c_api_v2`, from `capi_entrypoint_symbol`): - Linux and other GNU/Clang platforms: a version script, `{ global: <entrypoint>; local: *; };` - macOS: `-exported_symbol,_<entrypoint>`, as for C++ extensions - Wasm, Windows and z/OS are unchanged. Wasm already exports only `EXPORTED_FUNCTIONS`, and Windows only `dllexport` symbols. Because the release builds use this file, this also fixes avro at its current pin, with no avro bump needed. duckdb/duckdb-avro#167 makes the same change in avro's own CMake. ### Testing (linux_arm64, reldebug, `BUILD_EXTENSIONS=demo_capi` + `.github/config/extensions/avro.cmake`) - `nm -D --defined-only`: avro now exports only `avro_init_c_api_v2`, and `demo_capi` only `demo_capi_init_c_api`. C++ extensions are unchanged. - Repro without Postgres: `LD_PRELOAD` a library that defines an aborting `json_object`, then `LOAD` avro and `read_avro(...)` an Iceberg manifest. Before: `host json_object called (symbol clash)`, SIGABRT. After: the query returns normally. - `LOAD demo_capi; SELECT add_numbers_together(40, 2)` returns 42. - avro's `test/*` with `--test-dir`: 105 test cases pass. `*capi*`: 38 pass. `test/extension/*`: 29 pass. - I couldn't test macOS locally.
eraycep
pushed a commit
to eraycep/duckdb
that referenced
this pull request
Nov 19, 2026
C++ ABI loadable extensions are linked so that they export only `<name>_duckdb_cpp_init`. For C API extensions (`C_STRUCT` / `C_STRUCT_UNSTABLE`) this was still a TODO in `build_loadable_extension_directory` (`# TODO strip all symbols except the capi init`), so they exported every symbol of the libraries they bundle. The v2.0.1 avro extension, which moved to the C API, exports 1336 symbols on linux_amd64, including jansson's `json_*` functions. The v2.0.0 C++ ABI build exported 12. On Linux, a symbol that the host executable defines takes precedence over one in a `dlopen`-ed library. When DuckDB runs inside Postgres (pg_duckdb), jansson's internal call to `json_object()` binds to Postgres's exported SQL function `json_object(fcinfo)` instead. It then crashes in `pg_detoast_datum` while avro parses an Avro schema, for example on the first `iceberg_scan`. This PR (the `main` counterpart of duckdb#29057) exports only the C API entrypoint (`<name>_init_c_api` or `<name>_init_c_api_v2`, from `capi_entrypoint_symbol`): - Linux and other GNU/Clang platforms: a version script, `{ global: <entrypoint>; local: *; };` - macOS: `-exported_symbol,_<entrypoint>`, as for C++ extensions - Wasm, Windows and z/OS are unchanged. Wasm already exports only `EXPORTED_FUNCTIONS`, and Windows only `dllexport` symbols. Because the release builds use this file, this also fixes avro at its current pin, with no avro bump needed. duckdb/duckdb-avro#167 makes the same change in avro's own CMake. ### Testing (linux_arm64, reldebug, `BUILD_EXTENSIONS=demo_capi` + `.github/config/extensions/avro.cmake`) - `nm -D --defined-only`: avro now exports only `avro_init_c_api_v2`, and `demo_capi` only `demo_capi_init_c_api`. C++ extensions are unchanged. - Repro without Postgres: `LD_PRELOAD` a library that defines an aborting `json_object`, then `LOAD` avro and `read_avro(...)` an Iceberg manifest. Before: `host json_object called (symbol clash)`, SIGABRT. After: the query returns normally. - `LOAD demo_capi; SELECT add_numbers_together(40, 2)` returns 42. - avro's `test/*` with `--test-dir`: 105 test cases pass. `*capi*`: 38 pass. `test/extension/*`: 29 pass. - I couldn't test macOS locally.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Since the port to the C API (
C_STRUCT_UNSTABLE), the loadable avro extension exports all of its symbols. That includes avro-c and the bundled jansson. The published v2.0.1 binary exports 1336 symbols on linux_amd64, 75 of themjson_*. The C++ ABI v2.0.0 binary exported 12. DuckDB's build doesn't restrict exports for C API extensions yet (# TODO strip all symbols except the capi initinextension_build_tools.cmake).On Linux, a symbol that the host executable defines takes precedence over one in a
dlopen-ed library. When DuckDB runs inside Postgres (pg_duckdb), jansson's internal call tojson_object()binds to Postgres's exported SQL functionjson_object(fcinfo)instead. It then crashes inpg_detoast_datumwhile avro parses an Avro file's schema, for example on the firsticeberg_scan.This PR links the loadable extension so it exports only
avro_init_c_api_v2:{ global: avro_init_c_api_v2; local: *; };-exported_symbol,_avro_init_c_api_v2, the same flag DuckDB uses for C++ extensionsEXPORTED_FUNCTIONSanddllexportsymbols, respectively.Testing (linux_arm64, reldebug)
nm -D --defined-only avro.duckdb_extension: 1298 symbols,json_objectamong them, before; onlyavro_init_c_api_v2after.LD_PRELOADa library that defines an abortingjson_object, thenLOADthe extension andread_avro(...)an Iceberg manifest. Before:host json_object called (symbol clash), SIGABRT. After: the query returns normally.unittest "test/*": all 32 test files pass.