[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


================
@@ -0,0 +1,37 @@
+//===----------------------------------------------------------------------===//
+//
+// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
+// See https://llvm.org/LICENSE.txt for license information.
+// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
+//
+//===----------------------------------------------------------------------===/
+
+#include "hdr/types/size_t.h"
+#include "src/link/dl_iterate_phdr.h"
+#include "test/UnitTest/Test.h"
+
+int SaveReturn1(struct dl_phdr_info *info, [[maybe_unused]] size_t info_size,
+                void *arg) {
+  *static_cast<void **>(arg) = info;
+  return 1;
+}
+
+TEST(LlvmLibcLinkDlIteratePhdrTest, OnlyExecutable) {
+  struct dl_phdr_info executable_info;
+  EXPECT_EQ(LIBC_NAMESPACE::dl_iterate_phdr(SaveReturn1, &executable_info), 1);
+  int program_header_count = executable_info.dlpi_phnum;
----------------
kaladron wrote:

Since you're testing the return code, perhaps put an int in the arg.  Then you could just return that and combine SaveReturn1 and saveReturn0 to a return_int_arg function.

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


More information about the libc-commits mailing list