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

From: BharatDB <bharatdbpg(at)gmail(dot)com>
To: Andres Freund <andres(at)anarazel(dot)de>, Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us>
Cc: torsten(dot)rupp(at)gmx(dot)net, pgsql-bugs(at)lists(dot)postgresql(dot)org, VASUKI M <vasukim1992002(at)gmail(dot)com>, daniel(at)yesql(dot)se, michael(at)paquier(dot)xyz
Subject: Re: BUG #19095: Test if function exit() is used fail when linked static
Date: 2025-11-19 12:29:09
Message-ID: CAAh00ERij397C5BXe=R6T38Ki7_G=0svdcFuTtz7eG-qs7vtuw@mail.gmail.com
Views: Whole Thread | Raw Message | Download mbox | Resend email
Thread:
Lists: pgsql-bugs pgsql-hackers

Sorry,for the wrong patch this is the correct one.kindly find the attached
patch for testing
I would love to hear the feedback from you committers.

regards,
Vasuki M
BharatDB,C-DAC Chennai.

On Wed, Nov 19, 2025 at 2:38 PM BharatDB <bharatdbpg(at)gmail(dot)com> wrote:

> Hi Andres and hackers,
> I came up with the solution
> — short follow-up with what I changed and how the Meson check actually
> runs.
>
> Summary of what I did
> - Added a Meson custom_target in src/interfaces/libpq/meson.build that
> scans libpq's object files for direct exit() references.
> - Added pthread_exit to the Makefile whitelist (the Makefile test
> already existed; this just updates the whitelist).
> -Added the custom target in the top level meson.build
>
> Where the Meson check lives and when it runs
> - I put the custom_target in src/interfaces/libpq/meson.build,
> immediately after the libpq shared/static library targets are
> defined and after the declare_dependency for libpq. That is the
> correct location in the libpq build file.
> - The custom_target declares `depends: [libpq_st, libpq_so]`. This
> is important: it tells Meson to build those targets first so the
> .o files are present in the build directory before the check runs.
> The check itself does not scan libpq_st or libpq_so; it scans
> files in build/src/interfaces/libpq/*.o.
> - The command uses `find <builddir>/src/interfaces/libpq -name '*.o'`
> and runs `nm -u` on each .o, piping through `grep -v` for the
> whitelisted names and finally checking for exit.
> - The check is skipped for:
> * cross-builds
> * when coverage (b_coverage) is enabled
> * on Windows (no nm/grep in the same form there) as Andrew questioned
>
> Why pthread_exit is whitelisted
> - pthread_exit can legitimately appear in a few build/runtime
> configurations (thread runtimes or link-time glue), and the
> Makefile test was updated to whitelist it. The Meson check has the
> same whitelist so both build systems behave the same.
> - Whitelisting pthread_exit doesn't remove the value of the test:
> it only avoids false positives for legitimate thread shutdown code.
> We still catch direct exit()/ _exit()/abort()-style calls as tom said.
>
> How to reproduce locally
> - From repo root:
> rm -rf build
> meson setup build
> cd build
> ninja
> The custom_target runs as part of the normal build and will fail
> the build if any .o contains an un-whitelisted exit() reference.
>
> On Fri, Nov 14, 2025 at 7:31 PM Andres Freund <andres(at)anarazel(dot)de> wrote:
>
> But more generally: If we allow pthread_exit(), what's the point of this
>> test?
>> That's one of the functions we better avoid calling, no?
>>
> I agree it's worth questioning which functions we allow. The
> current choice (whitelist pthread_exit) mirrors the Makefile
> behavior, avoids false positives, and keeps the test focused on
> direct process-termination calls authored in our code. If the
> community prefers a stricter policy so we can adjust the whitelist.
>
>
>> ISTM that if we do want to continue having this test, the issue is that
>> we're
>> testing the shared library - which will have already linked against static
>> libraries like the sanitizer ones or in this case libcrypto. What we
>> ought to
>> do is to test the .o files constituting libpq.so, rather than the already
>> linked .so. That way we will find our own calls to exit etc, but not ones
>> in
>> static libraries.
>>
>
> TBH After so many test runs I have finalized
> Why scan .o files (not the final .so)?
> - A shared library is usually linked with other static libraries
> (libcrypto, sanitizer runtimes). If we scan the final .so we'll
> see references that originate in those static libraries and produce
> false positives.
> - If we scan the .o files that make up libpq, we only inspect our
> own compilation units and will catch only exit() calls introduced
> by our code.
>
> HTH! I attached the patch and also added the meson test output before
> /after of any file containing an 'exit' explicitly; it fails the
> build[ninja].
>
> Regards,
> Vasuki M
> BharatDB[CDAC chennai]
>

Attachment Content-Type Size
0001-libpq-Add-exit-function-check-for-Meson-build-and-wh.patch text/x-patch 4.4 KB

In response to

Browse pgsql-bugs by date

  From Date Subject
Next Message Nazir Bilal Yavuz 2025-11-19 13:17:07 Re: BUG #19095: Test if function exit() is used fail when linked static
Previous Message Hans Buschmann 2025-11-19 11:44:43 AW: BUG #19113: Missing updated libpq5 rpm in repo pgdg-common after minor release to 18.1

Browse pgsql-hackers by date

  From Date Subject
Next Message Fujii Masao 2025-11-19 13:01:03 Re: [PATCH] Add hints for invalid binary encoding names in encode/decode functions
Previous Message David Geier 2025-11-19 12:28:51 Re: Performance issues with parallelism and LIMIT