File tree 24 files changed +325
-3
lines changed
24 files changed +325
-3
lines changed Original file line number Diff line number Diff line change @@ -18,6 +18,7 @@ set(TARGET_LIBC_ENTRYPOINTS
18
18
libc.src.ctype.toupper
19
19
20
20
# dlfcn.h entrypoints
21
+ libc.src.dlfcn.dladdr
21
22
libc.src.dlfcn.dlclose
22
23
libc.src.dlfcn.dlerror
23
24
libc.src.dlfcn.dlopen
@@ -32,6 +33,9 @@ set(TARGET_LIBC_ENTRYPOINTS
32
33
libc.src.fcntl.open
33
34
libc.src.fcntl.openat
34
35
36
+ # link.h entrypoints
37
+ libc.src.link.dl_iterate_phdr
38
+
35
39
# sched.h entrypoints
36
40
libc.src.sched.sched_get_priority_max
37
41
libc.src.sched.sched_get_priority_min
Original file line number Diff line number Diff line change @@ -2,13 +2,15 @@ set(TARGET_PUBLIC_HEADERS
2
2
libc.include.assert
3
3
libc.include.ctype
4
4
libc.include.dlfcn
5
+ libc.include.elf
5
6
libc.include.errno
6
7
libc.include.features
7
8
libc.include.fenv
8
9
libc.include.float
9
10
libc.include.stdint
10
11
libc.include.inttypes
11
12
libc.include.limits
13
+ libc.include.link
12
14
libc.include.math
13
15
libc.include.pthread
14
16
libc.include.signal
Original file line number Diff line number Diff line change @@ -308,3 +308,16 @@ def SearchAPI : PublicAPI<"search.h"> {
308
308
def SysStatvfsAPI : PublicAPI<"sys/statvfs.h"> {
309
309
let Types = ["fsblkcnt_t", "fsfilcnt_t", "struct statvfs"];
310
310
}
311
+
312
+ def LinkAPI : PublicAPI<"link.h"> {
313
+ let Types = [
314
+ "struct dl_phdr_info",
315
+ "__dl_iterate_phdr_callback_t"
316
+ ];
317
+ }
318
+
319
+ def DlfcnAPI : PublicAPI<"dlfcn.h"> {
320
+ let Types = [
321
+ "Dl_info"
322
+ ];
323
+ }
Original file line number Diff line number Diff line change @@ -18,6 +18,7 @@ set(TARGET_LIBC_ENTRYPOINTS
18
18
libc.src.ctype.toupper
19
19
20
20
# dlfcn.h entrypoints
21
+ libc.src.dlfcn.dladdr
21
22
libc.src.dlfcn.dlclose
22
23
libc.src.dlfcn.dlerror
23
24
libc.src.dlfcn.dlopen
@@ -32,6 +33,9 @@ set(TARGET_LIBC_ENTRYPOINTS
32
33
libc.src.fcntl.open
33
34
libc.src.fcntl.openat
34
35
36
+ # link.h entrypoints
37
+ libc.src.link.dl_iterate_phdr
38
+
35
39
# sched.h entrypoints
36
40
libc.src.sched.sched_get_priority_max
37
41
libc.src.sched.sched_get_priority_min
Original file line number Diff line number Diff line change @@ -3,6 +3,7 @@ set(TARGET_PUBLIC_HEADERS
3
3
libc.include.ctype
4
4
libc.include.dirent
5
5
libc.include.dlfcn
6
+ libc.include.elf
6
7
libc.include.errno
7
8
libc.include.fcntl
8
9
libc.include.features
@@ -11,6 +12,7 @@ set(TARGET_PUBLIC_HEADERS
11
12
libc.include.stdint
12
13
libc.include.inttypes
13
14
libc.include.limits
15
+ libc.include.link
14
16
libc.include.math
15
17
libc.include.pthread
16
18
libc.include.sched
Original file line number Diff line number Diff line change @@ -56,6 +56,7 @@ add_gen_header(
56
56
DEF_FILE dlfcn.h.def
57
57
GEN_HDR dlfcn.h
58
58
DEPENDS
59
+ .llvm-libc-types.Dl_info
59
60
.llvm-libc-macros .dlfcn_macros
60
61
.llvm_libc_common_h
61
62
)
@@ -367,6 +368,25 @@ add_gen_header(
367
368
.llvm-libc-types.posix_spawn_file_actions_t
368
369
)
369
370
371
+ add_gen_header(
372
+ link
373
+ DEF_FILE link.h.def
374
+ GEN_HDR link.h
375
+ DEPENDS
376
+ .llvm_libc_common_h
377
+ .llvm-libc-types.struct_dl_phdr_info
378
+ .llvm-libc-types.__dl_iterate_phdr_callback_t
379
+ .llvm-libc-macros .link_macros
380
+ )
381
+
382
+ add_gen_header(
383
+ elf
384
+ DEF_FILE elf.h.def
385
+ GEN_HDR elf.h
386
+ DEPENDS
387
+ .llvm-libc-macros .elf_macros
388
+ )
389
+
370
390
# TODO: Not all platforms will have a include/sys directory. Add the sys
371
391
# directory and the targets for sys/*.h files conditional to the OS requiring
372
392
# them.
Original file line number Diff line number Diff line change
1
+ //===-- C standard library header elf.h -----------------------------------===//
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_ELF_H
10
+ #define LLVM_LIBC_ELF_H
11
+
12
+ #include "llvm-libc-macros/elf-macros.h"
13
+
14
+ #endif // LLVM_LIBC_ELF_H
Original file line number Diff line number Diff line change
1
+ //===-- C standard library header link.h ----------------------------------===//
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_LINK_H
10
+ #define LLVM_LIBC_LINK_H
11
+
12
+ #include "llvm-libc-macros/link-macros.h"
13
+
14
+ %%public_api()
15
+
16
+ #endif // LLVM_LIBC_LINK_H
Original file line number Diff line number Diff line change @@ -283,3 +283,9 @@ add_macro_header(
283
283
HDR
284
284
dlfcn-macros .h
285
285
)
286
+
287
+ add_macro_header(
288
+ elf_macros
289
+ HDR
290
+ elf-macros .h
291
+ )
Original file line number Diff line number Diff line change
1
+ //===-- Definition of macros from elf.h -----------------------------------===//
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_MACROS_ELF_MACROS_H
10
+ #define LLVM_LIBC_MACROS_ELF_MACROS_H
11
+
12
+ #if __has_include (< linux /elf .h > )
13
+ #include <linux/elf.h>
14
+ #else
15
+ #error "cannot use <sys/elf.h> without proper system headers."
16
+ #endif
17
+
18
+ #endif // LLVM_LIBC_MACROS_ELF_MACROS_H
Original file line number Diff line number Diff line change 6
6
//
7
7
//===----------------------------------------------------------------------===//
8
8
9
+ #ifndef LLVM_LIBC_MACROS_LINK_MACROS_H
10
+ #define LLVM_LIBC_MACROS_LINK_MACROS_H
11
+
12
+ #include "elf-macros.h"
13
+
9
14
#ifdef __LP64__
10
- #define ElfW (type ) Elf64_ ## type
15
+ #define ElfW (type ) Elf64_## type
11
16
#else
12
- #define ElfW (type ) Elf32_ ## type
17
+ #define ElfW (type ) Elf32_##type
18
+ #endif
19
+
20
+ struct link_map {
21
+ ElfW (Addr ) l_addr ;
22
+ char * l_name ;
23
+ ElfW (Dyn ) * l_ld ;
24
+ struct link_map * l_next , * l_prev ;
25
+ };
26
+
27
+ struct r_debug {
28
+ int r_version ;
29
+ struct link_map * r_map ;
30
+ ElfW (Addr ) r_brk ;
31
+ enum { RT_CONSISTENT , RT_ADD , RT_DELETE } r_state ;
32
+ ElfW (Addr ) r_ldbase ;
33
+ };
34
+
13
35
#endif
Original file line number Diff line number Diff line change @@ -89,6 +89,9 @@ add_header(thrd_t HDR thrd_t.h DEPENDS .__thread_type)
89
89
add_header(tss_t HDR tss_t.h)
90
90
add_header(tss_dtor_t HDR tss_dtor_t.h)
91
91
add_header(__atexithandler_t HDR __atexithandler_t.h)
92
+ add_header(Dl_info HDR Dl_info.h)
93
+ add_header(struct_dl_phdr_info HDR struct_dl_phdr_info.h)
94
+ add_header(__dl_iterate_phdr_callback_t HDR __dl_iterate_phdr_callback_t.h)
92
95
add_header(speed_t HDR speed_t.h)
93
96
add_header(tcflag_t HDR tcflag_t.h)
94
97
add_header(struct_termios HDR struct_termios.h DEPENDS .cc_t .speed_t .tcflag_t)
Original file line number Diff line number Diff line change
1
+ //===-- Definition of type Dl_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_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
Original file line number Diff line number Diff line change
1
+ //===-- Definition of __dl_iterate_phdr_callback_t 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_ITERATE_PHDR_CALLBACK_T_H
10
+ #define LLVM_LIBC_TYPES___DL_ITERATE_PHDR_CALLBACK_T_H
11
+
12
+ #include "llvm-libc-types/size_t.h"
13
+
14
+ typedef int (* __dl_iterate_phdr_callback_t )(struct dl_phdr_info * info ,
15
+ size_t size , void * data );
16
+
17
+ #endif // LLVM_LIBC_TYPES___DL_ITERATE_PHDR_CALLBACK_T_H
Original file line number Diff line number Diff line change
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 "llvm-libc-types/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 int dlpi_adds ;
21
+ unsigned long long int 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
Original file line number Diff line number Diff line change @@ -3,6 +3,9 @@ def StructEpollEventPtr : PtrType<StructEpollEvent>;
3
3
4
4
def StructEpollData : NamedType<"struct epoll_data">;
5
5
6
+ def StructDlPhdrInfo : NamedType<"struct dl_phdr_info">;
7
+ def DlIteratePhdrCallback : NamedType<"__dl_iterate_phdr_callback_t">;
8
+
6
9
def Linux : StandardSpec<"Linux"> {
7
10
HeaderSpec Errno = HeaderSpec<
8
11
"errno.h",
@@ -264,8 +267,35 @@ def Linux : StandardSpec<"Linux"> {
264
267
]
265
268
>;
266
269
270
+ HeaderSpec Link = HeaderSpec<
271
+ "link.h",
272
+ [], // Macros
273
+ [StructDlPhdrInfo, DlIteratePhdrCallback], // Types
274
+ [], // Enumerations
275
+ [
276
+ FunctionSpec<
277
+ "dl_iterate_phdr",
278
+ RetValSpec<IntType>,
279
+ [
280
+ ArgSpec<DlIteratePhdrCallback>,
281
+ ArgSpec<VoidPtr>
282
+ ]
283
+ >,
284
+ ] // Functions
285
+ >;
286
+
287
+ HeaderSpec Elf = HeaderSpec<
288
+ "elf.h",
289
+ [], // Macros
290
+ [], // Types
291
+ [], // Enumerations
292
+ [] // Functions
293
+ >;
294
+
267
295
let Headers = [
296
+ Elf,
268
297
Errno,
298
+ Link,
269
299
SysEpoll,
270
300
SysMMan,
271
301
SysPrctl,
Original file line number Diff line number Diff line change @@ -21,6 +21,9 @@ def PThreadOnceT : NamedType<"pthread_once_t">;
21
21
def PThreadOnceTPtr : PtrType<PThreadOnceT>;
22
22
def PThreadOnceCallback : NamedType<"__pthread_once_func_t">;
23
23
24
+ def DlInfo : NamedType<"Dl_info">;
25
+ def DlInfoPtr : PtrType<DlInfo>;
26
+
24
27
def InoT : NamedType<"ino_t">;
25
28
def UidT : NamedType<"uid_t">;
26
29
def GidT : NamedType<"gid_t">;
@@ -230,9 +233,14 @@ def POSIX : StandardSpec<"POSIX"> {
230
233
Macro<"RTLD_GLOBAL">,
231
234
Macro<"RTLD_LOCAL">,
232
235
],
233
- [], // Types
236
+ [DlInfo ], // Types
234
237
[], // Enumerations
235
238
[
239
+ FunctionSpec<
240
+ "dladdr",
241
+ RetValSpec<IntType>,
242
+ [ArgSpec<ConstVoidPtr>, ArgSpec<DlInfoPtr>]
243
+ >,
236
244
FunctionSpec<
237
245
"dlclose",
238
246
RetValSpec<IntType>,
Original file line number Diff line number Diff line change @@ -5,6 +5,7 @@ add_subdirectory(dlfcn)
5
5
add_subdirectory (errno)
6
6
add_subdirectory (fenv)
7
7
add_subdirectory (inttypes)
8
+ add_subdirectory (link)
8
9
add_subdirectory (math)
9
10
add_subdirectory (stdbit)
10
11
add_subdirectory (stdfix)
Original file line number Diff line number Diff line change
1
+ add_entrypoint_object(
2
+ dladdr
3
+ SRCS
4
+ dladdr.cpp
5
+ HDRS
6
+ dladdr.h
7
+ DEPENDS
8
+ libc.include .dlfcn
9
+ libc.src.errno.errno
10
+ )
11
+
1
12
add_entrypoint_object(
2
13
dlclose
3
14
SRCS
You can’t perform that action at this time.
0 commit comments