public inbox for libc-help@sourceware.org
 help / color / mirror / Atom feed
* Asking for consideration behind making RTLD_DI_SERINFOSIZE request twice
@ 2023-04-12 15:50 Qixing Xue
  0 siblings, 0 replies; only message in thread
From: Qixing Xue @ 2023-04-12 15:50 UTC (permalink / raw)
  To: libc-help

[-- Attachment #1: Type: text/plain, Size: 1754 bytes --]

Hi,

Recently I am working with dlinfo and from my understanding of the use of RTLD_DI_SERINFO in [dlinfo](https://man7.org/linux/man-pages/man3/dlinfo.3.html), the first call gives dls_size value that helps ensure the struct is large enough, but the second call is seemly doing nothing new but repeating computation of first call to fill out the two fields dls_size and dls_cnt. Besides, from the [code called](https://elixir.bootlin.com/glibc/glibc-2.37.9000/source/elf/dl-load.c#L2298) by the dlopen [interface](https://elixir.bootlin.com/glibc/glibc-2.37.9000/source/dlfcn/dlinfo.c#L63), I am unable to locate some code distinguishing the two calls and therefore my question is whether this two-step call sequence is something really necessary, or is it already enough to just copy over the stats like cnt and size, through, for example, having a new request item called RTLD_DI_SERINFOSIZE_COPY to provide some forward compatibility from library authors’ viewpoint. As a running example, the following code prints two exact same line on my machine.

```c
  Dl_serinfo dl_search_size;
  if (dlinfo(dl_handle, RTLD_DI_SERINFOSIZE, &dl_search_size)) {
    printf("dlinfo: %s while populating search info size", dlerror());
    return;
  }
  printf("%d %ld\n", dl_search_size.dls_cnt, dl_search_size.dls_size);
  Dl_serinfo *dl_search_info = (Dl_serinfo *)malloc(dl_search_size.dls_size);
  if (!dl_search_info) {
    perror("malloc");
    return;
  }
  if (dlinfo(dl_handle, RTLD_DI_SERINFOSIZE, dl_search_info)) {
    printf("dlinfo: %s while ", dlerror());
    return;
  }
  printf("%d %ld\n", dl_search_info->dls_cnt, dl_search_info->dls_size);
```

Thanks a lot for your attention and hope you a great day.

Best,
Qixing

^ permalink raw reply	[flat|nested] only message in thread

only message in thread, other threads:[~2023-04-12 15:51 UTC | newest]

Thread overview: (only message) (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2023-04-12 15:50 Asking for consideration behind making RTLD_DI_SERINFOSIZE request twice Qixing Xue

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).