[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;
+ executable_info.dlpi_phdr = reinterpret_cast<ElfW(Phdr) *>(
+ reinterpret_cast<uintptr_t>(executable_header) +
+ executable_header->e_phoff);
+ executable_info.dlpi_phnum = executable_header->e_phnum;
+ executable_info.dlpi_adds = 0;
+ executable_info.dlpi_subs = 0;
+ executable_info.dlpi_tls_modid = 0;
+ executable_info.dlpi_tls_data = nullptr;
+ int executable_return_code =
+ callback(&executable_info, sizeof(executable_info), arg);
+ if (executable_return_code != 0)
+ return executable_return_code;
+
+ cpp::optional<unsigned long> vdso_start_address =
+ LIBC_NAMESPACE::auxv::get(AT_SYSINFO_EHDR);
----------------
kaladron wrote:
```suggestion
auxv::get(AT_SYSINFO_EHDR);
```
https://github.com/llvm/llvm-project/pull/194196
More information about the libc-commits
mailing list