[libc-commits] [libc] [libc] Add barebones dl_iterate_phdr implementation (PR #194196)

Jeff Bailey via libc-commits libc-commits at lists.llvm.org
Sun Apr 26 01:18:05 PDT 2026


================
@@ -8,18 +8,61 @@
 
 #include "dl_iterate_phdr.h"
 
+#include "llvm-libc-macros/link-macros.h"
+#include "src/__support/OSUtil/linux/auxv.h"
 #include "src/__support/common.h"
 #include "src/__support/macros/config.h"
 
+#include <elf.h>
+
+extern "C" void *__executable_start;
+
 namespace LIBC_NAMESPACE_DECL {
 
 LLVM_LIBC_FUNCTION(int, dl_iterate_phdr,
                    (__dl_iterate_phdr_callback_t callback, void *arg)) {
-  // FIXME: For pure static linking, this can report just the executable with
-  // info from __ehdr_start or AT_{PHDR,PHNUM} decoding, and its PT_TLS; and it
-  // could report the vDSO.
-  (void)callback, (void)arg;
-  return 0;
+  ElfW(Ehdr) *executable_header =
+      reinterpret_cast<ElfW(Ehdr) *>(&__executable_start);
+  struct dl_phdr_info executable_info;
+  executable_info.dlpi_addr = 0;
+  executable_info.dlpi_name = nullptr;
----------------
kaladron wrote:

The man page says this:

> The first object visited by callback is the main program.  For the main program, the dlpi_name field will be an empty string.

And the example they give is a printf.  That suggests to me that for a stub implementation we should probably do "" instead for now.

https://github.com/llvm/llvm-project/pull/194196


More information about the libc-commits mailing list