-
Notifications
You must be signed in to change notification settings - Fork 14.7k
[libc] Add dladdr to dlfcn.h #149872
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[libc] Add dladdr to dlfcn.h #149872
Conversation
Related to llvm#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.
@llvm/pr-subscribers-libc Author: Caslyn Tonelli (Caslyn) ChangesA initial commit for #97929, this adds a stub implementation for While the Full diff: https://github.com/llvm/llvm-project/pull/149872.diff 4 Files Affected:
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
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
lgtm with the correct identifier names.
A initial commit for #97929, this adds a stub implementation for
dladdr
and includes the definition for theDL_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 generateddlfcn.h
header so that it can be used by downstream platforms that have their owndladdr
implementation.