Skip to content

Commit e50ab27

Browse files
[libc] Add link.h and elf.h
1 parent ba25507 commit e50ab27

File tree

14 files changed

+189
-1
lines changed

14 files changed

+189
-1
lines changed

libc/config/linux/aarch64/entrypoints.txt

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ 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
@@ -32,6 +33,9 @@ set(TARGET_LIBC_ENTRYPOINTS
3233
libc.src.fcntl.open
3334
libc.src.fcntl.openat
3435

36+
# link.h entrypoints
37+
libc.src.link.dl_iterate_phdr
38+
3539
# sched.h entrypoints
3640
libc.src.sched.sched_get_priority_max
3741
libc.src.sched.sched_get_priority_min

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: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ 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
@@ -32,6 +33,9 @@ set(TARGET_LIBC_ENTRYPOINTS
3233
libc.src.fcntl.open
3334
libc.src.fcntl.openat
3435

36+
# link.h entrypoints
37+
libc.src.link.dl_iterate_phdr
38+
3539
# sched.h entrypoints
3640
libc.src.sched.sched_get_priority_max
3741
libc.src.sched.sched_get_priority_min

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/spec/linux.td

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,9 @@ def StructEpollEventPtr : PtrType<StructEpollEvent>;
33

44
def StructEpollData : NamedType<"struct epoll_data">;
55

6+
def StructDlPhdrInfo : NamedType<"struct dl_phdr_info">;
7+
def DlIteratePhdrCallback : NamedType<"__dl_iterate_phdr_callback_t">;
8+
69
def Linux : StandardSpec<"Linux"> {
710
HeaderSpec Errno = HeaderSpec<
811
"errno.h",
@@ -264,8 +267,35 @@ def Linux : StandardSpec<"Linux"> {
264267
]
265268
>;
266269

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+
267295
let Headers = [
296+
Elf,
268297
Errno,
298+
Link,
269299
SysEpoll,
270300
SysMMan,
271301
SysPrctl,

libc/spec/posix.td

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,9 @@ def PThreadOnceT : NamedType<"pthread_once_t">;
2121
def PThreadOnceTPtr : PtrType<PThreadOnceT>;
2222
def PThreadOnceCallback : NamedType<"__pthread_once_func_t">;
2323

24+
def DlInfo : NamedType<"Dl_info">;
25+
def DlInfoPtr : PtrType<DlInfo>;
26+
2427
def InoT : NamedType<"ino_t">;
2528
def UidT : NamedType<"uid_t">;
2629
def GidT : NamedType<"gid_t">;
@@ -230,9 +233,14 @@ def POSIX : StandardSpec<"POSIX"> {
230233
Macro<"RTLD_GLOBAL">,
231234
Macro<"RTLD_LOCAL">,
232235
],
233-
[], // Types
236+
[DlInfo], // Types
234237
[], // Enumerations
235238
[
239+
FunctionSpec<
240+
"dladdr",
241+
RetValSpec<IntType>,
242+
[ArgSpec<ConstVoidPtr>, ArgSpec<DlInfoPtr>]
243+
>,
236244
FunctionSpec<
237245
"dlclose",
238246
RetValSpec<IntType>,

libc/src/CMakeLists.txt

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

libc/src/dlfcn/CMakeLists.txt

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,14 @@
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+
112
add_entrypoint_object(
213
dlclose
314
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+
13+
namespace LIBC_NAMESPACE {
14+
15+
// TODO(@izaakschroeder): https://github.com/llvm/llvm-project/issues/97929
16+
LLVM_LIBC_FUNCTION(int, dladdr, (const void *, Dl_info *)) { return 0; }
17+
18+
} // namespace LIBC_NAMESPACE

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+
namespace LIBC_NAMESPACE {
13+
14+
#include "include/llvm-libc-types/Dl_info.h"
15+
16+
int dladdr(const void *, Dl_info *);
17+
18+
} // namespace LIBC_NAMESPACE
19+
20+
#endif // LLVM_LIBC_SRC_DLFCN_DLADDR_H

libc/src/link/CMakeLists.txt

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
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.src.__support.common
9+
)

libc/src/link/dl_iterate_phdr.cpp

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
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 "dl_iterate_phdr.h"
10+
#include "src/__support/common.h"
11+
12+
namespace LIBC_NAMESPACE {
13+
14+
// TODO(@izaakschroeder): https://github.com/llvm/llvm-project/issues/97928
15+
LLVM_LIBC_FUNCTION(int, dl_iterate_phdr,
16+
(__dl_iterate_phdr_callback_t, void *)) {
17+
return -1;
18+
}
19+
20+
} // namespace LIBC_NAMESPACE

libc/src/link/dl_iterate_phdr.h

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
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+
namespace LIBC_NAMESPACE {
13+
14+
#include "include/llvm-libc-types/__dl_iterate_phdr_callback_t.h"
15+
16+
int dl_iterate_phdr(__dl_iterate_phdr_callback_t, void *);
17+
18+
} // namespace LIBC_NAMESPACE
19+
20+
#endif // LLVM_LIBC_SRC_LINK_DL_ITERATE_PHDR_H

0 commit comments

Comments
 (0)