Skip to content

Commit ba25507

Browse files
[libc] Add link.h and elf.h headers (#97924)
Headers for #97504
1 parent 57fa508 commit ba25507

File tree

10 files changed

+150
-2
lines changed

10 files changed

+150
-2
lines changed

libc/config/linux/aarch64/headers.txt

+2
Original file line numberDiff line numberDiff line change
@@ -2,13 +2,15 @@ set(TARGET_PUBLIC_HEADERS
22
libc.include.assert
33
libc.include.ctype
44
libc.include.dlfcn
5+
libc.include.elf
56
libc.include.errno
67
libc.include.features
78
libc.include.fenv
89
libc.include.float
910
libc.include.stdint
1011
libc.include.inttypes
1112
libc.include.limits
13+
libc.include.link
1214
libc.include.math
1315
libc.include.pthread
1416
libc.include.signal

libc/config/linux/x86_64/headers.txt

+2
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ set(TARGET_PUBLIC_HEADERS
33
libc.include.ctype
44
libc.include.dirent
55
libc.include.dlfcn
6+
libc.include.elf
67
libc.include.errno
78
libc.include.fcntl
89
libc.include.features
@@ -11,6 +12,7 @@ set(TARGET_PUBLIC_HEADERS
1112
libc.include.stdint
1213
libc.include.inttypes
1314
libc.include.limits
15+
libc.include.link
1416
libc.include.math
1517
libc.include.pthread
1618
libc.include.sched

libc/include/CMakeLists.txt

+20
Original file line numberDiff line numberDiff line change
@@ -56,6 +56,7 @@ add_gen_header(
5656
DEF_FILE dlfcn.h.def
5757
GEN_HDR dlfcn.h
5858
DEPENDS
59+
.llvm-libc-types.Dl_info
5960
.llvm-libc-macros.dlfcn_macros
6061
.llvm_libc_common_h
6162
)
@@ -367,6 +368,25 @@ add_gen_header(
367368
.llvm-libc-types.posix_spawn_file_actions_t
368369
)
369370

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+
370390
# TODO: Not all platforms will have a include/sys directory. Add the sys
371391
# directory and the targets for sys/*.h files conditional to the OS requiring
372392
# them.

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

+6
Original file line numberDiff line numberDiff line change
@@ -283,3 +283,9 @@ add_macro_header(
283283
HDR
284284
dlfcn-macros.h
285285
)
286+
287+
add_macro_header(
288+
elf_macros
289+
HDR
290+
elf-macros.h
291+
)
+18
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
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

libc/include/llvm-libc-macros/link-macros.h

+24-2
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,30 @@
66
//
77
//===----------------------------------------------------------------------===//
88

9+
#ifndef LLVM_LIBC_MACROS_LINK_MACROS_H
10+
#define LLVM_LIBC_MACROS_LINK_MACROS_H
11+
12+
#include "elf-macros.h"
13+
914
#ifdef __LP64__
10-
#define ElfW(type) Elf64_ ## type
15+
#define ElfW(type) Elf64_##type
1116
#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+
1335
#endif

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

+16
Original file line numberDiff line numberDiff line change
@@ -89,6 +89,22 @@ add_header(thrd_t HDR thrd_t.h DEPENDS .__thread_type)
8989
add_header(tss_t HDR tss_t.h)
9090
add_header(tss_dtor_t HDR tss_dtor_t.h)
9191
add_header(__atexithandler_t HDR __atexithandler_t.h)
92+
add_header(Dl_info HDR Dl_info.h)
93+
add_header(
94+
__dl_iterate_phdr_callback_t
95+
HDR __dl_iterate_phdr_callback_t.h
96+
DEPENDS
97+
.size_t
98+
)
99+
add_header(
100+
struct_dl_phdr_info
101+
HDR struct_dl_phdr_info.h
102+
DEPENDS
103+
.__dl_iterate_phdr_callback_t
104+
.size_t
105+
libc.include.llvm-libc-macros.link_macros
106+
)
107+
92108
add_header(speed_t HDR speed_t.h)
93109
add_header(tcflag_t HDR tcflag_t.h)
94110
add_header(struct_termios HDR struct_termios.h DEPENDS .cc_t .speed_t .tcflag_t)
+19
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
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 numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
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 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 "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

0 commit comments

Comments
 (0)