Bug 278701 - Certain usage of thread_local and -fPIE results in an obscure message printout
Summary: Certain usage of thread_local and -fPIE results in an obscure message printout
Status: Closed FIXED
Alias: None
Product: Base System
Classification: Unclassified
Component: misc (show other bugs)
Version: 14.0-STABLE
Hardware: amd64 Any
: --- Affects Many People
Assignee: freebsd-bugs (Nobody)
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2024-05-02 17:07 UTC by Vasil Dimov
Modified: 2024-05-10 07:53 UTC (History)
1 user (show)

See Also:
vd: maintainer-feedback? (kib)


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description Vasil Dimov freebsd_committer freebsd_triage 2024-05-02 17:07:07 UTC
freefall:~$ cat > main.cc
#include <string>

thread_local std::string s;

int main(int argc, char** argv)
{
    s = "aaa";
    return 0;
}

freefall:~$ c++ -fPIE main.cc -o main

freefall:~$ ./main
__cxa_thread_call_dtors: dtr 0x820b65830 from unloaded dso, skipping
freefall:~$

Same result with FreeBSD-14.0/clang-16.0.6 and FreeBSD-15.0/clang-18.1.4

The printed message is obscure because it is not clear if there is a bug in the program or in the library or if I am supposed to do something to resolve the problem. Also, I think, the destructor of `s` is not called.

The message is printed from walk_cb_call() from lib/libc/stdlib/cxa_thread_atexit_impl.c.
Comment 1 Konstantin Belousov freebsd_committer freebsd_triage 2024-05-03 09:38:23 UTC
https://reviews.freebsd.org/D45074
Comment 2 commit-hook freebsd_committer freebsd_triage 2024-05-03 23:24:21 UTC
A commit in branch main references this bug:

URL: https://cgit.FreeBSD.org/src/commit/?id=b27eb9ce96b838622e125fd969e8dc4914aabe18

commit b27eb9ce96b838622e125fd969e8dc4914aabe18
Author:     Konstantin Belousov <kib@FreeBSD.org>
AuthorDate: 2024-05-03 09:32:01 +0000
Commit:     Konstantin Belousov <kib@FreeBSD.org>
CommitDate: 2024-05-03 23:23:15 +0000

    __cxa_thread_call_dtors(3): fix dtor pointer validity check

    When checking for the destructor pointer belonging to some still
    loaded dso, do not limit the possible dso to the one instantiated the
    destructor. For instance, dso could set up the dtr pointer to a function
    from libcxx.

    PR:     278701
    Reported by:    vd
    Reviewed by:    dim, emaste, markj
    Sponsored by:   The FreeBSD Foundation
    MFC after:      1 week
    Differential revision:  https://reviews.freebsd.org/D45074

 lib/libc/stdlib/cxa_thread_atexit_impl.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
Comment 3 Vasil Dimov freebsd_committer freebsd_triage 2024-05-04 06:31:49 UTC
I started investigating this from here:
https://groups.google.com/g/bsdmailinglist/c/22ncTZAbDp4/m/Dii_pII5AwAJ
I am not sure if that comment has merit. If that is an issue, it is different than the one from this bug report.
Comment 4 commit-hook freebsd_committer freebsd_triage 2024-05-10 07:49:46 UTC
A commit in branch stable/14 references this bug:

URL: https://cgit.FreeBSD.org/src/commit/?id=6a8ca2ff53389c36233e5e0b1576696d34b74407

commit 6a8ca2ff53389c36233e5e0b1576696d34b74407
Author:     Konstantin Belousov <kib@FreeBSD.org>
AuthorDate: 2024-05-03 09:32:01 +0000
Commit:     Konstantin Belousov <kib@FreeBSD.org>
CommitDate: 2024-05-10 07:49:10 +0000

    __cxa_thread_call_dtors(3): fix dtor pointer validity check

    PR:     278701

    (cherry picked from commit b27eb9ce96b838622e125fd969e8dc4914aabe18)

 lib/libc/stdlib/cxa_thread_atexit_impl.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
Comment 5 commit-hook freebsd_committer freebsd_triage 2024-05-10 07:50:54 UTC
A commit in branch stable/13 references this bug:

URL: https://cgit.FreeBSD.org/src/commit/?id=5cf78a5500345340771f7eb840724c2422b2ff96

commit 5cf78a5500345340771f7eb840724c2422b2ff96
Author:     Konstantin Belousov <kib@FreeBSD.org>
AuthorDate: 2024-05-03 09:32:01 +0000
Commit:     Konstantin Belousov <kib@FreeBSD.org>
CommitDate: 2024-05-10 07:49:36 +0000

    __cxa_thread_call_dtors(3): fix dtor pointer validity check

    PR:     278701

    (cherry picked from commit b27eb9ce96b838622e125fd969e8dc4914aabe18)

 lib/libc/stdlib/cxa_thread_atexit_impl.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)