mirror of https://github.com/postgres/postgres
This commit refactors the sanity check done by libpq to ensure that
there is no exit() reference in the build, moving the check from a
standalone Makefile rule to a perl script.
Platform-specific checks are now part of the script, avoiding most of
the duplication created by the introduction of this check for meson, but
not all of them:
- Solaris and Windows skipped in the script.
- Whitelist of symbols is in the script.
- nm availability, with its path given as an option of the script. Its
execution is checked in the script.
- Check is disabled if coverage reports are enabled. This part is not
pushed down to the script.
- Check is disabled for static builds of libpq. This part is filtered
out in each build script.
A trick is required for the stamp file, in the shape of an optional
argument that can be given to the script. Meson expects the stamp in
output and uses this argument, generating the stamp file in the script.
Meson is able to handle the removal of the stamp file internally when
libpq needs to be rebuilt and the check done again.
This refactoring piece has come up while discussing the addition of more
items in the symbols considered as acceptable.
This sanity check has never been run by meson since its introduction in
dc227eb82e, so it is possible that this fails in some of the buildfarm
members. At least the CI is happy with it, but let's see how it goes.
Author: Nazir Bilal Yavuz <byavuz81@gmail.com>
Co-authored-by: VASUKI M <vasukim1992002@gmail.com>
Reviewed-by: Daniel Gustafsson <daniel@yesql.se>
Reviewed-by: Michael Paquier <michael@paquier.xyz>
Discussion: https://postgr.es/m/19095-6d8256d0c37d4be2@postgresql.org
pull/256/head
parent
c004d68c93
commit
4a8e6f43a6
@ -0,0 +1,91 @@ |
||||
#!/usr/bin/perl |
||||
# |
||||
# src/interfaces/libpq/libpq_check.pl |
||||
# |
||||
# Copyright (c) 2025, PostgreSQL Global Development Group |
||||
# |
||||
# Check the state of a libpq library. Currently, this script checks that |
||||
# exit() is not called, because client libraries must not terminate the |
||||
# host application. |
||||
# |
||||
# This script is called by both Makefile and Meson. |
||||
|
||||
use strict; |
||||
use warnings FATAL => 'all'; |
||||
|
||||
use Getopt::Long; |
||||
use Config; |
||||
|
||||
my $nm_path; |
||||
my $input_file; |
||||
my $stamp_file; |
||||
my @problematic_lines; |
||||
|
||||
Getopt::Long::GetOptions( |
||||
'nm:s' => \$nm_path, |
||||
'input_file:s' => \$input_file, |
||||
'stamp_file:s' => \$stamp_file) or die "$0: wrong arguments\n"; |
||||
|
||||
die "$0: --input_file must be specified\n" unless defined $input_file; |
||||
die "$0: --nm must be specified\n" unless defined $nm_path and -x $nm_path; |
||||
|
||||
sub create_stamp_file |
||||
{ |
||||
if (!(-f $stamp_file)) |
||||
{ |
||||
open my $fh, '>', $stamp_file |
||||
or die "can't open $stamp_file: $!"; |
||||
close $fh; |
||||
} |
||||
} |
||||
|
||||
# Skip on Windows and Solaris |
||||
if ( $Config{osname} =~ /MSWin32|cygwin|msys/i |
||||
|| $Config{osname} =~ /solaris/i) |
||||
{ |
||||
exit 0; |
||||
} |
||||
|
||||
# Run nm to scan for symbols. If nm fails at runtime, skip the check. |
||||
open my $fh, '-|', "$nm_path -A -u $input_file 2>/dev/null" |
||||
or exit 0; |
||||
|
||||
while (<$fh>) |
||||
{ |
||||
# Set of symbols allowed. |
||||
|
||||
# The exclusion of __cxa_atexit is necessary on OpenBSD, which seems |
||||
# to insert references to that even in pure C code. |
||||
next if /__cxa_atexit/; |
||||
|
||||
# Excluding __tsan_func_exit is necessary when using ThreadSanitizer data |
||||
# race detector which uses this function for instrumentation of function |
||||
# exit. |
||||
next if /__tsan_func_exit/; |
||||
|
||||
# Anything containing "exit" is suspicious. |
||||
# (Ideally we should reject abort() too, but there are various scenarios |
||||
# where build toolchains insert abort() calls, e.g. to implement |
||||
# assert().) |
||||
if (/exit/) |
||||
{ |
||||
push @problematic_lines, $_; |
||||
} |
||||
} |
||||
close $fh; |
||||
|
||||
if (@problematic_lines) |
||||
{ |
||||
print "libpq must not be calling any function which invokes exit\n"; |
||||
print "Problematic symbol references:\n"; |
||||
print @problematic_lines; |
||||
|
||||
exit 1; |
||||
} |
||||
# Create stamp file, if required |
||||
if (defined($stamp_file)) |
||||
{ |
||||
create_stamp_file(); |
||||
} |
||||
|
||||
exit 0; |
||||
Loading…
Reference in new issue