[libc-commits] [libc] [WIP][libc] Add dladdr1 to dlfcn.h (PR #149896)
Caslyn Tonelli via libc-commits
libc-commits at lists.llvm.org
Mon Jul 21 13:55:34 PDT 2025
https://github.com/Caslyn updated https://github.com/llvm/llvm-project/pull/149896
>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/4] [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/4] 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 333315fdee30e0b2c180f262404ceb568fd8519f Mon Sep 17 00:00:00 2001
From: Caslyn Tonelli <caslyn at google.com>
Date: Mon, 21 Jul 2025 13:25:41 -0700
Subject: [PATCH 3/4] [libc] Add dladdr1 to dlfcn.h
---
libc/include/dlfcn.yaml | 10 ++++++++++
libc/src/dlfcn/dladdr.cpp | 5 +++++
libc/src/dlfcn/dladdr.h | 2 ++
3 files changed, 17 insertions(+)
diff --git a/libc/include/dlfcn.yaml b/libc/include/dlfcn.yaml
index 8e77d688e898c..fb610b6035c03 100644
--- a/libc/include/dlfcn.yaml
+++ b/libc/include/dlfcn.yaml
@@ -64,3 +64,13 @@ functions:
arguments:
- type: const void *
- type: DL_info *
+ - name: dladdr1
+ standards:
+ - GNUExtensions
+ return_type: int
+ arguments:
+ - type: const void *
+ - type: DL_info *
+ - type: void **
+ - type: int
+
diff --git a/libc/src/dlfcn/dladdr.cpp b/libc/src/dlfcn/dladdr.cpp
index faaefcf161b54..3f0e1b36895fe 100644
--- a/libc/src/dlfcn/dladdr.cpp
+++ b/libc/src/dlfcn/dladdr.cpp
@@ -16,4 +16,9 @@ namespace LIBC_NAMESPACE_DECL {
// TODO: https:// github.com/llvm/llvm-project/issues/97929
LLVM_LIBC_FUNCTION(int, dladdr, (const void *, DL_info *)) { return -1; }
+// TODO: https:// github.com/llvm/llvm-project/issues/97929
+LLVM_LIBC_FUNCTION(int, dladdr1, (const void *, DL_info *, void **, int)) {
+ return -1;
+}
+
} // namespace LIBC_NAMESPACE_DECL
diff --git a/libc/src/dlfcn/dladdr.h b/libc/src/dlfcn/dladdr.h
index a5f38973b7c02..07a64c761d758 100644
--- a/libc/src/dlfcn/dladdr.h
+++ b/libc/src/dlfcn/dladdr.h
@@ -15,6 +15,8 @@ namespace LIBC_NAMESPACE_DECL {
int dladdr(const void *, DL_info *);
+int dladdr1(const void *, DL_info *, void **, int);
+
} // namespace LIBC_NAMESPACE_DECL
#endif // LLVM_LIBC_SRC_DLFCN_DLADDR_H
>From d9791ba21d2172b73fb61c09d31524cd75bc5a3c Mon Sep 17 00:00:00 2001
From: Caslyn Tonelli <caslyn at google.com>
Date: Mon, 21 Jul 2025 13:55:19 -0700
Subject: [PATCH 4/4] add RTLD_DL_* macros specific to dladdr1
---
libc/include/dlfcn.yaml | 5 +++++
1 file changed, 5 insertions(+)
diff --git a/libc/include/dlfcn.yaml b/libc/include/dlfcn.yaml
index fb610b6035c03..75242fecef347 100644
--- a/libc/include/dlfcn.yaml
+++ b/libc/include/dlfcn.yaml
@@ -29,6 +29,11 @@ macros:
standards:
- gnu
macro_value: "0x01000"
+enums:
+ - name: RTLD_DL_SYMENT
+ value: 1
+ - name: RTLD_DL_LINKMAP
+ value: 2
types:
- type_name: DL_info
functions:
More information about the libc-commits
mailing list