[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;
----------------
kaladron wrote:

Since we have to do this twice and potential have to do some calculations for dlpi_addr, I'm wondering if a factory object is worth it here.  Probably not, since it's only twice.  But if it grows too much logic there's a risk that someone fixes one site and not the other.

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


More information about the libc-commits mailing list