[libc-commits] [libc] 5a076e3 - [libc] Add dladdr to dlfcn.h (#149872)

via libc-commits libc-commits at lists.llvm.org
Tue Aug 5 15:06:12 PDT 2025


Author: Caslyn Tonelli
Date: 2025-08-05T15:06:08-07:00
New Revision: 5a076e3b4d5ec26d8944bff129c1cae67a44b3ef

URL: https://github.com/llvm/llvm-project/commit/5a076e3b4d5ec26d8944bff129c1cae67a44b3ef
DIFF: https://github.com/llvm/llvm-project/commit/5a076e3b4d5ec26d8944bff129c1cae67a44b3ef.diff

LOG: [libc] Add dladdr to dlfcn.h (#149872)

A initial commit for #97929, this adds a stub implementation for
`dladdr` and includes the definition for the `DL_info` type used as one
of its arguments.

While the `dladdr` 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 `dladdr`
implementation.

Added: 
    libc/include/llvm-libc-types/Dl_info.h
    libc/src/dlfcn/dladdr.cpp
    libc/src/dlfcn/dladdr.h

Modified: 
    libc/include/dlfcn.yaml
    libc/src/dlfcn/CMakeLists.txt

Removed: 
    


################################################################################
diff  --git a/libc/include/dlfcn.yaml b/libc/include/dlfcn.yaml
index a8218b6780c2c..db2893aaff5d9 100644
--- a/libc/include/dlfcn.yaml
+++ b/libc/include/dlfcn.yaml
@@ -86,6 +86,8 @@ enums:
     standards:
       - gnu
     value: 11
+types:
+  - type_name: Dl_info
 functions:
   - name: dlclose
     standards:
@@ -120,3 +122,10 @@ functions:
       - type: void *__restrict
       - type: int
       - type: void *__restrict
+  - name: dladdr
+    standards:
+      - POSIX
+    return_type: int
+    arguments:
+      - type: const void *
+      - type: Dl_info *

diff  --git a/libc/include/llvm-libc-types/Dl_info.h b/libc/include/llvm-libc-types/Dl_info.h
new file mode 100644
index 0000000000000..b082e30549a02
--- /dev/null
+++ b/libc/include/llvm-libc-types/Dl_info.h
@@ -0,0 +1,19 @@
+//===-- Definition of Dl_info type ----------------------------------------===//
+//
+// 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_TYPES_DL_INFO_H
+#define LLVM_LIBC_TYPES_DL_INFO_H
+
+typedef struct {
+  const char *dli_fname;
+  void *dli_fbase;
+  const char *dli_sname;
+  void *dli_saddr;
+} Dl_info;
+
+#endif // LLVM_LIBC_TYPES_DL_INFO_H

diff  --git a/libc/src/dlfcn/CMakeLists.txt b/libc/src/dlfcn/CMakeLists.txt
index 1ee05fc380c94..8ef0540c01a2e 100644
--- a/libc/src/dlfcn/CMakeLists.txt
+++ b/libc/src/dlfcn/CMakeLists.txt
@@ -49,3 +49,14 @@ add_entrypoint_object(
     libc.include.dlfcn
     libc.src.errno.errno
 )
+
+add_entrypoint_object(
+  dladdr
+  SRCS
+    dladdr.cpp
+  HDRS
+    dladdr.h
+  DEPENDS
+    libc.include.dlfcn
+    libc.src.errno.errno
+)

diff  --git a/libc/src/dlfcn/dladdr.cpp b/libc/src/dlfcn/dladdr.cpp
new file mode 100644
index 0000000000000..61490fd9a64b5
--- /dev/null
+++ b/libc/src/dlfcn/dladdr.cpp
@@ -0,0 +1,21 @@
+//===-- Implementation of dladdr ------------------------------------------===//
+//
+// 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 "dladdr.h"
+
+#include "src/__support/common.h"
+#include "src/__support/macros/config.h"
+
+namespace LIBC_NAMESPACE_DECL {
+
+// TODO: https:// github.com/llvm/llvm-project/issues/97929
+LLVM_LIBC_FUNCTION(int, dladdr, (const void *addr, Dl_info *info)) {
+  return -1;
+}
+
+} // namespace LIBC_NAMESPACE_DECL

diff  --git a/libc/src/dlfcn/dladdr.h b/libc/src/dlfcn/dladdr.h
new file mode 100644
index 0000000000000..346fc8dc27aed
--- /dev/null
+++ b/libc/src/dlfcn/dladdr.h
@@ -0,0 +1,20 @@
+//===-- Implementation header of dladdr -------------------------*- 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_DLADDR_H
+#define LLVM_LIBC_SRC_DLFCN_DLADDR_H
+
+#include "src/__support/macros/config.h"
+
+namespace LIBC_NAMESPACE_DECL {
+
+int dladdr(const void *, Dl_info *);
+
+} // namespace LIBC_NAMESPACE_DECL
+
+#endif // LLVM_LIBC_SRC_DLFCN_DLADDR_H


        


More information about the libc-commits mailing list