[Bug 267671] [libc] Remove unnecessary printf to stderr in stdlib/cxa_thread_atexit_impl.c

From: <bugzilla-noreply_at_freebsd.org>
Date: Wed, 09 Nov 2022 22:18:11 UTC
https://bugs.freebsd.org/bugzilla/show_bug.cgi?id=267671

            Bug ID: 267671
           Summary: [libc] Remove unnecessary printf to stderr in
                    stdlib/cxa_thread_atexit_impl.c
           Product: Base System
           Version: 13.1-RELEASE
          Hardware: amd64
                OS: Any
            Status: New
          Severity: Affects Some People
          Priority: ---
         Component: kern
          Assignee: bugs@FreeBSD.org
          Reporter: erik@tenku.dk

This is a request to remove the printf statement in
stdlib/cxa_thread_atexit_impl.c in the function walk_cb_call.



The function signature is currently
"
static void
walk_cb_call(struct cxa_thread_dtor *dtor)
{
        struct dl_phdr_info phdr_info;

        if (_rtld_addr_phdr(dtor->dso, &phdr_info) &&
            __elf_phdr_match_addr(&phdr_info, dtor->func))
                dtor->func(dtor->obj);
        else
                fprintf(stderr, "__cxa_thread_call_dtors: dtr %p from "
                    "unloaded dso, skipping\n", (void *)(dtor->func));
}
"

and I suggest to modify it to read

"
static void
walk_cb_call(struct cxa_thread_dtor *dtor)
{
        struct dl_phdr_info phdr_info;

        if (_rtld_addr_phdr(dtor->dso, &phdr_info) &&
            __elf_phdr_match_addr(&phdr_info, dtor->func))
                dtor->func(dtor->obj);
}
"

Currently, walk_cb_call does all the necessary checks (as far as I can tell) in
its if-statement, calling the destructor of a given dso only if the dso has not
already been unloaded.
If the dso appears multiple times as the list of dsos is iterated over in the
function cxa_thread_walk (in the same source file), the error message will be
printed multiple times to the user.

A specific dso might very well appear multiple times in the list of dsos, if it
is linked into several other dsos on which a given program relies.

The error message could perhaps be considered informative while debugging, but
it does not add any functionality and it potentially gives any end-user a wrong
impression of the integrity of a program that has this behaviour.
As such, I suggest to remove the print statement from the source code.

-- 
You are receiving this mail because:
You are the assignee for the bug.