-
Notifications
You must be signed in to change notification settings - Fork 14.6k
[libc] Add dlinfo + RTLD_DI_* macros to dlfcn.h #149938
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
base: main
Are you sure you want to change the base?
Conversation
An initial commit for llvm#149911, this adds a stub implementation for dlinfo and the enums list of `RTLD_DI_*` values.
@llvm/pr-subscribers-libc Author: Caslyn Tonelli (Caslyn) ChangesAn initial commit for #149911, this adds a stub implementation for dlinfo and the enums list of Full diff: https://github.com/llvm/llvm-project/pull/149938.diff 4 Files Affected:
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
|
- name: RTLD_DI_PHDR | ||
value: 11 | ||
- name: RTLD_DI_MAX | ||
value: 11 |
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.
I'm wondering if we should add support for standards
to enums
? I also noticed that standards
are defined for the macro definitions above, but seem to be ignored by https://github.com/llvm/llvm-project/blob/main/libc/utils/hdrgen/hdrgen/yaml_to_classes.py#L42-L48
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.
Yes, the intended schema is that every kind of entity can have a standards
list.
It should be mandatory at the top level for the header itself. For each entity of whatever kind inside the header, it should be specified only if it's different from the list for the overall header.
Today, hdrgen doesn't do anything with these. But eventually it will. When we make the header generation more sophisticated then we'll have to do a mass audit to make sure we have all the finer-grained lists right. But I like to keep them maintained now as best we can whenever we touch the YAML files for other reasons, so that we'll have less to fix when we get there.
Since dlinfo
is a GNU extension, all these should be thus marked as well.
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
- name: RTLD_DI_PHDR | ||
value: 11 | ||
- name: RTLD_DI_MAX | ||
value: 11 |
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.
Yes, the intended schema is that every kind of entity can have a standards
list.
It should be mandatory at the top level for the header itself. For each entity of whatever kind inside the header, it should be specified only if it's different from the list for the overall header.
Today, hdrgen doesn't do anything with these. But eventually it will. When we make the header generation more sophisticated then we'll have to do a mass audit to make sure we have all the finer-grained lists right. But I like to keep them maintained now as best we can whenever we touch the YAML files for other reasons, so that we'll have less to fix when we get there.
Since dlinfo
is a GNU extension, all these should be thus marked as well.
@@ -55,3 +80,11 @@ functions: | |||
arguments: | |||
- type: void *__restrict | |||
- type: const char *__restrict | |||
- name: dlinfo | |||
standards: | |||
- GNUExtensions |
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.
gnu
namespace LIBC_NAMESPACE_DECL { | ||
|
||
// TODO: https://github.com/llvm/llvm-project/issues/149911 | ||
LLVM_LIBC_FUNCTION(int, dlinfo, (void *restrict, int, void *restrict)) { |
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.
Use parameter names in the definition.
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.