Skip to content

Commit e80d5d2

Browse files
nickdesaulniersAlexisPerry
authored andcommitted
[libc][startup] create header for ElfW and use in startup (llvm#96510)
This is necessary for 32b platforms such as ARM and i386. Link: llvm#94128
1 parent 6843059 commit e80d5d2

File tree

4 files changed

+25
-4
lines changed

4 files changed

+25
-4
lines changed

libc/include/llvm-libc-macros/CMakeLists.txt

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -103,6 +103,12 @@ add_macro_header(
103103
limits-macros.h
104104
)
105105

106+
add_macro_header(
107+
link_macros
108+
HDR
109+
link-macros.h
110+
)
111+
106112
add_macro_header(
107113
math_macros
108114
HDR
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
//===-- Definition of macros to for extra dynamic linker functionality ----===//
2+
//
3+
// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4+
// See https://llvm.org/LICENSE.txt for license information.
5+
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
6+
//
7+
//===----------------------------------------------------------------------===//
8+
9+
#ifdef __LP64__
10+
#define ElfW(type) Elf64_ ## type
11+
#else
12+
#define ElfW(type) Elf32_ ## type
13+
#endif

libc/startup/linux/CMakeLists.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -98,6 +98,7 @@ add_object_library(
9898
libc.config.linux.app_h
9999
libc.include.sys_mman
100100
libc.include.sys_syscall
101+
libc.include.llvm-libc-macros.link_macros
101102
libc.src.__support.threads.thread
102103
libc.src.__support.OSUtil.osutil
103104
libc.src.stdlib.exit

libc/startup/linux/do_start.cpp

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
//
77
//===----------------------------------------------------------------------===//
88
#include "startup/linux/do_start.h"
9+
#include "include/llvm-libc-macros/link-macros.h"
910
#include "src/__support/OSUtil/syscall.h"
1011
#include "src/__support/threads/thread.h"
1112
#include "src/stdlib/atexit.h"
@@ -79,13 +80,13 @@ static ThreadAttributes main_thread_attrib;
7980

8081
// After the env array, is the aux-vector. The end of the aux-vector is
8182
// denoted by an AT_NULL entry.
82-
Elf64_Phdr *program_hdr_table = nullptr;
83+
ElfW(Phdr) *program_hdr_table = nullptr;
8384
uintptr_t program_hdr_count = 0;
8485
app.auxv_ptr = reinterpret_cast<AuxEntry *>(env_end_marker + 1);
8586
for (auto *aux_entry = app.auxv_ptr; aux_entry->id != AT_NULL; ++aux_entry) {
8687
switch (aux_entry->id) {
8788
case AT_PHDR:
88-
program_hdr_table = reinterpret_cast<Elf64_Phdr *>(aux_entry->value);
89+
program_hdr_table = reinterpret_cast<ElfW(Phdr) *>(aux_entry->value);
8990
break;
9091
case AT_PHNUM:
9192
program_hdr_count = aux_entry->value;
@@ -100,10 +101,10 @@ static ThreadAttributes main_thread_attrib;
100101

101102
ptrdiff_t base = 0;
102103
app.tls.size = 0;
103-
Elf64_Phdr *tls_phdr = nullptr;
104+
ElfW(Phdr) *tls_phdr = nullptr;
104105

105106
for (uintptr_t i = 0; i < program_hdr_count; ++i) {
106-
Elf64_Phdr &phdr = program_hdr_table[i];
107+
ElfW(Phdr) &phdr = program_hdr_table[i];
107108
if (phdr.p_type == PT_PHDR)
108109
base = reinterpret_cast<ptrdiff_t>(program_hdr_table) - phdr.p_vaddr;
109110
if (phdr.p_type == PT_DYNAMIC && _DYNAMIC)

0 commit comments

Comments
 (0)