Bug 272992 - Calling dl_iterate_phdr via dlopen/dlsym causes failure: ld-elf.so.1: Can't find module with TLS index 1
Summary: Calling dl_iterate_phdr via dlopen/dlsym causes failure: ld-elf.so.1: Can't f...
Status: Closed Works As Intended
Alias: None
Product: Base System
Classification: Unclassified
Component: misc (show other bugs)
Version: 13.2-STABLE
Hardware: Any Any
: --- Affects Only Me
Assignee: freebsd-bugs (Nobody)
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2023-08-07 06:40 UTC by Yuri Victorovich
Modified: 2024-01-09 12:58 UTC (History)
2 users (show)

See Also:


Attachments
dl_iterate_phdr-via-dlsym.c (1.25 KB, text/plain)
2023-08-07 06:40 UTC, Yuri Victorovich
no flags Details

Note You need to log in before you can comment on or make changes to this bug.
Description Yuri Victorovich freebsd_committer freebsd_triage 2023-08-07 06:40:17 UTC
Created attachment 243919 [details]
dl_iterate_phdr-via-dlsym.c

Please see the attached testcase.

Author: GitHub user ptrajdos, see https://github.com/python/cpython/issues/92828#issuecomment-1666779016
Comment 1 Konstantin Belousov freebsd_committer freebsd_triage 2023-08-07 07:30:20 UTC
This is expected outcome, since libc only provides stubs to satisfy the static
linker.

In the test program, change the "/lib/libc.so.7" path into RTLD_DEFAULT. It
should work then.
Comment 2 Yuri Victorovich freebsd_committer freebsd_triage 2023-08-07 18:17:10 UTC
(In reply to Konstantin Belousov from comment #1)

Thank you.
Comment 3 commit-hook freebsd_committer freebsd_triage 2023-08-09 05:29:08 UTC
A commit in branch main references this bug:

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

commit 21a52f99440c9bec7679f3b0c5c9d888901c3694
Author:     Konstantin Belousov <kib@FreeBSD.org>
AuthorDate: 2023-08-09 05:07:05 +0000
Commit:     Konstantin Belousov <kib@FreeBSD.org>
CommitDate: 2023-08-09 05:07:05 +0000

    libc dlfcn.c: make dl_iterate_phdr() from libc more useful

    Apparently there are applications that resolve dl_iterate_phdr from libc
    and try to call the symbol. Our libc only provides stubs for dl* to
    satisfy static linker or statically linked binaries, and is not prepared
    to this situation.

    Add a code to dso libc to find real dl_iterate_phdr and redirect the
    call to it.

    Reported by:    yuri
    PR:     272992
    Sponsored by:   The FreeBSD Foundation
    MFC after:      1 week

 lib/libc/gen/dlfcn.c | 15 ++++++++++++---
 1 file changed, 12 insertions(+), 3 deletions(-)
Comment 4 commit-hook freebsd_committer freebsd_triage 2023-08-13 04:38:47 UTC
A commit in branch stable/13 references this bug:

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

commit b53ecd5cf63b90a72436642056733b686d881eb1
Author:     Konstantin Belousov <kib@FreeBSD.org>
AuthorDate: 2023-08-09 05:07:05 +0000
Commit:     Konstantin Belousov <kib@FreeBSD.org>
CommitDate: 2023-08-13 04:35:41 +0000

    libc dlfcn.c: make dl_iterate_phdr() from libc more useful

    PR:     272992

    (cherry picked from commit 21a52f99440c9bec7679f3b0c5c9d888901c3694)

 lib/libc/gen/dlfcn.c | 15 ++++++++++++---
 1 file changed, 12 insertions(+), 3 deletions(-)
Comment 5 Jason W. Bacon freebsd_committer freebsd_triage 2024-01-09 12:58:56 UTC
Has anyone checked whether this commit resolves the threadpoolctl issue?

https://github.com/joblib/threadpoolctl/issues/125

Thanks...