Skip to content

Commit a0eda10

Browse files
[libc][NFC] unify startup library's code style with the rest (#74041)
This PR unifies the startup library's code style with the rest of libc.
1 parent c146c3b commit a0eda10

File tree

5 files changed

+48
-47
lines changed

5 files changed

+48
-47
lines changed

libc/config/linux/app.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -69,15 +69,15 @@ struct Args {
6969
// Data structure which captures properties of a linux application.
7070
struct AppProperties {
7171
// Page size used for the application.
72-
uintptr_t pageSize;
72+
uintptr_t page_size;
7373

7474
Args *args;
7575

7676
// The properties of an application's TLS image.
7777
TLSImage tls;
7878

7979
// Environment data.
80-
EnvironType *envPtr;
80+
EnvironType *env_ptr;
8181
};
8282

8383
extern AppProperties app;

libc/src/stdlib/getenv.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@
1616
namespace LIBC_NAMESPACE {
1717

1818
LLVM_LIBC_FUNCTION(char *, getenv, (const char *name)) {
19-
char **env_ptr = reinterpret_cast<char **>(LIBC_NAMESPACE::app.envPtr);
19+
char **env_ptr = reinterpret_cast<char **>(LIBC_NAMESPACE::app.env_ptr);
2020

2121
if (name == nullptr || env_ptr == nullptr)
2222
return nullptr;

libc/startup/linux/aarch64/start.cpp

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -74,7 +74,7 @@ void init_tls(TLSDescriptor &tls_descriptor) {
7474
MAP_ANONYMOUS | MAP_PRIVATE, -1, 0);
7575
// We cannot check the return value with MAP_FAILED as that is the return
7676
// of the mmap function and not the mmap syscall.
77-
if (mmap_ret_val < 0 && static_cast<uintptr_t>(mmap_ret_val) > -app.pageSize)
77+
if (mmap_ret_val < 0 && static_cast<uintptr_t>(mmap_ret_val) > -app.page_size)
7878
LIBC_NAMESPACE::syscall_impl<long>(SYS_exit, 1);
7979
uintptr_t thread_ptr = uintptr_t(reinterpret_cast<uintptr_t *>(mmap_ret_val));
8080
uintptr_t tls_addr = thread_ptr + size_of_pointers + padding;
@@ -144,7 +144,7 @@ __attribute__((noinline)) static void do_start() {
144144
// value. We step over it (the "+ 1" below) to get to the env values.
145145
uint64_t *env_ptr = app.args->argv + app.args->argc + 1;
146146
uint64_t *env_end_marker = env_ptr;
147-
app.envPtr = env_ptr;
147+
app.env_ptr = env_ptr;
148148
while (*env_end_marker)
149149
++env_end_marker;
150150

@@ -153,28 +153,28 @@ __attribute__((noinline)) static void do_start() {
153153

154154
// After the env array, is the aux-vector. The end of the aux-vector is
155155
// denoted by an AT_NULL entry.
156-
Elf64_Phdr *programHdrTable = nullptr;
157-
uintptr_t programHdrCount;
156+
Elf64_Phdr *program_hdr_table = nullptr;
157+
uintptr_t program_hdr_count;
158158
for (AuxEntry *aux_entry = reinterpret_cast<AuxEntry *>(env_end_marker + 1);
159159
aux_entry->type != AT_NULL; ++aux_entry) {
160160
switch (aux_entry->type) {
161161
case AT_PHDR:
162-
programHdrTable = reinterpret_cast<Elf64_Phdr *>(aux_entry->value);
162+
program_hdr_table = reinterpret_cast<Elf64_Phdr *>(aux_entry->value);
163163
break;
164164
case AT_PHNUM:
165-
programHdrCount = aux_entry->value;
165+
program_hdr_count = aux_entry->value;
166166
break;
167167
case AT_PAGESZ:
168-
app.pageSize = aux_entry->value;
168+
app.page_size = aux_entry->value;
169169
break;
170170
default:
171171
break; // TODO: Read other useful entries from the aux vector.
172172
}
173173
}
174174

175175
app.tls.size = 0;
176-
for (uintptr_t i = 0; i < programHdrCount; ++i) {
177-
Elf64_Phdr *phdr = programHdrTable + i;
176+
for (uintptr_t i = 0; i < program_hdr_count; ++i) {
177+
Elf64_Phdr *phdr = program_hdr_table + i;
178178
if (phdr->p_type != PT_TLS)
179179
continue;
180180
// TODO: p_vaddr value has to be adjusted for static-pie executables.

libc/startup/linux/riscv/start.cpp

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -61,7 +61,7 @@ void init_tls(TLSDescriptor &tls_descriptor) {
6161
MAP_ANONYMOUS | MAP_PRIVATE, -1, 0);
6262
// We cannot check the return value with MAP_FAILED as that is the return
6363
// of the mmap function and not the mmap syscall.
64-
if (mmap_ret_val < 0 && static_cast<uintptr_t>(mmap_ret_val) > -app.pageSize)
64+
if (mmap_ret_val < 0 && static_cast<uintptr_t>(mmap_ret_val) > -app.page_size)
6565
LIBC_NAMESPACE::syscall_impl<long>(SYS_exit, 1);
6666
uintptr_t thread_ptr = uintptr_t(reinterpret_cast<uintptr_t *>(mmap_ret_val));
6767
uintptr_t tls_addr = thread_ptr + size_of_pointers + padding;
@@ -147,7 +147,7 @@ __attribute__((noinline)) static void do_start() {
147147
// value. We step over it (the "+ 1" below) to get to the env values.
148148
LIBC_NAMESPACE::ArgVEntryType *env_ptr = app.args->argv + app.args->argc + 1;
149149
LIBC_NAMESPACE::ArgVEntryType *env_end_marker = env_ptr;
150-
app.envPtr = env_ptr;
150+
app.env_ptr = env_ptr;
151151
while (*env_end_marker)
152152
++env_end_marker;
153153

@@ -156,28 +156,28 @@ __attribute__((noinline)) static void do_start() {
156156

157157
// After the env array, is the aux-vector. The end of the aux-vector is
158158
// denoted by an AT_NULL entry.
159-
PgrHdrTableType *programHdrTable = nullptr;
160-
uintptr_t programHdrCount;
159+
PgrHdrTableType *program_hdr_table = nullptr;
160+
uintptr_t program_hdr_count;
161161
for (AuxEntry *aux_entry = reinterpret_cast<AuxEntry *>(env_end_marker + 1);
162162
aux_entry->type != AT_NULL; ++aux_entry) {
163163
switch (aux_entry->type) {
164164
case AT_PHDR:
165-
programHdrTable = reinterpret_cast<PgrHdrTableType *>(aux_entry->value);
165+
program_hdr_table = reinterpret_cast<PgrHdrTableType *>(aux_entry->value);
166166
break;
167167
case AT_PHNUM:
168-
programHdrCount = aux_entry->value;
168+
program_hdr_count = aux_entry->value;
169169
break;
170170
case AT_PAGESZ:
171-
app.pageSize = aux_entry->value;
171+
app.page_size = aux_entry->value;
172172
break;
173173
default:
174174
break; // TODO: Read other useful entries from the aux vector.
175175
}
176176
}
177177

178178
app.tls.size = 0;
179-
for (uintptr_t i = 0; i < programHdrCount; ++i) {
180-
PgrHdrTableType *phdr = programHdrTable + i;
179+
for (uintptr_t i = 0; i < program_hdr_count; ++i) {
180+
PgrHdrTableType *phdr = program_hdr_table + i;
181181
if (phdr->p_type != PT_TLS)
182182
continue;
183183
// TODO: p_vaddr value has to be adjusted for static-pie executables.

libc/startup/linux/x86_64/start.cpp

Lines changed: 27 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -33,9 +33,9 @@ extern "C" void __stack_chk_fail() {
3333
namespace LIBC_NAMESPACE {
3434

3535
#ifdef SYS_mmap2
36-
static constexpr long mmapSyscallNumber = SYS_mmap2;
36+
static constexpr long MMAP_SYSCALL_NUMBER = SYS_mmap2;
3737
#elif SYS_mmap
38-
static constexpr long mmapSyscallNumber = SYS_mmap;
38+
static constexpr long MMAP_SYSCALL_NUMBER = SYS_mmap;
3939
#else
4040
#error "mmap and mmap2 syscalls not available."
4141
#endif
@@ -54,49 +54,50 @@ void init_tls(TLSDescriptor &tls_descriptor) {
5454
}
5555

5656
// We will assume the alignment is always a power of two.
57-
uintptr_t tlsSize = app.tls.size & -app.tls.align;
58-
if (tlsSize != app.tls.size)
59-
tlsSize += app.tls.align;
57+
uintptr_t tls_size = app.tls.size & -app.tls.align;
58+
if (tls_size != app.tls.size)
59+
tls_size += app.tls.align;
6060

6161
// Per the x86_64 TLS ABI, the entry pointed to by the thread pointer is the
6262
// address of the TLS block. So, we add more size to accomodate this address
6363
// entry.
6464
// We also need to include space for the stack canary. The canary is at
6565
// offset 0x28 (40) and is of size uintptr_t.
66-
uintptr_t tlsSizeWithAddr = tlsSize + sizeof(uintptr_t) + 40;
66+
uintptr_t tls_size_with_addr = tls_size + sizeof(uintptr_t) + 40;
6767

6868
// We cannot call the mmap function here as the functions set errno on
6969
// failure. Since errno is implemented via a thread local variable, we cannot
7070
// use errno before TLS is setup.
71-
long mmapRetVal = LIBC_NAMESPACE::syscall_impl<long>(
72-
mmapSyscallNumber, nullptr, tlsSizeWithAddr, PROT_READ | PROT_WRITE,
71+
long mmap_retval = LIBC_NAMESPACE::syscall_impl<long>(
72+
MMAP_SYSCALL_NUMBER, nullptr, tls_size_with_addr, PROT_READ | PROT_WRITE,
7373
MAP_ANONYMOUS | MAP_PRIVATE, -1, 0);
7474
// We cannot check the return value with MAP_FAILED as that is the return
7575
// of the mmap function and not the mmap syscall.
76-
if (mmapRetVal < 0 && static_cast<uintptr_t>(mmapRetVal) > -app.pageSize)
76+
if (mmap_retval < 0 && static_cast<uintptr_t>(mmap_retval) > -app.page_size)
7777
LIBC_NAMESPACE::syscall_impl<long>(SYS_exit, 1);
78-
uintptr_t *tlsAddr = reinterpret_cast<uintptr_t *>(mmapRetVal);
78+
uintptr_t *tls_addr = reinterpret_cast<uintptr_t *>(mmap_retval);
7979

8080
// x86_64 TLS faces down from the thread pointer with the first entry
8181
// pointing to the address of the first real TLS byte.
82-
uintptr_t endPtr = reinterpret_cast<uintptr_t>(tlsAddr) + tlsSize;
83-
*reinterpret_cast<uintptr_t *>(endPtr) = endPtr;
82+
uintptr_t end_ptr = reinterpret_cast<uintptr_t>(tls_addr) + tls_size;
83+
*reinterpret_cast<uintptr_t *>(end_ptr) = end_ptr;
8484

85-
LIBC_NAMESPACE::inline_memcpy(reinterpret_cast<char *>(tlsAddr),
85+
LIBC_NAMESPACE::inline_memcpy(reinterpret_cast<char *>(tls_addr),
8686
reinterpret_cast<const char *>(app.tls.address),
8787
app.tls.init_size);
88-
uintptr_t *stackGuardAddr = reinterpret_cast<uintptr_t *>(endPtr + 40);
88+
uintptr_t *stack_guard_addr = reinterpret_cast<uintptr_t *>(end_ptr + 40);
8989
// Setting the stack guard to a random value.
9090
// We cannot call the get_random function here as the function sets errno on
9191
// failure. Since errno is implemented via a thread local variable, we cannot
9292
// use errno before TLS is setup.
93-
ssize_t stackGuardRetVal = LIBC_NAMESPACE::syscall_impl<ssize_t>(
94-
SYS_getrandom, reinterpret_cast<long>(stackGuardAddr), sizeof(uint64_t),
93+
ssize_t stack_guard_retval = LIBC_NAMESPACE::syscall_impl<ssize_t>(
94+
SYS_getrandom, reinterpret_cast<long>(stack_guard_addr), sizeof(uint64_t),
9595
0);
96-
if (stackGuardRetVal < 0)
96+
if (stack_guard_retval < 0)
9797
LIBC_NAMESPACE::syscall_impl(SYS_exit, 1);
9898

99-
tls_descriptor = {tlsSizeWithAddr, uintptr_t(tlsAddr), endPtr};
99+
tls_descriptor = {tls_size_with_addr, reinterpret_cast<uintptr_t>(tls_addr),
100+
end_ptr};
100101
return;
101102
}
102103

@@ -181,7 +182,7 @@ extern "C" void _start() {
181182
// value. We step over it (the "+ 1" below) to get to the env values.
182183
uint64_t *env_ptr = app.args->argv + app.args->argc + 1;
183184
uint64_t *env_end_marker = env_ptr;
184-
app.envPtr = env_ptr;
185+
app.env_ptr = env_ptr;
185186
while (*env_end_marker)
186187
++env_end_marker;
187188

@@ -190,28 +191,28 @@ extern "C" void _start() {
190191

191192
// After the env array, is the aux-vector. The end of the aux-vector is
192193
// denoted by an AT_NULL entry.
193-
Elf64_Phdr *programHdrTable = nullptr;
194-
uintptr_t programHdrCount;
194+
Elf64_Phdr *program_hdr_table = nullptr;
195+
uintptr_t program_hdr_count = 0;
195196
for (AuxEntry *aux_entry = reinterpret_cast<AuxEntry *>(env_end_marker + 1);
196197
aux_entry->type != AT_NULL; ++aux_entry) {
197198
switch (aux_entry->type) {
198199
case AT_PHDR:
199-
programHdrTable = reinterpret_cast<Elf64_Phdr *>(aux_entry->value);
200+
program_hdr_table = reinterpret_cast<Elf64_Phdr *>(aux_entry->value);
200201
break;
201202
case AT_PHNUM:
202-
programHdrCount = aux_entry->value;
203+
program_hdr_count = aux_entry->value;
203204
break;
204205
case AT_PAGESZ:
205-
app.pageSize = aux_entry->value;
206+
app.page_size = aux_entry->value;
206207
break;
207208
default:
208209
break; // TODO: Read other useful entries from the aux vector.
209210
}
210211
}
211212

212213
app.tls.size = 0;
213-
for (uintptr_t i = 0; i < programHdrCount; ++i) {
214-
Elf64_Phdr *phdr = programHdrTable + i;
214+
for (uintptr_t i = 0; i < program_hdr_count; ++i) {
215+
Elf64_Phdr *phdr = program_hdr_table + i;
215216
if (phdr->p_type != PT_TLS)
216217
continue;
217218
// TODO: p_vaddr value has to be adjusted for static-pie executables.

0 commit comments

Comments
 (0)