Skip to content

Commit 90f5bcb

Browse files
[libc] Add link.h and elf.h
1 parent eb52173 commit 90f5bcb

24 files changed

+329
-4
lines changed

libc/config/linux/aarch64/entrypoints.txt

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,8 @@ set(TARGET_LIBC_ENTRYPOINTS
2222
libc.src.dlfcn.dlsym
2323
libc.src.dlfcn.dlclose
2424
libc.src.dlfcn.dlerror
25+
libc.src.dlfcn.dlsym
26+
libc.src.dlfcn.dladdr
2527

2628
# errno.h entrypoints
2729
libc.src.errno.errno
@@ -32,6 +34,9 @@ set(TARGET_LIBC_ENTRYPOINTS
3234
libc.src.fcntl.open
3335
libc.src.fcntl.openat
3436

37+
# link.h entrypoints
38+
libc.src.link.dl_iterate_phdr
39+
3540
# sched.h entrypoints
3641
libc.src.sched.sched_get_priority_max
3742
libc.src.sched.sched_get_priority_min

libc/config/linux/aarch64/headers.txt

Lines changed: 2 additions & 0 deletions
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/api.td

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -308,3 +308,16 @@ def SearchAPI : PublicAPI<"search.h"> {
308308
def SysStatvfsAPI : PublicAPI<"sys/statvfs.h"> {
309309
let Types = ["fsblkcnt_t", "fsfilcnt_t", "struct statvfs"];
310310
}
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+
}

libc/config/linux/x86_64/entrypoints.txt

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,8 @@ set(TARGET_LIBC_ENTRYPOINTS
2222
libc.src.dlfcn.dlsym
2323
libc.src.dlfcn.dlclose
2424
libc.src.dlfcn.dlerror
25+
libc.src.dlfcn.dlsym
26+
libc.src.dlfcn.dladdr
2527

2628
# errno.h entrypoints
2729
libc.src.errno.errno
@@ -32,6 +34,9 @@ set(TARGET_LIBC_ENTRYPOINTS
3234
libc.src.fcntl.open
3335
libc.src.fcntl.openat
3436

37+
# link.h entrypoints
38+
libc.src.link.dl_iterate_phdr
39+
3540
# sched.h entrypoints
3641
libc.src.sched.sched_get_priority_max
3742
libc.src.sched.sched_get_priority_min

libc/config/linux/x86_64/headers.txt

Lines changed: 2 additions & 0 deletions
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

Lines changed: 20 additions & 0 deletions
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/elf.h.def

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
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

libc/include/link.h.def

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
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

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

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -282,4 +282,10 @@ add_macro_header(
282282
dlfcn_macros
283283
HDR
284284
dlfcn-macros.h
285-
)
285+
)
286+
287+
add_macro_header(
288+
elf_macros
289+
HDR
290+
elf-macros.h
291+
)
Lines changed: 18 additions & 0 deletions
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

0 commit comments

Comments
 (0)