Skip to content

Conversation

@Caslyn
Copy link
Contributor

@Caslyn Caslyn commented Jul 21, 2025

An initial commit for #149911, this adds a stub implementation for dlinfo and the enums list of RTLD_DI_* values.

While the dlinfo implementation relies on dynamic linker support, this patch will add its prototype in the generated dlfcn.h header so that it can be used by downstream platforms that have their own dlinfo implementation.

An initial commit for llvm#149911, this adds a stub implementation for
dlinfo and the enums list of `RTLD_DI_*` values.
@Caslyn Caslyn self-assigned this Jul 21, 2025
@Caslyn Caslyn added the libc label Jul 21, 2025
@llvmbot
Copy link
Member

llvmbot commented Jul 21, 2025

@llvm/pr-subscribers-libc

Author: Caslyn Tonelli (Caslyn)

Changes

An initial commit for #149911, this adds a stub implementation for dlinfo and the enums list of RTLD_DI_* values.


Full diff: https://github.com/llvm/llvm-project/pull/149938.diff

4 Files Affected:

  • (modified) libc/include/dlfcn.yaml (+31)
  • (modified) libc/src/dlfcn/CMakeLists.txt (+11)
  • (added) libc/src/dlfcn/dlinfo.cpp (+22)
  • (added) libc/src/dlfcn/dlinfo.h (+20)
diff --git a/libc/include/dlfcn.yaml b/libc/include/dlfcn.yaml
index 28be34dbd95bd..275279afb48d2 100644
--- a/libc/include/dlfcn.yaml
+++ b/libc/include/dlfcn.yaml
@@ -29,6 +29,29 @@ macros:
     standards:
       - gnu
     macro_value: "0x01000"
+enums:
+  - name: RTLD_DI_LMID
+    value: 1
+  - name: RTLD_DI_LINKMAP
+    value: 2
+  - name: RTLD_DI_CONFIGADDR,
+    value: 3
+  - name: RTLD_DI_SERINFO
+    value: 4
+  - name: RTLD_DI_SERINFOSIZE
+    value: 5
+  - name: RTLD_DI_ORIGIN
+    value: 6
+  - name: RTLD_DI_PROFILENAME
+    value: 7
+  - name: RTLD_DI_PROFILEOUT
+    value: 8
+  - name: RTLD_DI_TLSMODID
+    value: 9
+  - name: RTLD_DI_TLS_DATA
+    value: 10
+  - name: RTLD_DI_PHDR
+    value: 11
 functions:
   - name: dlclose
     standards:
@@ -55,3 +78,11 @@ functions:
     arguments:
       - type: void *__restrict
       - type: const char *__restrict
+  - name: dlinfo
+    standards:
+      - GNUExtensions
+    return_type: int
+    arguments:
+      - type: void *__restrict
+      - type: int
+      - type: void *__restrict
diff --git a/libc/src/dlfcn/CMakeLists.txt b/libc/src/dlfcn/CMakeLists.txt
index e3a51ba65764d..1ee05fc380c94 100644
--- a/libc/src/dlfcn/CMakeLists.txt
+++ b/libc/src/dlfcn/CMakeLists.txt
@@ -38,3 +38,14 @@ add_entrypoint_object(
     libc.include.dlfcn
     libc.src.errno.errno
 )
+
+add_entrypoint_object(
+  dlinfo
+  SRCS
+    dlinfo.cpp
+  HDRS
+    dlinfo.h
+  DEPENDS
+    libc.include.dlfcn
+    libc.src.errno.errno
+)
diff --git a/libc/src/dlfcn/dlinfo.cpp b/libc/src/dlfcn/dlinfo.cpp
new file mode 100644
index 0000000000000..7dae9592a9d90
--- /dev/null
+++ b/libc/src/dlfcn/dlinfo.cpp
@@ -0,0 +1,22 @@
+
+//===-- Implementation of dlinfo ------------------------------------------===//
+//
+// 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 "dlinfo.h"
+
+#include "src/__support/common.h"
+#include "src/__support/macros/config.h"
+
+namespace LIBC_NAMESPACE_DECL {
+
+// TODO: https://github.com/llvm/llvm-project/issues/149911
+LLVM_LIBC_FUNCTION(int, dlinfo, (void *restrict, int, void *restrict)) {
+  return -1;
+}
+
+} // namespace LIBC_NAMESPACE_DECL
diff --git a/libc/src/dlfcn/dlinfo.h b/libc/src/dlfcn/dlinfo.h
new file mode 100644
index 0000000000000..c2c34f02bd6f1
--- /dev/null
+++ b/libc/src/dlfcn/dlinfo.h
@@ -0,0 +1,20 @@
+//===-- Implementation header of dlinfo -------------------------*- C++ -*-===//
+//
+// 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
+//
+//===----------------------------------------------------------------------===//
+
+#ifndef LLVM_LIBC_SRC_DLFCN_DLINFO_H
+#define LLVM_LIBC_SRC_DLFCN_DLINFO_H
+
+#include "src/__support/macros/config.h"
+
+namespace LIBC_NAMESPACE_DECL {
+
+int dlinfo(void *restrict, int, void *restrict);
+
+} // namespace LIBC_NAMESPACE_DECL
+
+#endif // LLVM_LIBC_SRC_DLFCN_DLINFO_H

Copy link
Contributor

@frobtech frobtech left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

lgtm

@Caslyn Caslyn merged commit cfd1ee7 into llvm:main Aug 5, 2025
19 checks passed
@Caslyn Caslyn deleted the libc-dlinfo branch August 5, 2025 20:34
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants