[libc-commits] [libc] [libc] Add dladdr to dlfcn.h (PR #149872)
Caslyn Tonelli via libc-commits
libc-commits at lists.llvm.org
Tue Aug 5 14:26:35 PDT 2025
https://github.com/Caslyn updated https://github.com/llvm/llvm-project/pull/149872
>From 948a56466e4ad0c7d2fc72fc5133c119b933f9a0 Mon Sep 17 00:00:00 2001
From: Caslyn Tonelli <caslyn at google.com>
Date: Fri, 18 Jul 2025 14:17:13 -0700
Subject: [PATCH 1/7] [libc] Add dladdr to dlfcn.h
Related to #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.
---
libc/include/dlfcn.yaml | 9 +++++++++
libc/include/llvm-libc-types/DL_info.h | 19 +++++++++++++++++++
libc/src/dlfcn/dladdr.cpp | 19 +++++++++++++++++++
libc/src/dlfcn/dladdr.h | 20 ++++++++++++++++++++
4 files changed, 67 insertions(+)
create mode 100644 libc/include/llvm-libc-types/DL_info.h
create mode 100644 libc/src/dlfcn/dladdr.cpp
create mode 100644 libc/src/dlfcn/dladdr.h
diff --git a/libc/include/dlfcn.yaml b/libc/include/dlfcn.yaml
index 28be34dbd95bd..ea4de6860e7ba 100644
--- a/libc/include/dlfcn.yaml
+++ b/libc/include/dlfcn.yaml
@@ -29,6 +29,8 @@ macros:
standards:
- gnu
macro_value: "0x01000"
+types:
+ - type_name: DL_info
functions:
- name: dlclose
standards:
@@ -55,3 +57,10 @@ functions:
arguments:
- type: void *__restrict
- type: const char *__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..08dcba2c2945f
--- /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/dladdr.cpp b/libc/src/dlfcn/dladdr.cpp
new file mode 100644
index 0000000000000..faaefcf161b54
--- /dev/null
+++ b/libc/src/dlfcn/dladdr.cpp
@@ -0,0 +1,19 @@
+//===-- 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 *, DL_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..a5f38973b7c02
--- /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
>From e6c784b99c86af05068a4195295e3f0705c30430 Mon Sep 17 00:00:00 2001
From: Caslyn Tonelli <caslyn at google.com>
Date: Mon, 21 Jul 2025 13:06:42 -0700
Subject: [PATCH 2/7] mark dladdr as GNUExtensions
---
libc/include/dlfcn.yaml | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/libc/include/dlfcn.yaml b/libc/include/dlfcn.yaml
index ea4de6860e7ba..8e77d688e898c 100644
--- a/libc/include/dlfcn.yaml
+++ b/libc/include/dlfcn.yaml
@@ -59,7 +59,7 @@ functions:
- type: const char *__restrict
- name: dladdr
standards:
- - POSIX
+ - GNUExtensions
return_type: int
arguments:
- type: const void *
>From eb15542b92b6fbe4816437a2148ad8907ac20dcb Mon Sep 17 00:00:00 2001
From: Caslyn Tonelli <caslyn at google.com>
Date: Mon, 21 Jul 2025 15:10:42 -0700
Subject: [PATCH 3/7] add cmake entry point
---
libc/src/dlfcn/CMakeLists.txt | 11 +++++++++++
1 file changed, 11 insertions(+)
diff --git a/libc/src/dlfcn/CMakeLists.txt b/libc/src/dlfcn/CMakeLists.txt
index e3a51ba65764d..6df4c5c8d8f4e 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(
+ dladdr
+ SRCS
+ dladdr.cpp
+ HDRS
+ dladdr.h
+ DEPENDS
+ libc.include.dlfcn
+ libc.src.errno.errno
+)
>From 469e8d521b22450ac57a40baaea76bfa740eb10d Mon Sep 17 00:00:00 2001
From: Caslyn Tonelli <caslyn at google.com>
Date: Tue, 22 Jul 2025 14:59:30 -0700
Subject: [PATCH 4/7] fix: dladdr is part of the posix standard
---
libc/include/dlfcn.yaml | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/libc/include/dlfcn.yaml b/libc/include/dlfcn.yaml
index 8e77d688e898c..ea4de6860e7ba 100644
--- a/libc/include/dlfcn.yaml
+++ b/libc/include/dlfcn.yaml
@@ -59,7 +59,7 @@ functions:
- type: const char *__restrict
- name: dladdr
standards:
- - GNUExtensions
+ - POSIX
return_type: int
arguments:
- type: const void *
>From 957d02748771c8ee3ed03187a9dc8a7564f3bd04 Mon Sep 17 00:00:00 2001
From: Caslyn Tonelli <caslyn at google.com>
Date: Mon, 4 Aug 2025 16:59:13 -0700
Subject: [PATCH 5/7] correct DL_info -> Dl_info
---
libc/include/dlfcn.yaml | 4 ++--
libc/include/llvm-libc-types/{DL_info.h => Dl_info.h} | 10 +++++-----
libc/src/dlfcn/dladdr.cpp | 2 +-
libc/src/dlfcn/dladdr.h | 2 +-
4 files changed, 9 insertions(+), 9 deletions(-)
rename libc/include/llvm-libc-types/{DL_info.h => Dl_info.h} (69%)
diff --git a/libc/include/dlfcn.yaml b/libc/include/dlfcn.yaml
index ea4de6860e7ba..514075b444556 100644
--- a/libc/include/dlfcn.yaml
+++ b/libc/include/dlfcn.yaml
@@ -30,7 +30,7 @@ macros:
- gnu
macro_value: "0x01000"
types:
- - type_name: DL_info
+ - type_name: Dl_info
functions:
- name: dlclose
standards:
@@ -63,4 +63,4 @@ functions:
return_type: int
arguments:
- type: const void *
- - type: DL_info *
+ - type: Dl_info *
diff --git a/libc/include/llvm-libc-types/DL_info.h b/libc/include/llvm-libc-types/Dl_info.h
similarity index 69%
rename from libc/include/llvm-libc-types/DL_info.h
rename to libc/include/llvm-libc-types/Dl_info.h
index 08dcba2c2945f..5a0c473b5cfc6 100644
--- a/libc/include/llvm-libc-types/DL_info.h
+++ b/libc/include/llvm-libc-types/Dl_info.h
@@ -1,4 +1,4 @@
-//===-- Definition of DL_info type ----------------------------------------===//
+//===-- 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.
@@ -6,14 +6,14 @@
//
//===----------------------------------------------------------------------===//
-#ifndef LLVM_LIBC_TYPES_DL_INFO_H
-#define LLVM_LIBC_TYPES_DL_INFO_H
+#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;
+} Dl_info;
-#endif // LLVM_LIBC_TYPES_DL_INFO_H
+#endif // LLVM_LIBC_TYPES_Dl_INFO_H
diff --git a/libc/src/dlfcn/dladdr.cpp b/libc/src/dlfcn/dladdr.cpp
index faaefcf161b54..41c81c6ecae3d 100644
--- a/libc/src/dlfcn/dladdr.cpp
+++ b/libc/src/dlfcn/dladdr.cpp
@@ -14,6 +14,6 @@
namespace LIBC_NAMESPACE_DECL {
// TODO: https:// github.com/llvm/llvm-project/issues/97929
-LLVM_LIBC_FUNCTION(int, dladdr, (const void *, DL_info *)) { return -1; }
+LLVM_LIBC_FUNCTION(int, dladdr, (const void *, Dl_info *)) { return -1; }
} // namespace LIBC_NAMESPACE_DECL
diff --git a/libc/src/dlfcn/dladdr.h b/libc/src/dlfcn/dladdr.h
index a5f38973b7c02..346fc8dc27aed 100644
--- a/libc/src/dlfcn/dladdr.h
+++ b/libc/src/dlfcn/dladdr.h
@@ -13,7 +13,7 @@
namespace LIBC_NAMESPACE_DECL {
-int dladdr(const void *, DL_info *);
+int dladdr(const void *, Dl_info *);
} // namespace LIBC_NAMESPACE_DECL
>From 5814816bb7229e3b13475ea957b2ff7f8b023f37 Mon Sep 17 00:00:00 2001
From: Caslyn Tonelli <caslyn at google.com>
Date: Mon, 4 Aug 2025 17:12:16 -0700
Subject: [PATCH 6/7] correct header guard
---
libc/include/llvm-libc-types/Dl_info.h | 6 +++---
1 file changed, 3 insertions(+), 3 deletions(-)
diff --git a/libc/include/llvm-libc-types/Dl_info.h b/libc/include/llvm-libc-types/Dl_info.h
index 5a0c473b5cfc6..b082e30549a02 100644
--- a/libc/include/llvm-libc-types/Dl_info.h
+++ b/libc/include/llvm-libc-types/Dl_info.h
@@ -6,8 +6,8 @@
//
//===----------------------------------------------------------------------===//
-#ifndef LLVM_LIBC_TYPES_Dl_INFO_H
-#define LLVM_LIBC_TYPES_Dl_INFO_H
+#ifndef LLVM_LIBC_TYPES_DL_INFO_H
+#define LLVM_LIBC_TYPES_DL_INFO_H
typedef struct {
const char *dli_fname;
@@ -16,4 +16,4 @@ typedef struct {
void *dli_saddr;
} Dl_info;
-#endif // LLVM_LIBC_TYPES_Dl_INFO_H
+#endif // LLVM_LIBC_TYPES_DL_INFO_H
>From 5174987a25fb84f7e34cdea663165c0e8f18fdff Mon Sep 17 00:00:00 2001
From: Caslyn Tonelli <caslyn at google.com>
Date: Tue, 5 Aug 2025 10:42:01 -0700
Subject: [PATCH 7/7] add parameter names in definition
---
libc/src/dlfcn/dladdr.cpp | 4 +++-
1 file changed, 3 insertions(+), 1 deletion(-)
diff --git a/libc/src/dlfcn/dladdr.cpp b/libc/src/dlfcn/dladdr.cpp
index 41c81c6ecae3d..61490fd9a64b5 100644
--- a/libc/src/dlfcn/dladdr.cpp
+++ b/libc/src/dlfcn/dladdr.cpp
@@ -14,6 +14,8 @@
namespace LIBC_NAMESPACE_DECL {
// TODO: https:// github.com/llvm/llvm-project/issues/97929
-LLVM_LIBC_FUNCTION(int, dladdr, (const void *, Dl_info *)) { return -1; }
+LLVM_LIBC_FUNCTION(int, dladdr, (const void *addr, Dl_info *info)) {
+ return -1;
+}
} // namespace LIBC_NAMESPACE_DECL
More information about the libc-commits
mailing list