[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.
This commit is contained in:
Roland McGrath 2025-03-18 11:38:33 -07:00 committed by GitHub
parent 14c95e0c8b
commit 123c0040d4
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
16 changed files with 166 additions and 25 deletions

View File

@ -842,6 +842,9 @@ if(LLVM_LIBC_FULL_BUILD)
libc.src.arpa.inet.ntohl
libc.src.arpa.inet.ntohs
# link.h entrypoints
libc.src.link.dl_iterate_phdr
# pthread.h entrypoints
libc.src.pthread.pthread_atfork
libc.src.pthread.pthread_attr_destroy

View File

@ -795,6 +795,9 @@ if(LLVM_LIBC_FULL_BUILD)
libc.src.arpa.inet.ntohl
libc.src.arpa.inet.ntohs
# link.h entrypoints
libc.src.link.dl_iterate_phdr
# pthread.h entrypoints
libc.src.pthread.pthread_atfork
libc.src.pthread.pthread_attr_destroy

View File

@ -960,6 +960,9 @@ if(LLVM_LIBC_FULL_BUILD)
libc.src.arpa.inet.ntohl
libc.src.arpa.inet.ntohs
# link.h entrypoints
libc.src.link.dl_iterate_phdr
# pthread.h entrypoints
libc.src.pthread.pthread_atfork
libc.src.pthread.pthread_attr_destroy

View File

@ -9,6 +9,14 @@ add_proxy_header_library(
libc.include.stdlib
)
add_proxy_header_library(
struct_dl_phdr_info
HDRS
struct_dl_phdr_info.h
FULL_BUILD_DEPENDS
libc.include.llvm-libc-types.struct_dl_phdr_info
)
add_proxy_header_library(
ldiv_t
HDRS

View File

@ -0,0 +1,21 @@
//===-- Proxy for struct dl_phdr_info -----------------------------------===//
//
// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
// See https://llvm.org/LICENSE.txt for license information.
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
//
//===---------------------------------------------------------------------===//
#ifndef LLVM_LIBC_HDR_TYPES_STRUCT_DL_PHDR_INFO_H
#define LLVM_LIBC_HDR_TYPES_STRUCT_DL_PHDR_INFO_H
#ifdef LIBC_FULL_BUILD
#include "include/llvm-libc-types/struct_dl_phdr_info.h"
#else
#include <link.h>
#endif // LIBC_FULL_BUILD
#endif // LLVM_LIBC_HDR_TYPES_STRUCT_DL_PHDR_INFO_H

View File

@ -431,6 +431,8 @@ add_header_macro(
DEPENDS
.llvm_libc_common_h
.llvm-libc-macros.link_macros
.llvm-libc-types.struct_dl_phdr_info
.llvm-libc-types.__dl_iterate_phdr_callback_t
)
add_header_macro(

View File

@ -1,17 +0,0 @@
//===-- GNU header link.h -------------------------------------------------===//
//
// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
// See https://llvm.org/LICENSE.txt for license information.
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
//
//===----------------------------------------------------------------------===//
#ifndef LLVM_LIBC_LINK_H
#define LLVM_LIBC_LINK_H
#include "__llvm-libc-common.h"
#include "llvm-libc-macros/link-macros.h"
%%public_api()
#endif // LLVM_LIBC_LINK_H

View File

@ -1,9 +1,20 @@
header: link.h
header_template: link.h.def
standards:
- Linux
macros: []
types: []
enums: []
objects: []
functions: []
- svid
macros:
- macro_name: ElfW
standards:
- gnu
macro_header: link-macros.h
types:
- type_name: struct_dl_phdr_info
standards:
- gnu
functions:
- name: dl_iterate_phdr
standards:
- gnu
return_type: int
arguments:
- type: __dl_iterate_phdr_callback_t
- type: void *

View File

@ -5,6 +5,7 @@ add_header(__atfork_callback_t HDR __atfork_callback_t.h)
add_header(__bsearchcompare_t HDR __bsearchcompare_t.h)
add_header(__lsearchcompare_t HDR __lsearchcompare_t.h)
add_header(__call_once_func_t HDR __call_once_func_t.h)
add_header(__dl_iterate_phdr_callback_t HDR __dl_iterate_phdr_callback_t.h DEPENDS .size_t)
add_header(__exec_argv_t HDR __exec_argv_t.h)
add_header(__exec_envp_t HDR __exec_envp_t.h)
add_header(__futex_word HDR __futex_word.h)
@ -69,6 +70,7 @@ add_header(sighandler_t HDR sighandler_t.h)
add_header(stack_t HDR stack_t.h DEPENDS .size_t)
add_header(suseconds_t HDR suseconds_t.h)
add_header(struct_dirent HDR struct_dirent.h DEPENDS .ino_t .off_t)
add_header(struct_dl_phdr_info HDR struct_dl_phdr_info.h DEPENDS .size_t libc.include.llvm-libc-macros.link_macros)
add_header(struct_f_owner_ex HDR struct_f_owner_ex.h DEPENDS .pid_t)
add_header(struct_flock HDR struct_flock.h DEPENDS .off_t .pid_t)
add_header(struct_flock64 HDR struct_flock64.h DEPENDS .off64_t .pid_t)

View File

@ -0,0 +1,19 @@
//===-- Definition of type __dl_iterate_phdr_callback_t ------------------===//
//
// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
// See https://llvm.org/LICENSE.txt for license information.
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
//
//===---------------------------------------------------------------------===//
#ifndef LLVM_LIBC_TYPES___DL_ITERATE_PHDR_CALLBACK_T_H
#define LLVM_LIBC_TYPES___DL_ITERATE_PHDR_CALLBACK_T_H
#include "size_t.h"
struct dl_phdr_info;
typedef int (*__dl_iterate_phdr_callback_t)(struct dl_phdr_info *, size_t,
void *);
#endif // LLVM_LIBC_TYPES___DL_ITERATE_PHDR_CALLBACK_T_H

View File

@ -0,0 +1,30 @@
//===-- Definition of type struct dl_phdr_info ---------------------------===//
//
// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
// See https://llvm.org/LICENSE.txt for license information.
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
//
//===---------------------------------------------------------------------===//
#ifndef LLVM_LIBC_TYPES_STRUCT_DL_PHDR_INFO_H
#define LLVM_LIBC_TYPES_STRUCT_DL_PHDR_INFO_H
#include "../llvm-libc-macros/link-macros.h"
#include "size_t.h"
#include <elf.h>
#include <stdint.h>
struct dl_phdr_info {
ElfW(Addr) dlpi_addr;
const char *dlpi_name;
const ElfW(Phdr) * dlpi_phdr;
ElfW(Half) dlpi_phnum;
uint64_t dlpi_adds;
uint64_t dlpi_subs;
size_t dlpi_tls_modid;
void *dlpi_tls_data;
};
#endif // LLVM_LIBC_TYPES_STRUCT_DL_PHDR_INFO_H

View File

@ -6,6 +6,7 @@ add_subdirectory(dlfcn)
add_subdirectory(errno)
add_subdirectory(fenv)
add_subdirectory(inttypes)
add_subdirectory(link)
add_subdirectory(math)
add_subdirectory(stdbit)
add_subdirectory(stdfix)
@ -13,9 +14,9 @@ add_subdirectory(stdio)
add_subdirectory(stdlib)
add_subdirectory(string)
add_subdirectory(strings)
add_subdirectory(wchar)
add_subdirectory(time)
add_subdirectory(unistd)
add_subdirectory(wchar)
if(${LIBC_TARGET_OS} STREQUAL "linux")
add_subdirectory(dirent)

View File

@ -0,0 +1,7 @@
add_entrypoint_object(
dl_iterate_phdr
SRCS
dl_iterate_phdr.cpp
HDRS
dl_iterate_phdr.h
)

View File

@ -0,0 +1,25 @@
//===-- Implementation of dl_iterate_phdr --------------------------------===//
//
// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
// See https://llvm.org/LICENSE.txt for license information.
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
//
//===---------------------------------------------------------------------===//
#include "dl_iterate_phdr.h"
#include "src/__support/common.h"
#include "src/__support/macros/config.h"
namespace LIBC_NAMESPACE_DECL {
LLVM_LIBC_FUNCTION(int, dl_iterate_phdr,
(__dl_iterate_phdr_callback_t callback, void *arg)) {
// FIXME: For pure static linking, this can report just the executable with
// info from __ehdr_start or AT_{PHDR,PHNUM} decoding, and its PT_TLS; and it
// could report the vDSO.
(void)callback, (void)arg;
return 0;
}
} // namespace LIBC_NAMESPACE_DECL

View File

@ -0,0 +1,22 @@
//===-- Implementation header of dl_iterate_phdr ---------------*- C++ -*-===//
//
// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
// See https://llvm.org/LICENSE.txt for license information.
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
//
//===---------------------------------------------------------------------===//
#ifndef LLVM_LIBC_SRC_DLFCN_DL_ITERATE_PHDR_H
#define LLVM_LIBC_SRC_DLFCN_DL_ITERATE_PHDR_H
#include "hdr/types/struct_dl_phdr_info.h"
#include "include/llvm-libc-types/__dl_iterate_phdr_callback_t.h"
#include "src/__support/macros/config.h"
namespace LIBC_NAMESPACE_DECL {
int dl_iterate_phdr(__dl_iterate_phdr_callback_t, void *);
} // namespace LIBC_NAMESPACE_DECL
#endif // LLVM_LIBC_SRC_DLFCN_DL_ITERATE_PHDR_H

View File

@ -44,6 +44,7 @@ LIBRARY_DESCRIPTIONS = {
"gnu": "GNU",
"linux": "Linux",
"uefi": "UEFI",
"svid": "SVID",
}
HEADER_TEMPLATE = """\