Skip to content

Commit 123c004

Browse files
authored
[libc] Define (stub) dl_iterate_phdr (llvm#131436)
This fleshes out the <link.h> a little more, including the `struct dl_phdr_info` type and declaring the dl_iterate_phdr function. There is only a no-op implementation without tests, as for the existing dlfcn functions.
1 parent 14c95e0 commit 123c004

File tree

16 files changed

+166
-25
lines changed

16 files changed

+166
-25
lines changed

libc/config/linux/aarch64/entrypoints.txt

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -842,6 +842,9 @@ if(LLVM_LIBC_FULL_BUILD)
842842
libc.src.arpa.inet.ntohl
843843
libc.src.arpa.inet.ntohs
844844

845+
# link.h entrypoints
846+
libc.src.link.dl_iterate_phdr
847+
845848
# pthread.h entrypoints
846849
libc.src.pthread.pthread_atfork
847850
libc.src.pthread.pthread_attr_destroy

libc/config/linux/riscv/entrypoints.txt

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -795,6 +795,9 @@ if(LLVM_LIBC_FULL_BUILD)
795795
libc.src.arpa.inet.ntohl
796796
libc.src.arpa.inet.ntohs
797797

798+
# link.h entrypoints
799+
libc.src.link.dl_iterate_phdr
800+
798801
# pthread.h entrypoints
799802
libc.src.pthread.pthread_atfork
800803
libc.src.pthread.pthread_attr_destroy

libc/config/linux/x86_64/entrypoints.txt

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -960,6 +960,9 @@ if(LLVM_LIBC_FULL_BUILD)
960960
libc.src.arpa.inet.ntohl
961961
libc.src.arpa.inet.ntohs
962962

963+
# link.h entrypoints
964+
libc.src.link.dl_iterate_phdr
965+
963966
# pthread.h entrypoints
964967
libc.src.pthread.pthread_atfork
965968
libc.src.pthread.pthread_attr_destroy

libc/hdr/types/CMakeLists.txt

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,14 @@ add_proxy_header_library(
99
libc.include.stdlib
1010
)
1111

12+
add_proxy_header_library(
13+
struct_dl_phdr_info
14+
HDRS
15+
struct_dl_phdr_info.h
16+
FULL_BUILD_DEPENDS
17+
libc.include.llvm-libc-types.struct_dl_phdr_info
18+
)
19+
1220
add_proxy_header_library(
1321
ldiv_t
1422
HDRS

libc/hdr/types/struct_dl_phdr_info.h

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
//===-- Proxy for 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+
#ifndef LLVM_LIBC_HDR_TYPES_STRUCT_DL_PHDR_INFO_H
9+
#define LLVM_LIBC_HDR_TYPES_STRUCT_DL_PHDR_INFO_H
10+
11+
#ifdef LIBC_FULL_BUILD
12+
13+
#include "include/llvm-libc-types/struct_dl_phdr_info.h"
14+
15+
#else
16+
17+
#include <link.h>
18+
19+
#endif // LIBC_FULL_BUILD
20+
21+
#endif // LLVM_LIBC_HDR_TYPES_STRUCT_DL_PHDR_INFO_H

libc/include/CMakeLists.txt

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -431,6 +431,8 @@ add_header_macro(
431431
DEPENDS
432432
.llvm_libc_common_h
433433
.llvm-libc-macros.link_macros
434+
.llvm-libc-types.struct_dl_phdr_info
435+
.llvm-libc-types.__dl_iterate_phdr_callback_t
434436
)
435437

436438
add_header_macro(

libc/include/link.h.def

Lines changed: 0 additions & 17 deletions
This file was deleted.

libc/include/link.yaml

Lines changed: 18 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,20 @@
11
header: link.h
2-
header_template: link.h.def
32
standards:
4-
- Linux
5-
macros: []
6-
types: []
7-
enums: []
8-
objects: []
9-
functions: []
3+
- svid
4+
macros:
5+
- macro_name: ElfW
6+
standards:
7+
- gnu
8+
macro_header: link-macros.h
9+
types:
10+
- type_name: struct_dl_phdr_info
11+
standards:
12+
- gnu
13+
functions:
14+
- name: dl_iterate_phdr
15+
standards:
16+
- gnu
17+
return_type: int
18+
arguments:
19+
- type: __dl_iterate_phdr_callback_t
20+
- type: void *

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

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ add_header(__atfork_callback_t HDR __atfork_callback_t.h)
55
add_header(__bsearchcompare_t HDR __bsearchcompare_t.h)
66
add_header(__lsearchcompare_t HDR __lsearchcompare_t.h)
77
add_header(__call_once_func_t HDR __call_once_func_t.h)
8+
add_header(__dl_iterate_phdr_callback_t HDR __dl_iterate_phdr_callback_t.h DEPENDS .size_t)
89
add_header(__exec_argv_t HDR __exec_argv_t.h)
910
add_header(__exec_envp_t HDR __exec_envp_t.h)
1011
add_header(__futex_word HDR __futex_word.h)
@@ -69,6 +70,7 @@ add_header(sighandler_t HDR sighandler_t.h)
6970
add_header(stack_t HDR stack_t.h DEPENDS .size_t)
7071
add_header(suseconds_t HDR suseconds_t.h)
7172
add_header(struct_dirent HDR struct_dirent.h DEPENDS .ino_t .off_t)
73+
add_header(struct_dl_phdr_info HDR struct_dl_phdr_info.h DEPENDS .size_t libc.include.llvm-libc-macros.link_macros)
7274
add_header(struct_f_owner_ex HDR struct_f_owner_ex.h DEPENDS .pid_t)
7375
add_header(struct_flock HDR struct_flock.h DEPENDS .off_t .pid_t)
7476
add_header(struct_flock64 HDR struct_flock64.h DEPENDS .off64_t .pid_t)
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
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+
14+
struct dl_phdr_info;
15+
16+
typedef int (*__dl_iterate_phdr_callback_t)(struct dl_phdr_info *, size_t,
17+
void *);
18+
19+
#endif // LLVM_LIBC_TYPES___DL_ITERATE_PHDR_CALLBACK_T_H

0 commit comments

Comments
 (0)