Location via proxy:   [ UP ]  
[Report a bug]   [Manage cookies]                
Skip to content

Commit d6d1dfc

Browse files
committed
Add ABI extra field to fmgr magic block
This allows derived products to intentionally make their fmgr ABI incompatible, with a clean error message. Discussion: https://www.postgresql.org/message-id/flat/55215fda-db31-a045-d6b7-d6f2d2dc9920%40enterprisedb.com
1 parent 1b06d7b commit d6d1dfc

File tree

3 files changed

+38
-1
lines changed

3 files changed

+38
-1
lines changed

src/backend/utils/fmgr/dfmgr.c

+15
Original file line numberDiff line numberDiff line change
@@ -330,6 +330,21 @@ incompatible_module_error(const char *libname,
330330
magic_data.version / 100, library_version)));
331331
}
332332

333+
/*
334+
* Similarly, if the ABI extra field doesn't match, error out. Other
335+
* fields below might also mismatch, but that isn't useful information if
336+
* you're using the wrong product altogether.
337+
*/
338+
if (strcmp(module_magic_data->abi_extra, magic_data.abi_extra) != 0)
339+
{
340+
ereport(ERROR,
341+
(errmsg("incompatible library \"%s\": ABI mismatch",
342+
libname),
343+
errdetail("Server has ABI \"%s\", library has \"%s\".",
344+
magic_data.abi_extra,
345+
module_magic_data->abi_extra)));
346+
}
347+
333348
/*
334349
* Otherwise, spell out which fields don't agree.
335350
*

src/include/fmgr.h

+6-1
Original file line numberDiff line numberDiff line change
@@ -458,6 +458,7 @@ typedef struct
458458
int indexmaxkeys; /* INDEX_MAX_KEYS */
459459
int namedatalen; /* NAMEDATALEN */
460460
int float8byval; /* FLOAT8PASSBYVAL */
461+
char abi_extra[32]; /* see pg_config_manual.h */
461462
} Pg_magic_struct;
462463

463464
/* The actual data block contents */
@@ -468,9 +469,13 @@ typedef struct
468469
FUNC_MAX_ARGS, \
469470
INDEX_MAX_KEYS, \
470471
NAMEDATALEN, \
471-
FLOAT8PASSBYVAL \
472+
FLOAT8PASSBYVAL, \
473+
FMGR_ABI_EXTRA, \
472474
}
473475

476+
StaticAssertDecl(sizeof(FMGR_ABI_EXTRA) <= sizeof(((Pg_magic_struct*)0)->abi_extra),
477+
"FMGR_ABI_EXTRA too long");
478+
474479
/*
475480
* Declare the module magic function. It needs to be a function as the dlsym
476481
* in the backend is only guaranteed to work on functions, not data

src/include/pg_config_manual.h

+17
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,23 @@
4242
*/
4343
#define FUNC_MAX_ARGS 100
4444

45+
/*
46+
* When creating a product derived from PostgreSQL with changes that cause
47+
* incompatibilities for loadable modules, it is recommended to change this
48+
* string so that dfmgr.c can refuse to load incompatible modules with a clean
49+
* error message. Typical examples that cause incompatibilities are any
50+
* changes to node tags or node structures. (Note that dfmgr.c already
51+
* detects common sources of incompatibilities due to major version
52+
* differences and due to some changed compile-time constants. This setting
53+
* is for catching anything that cannot be detected in a straightforward way.)
54+
*
55+
* There is no prescribed format for the string. The suggestion is to include
56+
* product or company name, and optionally any internally-relevant ABI
57+
* version. Example: "ACME Postgres/1.2". Note that the string will appear
58+
* in a user-facing error message if an ABI mismatch is detected.
59+
*/
60+
#define FMGR_ABI_EXTRA "PostgreSQL"
61+
4562
/*
4663
* Maximum number of columns in an index. There is little point in making
4764
* this anything but a multiple of 32, because the main cost is associated

0 commit comments

Comments
 (0)