[libc-commits] [libc] [libc] add macro/type definitions for ELF headers (PR #243648)
Michael Jones via libc-commits
libc-commits at lists.llvm.org
Tue Nov 17 15:03:38 PST 2026
https://github.com/michaelrj-google created https://github.com/llvm/llvm-project/pull/243648
This PR adds ar.h, sys/procfs.h, their macro and type definitions, as
well as various constants for elf.h. The constants are based off the
values from the ELFRelocs definitions in LLVM.
Assisted-by: Automated tooling, human reviewed.
>From ed7b9b786465962a9a92e74c65c3e9cfb9f2ac36 Mon Sep 17 00:00:00 2001
From: Michael Jones <michaelrj at google.com>
Date: Tue, 17 Nov 2026 02:37:16 +0000
Subject: [PATCH] [libc] add macro/type definitions for ELF headers
This PR adds ar.h, sys/procfs.h, their macro and type definitions, as
well as various constants for elf.h. The constants are based off the
values from the ELFRelocs definitions in LLVM.
Assisted-by: Automated tooling, human reviewed.
---
libc/config/linux/aarch64/headers.txt | 2 +
libc/config/linux/riscv/headers.txt | 1 +
libc/config/linux/x86_64/headers.txt | 2 +
libc/include/CMakeLists.txt | 32 +++++
libc/include/ar.yaml | 12 ++
libc/include/llvm-libc-macros/CMakeLists.txt | 6 +
.../llvm-libc-macros/sys-procfs-macros.h | 24 ++++
libc/include/llvm-libc-proxy/elf_proxy.yaml | 119 ++++++++++++++++++
libc/include/llvm-libc-types/CMakeLists.txt | 40 ++++++
.../llvm-libc-types/aarch64/CMakeLists.txt | 5 +
.../aarch64/struct_user_regs_struct.h | 25 ++++
libc/include/llvm-libc-types/elf_fpregset_t.h | 29 +++++
libc/include/llvm-libc-types/elf_greg_t.h | 19 +++
libc/include/llvm-libc-types/elf_gregset_t.h | 23 ++++
libc/include/llvm-libc-types/lwpid_t.h | 21 ++++
libc/include/llvm-libc-types/prfpregset_t.h | 21 ++++
libc/include/llvm-libc-types/prgregset_t.h | 21 ++++
libc/include/llvm-libc-types/prpsinfo_t.h | 21 ++++
libc/include/llvm-libc-types/prstatus_t.h | 21 ++++
libc/include/llvm-libc-types/psaddr_t.h | 19 +++
libc/include/llvm-libc-types/struct_ar_hdr.h | 28 +++++
.../llvm-libc-types/struct_elf_prpsinfo.h | 40 ++++++
.../llvm-libc-types/struct_elf_prstatus.h | 42 +++++++
.../llvm-libc-types/struct_elf_siginfo.h | 24 ++++
.../struct_user_fpregs_struct.h | 23 ++++
.../llvm-libc-types/struct_user_regs_struct.h | 2 +
.../llvm-libc-types/x86_64/CMakeLists.txt | 6 +
.../x86_64/struct_user_fpregs_struct.h | 33 +++++
libc/include/sys/procfs.yaml | 22 ++++
libc/include/sys/user.yaml | 1 +
libc/test/include/CMakeLists.txt | 27 ++++
libc/test/include/ar_test.cpp | 20 +++
libc/test/include/sys_procfs_test.cpp | 40 ++++++
33 files changed, 771 insertions(+)
create mode 100644 libc/include/ar.yaml
create mode 100644 libc/include/llvm-libc-macros/sys-procfs-macros.h
create mode 100644 libc/include/llvm-libc-types/aarch64/CMakeLists.txt
create mode 100644 libc/include/llvm-libc-types/aarch64/struct_user_regs_struct.h
create mode 100644 libc/include/llvm-libc-types/elf_fpregset_t.h
create mode 100644 libc/include/llvm-libc-types/elf_greg_t.h
create mode 100644 libc/include/llvm-libc-types/elf_gregset_t.h
create mode 100644 libc/include/llvm-libc-types/lwpid_t.h
create mode 100644 libc/include/llvm-libc-types/prfpregset_t.h
create mode 100644 libc/include/llvm-libc-types/prgregset_t.h
create mode 100644 libc/include/llvm-libc-types/prpsinfo_t.h
create mode 100644 libc/include/llvm-libc-types/prstatus_t.h
create mode 100644 libc/include/llvm-libc-types/psaddr_t.h
create mode 100644 libc/include/llvm-libc-types/struct_ar_hdr.h
create mode 100644 libc/include/llvm-libc-types/struct_elf_prpsinfo.h
create mode 100644 libc/include/llvm-libc-types/struct_elf_prstatus.h
create mode 100644 libc/include/llvm-libc-types/struct_elf_siginfo.h
create mode 100644 libc/include/llvm-libc-types/struct_user_fpregs_struct.h
create mode 100644 libc/include/llvm-libc-types/x86_64/struct_user_fpregs_struct.h
create mode 100644 libc/include/sys/procfs.yaml
create mode 100644 libc/test/include/ar_test.cpp
create mode 100644 libc/test/include/sys_procfs_test.cpp
diff --git a/libc/config/linux/aarch64/headers.txt b/libc/config/linux/aarch64/headers.txt
index 2136903109b514..f7b00f27207064 100644
--- a/libc/config/linux/aarch64/headers.txt
+++ b/libc/config/linux/aarch64/headers.txt
@@ -1,5 +1,6 @@
set(TARGET_PUBLIC_HEADERS
libc.include.alloca
+ libc.include.ar
libc.include.arpa_inet
libc.include.assert
libc.include.byteswap
@@ -63,6 +64,7 @@ set(TARGET_PUBLIC_HEADERS
libc.include.sys_personality
libc.include.sys_poll
libc.include.sys_prctl
+ libc.include.sys_procfs
libc.include.sys_queue
libc.include.sys_random
libc.include.sys_resource
diff --git a/libc/config/linux/riscv/headers.txt b/libc/config/linux/riscv/headers.txt
index b6a28c6226303b..08d1cab67306fc 100644
--- a/libc/config/linux/riscv/headers.txt
+++ b/libc/config/linux/riscv/headers.txt
@@ -1,5 +1,6 @@
set(TARGET_PUBLIC_HEADERS
libc.include.alloca
+ libc.include.ar
libc.include.arpa_inet
libc.include.assert
libc.include.byteswap
diff --git a/libc/config/linux/x86_64/headers.txt b/libc/config/linux/x86_64/headers.txt
index f7e5dd3bd6b80a..cf90e69c6b2430 100644
--- a/libc/config/linux/x86_64/headers.txt
+++ b/libc/config/linux/x86_64/headers.txt
@@ -1,5 +1,6 @@
set(TARGET_PUBLIC_HEADERS
libc.include.alloca
+ libc.include.ar
libc.include.arpa_inet
libc.include.assert
libc.include.byteswap
@@ -65,6 +66,7 @@ set(TARGET_PUBLIC_HEADERS
libc.include.sys_personality
libc.include.sys_poll
libc.include.sys_prctl
+ libc.include.sys_procfs
libc.include.sys_queue
libc.include.sys_random
libc.include.sys_resource
diff --git a/libc/include/CMakeLists.txt b/libc/include/CMakeLists.txt
index 69ab3e2e9a4dcd..3b1e2a045bffc5 100644
--- a/libc/include/CMakeLists.txt
+++ b/libc/include/CMakeLists.txt
@@ -703,6 +703,15 @@ add_header_macro(
.llvm-libc-types.posix_spawn_file_actions_t
)
+add_header_macro(
+ ar
+ ../libc/include/ar.yaml
+ ar.h
+ DEPENDS
+ .llvm_libc_common_h
+ .llvm-libc-types.struct_ar_hdr
+)
+
add_header_macro(
elf
../libc/include/elf.yaml
@@ -864,6 +873,28 @@ add_header_macro(
.llvm-libc-macros.sys_ptrace_macros
)
+add_header_macro(
+ sys_procfs
+ ../libc/include/sys/procfs.yaml
+ sys/procfs.h
+ DEPENDS
+ .llvm_libc_common_h
+ .llvm-libc-macros.sys_procfs_macros
+ .llvm-libc-types.elf_fpregset_t
+ .llvm-libc-types.elf_greg_t
+ .llvm-libc-types.elf_gregset_t
+ .llvm-libc-types.lwpid_t
+ .llvm-libc-types.prfpregset_t
+ .llvm-libc-types.prgregset_t
+ .llvm-libc-types.prpsinfo_t
+ .llvm-libc-types.prstatus_t
+ .llvm-libc-types.psaddr_t
+ .llvm-libc-types.struct_elf_prpsinfo
+ .llvm-libc-types.struct_elf_prstatus
+ .llvm-libc-types.struct_elf_siginfo
+ .llvm-libc-types.struct_user_regs_struct
+)
+
add_header(
sys_queue
HDR
@@ -1141,6 +1172,7 @@ add_header_macro(
sys/user.h
DEPENDS
.llvm_libc_common_h
+ .llvm-libc-types.struct_user_fpregs_struct
.llvm-libc-types.struct_user_regs_struct
)
diff --git a/libc/include/ar.yaml b/libc/include/ar.yaml
new file mode 100644
index 00000000000000..65665cfabcc993
--- /dev/null
+++ b/libc/include/ar.yaml
@@ -0,0 +1,12 @@
+header: ar.h
+standards:
+ - bsd
+macros:
+ - macro_name: ARMAG
+ macro_value: '"!<arch>\n"'
+ - macro_name: SARMAG
+ macro_value: 8
+ - macro_name: ARFMAG
+ macro_value: '"`\n"'
+types:
+ - type_name: struct_ar_hdr
diff --git a/libc/include/llvm-libc-macros/CMakeLists.txt b/libc/include/llvm-libc-macros/CMakeLists.txt
index c10fa399b82883..ac9a55cd1859a4 100644
--- a/libc/include/llvm-libc-macros/CMakeLists.txt
+++ b/libc/include/llvm-libc-macros/CMakeLists.txt
@@ -278,6 +278,12 @@ add_macro_header(
sys-ptrace-macros.h
)
+add_macro_header(
+ sys_procfs_macros
+ HDR
+ sys-procfs-macros.h
+)
+
add_macro_header(
sys_epoll_macros
HDR
diff --git a/libc/include/llvm-libc-macros/sys-procfs-macros.h b/libc/include/llvm-libc-macros/sys-procfs-macros.h
new file mode 100644
index 00000000000000..af92d1df8700f8
--- /dev/null
+++ b/libc/include/llvm-libc-macros/sys-procfs-macros.h
@@ -0,0 +1,24 @@
+//===----------------------------------------------------------------------===//
+//
+// 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
+//
+//===----------------------------------------------------------------------===//
+///
+/// \file
+/// Definition of macros from sys/procfs.h.
+///
+//===----------------------------------------------------------------------===//
+
+#ifndef LLVM_LIBC_MACROS_SYS_PROCFS_MACROS_H
+#define LLVM_LIBC_MACROS_SYS_PROCFS_MACROS_H
+
+// Number of general purpose registers in elf_gregset_t, computed the same way
+// as the kernel's ELF_NGREG.
+#define ELF_NGREG (sizeof(struct user_regs_struct) / sizeof(elf_greg_t))
+
+// Size of elf_prpsinfo's pr_psargs, the kernel's ELF_PRARGSZ.
+#define ELF_PRARGSZ 80
+
+#endif // LLVM_LIBC_MACROS_SYS_PROCFS_MACROS_H
diff --git a/libc/include/llvm-libc-proxy/elf_proxy.yaml b/libc/include/llvm-libc-proxy/elf_proxy.yaml
index 42788f3b3f071c..ced9353fbaf63c 100644
--- a/libc/include/llvm-libc-proxy/elf_proxy.yaml
+++ b/libc/include/llvm-libc-proxy/elf_proxy.yaml
@@ -375,6 +375,38 @@ macros:
macro_value: '0x70000000'
- macro_name: DT_HIPROC
macro_value: '0x7fffffff'
+ - macro_name: DT_VALRNGLO
+ macro_value: '0x6ffffd00'
+ - macro_name: DT_GNU_PRELINKED
+ macro_value: '0x6ffffdf5'
+ standards:
+ - gnu
+ - macro_name: DT_GNU_CONFLICTSZ
+ macro_value: '0x6ffffdf6'
+ standards:
+ - gnu
+ - macro_name: DT_GNU_LIBLISTSZ
+ macro_value: '0x6ffffdf7'
+ standards:
+ - gnu
+ - macro_name: DT_CHECKSUM
+ macro_value: '0x6ffffdf8'
+ - macro_name: DT_PLTPADSZ
+ macro_value: '0x6ffffdf9'
+ - macro_name: DT_MOVEENT
+ macro_value: '0x6ffffdfa'
+ - macro_name: DT_MOVESZ
+ macro_value: '0x6ffffdfb'
+ - macro_name: DT_FEATURE_1
+ macro_value: '0x6ffffdfc'
+ - macro_name: DT_POSFLAG_1
+ macro_value: '0x6ffffdfd'
+ - macro_name: DT_SYMINSZ
+ macro_value: '0x6ffffdfe'
+ - macro_name: DT_SYMINENT
+ macro_value: '0x6ffffdff'
+ - macro_name: DT_VALRNGHI
+ macro_value: '0x6ffffdff'
- macro_name: DT_ADDRRNGLO
macro_value: '0x6ffffe00'
- macro_name: DT_GNU_HASH
@@ -524,8 +556,95 @@ macros:
macro_value: 160
- macro_name: R_RISCV_IRELATIVE
macro_value: 58
+ # x86-64 relocation types
+ - macro_name: R_X86_64_NONE
+ macro_value: 0
+ - macro_name: R_X86_64_64
+ macro_value: 1
+ - macro_name: R_X86_64_PC32
+ macro_value: 2
+ - macro_name: R_X86_64_GOT32
+ macro_value: 3
+ - macro_name: R_X86_64_PLT32
+ macro_value: 4
+ - macro_name: R_X86_64_COPY
+ macro_value: 5
+ - macro_name: R_X86_64_GLOB_DAT
+ macro_value: 6
+ - macro_name: R_X86_64_JUMP_SLOT
+ macro_value: 7
+ - macro_name: R_X86_64_RELATIVE
+ macro_value: 8
+ - macro_name: R_X86_64_GOTPCREL
+ macro_value: 9
+ - macro_name: R_X86_64_32
+ macro_value: 10
+ - macro_name: R_X86_64_32S
+ macro_value: 11
+ - macro_name: R_X86_64_16
+ macro_value: 12
+ - macro_name: R_X86_64_PC16
+ macro_value: 13
+ - macro_name: R_X86_64_8
+ macro_value: 14
+ - macro_name: R_X86_64_PC8
+ macro_value: 15
+ - macro_name: R_X86_64_DTPMOD64
+ macro_value: 16
+ - macro_name: R_X86_64_DTPOFF64
+ macro_value: 17
+ - macro_name: R_X86_64_TPOFF64
+ macro_value: 18
+ - macro_name: R_X86_64_TLSGD
+ macro_value: 19
+ - macro_name: R_X86_64_TLSLD
+ macro_value: 20
+ - macro_name: R_X86_64_DTPOFF32
+ macro_value: 21
+ - macro_name: R_X86_64_GOTTPOFF
+ macro_value: 22
+ - macro_name: R_X86_64_TPOFF32
+ macro_value: 23
+ - macro_name: R_X86_64_PC64
+ macro_value: 24
+ - macro_name: R_X86_64_GOTOFF64
+ macro_value: 25
+ - macro_name: R_X86_64_GOTPC32
+ macro_value: 26
+ - macro_name: R_X86_64_GOT64
+ macro_value: 27
+ - macro_name: R_X86_64_GOTPCREL64
+ macro_value: 28
+ - macro_name: R_X86_64_GOTPC64
+ macro_value: 29
+ - macro_name: R_X86_64_GOTPLT64
+ macro_value: 30
+ - macro_name: R_X86_64_PLTOFF64
+ macro_value: 31
+ - macro_name: R_X86_64_SIZE32
+ macro_value: 32
+ - macro_name: R_X86_64_SIZE64
+ macro_value: 33
+ - macro_name: R_X86_64_GOTPC32_TLSDESC
+ macro_value: 34
+ - macro_name: R_X86_64_TLSDESC_CALL
+ macro_value: 35
+ - macro_name: R_X86_64_TLSDESC
+ macro_value: 36
- macro_name: R_X86_64_IRELATIVE
macro_value: 37
+ - macro_name: R_X86_64_GOTPCRELX
+ macro_value: 41
+ - macro_name: R_X86_64_REX_GOTPCRELX
+ macro_value: 42
+ - macro_name: R_X86_64_CODE_4_GOTPCRELX
+ macro_value: 43
+ - macro_name: R_X86_64_CODE_4_GOTTPOFF
+ macro_value: 44
+ - macro_name: R_X86_64_CODE_4_GOTPC32_TLSDESC
+ macro_value: 45
+ - macro_name: R_X86_64_CODE_6_GOTTPOFF
+ macro_value: 50
- macro_name: ELF32_ST_BIND
macro_header: elf-macros.h
- macro_name: ELF32_ST_TYPE
diff --git a/libc/include/llvm-libc-types/CMakeLists.txt b/libc/include/llvm-libc-types/CMakeLists.txt
index 22add8bdd81f0f..c6c8ef3deed354 100644
--- a/libc/include/llvm-libc-types/CMakeLists.txt
+++ b/libc/include/llvm-libc-types/CMakeLists.txt
@@ -645,6 +645,46 @@ endif()
add_type_header(mcontext_t HDR mcontext_t.h)
add_type_header(ucontext_t HDR ucontext_t.h)
add_type_header(struct_user_regs_struct HDR struct_user_regs_struct.h)
+add_type_header(struct_user_fpregs_struct HDR struct_user_fpregs_struct.h)
+add_header(elf_greg_t HDR elf_greg_t.h)
+add_header(
+ elf_gregset_t
+ HDR
+ elf_gregset_t.h
+ DEPENDS
+ .elf_greg_t
+ .struct_user_regs_struct
+ libc.include.llvm-libc-macros.sys_procfs_macros
+)
+add_header(elf_fpregset_t HDR elf_fpregset_t.h DEPENDS .struct_user_fpregs_struct)
+add_header(struct_elf_siginfo HDR struct_elf_siginfo.h)
+add_header(
+ struct_elf_prstatus
+ HDR
+ struct_elf_prstatus.h
+ DEPENDS
+ .elf_gregset_t
+ .pid_t
+ .struct_elf_siginfo
+ .struct_timeval
+)
+add_header(
+ struct_elf_prpsinfo
+ HDR
+ struct_elf_prpsinfo.h
+ DEPENDS
+ .gid_t
+ .pid_t
+ .uid_t
+ libc.include.llvm-libc-macros.sys_procfs_macros
+)
+add_header(prgregset_t HDR prgregset_t.h DEPENDS .elf_gregset_t)
+add_header(prfpregset_t HDR prfpregset_t.h DEPENDS .elf_fpregset_t)
+add_header(prstatus_t HDR prstatus_t.h DEPENDS .struct_elf_prstatus)
+add_header(prpsinfo_t HDR prpsinfo_t.h DEPENDS .struct_elf_prpsinfo)
+add_header(lwpid_t HDR lwpid_t.h DEPENDS .pid_t)
+add_header(psaddr_t HDR psaddr_t.h)
+add_header(struct_ar_hdr HDR struct_ar_hdr.h)
# UEFI
add_header(EFI_GUID HDR EFI_GUID.h DEPENDS libc.include.llvm-libc-macros.stdint_macros)
diff --git a/libc/include/llvm-libc-types/aarch64/CMakeLists.txt b/libc/include/llvm-libc-types/aarch64/CMakeLists.txt
new file mode 100644
index 00000000000000..efb30ed4a92601
--- /dev/null
+++ b/libc/include/llvm-libc-types/aarch64/CMakeLists.txt
@@ -0,0 +1,5 @@
+add_header(
+ struct_user_regs_struct
+ HDR
+ struct_user_regs_struct.h
+)
diff --git a/libc/include/llvm-libc-types/aarch64/struct_user_regs_struct.h b/libc/include/llvm-libc-types/aarch64/struct_user_regs_struct.h
new file mode 100644
index 00000000000000..5f69a8856ef3a7
--- /dev/null
+++ b/libc/include/llvm-libc-types/aarch64/struct_user_regs_struct.h
@@ -0,0 +1,25 @@
+//===----------------------------------------------------------------------===//
+//
+// 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
+//
+//===----------------------------------------------------------------------===//
+///
+/// \file
+/// Definition of struct user_regs_struct for aarch64.
+///
+//===----------------------------------------------------------------------===//
+
+#ifndef LLVM_LIBC_TYPES_AARCH64_STRUCT_USER_REGS_STRUCT_H
+#define LLVM_LIBC_TYPES_AARCH64_STRUCT_USER_REGS_STRUCT_H
+
+// Same layout as the kernel's struct user_pt_regs in <asm/ptrace.h>.
+struct user_regs_struct {
+ unsigned long long regs[31];
+ unsigned long long sp;
+ unsigned long long pc;
+ unsigned long long pstate;
+};
+
+#endif // LLVM_LIBC_TYPES_AARCH64_STRUCT_USER_REGS_STRUCT_H
diff --git a/libc/include/llvm-libc-types/elf_fpregset_t.h b/libc/include/llvm-libc-types/elf_fpregset_t.h
new file mode 100644
index 00000000000000..cfccd466b9072b
--- /dev/null
+++ b/libc/include/llvm-libc-types/elf_fpregset_t.h
@@ -0,0 +1,29 @@
+//===----------------------------------------------------------------------===//
+//
+// 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
+//
+//===----------------------------------------------------------------------===//
+///
+/// \file
+/// Definition of elf_fpregset_t type.
+///
+//===----------------------------------------------------------------------===//
+
+#ifndef LLVM_LIBC_TYPES_ELF_FPREGSET_T_H
+#define LLVM_LIBC_TYPES_ELF_FPREGSET_T_H
+
+// The floating-point register set the kernel writes to an NT_PRFPREG core
+// dump note (see elf_core_copy_task_fpregs in the kernel).
+#if defined(__x86_64__)
+#include "struct_user_fpregs_struct.h"
+typedef struct user_fpregs_struct elf_fpregset_t;
+#elif defined(__aarch64__)
+#include <asm/ptrace.h>
+typedef struct user_fpsimd_state elf_fpregset_t;
+#else
+#error "elf_fpregset_t not available for your target architecture."
+#endif
+
+#endif // LLVM_LIBC_TYPES_ELF_FPREGSET_T_H
diff --git a/libc/include/llvm-libc-types/elf_greg_t.h b/libc/include/llvm-libc-types/elf_greg_t.h
new file mode 100644
index 00000000000000..d29aa0d470a872
--- /dev/null
+++ b/libc/include/llvm-libc-types/elf_greg_t.h
@@ -0,0 +1,19 @@
+//===----------------------------------------------------------------------===//
+//
+// 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
+//
+//===----------------------------------------------------------------------===//
+///
+/// \file
+/// Definition of elf_greg_t type.
+///
+//===----------------------------------------------------------------------===//
+
+#ifndef LLVM_LIBC_TYPES_ELF_GREG_T_H
+#define LLVM_LIBC_TYPES_ELF_GREG_T_H
+
+typedef unsigned long elf_greg_t;
+
+#endif // LLVM_LIBC_TYPES_ELF_GREG_T_H
diff --git a/libc/include/llvm-libc-types/elf_gregset_t.h b/libc/include/llvm-libc-types/elf_gregset_t.h
new file mode 100644
index 00000000000000..673e64c7a96d39
--- /dev/null
+++ b/libc/include/llvm-libc-types/elf_gregset_t.h
@@ -0,0 +1,23 @@
+//===----------------------------------------------------------------------===//
+//
+// 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
+//
+//===----------------------------------------------------------------------===//
+///
+/// \file
+/// Definition of elf_gregset_t type.
+///
+//===----------------------------------------------------------------------===//
+
+#ifndef LLVM_LIBC_TYPES_ELF_GREGSET_T_H
+#define LLVM_LIBC_TYPES_ELF_GREGSET_T_H
+
+#include "../llvm-libc-macros/sys-procfs-macros.h"
+#include "elf_greg_t.h"
+#include "struct_user_regs_struct.h"
+
+typedef elf_greg_t elf_gregset_t[ELF_NGREG];
+
+#endif // LLVM_LIBC_TYPES_ELF_GREGSET_T_H
diff --git a/libc/include/llvm-libc-types/lwpid_t.h b/libc/include/llvm-libc-types/lwpid_t.h
new file mode 100644
index 00000000000000..b1d774d2447620
--- /dev/null
+++ b/libc/include/llvm-libc-types/lwpid_t.h
@@ -0,0 +1,21 @@
+//===----------------------------------------------------------------------===//
+//
+// 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
+//
+//===----------------------------------------------------------------------===//
+///
+/// \file
+/// Definition of lwpid_t type.
+///
+//===----------------------------------------------------------------------===//
+
+#ifndef LLVM_LIBC_TYPES_LWPID_T_H
+#define LLVM_LIBC_TYPES_LWPID_T_H
+
+#include "pid_t.h"
+
+typedef pid_t lwpid_t;
+
+#endif // LLVM_LIBC_TYPES_LWPID_T_H
diff --git a/libc/include/llvm-libc-types/prfpregset_t.h b/libc/include/llvm-libc-types/prfpregset_t.h
new file mode 100644
index 00000000000000..be34fc8648ca3f
--- /dev/null
+++ b/libc/include/llvm-libc-types/prfpregset_t.h
@@ -0,0 +1,21 @@
+//===----------------------------------------------------------------------===//
+//
+// 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
+//
+//===----------------------------------------------------------------------===//
+///
+/// \file
+/// Definition of prfpregset_t type.
+///
+//===----------------------------------------------------------------------===//
+
+#ifndef LLVM_LIBC_TYPES_PRFPREGSET_T_H
+#define LLVM_LIBC_TYPES_PRFPREGSET_T_H
+
+#include "elf_fpregset_t.h"
+
+typedef elf_fpregset_t prfpregset_t;
+
+#endif // LLVM_LIBC_TYPES_PRFPREGSET_T_H
diff --git a/libc/include/llvm-libc-types/prgregset_t.h b/libc/include/llvm-libc-types/prgregset_t.h
new file mode 100644
index 00000000000000..347fae2d66dd0d
--- /dev/null
+++ b/libc/include/llvm-libc-types/prgregset_t.h
@@ -0,0 +1,21 @@
+//===----------------------------------------------------------------------===//
+//
+// 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
+//
+//===----------------------------------------------------------------------===//
+///
+/// \file
+/// Definition of prgregset_t type.
+///
+//===----------------------------------------------------------------------===//
+
+#ifndef LLVM_LIBC_TYPES_PRGREGSET_T_H
+#define LLVM_LIBC_TYPES_PRGREGSET_T_H
+
+#include "elf_gregset_t.h"
+
+typedef elf_gregset_t prgregset_t;
+
+#endif // LLVM_LIBC_TYPES_PRGREGSET_T_H
diff --git a/libc/include/llvm-libc-types/prpsinfo_t.h b/libc/include/llvm-libc-types/prpsinfo_t.h
new file mode 100644
index 00000000000000..1544c1da453095
--- /dev/null
+++ b/libc/include/llvm-libc-types/prpsinfo_t.h
@@ -0,0 +1,21 @@
+//===----------------------------------------------------------------------===//
+//
+// 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
+//
+//===----------------------------------------------------------------------===//
+///
+/// \file
+/// Definition of prpsinfo_t type.
+///
+//===----------------------------------------------------------------------===//
+
+#ifndef LLVM_LIBC_TYPES_PRPSINFO_T_H
+#define LLVM_LIBC_TYPES_PRPSINFO_T_H
+
+#include "struct_elf_prpsinfo.h"
+
+typedef struct elf_prpsinfo prpsinfo_t;
+
+#endif // LLVM_LIBC_TYPES_PRPSINFO_T_H
diff --git a/libc/include/llvm-libc-types/prstatus_t.h b/libc/include/llvm-libc-types/prstatus_t.h
new file mode 100644
index 00000000000000..517dfde957e55e
--- /dev/null
+++ b/libc/include/llvm-libc-types/prstatus_t.h
@@ -0,0 +1,21 @@
+//===----------------------------------------------------------------------===//
+//
+// 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
+//
+//===----------------------------------------------------------------------===//
+///
+/// \file
+/// Definition of prstatus_t type.
+///
+//===----------------------------------------------------------------------===//
+
+#ifndef LLVM_LIBC_TYPES_PRSTATUS_T_H
+#define LLVM_LIBC_TYPES_PRSTATUS_T_H
+
+#include "struct_elf_prstatus.h"
+
+typedef struct elf_prstatus prstatus_t;
+
+#endif // LLVM_LIBC_TYPES_PRSTATUS_T_H
diff --git a/libc/include/llvm-libc-types/psaddr_t.h b/libc/include/llvm-libc-types/psaddr_t.h
new file mode 100644
index 00000000000000..a03e82c38ecebf
--- /dev/null
+++ b/libc/include/llvm-libc-types/psaddr_t.h
@@ -0,0 +1,19 @@
+//===----------------------------------------------------------------------===//
+//
+// 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
+//
+//===----------------------------------------------------------------------===//
+///
+/// \file
+/// Definition of psaddr_t type.
+///
+//===----------------------------------------------------------------------===//
+
+#ifndef LLVM_LIBC_TYPES_PSADDR_T_H
+#define LLVM_LIBC_TYPES_PSADDR_T_H
+
+typedef void *psaddr_t;
+
+#endif // LLVM_LIBC_TYPES_PSADDR_T_H
diff --git a/libc/include/llvm-libc-types/struct_ar_hdr.h b/libc/include/llvm-libc-types/struct_ar_hdr.h
new file mode 100644
index 00000000000000..caf9ea9bcd9be3
--- /dev/null
+++ b/libc/include/llvm-libc-types/struct_ar_hdr.h
@@ -0,0 +1,28 @@
+//===----------------------------------------------------------------------===//
+//
+// 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
+//
+//===----------------------------------------------------------------------===//
+///
+/// \file
+/// Definition of struct ar_hdr.
+///
+//===----------------------------------------------------------------------===//
+
+#ifndef LLVM_LIBC_TYPES_STRUCT_AR_HDR_H
+#define LLVM_LIBC_TYPES_STRUCT_AR_HDR_H
+
+// Archive member header. Every field is ASCII text padded with spaces.
+struct ar_hdr {
+ char ar_name[16]; // Member name, terminated by '/' in the System V format.
+ char ar_date[12]; // Modification time, decimal seconds since the Epoch.
+ char ar_uid[6]; // User ID, decimal.
+ char ar_gid[6]; // Group ID, decimal.
+ char ar_mode[8]; // File mode, octal.
+ char ar_size[10]; // Member size in bytes, decimal.
+ char ar_fmag[2]; // Always ARFMAG.
+};
+
+#endif // LLVM_LIBC_TYPES_STRUCT_AR_HDR_H
diff --git a/libc/include/llvm-libc-types/struct_elf_prpsinfo.h b/libc/include/llvm-libc-types/struct_elf_prpsinfo.h
new file mode 100644
index 00000000000000..2d9449c792a429
--- /dev/null
+++ b/libc/include/llvm-libc-types/struct_elf_prpsinfo.h
@@ -0,0 +1,40 @@
+//===----------------------------------------------------------------------===//
+//
+// 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
+//
+//===----------------------------------------------------------------------===//
+///
+/// \file
+/// Definition of struct elf_prpsinfo.
+///
+//===----------------------------------------------------------------------===//
+
+#ifndef LLVM_LIBC_TYPES_STRUCT_ELF_PRPSINFO_H
+#define LLVM_LIBC_TYPES_STRUCT_ELF_PRPSINFO_H
+
+#include "../llvm-libc-macros/sys-procfs-macros.h"
+#include "gid_t.h"
+#include "pid_t.h"
+#include "uid_t.h"
+
+// The NT_PRPSINFO core dump note. The layout matches the kernel's
+// struct elf_prpsinfo in include/linux/elfcore.h.
+struct elf_prpsinfo {
+ char pr_state;
+ char pr_sname;
+ char pr_zomb;
+ char pr_nice;
+ unsigned long pr_flag;
+ uid_t pr_uid;
+ gid_t pr_gid;
+ pid_t pr_pid;
+ pid_t pr_ppid;
+ pid_t pr_pgrp;
+ pid_t pr_sid;
+ char pr_fname[16];
+ char pr_psargs[ELF_PRARGSZ];
+};
+
+#endif // LLVM_LIBC_TYPES_STRUCT_ELF_PRPSINFO_H
diff --git a/libc/include/llvm-libc-types/struct_elf_prstatus.h b/libc/include/llvm-libc-types/struct_elf_prstatus.h
new file mode 100644
index 00000000000000..6520036f42d6c5
--- /dev/null
+++ b/libc/include/llvm-libc-types/struct_elf_prstatus.h
@@ -0,0 +1,42 @@
+//===----------------------------------------------------------------------===//
+//
+// 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
+//
+//===----------------------------------------------------------------------===//
+///
+/// \file
+/// Definition of struct elf_prstatus.
+///
+//===----------------------------------------------------------------------===//
+
+#ifndef LLVM_LIBC_TYPES_STRUCT_ELF_PRSTATUS_H
+#define LLVM_LIBC_TYPES_STRUCT_ELF_PRSTATUS_H
+
+#include "elf_gregset_t.h"
+#include "pid_t.h"
+#include "struct_elf_siginfo.h"
+#include "struct_timeval.h"
+
+// The NT_PRSTATUS core dump note. The layout matches the kernel's
+// struct elf_prstatus (struct elf_prstatus_common followed by pr_reg and
+// pr_fpvalid) in include/linux/elfcore.h, with the common fields flattened.
+struct elf_prstatus {
+ struct elf_siginfo pr_info;
+ short pr_cursig;
+ unsigned long pr_sigpend;
+ unsigned long pr_sighold;
+ pid_t pr_pid;
+ pid_t pr_ppid;
+ pid_t pr_pgrp;
+ pid_t pr_sid;
+ struct timeval pr_utime;
+ struct timeval pr_stime;
+ struct timeval pr_cutime;
+ struct timeval pr_cstime;
+ elf_gregset_t pr_reg;
+ int pr_fpvalid;
+};
+
+#endif // LLVM_LIBC_TYPES_STRUCT_ELF_PRSTATUS_H
diff --git a/libc/include/llvm-libc-types/struct_elf_siginfo.h b/libc/include/llvm-libc-types/struct_elf_siginfo.h
new file mode 100644
index 00000000000000..49b7f9e1b29c92
--- /dev/null
+++ b/libc/include/llvm-libc-types/struct_elf_siginfo.h
@@ -0,0 +1,24 @@
+//===----------------------------------------------------------------------===//
+//
+// 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
+//
+//===----------------------------------------------------------------------===//
+///
+/// \file
+/// Definition of struct elf_siginfo.
+///
+//===----------------------------------------------------------------------===//
+
+#ifndef LLVM_LIBC_TYPES_STRUCT_ELF_SIGINFO_H
+#define LLVM_LIBC_TYPES_STRUCT_ELF_SIGINFO_H
+
+// Matches struct elf_siginfo in the kernel's include/linux/elfcore.h.
+struct elf_siginfo {
+ int si_signo;
+ int si_code;
+ int si_errno;
+};
+
+#endif // LLVM_LIBC_TYPES_STRUCT_ELF_SIGINFO_H
diff --git a/libc/include/llvm-libc-types/struct_user_fpregs_struct.h b/libc/include/llvm-libc-types/struct_user_fpregs_struct.h
new file mode 100644
index 00000000000000..eb491d0c476f78
--- /dev/null
+++ b/libc/include/llvm-libc-types/struct_user_fpregs_struct.h
@@ -0,0 +1,23 @@
+//===----------------------------------------------------------------------===//
+//
+// 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
+//
+//===----------------------------------------------------------------------===//
+///
+/// \file
+/// Definition of type struct user_fpregs_struct.
+///
+//===----------------------------------------------------------------------===//
+
+#ifndef LLVM_LIBC_TYPES_STRUCT_USER_FPREGS_STRUCT_H
+#define LLVM_LIBC_TYPES_STRUCT_USER_FPREGS_STRUCT_H
+
+#if defined(__x86_64__)
+#include "x86_64/struct_user_fpregs_struct.h"
+#else
+#error "struct user_fpregs_struct not available for your target architecture."
+#endif
+
+#endif // LLVM_LIBC_TYPES_STRUCT_USER_FPREGS_STRUCT_H
diff --git a/libc/include/llvm-libc-types/struct_user_regs_struct.h b/libc/include/llvm-libc-types/struct_user_regs_struct.h
index a8a0fd7356d2fa..4320abb3e9c5e0 100644
--- a/libc/include/llvm-libc-types/struct_user_regs_struct.h
+++ b/libc/include/llvm-libc-types/struct_user_regs_struct.h
@@ -16,6 +16,8 @@
#if defined(__x86_64__)
#include "x86_64/struct_user_regs_struct.h"
+#elif defined(__aarch64__)
+#include "aarch64/struct_user_regs_struct.h"
#else
#error "struct user_regs_struct not available for your target architecture."
#endif
diff --git a/libc/include/llvm-libc-types/x86_64/CMakeLists.txt b/libc/include/llvm-libc-types/x86_64/CMakeLists.txt
index ec5202f9881f0c..11a90a1ee80185 100644
--- a/libc/include/llvm-libc-types/x86_64/CMakeLists.txt
+++ b/libc/include/llvm-libc-types/x86_64/CMakeLists.txt
@@ -19,3 +19,9 @@ add_header(
libc.include.llvm-libc-types.sigset_t
libc.include.llvm-libc-types.stack_t
)
+
+add_header(
+ struct_user_fpregs_struct
+ HDR
+ struct_user_fpregs_struct.h
+)
diff --git a/libc/include/llvm-libc-types/x86_64/struct_user_fpregs_struct.h b/libc/include/llvm-libc-types/x86_64/struct_user_fpregs_struct.h
new file mode 100644
index 00000000000000..e6c78a9655ef82
--- /dev/null
+++ b/libc/include/llvm-libc-types/x86_64/struct_user_fpregs_struct.h
@@ -0,0 +1,33 @@
+//===----------------------------------------------------------------------===//
+//
+// 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
+//
+//===----------------------------------------------------------------------===//
+///
+/// \file
+/// Definition of struct user_fpregs_struct for x86_64.
+///
+//===----------------------------------------------------------------------===//
+
+#ifndef LLVM_LIBC_TYPES_X86_64_STRUCT_USER_FPREGS_STRUCT_H
+#define LLVM_LIBC_TYPES_X86_64_STRUCT_USER_FPREGS_STRUCT_H
+
+// The 512-byte FXSAVE area, which the kernel exposes through PTRACE_GETFPREGS
+// and the NT_PRFPREG core dump note.
+struct user_fpregs_struct {
+ unsigned short cwd;
+ unsigned short swd;
+ unsigned short ftw;
+ unsigned short fop;
+ unsigned long long rip;
+ unsigned long long rdp;
+ unsigned int mxcsr;
+ unsigned int mxcr_mask;
+ unsigned int st_space[32];
+ unsigned int xmm_space[64];
+ unsigned int padding[24];
+};
+
+#endif // LLVM_LIBC_TYPES_X86_64_STRUCT_USER_FPREGS_STRUCT_H
diff --git a/libc/include/sys/procfs.yaml b/libc/include/sys/procfs.yaml
new file mode 100644
index 00000000000000..e76b7795a9863b
--- /dev/null
+++ b/libc/include/sys/procfs.yaml
@@ -0,0 +1,22 @@
+header: sys/procfs.h
+standards:
+ - linux
+macros:
+ - macro_name: ELF_NGREG
+ macro_header: sys-procfs-macros.h
+ - macro_name: ELF_PRARGSZ
+ macro_header: sys-procfs-macros.h
+types:
+ - type_name: elf_fpregset_t
+ - type_name: elf_greg_t
+ - type_name: elf_gregset_t
+ - type_name: lwpid_t
+ - type_name: prfpregset_t
+ - type_name: prgregset_t
+ - type_name: prpsinfo_t
+ - type_name: prstatus_t
+ - type_name: psaddr_t
+ - type_name: struct_elf_prpsinfo
+ - type_name: struct_elf_prstatus
+ - type_name: struct_elf_siginfo
+ - type_name: struct_user_regs_struct
diff --git a/libc/include/sys/user.yaml b/libc/include/sys/user.yaml
index 8f3d209cfd8c19..d56439bc6b7ea4 100644
--- a/libc/include/sys/user.yaml
+++ b/libc/include/sys/user.yaml
@@ -2,4 +2,5 @@ header: sys/user.h
standards:
- linux
types:
+ - type_name: struct_user_fpregs_struct
- type_name: struct_user_regs_struct
diff --git a/libc/test/include/CMakeLists.txt b/libc/test/include/CMakeLists.txt
index 7f6706e2621e66..ebce7f3ec59dfc 100644
--- a/libc/test/include/CMakeLists.txt
+++ b/libc/test/include/CMakeLists.txt
@@ -257,6 +257,33 @@ add_libc_test(
libc.include.llvm-libc-macros.netinet_in_macros
)
+add_libc_test(
+ ar_test
+ SUITE
+ libc-include-tests
+ SRCS
+ ar_test.cpp
+ DEPENDS
+ libc.include.llvm-libc-types.struct_ar_hdr
+)
+
+if(LIBC_TARGET_ARCHITECTURE_IS_X86_64 OR LIBC_TARGET_ARCHITECTURE_IS_AARCH64)
+ add_libc_test(
+ sys_procfs_test
+ SUITE
+ libc-include-tests
+ SRCS
+ sys_procfs_test.cpp
+ DEPENDS
+ libc.include.llvm-libc-macros.sys_procfs_macros
+ libc.include.llvm-libc-types.elf_fpregset_t
+ libc.include.llvm-libc-types.elf_gregset_t
+ libc.include.llvm-libc-types.struct_elf_prpsinfo
+ libc.include.llvm-libc-types.struct_elf_prstatus
+ libc.include.llvm-libc-types.struct_user_regs_struct
+ )
+endif()
+
add_subdirectory(net)
add_libc_test(
diff --git a/libc/test/include/ar_test.cpp b/libc/test/include/ar_test.cpp
new file mode 100644
index 00000000000000..f4471b97060fe7
--- /dev/null
+++ b/libc/test/include/ar_test.cpp
@@ -0,0 +1,20 @@
+//===----------------------------------------------------------------------===//
+//
+// 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
+//
+//===----------------------------------------------------------------------===//
+///
+/// \file
+/// Unittests for the struct ar_hdr type.
+///
+//===----------------------------------------------------------------------===//
+
+#include "include/llvm-libc-types/struct_ar_hdr.h"
+#include "test/UnitTest/Test.h"
+
+TEST(LlvmLibcArTest, HeaderIsSixtyBytes) {
+ ASSERT_EQ(sizeof(struct ar_hdr), size_t(60));
+ ASSERT_EQ(__builtin_offsetof(struct ar_hdr, ar_fmag), size_t(58));
+}
diff --git a/libc/test/include/sys_procfs_test.cpp b/libc/test/include/sys_procfs_test.cpp
new file mode 100644
index 00000000000000..c8832006eddf0f
--- /dev/null
+++ b/libc/test/include/sys_procfs_test.cpp
@@ -0,0 +1,40 @@
+//===----------------------------------------------------------------------===//
+//
+// 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
+//
+//===----------------------------------------------------------------------===//
+///
+/// \file
+/// Unittests for sys/procfs.h types.
+///
+//===----------------------------------------------------------------------===//
+
+#include "include/llvm-libc-macros/sys-procfs-macros.h"
+#include "include/llvm-libc-types/elf_fpregset_t.h"
+#include "include/llvm-libc-types/elf_gregset_t.h"
+#include "include/llvm-libc-types/struct_elf_prpsinfo.h"
+#include "include/llvm-libc-types/struct_elf_prstatus.h"
+#include "include/llvm-libc-types/struct_user_regs_struct.h"
+#include "test/UnitTest/Test.h"
+
+// These layouts are written to core dump notes by the kernel, so they are
+// checked against the sizes of the kernel's structures.
+#if defined(__x86_64__)
+static_assert(ELF_NGREG == 27);
+static_assert(sizeof(elf_fpregset_t) == 512);
+static_assert(__builtin_offsetof(struct elf_prstatus, pr_reg) == 112);
+static_assert(sizeof(struct elf_prstatus) == 336);
+static_assert(sizeof(struct elf_prpsinfo) == 136);
+#elif defined(__aarch64__)
+static_assert(ELF_NGREG == 34);
+static_assert(sizeof(elf_fpregset_t) == 528);
+static_assert(__builtin_offsetof(struct elf_prstatus, pr_reg) == 112);
+static_assert(sizeof(struct elf_prstatus) == 392);
+static_assert(sizeof(struct elf_prpsinfo) == 136);
+#endif
+
+TEST(LlvmLibcSysProcfsTest, GregsetHoldsUserRegs) {
+ ASSERT_EQ(sizeof(elf_gregset_t), sizeof(struct user_regs_struct));
+}
More information about the libc-commits
mailing list