fix: provide the test stubs for pg_sys extern statics via pg_module_magic! macro#2284
Open
peterkyle01 wants to merge 1 commit intopgcentralfoundation:developfrom
Open
fix: provide the test stubs for pg_sys extern statics via pg_module_magic! macro#2284peterkyle01 wants to merge 1 commit intopgcentralfoundation:developfrom
peterkyle01 wants to merge 1 commit intopgcentralfoundation:developfrom
Conversation
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.
Fixes #2281
A pgrx extension is compiled as a
.soor.dylibthat getsdlopen'd into PostgreSQL at runtime. All the PostgreSQL symbols likeCurrentMemoryContextandBufferBlocksare provided by the running PostgreSQL process so the.sodoesn't need to define them.When
cargo testruns, Rust produces a standalone test executable which is not loaded into PostgreSQL. Those symbols don't exist anywhere so the linker fails withundefined symbol.Normally
--gc-sectionsprunes all unreferencedpg_sysextern declarations. But#[typetag::serde]usesinventory::submit!()to register trait implementations via a "life before main" constructor and that constructor unconditionally references the trait impl methods, which referencepg_syssymbols, pulling them into the live-code set and defeating dead code elimination.In this PR:
The fix adds
#[unsafe(no_mangle)]stub definitions for the commonly-leakedpg_sysextern staticsCurrentMemoryContext,error_context_stack,PG_exception_stack,emit_log_hook,Log_error_verbosity,Log_line_prefix,Log_destination,Log_destination_string,syslog_sequence_numbers,syslog_split_messagesandBufferBlocksinside thepg_magic_func!()macro, gated behind#[cfg(test)].Why the macro?
#[cfg(test)]only fires in the crate under test so dependencies likepgrx-pg-sysare never compiled withcfg(test)by Cargo so placing the stubs in the macro ensures they expand in the extension's own source, wherecfg(test)actually works.pg_module_magic!().sobuild never includes the stubs (nocfg(test)) so PostgreSQL's real symbols are never shadowed.