Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions libc/config/linux/aarch64/entrypoints.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
3 changes: 3 additions & 0 deletions libc/config/linux/riscv/entrypoints.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
3 changes: 3 additions & 0 deletions libc/config/linux/x86_64/entrypoints.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
8 changes: 8 additions & 0 deletions libc/hdr/types/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
21 changes: 21 additions & 0 deletions libc/hdr/types/struct_dl_phdr_info.h
Original file line number Diff line number Diff line change
@@ -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
2 changes: 2 additions & 0 deletions libc/include/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand Down
17 changes: 0 additions & 17 deletions libc/include/link.h.def

This file was deleted.

25 changes: 18 additions & 7 deletions libc/include/link.yaml
Original file line number Diff line number Diff line change
@@ -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 *
2 changes: 2 additions & 0 deletions libc/include/llvm-libc-types/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -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)
Expand Down
19 changes: 19 additions & 0 deletions libc/include/llvm-libc-types/__dl_iterate_phdr_callback_t.h
Original file line number Diff line number Diff line change
@@ -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
30 changes: 30 additions & 0 deletions libc/include/llvm-libc-types/struct_dl_phdr_info.h
Original file line number Diff line number Diff line change
@@ -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
3 changes: 2 additions & 1 deletion libc/src/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -6,16 +6,17 @@ add_subdirectory(dlfcn)
add_subdirectory(errno)
add_subdirectory(fenv)
add_subdirectory(inttypes)
add_subdirectory(link)
add_subdirectory(math)
add_subdirectory(stdbit)
add_subdirectory(stdfix)
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)
Expand Down
7 changes: 7 additions & 0 deletions libc/src/link/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
add_entrypoint_object(
dl_iterate_phdr
SRCS
dl_iterate_phdr.cpp
HDRS
dl_iterate_phdr.h
)
25 changes: 25 additions & 0 deletions libc/src/link/dl_iterate_phdr.cpp
Original file line number Diff line number Diff line change
@@ -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
22 changes: 22 additions & 0 deletions libc/src/link/dl_iterate_phdr.h
Original file line number Diff line number Diff line change
@@ -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
1 change: 1 addition & 0 deletions libc/utils/hdrgen/hdrgen/header.py
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@
"gnu": "GNU",
"linux": "Linux",
"uefi": "UEFI",
"svid": "SVID",
}

HEADER_TEMPLATE = """\
Expand Down
Loading