Skip to content

Commit 123c004

Browse files
authored
[libc] Define (stub) dl_iterate_phdr (#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

16 files changed

+166
-25
lines changed

libc/config/linux/aarch64/entrypoints.txt

+3
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

+3
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

+3
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

+8
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

+21
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

+2
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

-17
This file was deleted.

libc/include/link.yaml

+18-7
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

+2
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)
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
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
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 "size_t.h"
14+
#include <elf.h>
15+
#include <stdint.h>
16+
17+
struct dl_phdr_info {
18+
ElfW(Addr) dlpi_addr;
19+
const char *dlpi_name;
20+
const ElfW(Phdr) * dlpi_phdr;
21+
ElfW(Half) dlpi_phnum;
22+
23+
uint64_t dlpi_adds;
24+
uint64_t dlpi_subs;
25+
26+
size_t dlpi_tls_modid;
27+
void *dlpi_tls_data;
28+
};
29+
30+
#endif // LLVM_LIBC_TYPES_STRUCT_DL_PHDR_INFO_H

libc/src/CMakeLists.txt

+2-1
Original file line numberDiff line numberDiff line change
@@ -6,16 +6,17 @@ add_subdirectory(dlfcn)
66
add_subdirectory(errno)
77
add_subdirectory(fenv)
88
add_subdirectory(inttypes)
9+
add_subdirectory(link)
910
add_subdirectory(math)
1011
add_subdirectory(stdbit)
1112
add_subdirectory(stdfix)
1213
add_subdirectory(stdio)
1314
add_subdirectory(stdlib)
1415
add_subdirectory(string)
1516
add_subdirectory(strings)
16-
add_subdirectory(wchar)
1717
add_subdirectory(time)
1818
add_subdirectory(unistd)
19+
add_subdirectory(wchar)
1920

2021
if(${LIBC_TARGET_OS} STREQUAL "linux")
2122
add_subdirectory(dirent)

libc/src/link/CMakeLists.txt

+7
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
add_entrypoint_object(
2+
dl_iterate_phdr
3+
SRCS
4+
dl_iterate_phdr.cpp
5+
HDRS
6+
dl_iterate_phdr.h
7+
)

libc/src/link/dl_iterate_phdr.cpp

+25
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
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+
11+
#include "src/__support/common.h"
12+
#include "src/__support/macros/config.h"
13+
14+
namespace LIBC_NAMESPACE_DECL {
15+
16+
LLVM_LIBC_FUNCTION(int, dl_iterate_phdr,
17+
(__dl_iterate_phdr_callback_t callback, void *arg)) {
18+
// FIXME: For pure static linking, this can report just the executable with
19+
// info from __ehdr_start or AT_{PHDR,PHNUM} decoding, and its PT_TLS; and it
20+
// could report the vDSO.
21+
(void)callback, (void)arg;
22+
return 0;
23+
}
24+
25+
} // namespace LIBC_NAMESPACE_DECL

libc/src/link/dl_iterate_phdr.h

+22
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
//===-- Implementation header of 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_DLFCN_DL_ITERATE_PHDR_H
10+
#define LLVM_LIBC_SRC_DLFCN_DL_ITERATE_PHDR_H
11+
12+
#include "hdr/types/struct_dl_phdr_info.h"
13+
#include "include/llvm-libc-types/__dl_iterate_phdr_callback_t.h"
14+
#include "src/__support/macros/config.h"
15+
16+
namespace LIBC_NAMESPACE_DECL {
17+
18+
int dl_iterate_phdr(__dl_iterate_phdr_callback_t, void *);
19+
20+
} // namespace LIBC_NAMESPACE_DECL
21+
22+
#endif // LLVM_LIBC_SRC_DLFCN_DL_ITERATE_PHDR_H

libc/utils/hdrgen/hdrgen/header.py

+1
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,7 @@
4444
"gnu": "GNU",
4545
"linux": "Linux",
4646
"uefi": "UEFI",
47+
"svid": "SVID",
4748
}
4849

4950
HEADER_TEMPLATE = """\

0 commit comments

Comments
 (0)