Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit02e6931

Browse files
committed
Avoid symbol collisions between pqsignal.c and legacy-pqsignal.c.
In the name of ABI stability (that is, to avoid a library majorversion bump for libpq), libpq still exports a version of pqsignal()that we no longer want to use ourselves. However, since that hasthe same link name as the function exported by src/port/pqsignal.c,there is a link ordering dependency determining which version willactually get used by code that uses libpq as well as libpgport.a.It now emerges that the wrong version has been used by pgbench andpsql since commit06843df rearranged their link commands. Thiscan result in odd failures in pgbench with the -T switch, since itsSIGALRM handler will now not be marked SA_RESTART. psql may havesome edge-case problems in \watch, too.Since we don't want to depend on link ordering effects anymore,let's fix this in the same spirit asb6c7cfa: use macros to changethe actual link names of the competing functions. We cannot changelegacy-pqsignal.c's exported name of course, so the victim has to besrc/port/pqsignal.c.In master, rename its exported name to be pqsignal_fe in frontend orpqsignal_be in backend. (We could perhaps have gotten away with usingthe same symbol in both cases, but since the FE and BE versions nowwork a little differently, it seems advisable to use different names.)In back branches, rename to pqsignal_fe in frontend but keep it aspqsignal in backend. The frontend change could affect third-partycode that is calling pqsignal from libpgport.a or libpgport_shlib.a,but only if the code is compiled against port.h from a different minorrelease than libpgport. Since we don't support using libpgport as ashared library, it seems unlikely that there will be such a problem.I left the backend symbol unchanged to avoid an ABI break forextensions. This means that the link ordering hazard still existsfor any extension that links against libpq. However, none of our ownextensions use both pqsignal() and libpq, and we're not making thingsany worse for third-party extensions that do.Report from Andy Fan, diagnosis by Fujii Masao, patch by me.Back-patch to all supported branches, as06843df was.Discussion:https://postgr.es/m/87msfz5qv2.fsf@163.com
1 parentd06ab3c commit02e6931

File tree

3 files changed

+17
-4
lines changed

3 files changed

+17
-4
lines changed

‎src/include/port.h

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -579,7 +579,10 @@ extern intpg_check_dir(const char *dir);
579579
/* port/pgmkdirp.c */
580580
externintpg_mkdir_p(char*path,intomode);
581581

582-
/* port/pqsignal.c */
582+
/* port/pqsignal.c (see also interfaces/libpq/legacy-pqsignal.c) */
583+
#ifdefFRONTEND
584+
#definepqsignal pqsignal_fe
585+
#endif
583586
typedefvoid (*pqsigfunc) (intsigno);
584587
externpqsigfuncpqsignal(intsigno,pqsigfuncfunc);
585588

‎src/interfaces/libpq/legacy-pqsignal.c

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -28,10 +28,16 @@
2828
* with the semantics it had in 9.2; in particular, this has different
2929
* behavior for SIGALRM than the version in src/port/pqsignal.c.
3030
*
31-
* libpq itself uses this only for SIGPIPE (and even then, only in
32-
* non-ENABLE_THREAD_SAFETY builds), so the incompatibility isn't
33-
* troublesome for internal references.
31+
* libpq itself does not use this, nor does anything else in our code.
32+
*
33+
* src/include/port.h will #define pqsignal as pqsignal_fe,
34+
* but here we want to export just plain "pqsignal". We can't rely on
35+
* port.h's extern declaration either. (The point of that #define
36+
* is to ensure that no in-tree code accidentally calls this version.)
3437
*/
38+
#undef pqsignal
39+
externpqsigfuncpqsignal(intsigno,pqsigfuncfunc);
40+
3541
pqsigfunc
3642
pqsignal(intsigno,pqsigfuncfunc)
3743
{

‎src/port/pqsignal.c

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,10 @@
3535
* Set up a signal handler, with SA_RESTART, for signal "signo"
3636
*
3737
* Returns the previous handler.
38+
*
39+
* Note: the actual name of this function is either pqsignal_fe when
40+
* compiled with -DFRONTEND, or pqsignal when compiled without that.
41+
* This is to avoid a name collision with libpq's legacy-pqsignal.c.
3842
*/
3943
pqsigfunc
4044
pqsignal(intsigno,pqsigfuncfunc)

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp