FazBrowse GitHub Viewer | Trending |
URL:
| Home
Tools: [Download Repo ZIP]   [Original HTTPS Page]

dl_iterate_phdr in `link.h` header but undefined at link time · Issue #21354 · emscripten-core/emscripten · GitHub

Repository navigation

dl_iterate_phdr in link.h header but undefined at link time #21354

Open

Description

With emcc 3.1.52 (fa47840):

#define _GNU_SOURCE
#include <link.h>
#include <stdio.h>

int
cb(struct dl_phdr_info *info, size_t size, void *data) {
    printf("name: '%s' size: %zu", info->dlpi_name, size);
    return 0;
}

int
main() {
    dl_iterate_phdr(cb, NULL);
    return 0;
}

With gcc it works as expected:

$ gcc -c a.c 
$ gcc a.o 
$ ./a.out
name: '' size: 64
name: 'linux-vdso.so.1' size: 64
name: '/lib/x86_64-linux-gnu/libc.so.6' size: 64
name: '/lib64/ld-linux-x86-64.so.2' size: 64

With emscripten, it compiles successfully but when I try to link it fails:

$ emcc -c a.c -fPIC
$ emcc a.o -sMAIN_MODULE=1
error: undefined symbol: dl_iterate_phdr (referenced by root reference (e.g. compiled C/C++ code))

Activity

  1. sbc100 commented on Feb 15, 2024

    Collaborator

    Indeed we don't support the dl_iterate_phdr API.

    I guess we should consider this as a feature request? Can I ask why your use case is for this function? Does your application have a hard dependency on it?

  2. hoodmane commented on Feb 15, 2024

    CollaboratorAuthor

    They just want the names of the loaded libs. We can work around this with:

    function *libNameIterator() {
       for (a in Module.LDSO.loadedLibsByName) {
          yield a;
       }
    }

    but it means that the user needs to detect Emscripten platform and have custom code on Emscripten compared to on linux, but with dl_iterate_phdr their linux code would just work for Emscripten.

  3. sbc100 commented on Feb 15, 2024

    Collaborator

    Who is "they" in this context? I'm curious where the requirement for getting the names of the loaded libs is coming from?

  4. jeremiedbb commented on Feb 15, 2024

    It's for runtime inspection of the loaded libs. The ones we're interested in particular in threadpoolctl are the libs managing their own threadpool like OpenMP or the different BLAS implementations, but there are other python packages that aim to do a more generic inspection. In fact, threadpoolctl goes beyond just inspection since it provides python bindings to control these threadpools.

  5. lesteve commented on Feb 16, 2024

    Note that this is not only threadpoolctl that cares about this. For example, there is this discussion in the CPython discourse to add a portable way to list the loaded libraries in the stdlib ctypes.util. This discussion mentions that dl_iterate_phdr is used in Python code. see Github search results.

    For now there is a package on PyPI dllist, the github repo is https://github.com/WardBrian/dllist. The implementation is very likely similar to what threadpoolctl does.

  6. hoodmane commented on Feb 16, 2024

    CollaboratorAuthor

    Perhaps we could start by adding an implementation in Pyodide and seeing if we can get it right and then upstream if it works out.

  7. sbc100 commented on Feb 16, 2024

    Collaborator

    Sounds like good argument adding this .. I don't think it should be too hard.

  8. hoodmane commented on Feb 16, 2024

    CollaboratorAuthor

    Should I look into making a PR to emscripten for this @sbc100?

  9. sbc100 commented on Feb 16, 2024

    Collaborator

    That would be great thanks!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions


      Back | FazBrowse Home | New Git URL