Skip to content

Commit 5a076e3

Browse files
authored
[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.
1 parent 07da480 commit 5a076e3

File tree

5 files changed

+80
-0
lines changed

5 files changed

+80
-0
lines changed

libc/include/dlfcn.yaml

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -86,6 +86,8 @@ enums:
8686
standards:
8787
- gnu
8888
value: 11
89+
types:
90+
- type_name: Dl_info
8991
functions:
9092
- name: dlclose
9193
standards:
@@ -120,3 +122,10 @@ functions:
120122
- type: void *__restrict
121123
- type: int
122124
- type: void *__restrict
125+
- name: dladdr
126+
standards:
127+
- POSIX
128+
return_type: int
129+
arguments:
130+
- type: const void *
131+
- type: Dl_info *
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
//===-- Definition of Dl_info type ----------------------------------------===//
2+
//
3+
// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4+
// See https://llvm.org/LICENSE.txt for license information.
5+
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
6+
//
7+
//===----------------------------------------------------------------------===//
8+
9+
#ifndef LLVM_LIBC_TYPES_DL_INFO_H
10+
#define LLVM_LIBC_TYPES_DL_INFO_H
11+
12+
typedef struct {
13+
const char *dli_fname;
14+
void *dli_fbase;
15+
const char *dli_sname;
16+
void *dli_saddr;
17+
} Dl_info;
18+
19+
#endif // LLVM_LIBC_TYPES_DL_INFO_H

libc/src/dlfcn/CMakeLists.txt

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -49,3 +49,14 @@ add_entrypoint_object(
4949
libc.include.dlfcn
5050
libc.src.errno.errno
5151
)
52+
53+
add_entrypoint_object(
54+
dladdr
55+
SRCS
56+
dladdr.cpp
57+
HDRS
58+
dladdr.h
59+
DEPENDS
60+
libc.include.dlfcn
61+
libc.src.errno.errno
62+
)

libc/src/dlfcn/dladdr.cpp

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
//===-- Implementation of dladdr ------------------------------------------===//
2+
//
3+
// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4+
// See https://llvm.org/LICENSE.txt for license information.
5+
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
6+
//
7+
//===----------------------------------------------------------------------===//
8+
9+
#include "dladdr.h"
10+
11+
#include "src/__support/common.h"
12+
#include "src/__support/macros/config.h"
13+
14+
namespace LIBC_NAMESPACE_DECL {
15+
16+
// TODO: https:// github.com/llvm/llvm-project/issues/97929
17+
LLVM_LIBC_FUNCTION(int, dladdr, (const void *addr, Dl_info *info)) {
18+
return -1;
19+
}
20+
21+
} // namespace LIBC_NAMESPACE_DECL

libc/src/dlfcn/dladdr.h

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
//===-- Implementation header of dladdr -------------------------*- C++ -*-===//
2+
//
3+
// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4+
// See https://llvm.org/LICENSE.txt for license information.
5+
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
6+
//
7+
//===----------------------------------------------------------------------===//
8+
9+
#ifndef LLVM_LIBC_SRC_DLFCN_DLADDR_H
10+
#define LLVM_LIBC_SRC_DLFCN_DLADDR_H
11+
12+
#include "src/__support/macros/config.h"
13+
14+
namespace LIBC_NAMESPACE_DECL {
15+
16+
int dladdr(const void *, Dl_info *);
17+
18+
} // namespace LIBC_NAMESPACE_DECL
19+
20+
#endif // LLVM_LIBC_SRC_DLFCN_DLADDR_H

0 commit comments

Comments
 (0)