Skip to content

Commit 0a3fbc2

Browse files
[libc] add dl_iterate_phdr and dladdr
1 parent 6e8a1a4 commit 0a3fbc2

File tree

15 files changed

+197
-3
lines changed

15 files changed

+197
-3
lines changed

libc/config/linux/aarch64/entrypoints.txt

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,11 +18,15 @@ set(TARGET_LIBC_ENTRYPOINTS
1818
libc.src.ctype.toupper
1919

2020
# dlfcn.h entrypoints
21+
libc.src.dlfcn.dladdr
2122
libc.src.dlfcn.dlclose
2223
libc.src.dlfcn.dlerror
2324
libc.src.dlfcn.dlopen
2425
libc.src.dlfcn.dlsym
2526

27+
# link.h entrypoints
28+
libc.src.link.dl_iterate_phdr
29+
2630
# errno.h entrypoints
2731
libc.src.errno.errno
2832

libc/hdrgen/yaml/dlfcn.yaml

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,8 @@ macros:
88
macro_value: null
99
- macro_name: RTLD_LOCAL
1010
macro_value: null
11-
types: []
11+
types:
12+
- type_name: Dl_info
1213
enums: []
1314
objects: []
1415
functions:
@@ -37,3 +38,10 @@ functions:
3738
arguments:
3839
- type: void *__restrict
3940
- type: const char *__restrict
41+
- name: dladdr
42+
standards:
43+
- GNUExtensions
44+
return_type: int
45+
arguments:
46+
- type: const void *
47+
- type: Dl_info *

libc/hdrgen/yaml/link.yaml

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,16 @@ header: link.h
22
standards:
33
- Linux
44
macros: []
5-
types: []
5+
types:
6+
- type_name: struct_dl_phdr_info
7+
- type_name: __dl_iterate_phdr_callback_t
68
enums: []
79
objects: []
8-
functions: []
10+
functions:
11+
- name: dl_iterate_phdr
12+
standards:
13+
- Linux
14+
return_type: int
15+
arguments:
16+
- type: __dl_iterate_phdr_callback_t
17+
- type: void *

libc/include/CMakeLists.txt

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -75,6 +75,7 @@ add_header_macro(
7575
dlfcn.h
7676
DEPENDS
7777
.llvm-libc-macros.dlfcn_macros
78+
.llvm-libc-types.Dl_info
7879
.llvm_libc_common_h
7980
)
8081

@@ -444,6 +445,8 @@ add_header_macro(
444445
link.h
445446
DEPENDS
446447
.llvm_libc_common_h
448+
.llvm-libc-types.__dl_iterate_phdr_callback_t
449+
.llvm-libc-types.struct_dl_phdr_info
447450
.llvm-libc-macros.link_macros
448451
)
449452

libc/include/llvm-libc-types/CMakeLists.txt

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
add_header(Dl_info HDR Dl_info.h)
12
add_header(off64_t HDR off64_t.h)
23
add_header(size_t HDR size_t.h)
34
add_header(ssize_t HDR ssize_t.h)
@@ -67,6 +68,8 @@ else()
6768
endif()
6869
add_header(stack_t HDR stack_t.h DEPENDS .size_t)
6970
add_header(suseconds_t HDR suseconds_t.h)
71+
add_header(struct_dl_phdr_info HDR struct_dl_phdr_info.h DEPENDS .size_t libc.include.llvm-libc-macros.link_macros)
72+
add_header(__dl_iterate_phdr_callback_t HDR __dl_iterate_phdr_callback_t.h DEPENDS .size_t .struct_dl_phdr_info)
7073
add_header(struct_flock HDR struct_flock.h DEPENDS .off_t .pid_t)
7174
add_header(struct_flock64 HDR struct_flock64.h DEPENDS .off64_t .pid_t)
7275
add_header(struct_f_owner_ex HDR struct_f_owner_ex.h DEPENDS .pid_t)
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
Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
//===-- Definition of type __dl_iterate_phdr_callback_t -------------------===//
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_ITERATE_PHDR_CALLBACK_T_H
10+
#define LLVM_LIBC_TYPES___DL_ITERATE_PHDR_CALLBACK_T_H
11+
12+
#include "size_t.h"
13+
#include "struct_dl_phdr_info.h"
14+
15+
typedef int (*__dl_iterate_phdr_callback_t)(struct dl_phdr_info *, size_t,
16+
void *);
17+
18+
#endif // LLVM_LIBC_TYPES___DL_ITERATE_PHDR_CALLBACK_T_H
Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
//===-- Definition of type struct dl_phdr_info ----------------------------===//
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_STRUCT_DL_PHDR_INFO_H
10+
#define LLVM_LIBC_TYPES_STRUCT_DL_PHDR_INFO_H
11+
12+
#include "../llvm-libc-macros/link-macros.h"
13+
#include "size_t.h"
14+
15+
struct dl_phdr_info {
16+
ElfW(Addr) dlpi_addr;
17+
const char *dlpi_name;
18+
const ElfW(Phdr) * dlpi_phdr;
19+
ElfW(Half) dlpi_phnum;
20+
unsigned long long dlpi_adds;
21+
unsigned long long dlpi_subs;
22+
size_t dlpi_tls_modid;
23+
void *dlpi_tls_data;
24+
};
25+
26+
#endif // LLVM_LIBC_TYPES_STRUCT_DL_PHDR_INFO_H

libc/src/CMakeLists.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ add_subdirectory(dlfcn)
66
add_subdirectory(errno)
77
add_subdirectory(fenv)
88
add_subdirectory(inttypes)
9+
add_subdirectory(link)
910
add_subdirectory(math)
1011
add_subdirectory(stdbit)
1112
add_subdirectory(stdfix)

libc/src/dlfcn/CMakeLists.txt

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,13 @@
1+
add_entrypoint_object(
2+
dladdr
3+
SRCS
4+
dladdr.cpp
5+
HDRS
6+
dladdr.h
7+
DEPENDS
8+
libc.include.dlfcn
9+
)
10+
111
add_entrypoint_object(
212
dlclose
313
SRCS

libc/src/dlfcn/dladdr.cpp

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
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+
LLVM_LIBC_FUNCTION(int, dladdr, (const void *, Dl_info *)) { return -1; }
17+
18+
} // namespace LIBC_NAMESPACE_DECL

libc/src/dlfcn/dladdr.h

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
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 "include/llvm-libc-types/Dl_info.h"
13+
#include "src/__support/macros/config.h"
14+
15+
namespace LIBC_NAMESPACE_DECL {
16+
17+
int dladdr(const void *, Dl_info *);
18+
19+
} // namespace LIBC_NAMESPACE_DECL
20+
21+
#endif // LLVM_LIBC_SRC_DLFCN_DLADDR_H

libc/src/link/CMakeLists.txt

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
add_entrypoint_object(
2+
dl_iterate_phdr
3+
SRCS
4+
dl_iterate_phdr.cpp
5+
HDRS
6+
dl_iterate_phdr.h
7+
DEPENDS
8+
libc.include.llvm-libc-types.__dl_iterate_phdr_callback_t
9+
libc.include.llvm-libc-types.struct_dl_phdr_info
10+
libc.include.llvm-libc-types.size_t
11+
)

libc/src/link/dl_iterate_phdr.cpp

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
//===-- Implementation of dl_iterate_phdr ---------------------------------===//
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 "src/link/dl_iterate_phdr.h"
10+
#include "src/__support/common.h"
11+
#include "src/__support/macros/config.h"
12+
13+
namespace LIBC_NAMESPACE_DECL {
14+
15+
LLVM_LIBC_FUNCTION(int, dl_iterate_phdr,
16+
(__dl_iterate_phdr_callback_t callback, void *data)) {
17+
(void)callback;
18+
(void)data;
19+
return 0;
20+
}
21+
22+
} // namespace LIBC_NAMESPACE_DECL

libc/src/link/dl_iterate_phdr.h

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
//===-- Implementation header for dl_iterate_phdr ---------------*- 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_LINK_DL_ITERATE_PHDR_H
10+
#define LLVM_LIBC_SRC_LINK_DL_ITERATE_PHDR_H
11+
12+
#include "include/llvm-libc-types/__dl_iterate_phdr_callback_t.h"
13+
#include "src/__support/macros/config.h"
14+
15+
namespace LIBC_NAMESPACE_DECL {
16+
17+
int dl_iterate_phdr(__dl_iterate_phdr_callback_t callback, void *data);
18+
19+
} // namespace LIBC_NAMESPACE_DECL
20+
21+
#endif // LLVM_LIBC_SRC_STRING_MEMCHR_H

0 commit comments

Comments
 (0)