Thread

  1. Re: BUG #19095: Test if function exit() is used fail when linked static

    VASUKI M <vasukim1992002@gmail.com> — 2025-12-08T04:41:08Z

    Hi Michael,
    
    Thanks for checking the v6 patch.
    
    Regarding the whitespace comment - I had already ran the pgperltidy on the
    perl
    script libpq-check.pl before  sending the patch,and I also verified the tab
    indentation
    with cat -T  to ensure the tabs were being used.FS,The current version of
    the scripts in
    v6 should already follow the standard pgindent/pgperltidy formatting
    
    If there is still any specific section that appears mis-indented on your
    side,
    please let me know and I will adjust it.
    
    cdac@cdac-Aspire-Lite-AL15-41:~/pg-libpq$ src/tools/pgindent/pgperltidy
    src/interfaces/libpq/libpq-check.pl
    
    cdac@cdac-Aspire-Lite-AL15-41:~/pg-libpq$
    
    cdac@cdac-Aspire-Lite-AL15-41:~/pg-libpq$ cat -T src/interfaces/libpq/
    libpq-check.pl
    #!/usr/bin/perl
    #
    # src/interfaces/libpq/libpq-check.pl
    #
    # Copyright (c) 2025, PostgreSQL Global Development Group
    #
    # Check that 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(
    ^I'nm:s' => \$nm_path,
    ^I'input_file:s' => \$input_file,
    ^I'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
    {
    ^Iif (!(-f $stamp_file))
    ^I{
    ^I^Iopen my $fh, '>', $stamp_file
    ^I^I  or die "can't open $stamp_file: $!";
    ^I^Iclose $fh;
    ^I}
    }
    
    # ---- Skip on Windows and Solaris ----
    if (   $Config{osname} =~ /MSWin32|cygwin|msys/i
    ^I|| $Config{osname} =~ /solaris/i)
    {
    ^Iexit 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>)
    {
    
    ^I# Set of symbols allowed:
    ^I#     __cxa_atexit     - injected by some libcs (e.g., OpenBSD)
    ^I#     __tsan_func_exit - ThreadSanitizer instrumentation
    ^I#     pthread_exit     - legitimate thread cleanup
    
    ^Inext if /__cxa_atexit/;
    ^Inext if /__tsan_func_exit/;
    ^Inext if /pthread_exit/;
    
    ^I# Anything containing "exit" is suspicious.
    ^I# (Ideally we should reject abort() too, but there are various scenarios
    ^I# where build toolchains insert abort() calls, e.g. to implement
    assert().)
    ^Iif (/exit/)
    ^I{
    ^I^Ipush @problematic_lines, $_;
    ^I}
    }
    close $fh;
    
    if (@problematic_lines)
    {
    ^Iprint "libpq must not be calling any function which invokes exit\n";
    ^Iprint "Problematic symbol references:\n";
    ^Iprint @problematic_lines;
    
    ^Iexit 1;
    }
    
    # Create stamp file, if required
    if (defined($stamp_file))
    {
    ^Icreate_stamp_file();
    }
    
    exit 0;
    cdac@cdac-Aspire-Lite-AL15-41:~/pg-libpq$
    
    Regards,
    
    Vasuki