Skip to content

Commit 6c1f56f

Browse files
[libc] expose aux vector (#75806)
This patch lifts aux vector related definitions to app.h. Because startup's refactoring is in progress, this patch still contains duplicated changes. This problem will be addressed very soon in an incoming patch.
1 parent 927926b commit 6c1f56f

File tree

4 files changed

+26
-28
lines changed

4 files changed

+26
-28
lines changed

libc/config/linux/app.h

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -49,11 +49,21 @@ typedef uintptr_t ArgcType;
4949
typedef uintptr_t ArgVEntryType;
5050

5151
typedef uintptr_t EnvironType;
52-
typedef uintptr_t AuxEntryType;
5352
#else
5453
#error "argc and argv types are not defined for the target platform."
5554
#endif
5655

56+
// Linux manpage on `proc(5)` says that the aux vector is an array of
57+
// unsigned long pairs.
58+
// (see: https://man7.org/linux/man-pages/man5/proc.5.html)
59+
using AuxEntryType = unsigned long;
60+
// Using the naming convention from `proc(5)`.
61+
// TODO: Would be nice to use the aux entry structure from elf.h when available.
62+
struct AuxEntry {
63+
AuxEntryType id;
64+
AuxEntryType value;
65+
};
66+
5767
struct Args {
5868
ArgcType argc;
5969

@@ -78,6 +88,9 @@ struct AppProperties {
7888

7989
// Environment data.
8090
EnvironType *env_ptr;
91+
92+
// Auxiliary vector data.
93+
AuxEntry *auxv_ptr;
8194
};
8295

8396
extern AppProperties app;

libc/startup/linux/aarch64/start.cpp

Lines changed: 4 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -126,12 +126,7 @@ static void call_fini_array_callbacks() {
126126
} // namespace LIBC_NAMESPACE
127127

128128
using LIBC_NAMESPACE::app;
129-
130-
// TODO: Would be nice to use the aux entry structure from elf.h when available.
131-
struct AuxEntry {
132-
uint64_t type;
133-
uint64_t value;
134-
};
129+
using LIBC_NAMESPACE::AuxEntry;
135130

136131
__attribute__((noinline)) static void do_start() {
137132
auto tid = LIBC_NAMESPACE::syscall_impl<long>(SYS_gettid);
@@ -155,9 +150,9 @@ __attribute__((noinline)) static void do_start() {
155150
// denoted by an AT_NULL entry.
156151
Elf64_Phdr *program_hdr_table = nullptr;
157152
uintptr_t program_hdr_count;
158-
for (AuxEntry *aux_entry = reinterpret_cast<AuxEntry *>(env_end_marker + 1);
159-
aux_entry->type != AT_NULL; ++aux_entry) {
160-
switch (aux_entry->type) {
153+
app.auxv_ptr = reinterpret_cast<AuxEntry *>(env_end_marker + 1);
154+
for (auto *aux_entry = app.auxv_ptr; aux_entry->id != AT_NULL; ++aux_entry) {
155+
switch (aux_entry->id) {
161156
case AT_PHDR:
162157
program_hdr_table = reinterpret_cast<Elf64_Phdr *>(aux_entry->value);
163158
break;

libc/startup/linux/riscv/start.cpp

Lines changed: 4 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -115,12 +115,7 @@ static void call_fini_array_callbacks() {
115115
} // namespace LIBC_NAMESPACE
116116

117117
using LIBC_NAMESPACE::app;
118-
119-
// TODO: Would be nice to use the aux entry structure from elf.h when available.
120-
struct AuxEntry {
121-
LIBC_NAMESPACE::AuxEntryType type;
122-
LIBC_NAMESPACE::AuxEntryType value;
123-
};
118+
using LIBC_NAMESPACE::AuxEntry;
124119

125120
#if defined(LIBC_TARGET_ARCH_IS_X86_64) || \
126121
defined(LIBC_TARGET_ARCH_IS_AARCH64) || \
@@ -158,9 +153,9 @@ __attribute__((noinline)) static void do_start() {
158153
// denoted by an AT_NULL entry.
159154
PgrHdrTableType *program_hdr_table = nullptr;
160155
uintptr_t program_hdr_count;
161-
for (AuxEntry *aux_entry = reinterpret_cast<AuxEntry *>(env_end_marker + 1);
162-
aux_entry->type != AT_NULL; ++aux_entry) {
163-
switch (aux_entry->type) {
156+
app.auxv_ptr = reinterpret_cast<AuxEntry *>(env_end_marker + 1);
157+
for (auto *aux_entry = app.auxv_ptr; aux_entry->id != AT_NULL; ++aux_entry) {
158+
switch (aux_entry->id) {
164159
case AT_PHDR:
165160
program_hdr_table = reinterpret_cast<PgrHdrTableType *>(aux_entry->value);
166161
break;

libc/startup/linux/x86_64/start.cpp

Lines changed: 4 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -144,12 +144,7 @@ static void call_fini_array_callbacks() {
144144
} // namespace LIBC_NAMESPACE
145145

146146
using LIBC_NAMESPACE::app;
147-
148-
// TODO: Would be nice to use the aux entry structure from elf.h when available.
149-
struct AuxEntry {
150-
uint64_t type;
151-
uint64_t value;
152-
};
147+
using LIBC_NAMESPACE::AuxEntry;
153148

154149
extern "C" void _start() {
155150
// This TU is compiled with -fno-omit-frame-pointer. Hence, the previous value
@@ -193,9 +188,9 @@ extern "C" void _start() {
193188
// denoted by an AT_NULL entry.
194189
Elf64_Phdr *program_hdr_table = nullptr;
195190
uintptr_t program_hdr_count = 0;
196-
for (AuxEntry *aux_entry = reinterpret_cast<AuxEntry *>(env_end_marker + 1);
197-
aux_entry->type != AT_NULL; ++aux_entry) {
198-
switch (aux_entry->type) {
191+
app.auxv_ptr = reinterpret_cast<AuxEntry *>(env_end_marker + 1);
192+
for (auto *aux_entry = app.auxv_ptr; aux_entry->id != AT_NULL; ++aux_entry) {
193+
switch (aux_entry->id) {
199194
case AT_PHDR:
200195
program_hdr_table = reinterpret_cast<Elf64_Phdr *>(aux_entry->value);
201196
break;

0 commit comments

Comments
 (0)