[libc-commits] [libc] [libc] Add more macro/type declarations to Elf headers. (PR #185348)
Alexey Samsonov via libc-commits
libc-commits at lists.llvm.org
Sun Mar 8 22:39:23 PDT 2026
https://github.com/vonosmas created https://github.com/llvm/llvm-project/pull/185348
* Add several `AT_` macro values from `<sys/auxv.h>`. In particular, this allows to make internal Linux auxv header parsing more hermetic by removing one of Linux header includes.
* Add constants between `DT_ADDRNGLO` and `DT_ADDRNGHI`, in particular `DT_GNU_HASH`, which is de-facto standard on many platforms.
* Add `Elf32_auxv_t` and `Elf64_auxv_t` types which define the auxv entries and can be used by VDSO parsing code. Note that this PR doesn't yet update libc's own Linux auxv header support (in `src/__support/OSUtil/linux/auxv.h`).
This fixes some of the missing definitions when building code working with Elf files, such as Abseil's debugging support in
https://github.com/abseil/abseil-cpp/tree/master/absl/debugging/internal.
>From a982e73ae3f9a728444e95da76b5f794382317f1 Mon Sep 17 00:00:00 2001
From: Alexey Samsonov <vonosmas at gmail.com>
Date: Mon, 9 Mar 2026 05:22:14 +0000
Subject: [PATCH] [libc] Add more macro/type declarations to Elf headers.
* Add several `AT_` macro values from `<sys/auxv.h>`. In particular,
this allows to make internal Linux auxv header parsing more hermetic
by removing one of Linux header includes.
* Add constants between `DT_ADDRNGLO` and `DT_ADDRNGHI`, in particular
`DT_GNU_HASH`, which is de-facto standard on many platforms.
* Add `Elf32_auxv_t` and `Elf64_auxv_t` types which define the auxv
entries and can be used by VDSO parsing code. Note that this PR
doesn't yet update libc's own Linux auxv header support
(in `src/__support/OSUtil/linux/auxv.h`).
This fixes some of the missing definitions when building code working
with Elf files, such as Abseil's debugging support
in
https://github.com/abseil/abseil-cpp/tree/master/absl/debugging/internal.
---
libc/hdr/CMakeLists.txt | 2 +
libc/hdr/types/CMakeLists.txt | 16 ++++++++
libc/hdr/types/Elf32_auxv_t.h | 22 +++++++++++
libc/hdr/types/Elf64_auxv_t.h | 22 +++++++++++
libc/include/CMakeLists.txt | 2 +
libc/include/elf.yaml | 38 +++++++++++++++++++
libc/include/llvm-libc-macros/link-macros.h | 2 +
.../llvm-libc-macros/sys-auxv-macros.h | 4 ++
libc/include/llvm-libc-types/CMakeLists.txt | 2 +
libc/include/llvm-libc-types/Elf32_auxv_t.h | 21 ++++++++++
libc/include/llvm-libc-types/Elf64_auxv_t.h | 21 ++++++++++
.../src/__support/OSUtil/linux/CMakeLists.txt | 1 +
libc/src/__support/OSUtil/linux/auxv.h | 2 +-
13 files changed, 154 insertions(+), 1 deletion(-)
create mode 100644 libc/hdr/types/Elf32_auxv_t.h
create mode 100644 libc/hdr/types/Elf64_auxv_t.h
create mode 100644 libc/include/llvm-libc-types/Elf32_auxv_t.h
create mode 100644 libc/include/llvm-libc-types/Elf64_auxv_t.h
diff --git a/libc/hdr/CMakeLists.txt b/libc/hdr/CMakeLists.txt
index 20d210c0c443f..8a1f40e64ca16 100644
--- a/libc/hdr/CMakeLists.txt
+++ b/libc/hdr/CMakeLists.txt
@@ -313,6 +313,7 @@ add_gen_header(
libc.include.llvm-libc-types.Elf32_Versym
libc.include.llvm-libc-types.Elf32_Word
libc.include.llvm-libc-types.Elf32_Xword
+ libc.include.llvm-libc-types.Elf32_auxv_t
libc.include.llvm-libc-types.Elf64_Addr
libc.include.llvm-libc-types.Elf64_Chdr
libc.include.llvm-libc-types.Elf64_Dyn
@@ -335,6 +336,7 @@ add_gen_header(
libc.include.llvm-libc-types.Elf64_Versym
libc.include.llvm-libc-types.Elf64_Word
libc.include.llvm-libc-types.Elf64_Xword
+ libc.include.llvm-libc-types.Elf64_auxv_t
PROXY
)
diff --git a/libc/hdr/types/CMakeLists.txt b/libc/hdr/types/CMakeLists.txt
index 1832f906d774c..dec73b0665f08 100644
--- a/libc/hdr/types/CMakeLists.txt
+++ b/libc/hdr/types/CMakeLists.txt
@@ -674,6 +674,14 @@ add_proxy_header_library(
libc.include.llvm-libc-types.Elf32_Xword
)
+add_proxy_header_library(
+ Elf32_auxv_t
+ HDRS
+ Elf32_auxv_t.h
+ FULL_BUILD_DEPENDS
+ libc.include.llvm-libc-types.Elf32_auxv_t
+)
+
add_proxy_header_library(
Elf64_Addr
HDRS
@@ -810,6 +818,14 @@ add_proxy_header_library(
libc.include.llvm-libc-types.Elf64_Xword
)
+add_proxy_header_library(
+ Elf64_auxv_t
+ HDRS
+ Elf64_auxv_t.h
+ FULL_BUILD_DEPENDS
+ libc.include.llvm-libc-types.Elf64_auxv_t
+)
+
add_proxy_header_library(
Elf64_Verdaux
HDRS
diff --git a/libc/hdr/types/Elf32_auxv_t.h b/libc/hdr/types/Elf32_auxv_t.h
new file mode 100644
index 0000000000000..3a0db27510e20
--- /dev/null
+++ b/libc/hdr/types/Elf32_auxv_t.h
@@ -0,0 +1,22 @@
+//===-- Proxy for Elf32_auxv_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_HDR_TYPES_ELF32_AUXV_T_H
+#define LLVM_LIBC_HDR_TYPES_ELF32_AUXV_T_H
+
+#ifdef LIBC_FULL_BUILD
+
+#include "include/llvm-libc-types/Elf32_auxv_t.h"
+
+#else // Overlay mode
+
+#include <elf.h>
+
+#endif // LLVM_LIBC_FULL_BUILD
+
+#endif // LLVM_LIBC_HDR_TYPES_ELF32_AUXV_T_H
diff --git a/libc/hdr/types/Elf64_auxv_t.h b/libc/hdr/types/Elf64_auxv_t.h
new file mode 100644
index 0000000000000..2b600880738c0
--- /dev/null
+++ b/libc/hdr/types/Elf64_auxv_t.h
@@ -0,0 +1,22 @@
+//===-- Proxy for Elf64_auxv_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_HDR_TYPES_ELF64_AUXV_T_H
+#define LLVM_LIBC_HDR_TYPES_ELF64_AUXV_T_H
+
+#ifdef LIBC_FULL_BUILD
+
+#include "include/llvm-libc-types/Elf64_auxv_t.h"
+
+#else // Overlay mode
+
+#include <elf.h>
+
+#endif // LLVM_LIBC_FULL_BUILD
+
+#endif // LLVM_LIBC_HDR_TYPES_ELF64_AUXV_T_H
diff --git a/libc/include/CMakeLists.txt b/libc/include/CMakeLists.txt
index 94c663c7d3917..b2ebd035872aa 100644
--- a/libc/include/CMakeLists.txt
+++ b/libc/include/CMakeLists.txt
@@ -498,6 +498,7 @@ add_header_macro(
.llvm-libc-types.Elf32_Versym
.llvm-libc-types.Elf32_Word
.llvm-libc-types.Elf32_Xword
+ .llvm-libc-types.Elf32_auxv_t
.llvm-libc-types.Elf64_Addr
.llvm-libc-types.Elf64_Chdr
.llvm-libc-types.Elf64_Dyn
@@ -520,6 +521,7 @@ add_header_macro(
.llvm-libc-types.Elf64_Versym
.llvm-libc-types.Elf64_Word
.llvm-libc-types.Elf64_Xword
+ .llvm-libc-types.Elf64_auxv_t
)
# TODO: Not all platforms will have a include/sys directory. Add the sys
diff --git a/libc/include/elf.yaml b/libc/include/elf.yaml
index 1b5e01123582f..903e85e88e3ad 100644
--- a/libc/include/elf.yaml
+++ b/libc/include/elf.yaml
@@ -358,6 +358,42 @@ macros:
macro_value: '0x70000000'
- macro_name: DT_HIPROC
macro_value: '0x7fffffff'
+ - macro_name: DT_ADDRRNGLO
+ macro_value: '0x6ffffe00'
+ - macro_name: DT_GNU_HASH
+ macro_value: '0x6ffffef5'
+ standards:
+ - gnu
+ - macro_name: DT_TLSDESC_PLT
+ macro_value: '0x6ffffef6'
+ standards:
+ - gnu
+ - macro_name: DT_TLSDESC_GOT
+ macro_value: '0x6ffffef7'
+ standards:
+ - gnu
+ - macro_name: DT_GNU_CONFLICT
+ macro_value: '0x6ffffef8'
+ standards:
+ - gnu
+ - macro_name: DT_GNU_LIBLIST
+ macro_value: '0x6ffffef9'
+ standards:
+ - gnu
+ - macro_name: DT_CONFIG
+ macro_value: '0x6ffffefa'
+ - macro_name: DT_DEPAUDIT
+ macro_value: '0x6ffffefb'
+ - macro_name: DT_AUDIT
+ macro_value: '0x6ffffefc'
+ - macro_name: DT_PLTPAD
+ macro_value: '0x6ffffefd'
+ - macro_name: DT_MOVETAB
+ macro_value: '0x6ffffefe'
+ - macro_name: DT_SYMINFO
+ macro_value: '0x6ffffeff'
+ - macro_name: DT_ADDRRNGHI
+ macro_value: '0x6ffffeff'
- macro_name: DT_VERSYM
macro_value: '0x6ffffff0'
- macro_name: DT_RELACOUNT
@@ -471,6 +507,7 @@ types:
- type_name: Elf32_Versym
- type_name: Elf32_Word
- type_name: Elf32_Xword
+ - type_name: Elf32_auxv_t
- type_name: Elf64_Addr
- type_name: Elf64_Chdr
- type_name: Elf64_Dyn
@@ -493,6 +530,7 @@ types:
- type_name: Elf64_Versym
- type_name: Elf64_Word
- type_name: Elf64_Xword
+ - type_name: Elf64_auxv_t
enums: []
objects: []
functions: []
diff --git a/libc/include/llvm-libc-macros/link-macros.h b/libc/include/llvm-libc-macros/link-macros.h
index 7430e5268b104..64fee52f936b0 100644
--- a/libc/include/llvm-libc-macros/link-macros.h
+++ b/libc/include/llvm-libc-macros/link-macros.h
@@ -25,6 +25,7 @@
#include "../llvm-libc-types/Elf32_Sym.h"
#include "../llvm-libc-types/Elf32_Word.h"
#include "../llvm-libc-types/Elf32_Xword.h"
+#include "../llvm-libc-types/Elf32_auxv_t.h"
#include "../llvm-libc-types/Elf64_Addr.h"
#include "../llvm-libc-types/Elf64_Chdr.h"
#include "../llvm-libc-types/Elf64_Dyn.h"
@@ -42,6 +43,7 @@
#include "../llvm-libc-types/Elf64_Sym.h"
#include "../llvm-libc-types/Elf64_Word.h"
#include "../llvm-libc-types/Elf64_Xword.h"
+#include "../llvm-libc-types/Elf64_auxv_t.h"
#ifdef __LP64__
#define ElfW(type) Elf64_##type
diff --git a/libc/include/llvm-libc-macros/sys-auxv-macros.h b/libc/include/llvm-libc-macros/sys-auxv-macros.h
index 2dcaa2f1a8ee8..2382b34b9cf08 100644
--- a/libc/include/llvm-libc-macros/sys-auxv-macros.h
+++ b/libc/include/llvm-libc-macros/sys-auxv-macros.h
@@ -33,8 +33,12 @@
#define AT_BASE_PLATFORM 24
#define AT_RANDOM 25
#define AT_HWCAP2 26
+#define AT_HWCAP3 29
+#define AT_HWCAP4 30
#define AT_EXECFN 31
+#define AT_SYSINFO 32
+#define AT_SYSINFO_EHDR 33
#ifndef AT_MINSIGSTKSZ
#define AT_MINSIGSTKSZ 51
diff --git a/libc/include/llvm-libc-types/CMakeLists.txt b/libc/include/llvm-libc-types/CMakeLists.txt
index eb8356cbfb8bb..5d82660fd6762 100644
--- a/libc/include/llvm-libc-types/CMakeLists.txt
+++ b/libc/include/llvm-libc-types/CMakeLists.txt
@@ -205,6 +205,7 @@ add_header(Elf32_Off HDR Elf32_Off.h DEPENDS libc.include.llvm-libc-macros.stdin
add_header(Elf32_Sword HDR Elf32_Sword.h DEPENDS libc.include.llvm-libc-macros.stdint_macros)
add_header(Elf32_Word HDR Elf32_Word.h DEPENDS libc.include.llvm-libc-macros.stdint_macros)
add_header(Elf32_Xword HDR Elf32_Xword.h DEPENDS libc.include.llvm-libc-macros.stdint_macros)
+add_header(Elf32_auxv_t HDR Elf32_auxv_t.h DEPENDS libc.include.llvm-libc-macros.stdint_macros)
add_header(
Elf32_Chdr
HDR
@@ -323,6 +324,7 @@ add_header(Elf64_Sword HDR Elf64_Sword.h DEPENDS libc.include.llvm-libc-macros.s
add_header(Elf64_Sxword HDR Elf64_Sxword.h DEPENDS libc.include.llvm-libc-macros.stdint_macros)
add_header(Elf64_Word HDR Elf64_Word.h DEPENDS libc.include.llvm-libc-macros.stdint_macros)
add_header(Elf64_Xword HDR Elf64_Xword.h DEPENDS libc.include.llvm-libc-macros.stdint_macros)
+add_header(Elf64_auxv_t HDR Elf64_auxv_t.h DEPENDS libc.include.llvm-libc-macros.stdint_macros)
add_header(
Elf64_Chdr
HDR
diff --git a/libc/include/llvm-libc-types/Elf32_auxv_t.h b/libc/include/llvm-libc-types/Elf32_auxv_t.h
new file mode 100644
index 0000000000000..280b85af9876f
--- /dev/null
+++ b/libc/include/llvm-libc-types/Elf32_auxv_t.h
@@ -0,0 +1,21 @@
+//===-- Definition of Elf32_auxv_t type -----------------------------------===//
+//
+// 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_ELF32_AUXV_T_H
+#define LLVM_LIBC_TYPES_ELF32_AUXV_T_H
+
+#include "../llvm-libc-macros/stdint-macros.h"
+
+typedef struct {
+ uint32_t a_type;
+ union {
+ uint32_t a_val;
+ } a_un;
+} Elf32_auxv_t;
+
+#endif // LLVM_LIBC_TYPES_ELF32_AUXV_T_H
diff --git a/libc/include/llvm-libc-types/Elf64_auxv_t.h b/libc/include/llvm-libc-types/Elf64_auxv_t.h
new file mode 100644
index 0000000000000..95494cfc0ecfc
--- /dev/null
+++ b/libc/include/llvm-libc-types/Elf64_auxv_t.h
@@ -0,0 +1,21 @@
+//===-- Definition of Elf64_auxv_t type -----------------------------------===//
+//
+// 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_ELF64_AUXV_T_H
+#define LLVM_LIBC_TYPES_ELF64_AUXV_T_H
+
+#include "../llvm-libc-macros/stdint-macros.h"
+
+typedef struct {
+ uint64_t a_type;
+ union {
+ uint64_t a_val;
+ } a_un;
+} Elf64_auxv_t;
+
+#endif // LLVM_LIBC_TYPES_ELF64_AUXV_T_H
diff --git a/libc/src/__support/OSUtil/linux/CMakeLists.txt b/libc/src/__support/OSUtil/linux/CMakeLists.txt
index bb7bd3fdf3f63..406c618eaba1c 100644
--- a/libc/src/__support/OSUtil/linux/CMakeLists.txt
+++ b/libc/src/__support/OSUtil/linux/CMakeLists.txt
@@ -30,6 +30,7 @@ add_header_library(
auxv.h
DEPENDS
libc.hdr.fcntl_macros
+ libc.hdr.sys_auxv_macros
libc.src.__support.OSUtil.osutil
libc.src.__support.common
libc.src.__support.CPP.optional
diff --git a/libc/src/__support/OSUtil/linux/auxv.h b/libc/src/__support/OSUtil/linux/auxv.h
index 9c07c544be241..1dc9bf0930b7c 100644
--- a/libc/src/__support/OSUtil/linux/auxv.h
+++ b/libc/src/__support/OSUtil/linux/auxv.h
@@ -10,11 +10,11 @@
#define LLVM_LIBC_SRC___SUPPORT_OSUTIL_LINUX_AUXV_H
#include "hdr/fcntl_macros.h" // For open flags
+#include "hdr/sys_auxv_macros.h" // For AT_ macros
#include "src/__support/OSUtil/syscall.h"
#include "src/__support/common.h"
#include "src/__support/threads/callonce.h"
-#include <linux/auxvec.h> // For AT_ macros
#include <linux/mman.h> // For mmap flags
#include <linux/param.h> // For EXEC_PAGESIZE
#include <linux/prctl.h> // For prctl
More information about the libc-commits
mailing list