[libc-commits] [libc] [libc] lift app's definition out of startup (PR #75717)
Schrodinger ZHU Yifan via libc-commits
libc-commits at lists.llvm.org
Mon Dec 18 14:23:21 PST 2023
https://github.com/SchrodingerZhu updated https://github.com/llvm/llvm-project/pull/75717
>From 75c1161521a7f9f530ad40c9653f300beddf4745 Mon Sep 17 00:00:00 2001
From: Schrodinger ZHU Yifan <yifanzhu at rochester.edu>
Date: Sat, 16 Dec 2023 16:39:24 -0500
Subject: [PATCH 1/2] [libc] lift app's definition out of startup
AppProperties are not target specific hence this patch lifts app from a header library to an object library.
In overlay mode, this also provides a way to check if libc is loaded by its own CRT.
---
libc/config/linux/CMakeLists.txt | 6 +++--
libc/config/linux/app.cpp | 13 +++++++++++
libc/config/linux/app.h | 22 +++++++++++--------
.../__support/threads/linux/CMakeLists.txt | 2 +-
libc/src/stdlib/CMakeLists.txt | 2 +-
libc/startup/linux/aarch64/CMakeLists.txt | 2 +-
libc/startup/linux/aarch64/start.cpp | 2 --
libc/startup/linux/riscv/CMakeLists.txt | 2 +-
libc/startup/linux/riscv/start.cpp | 2 --
libc/startup/linux/x86_64/CMakeLists.txt | 2 +-
libc/startup/linux/x86_64/start.cpp | 2 --
11 files changed, 35 insertions(+), 22 deletions(-)
create mode 100644 libc/config/linux/app.cpp
diff --git a/libc/config/linux/CMakeLists.txt b/libc/config/linux/CMakeLists.txt
index cf38ae3eed7267..ad2445697d3dbb 100644
--- a/libc/config/linux/CMakeLists.txt
+++ b/libc/config/linux/CMakeLists.txt
@@ -1,5 +1,7 @@
-add_header_library(
- app_h
+add_object_library(
+ app
+ SRCS
+ app.cpp
HDRS
app.h
DEPENDS
diff --git a/libc/config/linux/app.cpp b/libc/config/linux/app.cpp
new file mode 100644
index 00000000000000..b4ce253bc6361b
--- /dev/null
+++ b/libc/config/linux/app.cpp
@@ -0,0 +1,13 @@
+//===-- Implementation file for linux applications classes -----*- C++ -*-===//
+//
+// 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
+//
+//===----------------------------------------------------------------------===//
+
+#include "config/linux/app.h"
+
+namespace LIBC_NAMESPACE {
+AppProperties app;
+}
diff --git a/libc/config/linux/app.h b/libc/config/linux/app.h
index 548c141fd70535..9c59523bbaed6b 100644
--- a/libc/config/linux/app.h
+++ b/libc/config/linux/app.h
@@ -18,21 +18,23 @@ namespace LIBC_NAMESPACE {
// Data structure to capture properties of the linux/ELF TLS image.
struct TLSImage {
// The load address of the TLS.
- uintptr_t address;
+ uintptr_t address = 0;
// The byte size of the TLS image consisting of both initialized and
// uninitialized memory. In ELF executables, it is size of .tdata + size of
// .tbss. Put in another way, it is the memsz field of the PT_TLS header.
- uintptr_t size;
+ uintptr_t size = 0;
// The byte size of initialized memory in the TLS image. In ELF exectubles,
// this is the size of .tdata. Put in another way, it is the filesz of the
// PT_TLS header.
- uintptr_t init_size;
+ uintptr_t init_size = 0;
// The alignment of the TLS layout. It assumed that the alignment
// value is a power of 2.
- uintptr_t align;
+ uintptr_t align = 0;
+
+ constexpr TLSImage() = default;
};
#if defined(LIBC_TARGET_ARCH_IS_X86_64) || \
@@ -79,18 +81,20 @@ struct Args {
// Data structure which captures properties of a linux application.
struct AppProperties {
// Page size used for the application.
- uintptr_t page_size;
+ uintptr_t page_size = 0;
- Args *args;
+ Args *args = nullptr;
// The properties of an application's TLS image.
- TLSImage tls;
+ TLSImage tls{};
// Environment data.
- EnvironType *env_ptr;
+ EnvironType *env_ptr = nullptr;
// Auxiliary vector data.
- AuxEntry *auxv_ptr;
+ AuxEntry *auxv_ptr = nullptr;
+
+ constexpr AppProperties() = default;
};
extern AppProperties app;
diff --git a/libc/src/__support/threads/linux/CMakeLists.txt b/libc/src/__support/threads/linux/CMakeLists.txt
index 642eead7277262..d62d2c26c53d70 100644
--- a/libc/src/__support/threads/linux/CMakeLists.txt
+++ b/libc/src/__support/threads/linux/CMakeLists.txt
@@ -26,7 +26,7 @@ add_object_library(
thread.cpp
DEPENDS
.futex_word_type
- libc.config.linux.app_h
+ libc.config.linux.app
libc.include.sys_syscall
libc.src.errno.errno
libc.src.__support.CPP.atomic
diff --git a/libc/src/stdlib/CMakeLists.txt b/libc/src/stdlib/CMakeLists.txt
index a4d51fb9a11eef..3c8b63af85b7ac 100644
--- a/libc/src/stdlib/CMakeLists.txt
+++ b/libc/src/stdlib/CMakeLists.txt
@@ -49,7 +49,7 @@ add_entrypoint_object(
HDRS
getenv.h
DEPENDS
- libc.config.linux.app_h
+ libc.config.linux.app
)
add_entrypoint_object(
diff --git a/libc/startup/linux/aarch64/CMakeLists.txt b/libc/startup/linux/aarch64/CMakeLists.txt
index b47db8eb5d23f3..b39698f622566b 100644
--- a/libc/startup/linux/aarch64/CMakeLists.txt
+++ b/libc/startup/linux/aarch64/CMakeLists.txt
@@ -3,7 +3,7 @@ add_startup_object(
SRC
start.cpp
DEPENDS
- libc.config.linux.app_h
+ libc.config.linux.app
libc.include.sys_mman
libc.include.sys_syscall
libc.src.__support.threads.thread
diff --git a/libc/startup/linux/aarch64/start.cpp b/libc/startup/linux/aarch64/start.cpp
index bc01582aeb49c7..9777db7ba08b0e 100644
--- a/libc/startup/linux/aarch64/start.cpp
+++ b/libc/startup/linux/aarch64/start.cpp
@@ -37,8 +37,6 @@ static constexpr long MMAP_SYSCALL_NUMBER = SYS_mmap;
#error "mmap and mmap2 syscalls not available."
#endif
-AppProperties app;
-
static ThreadAttributes main_thread_attrib;
void init_tls(TLSDescriptor &tls_descriptor) {
diff --git a/libc/startup/linux/riscv/CMakeLists.txt b/libc/startup/linux/riscv/CMakeLists.txt
index b47db8eb5d23f3..b39698f622566b 100644
--- a/libc/startup/linux/riscv/CMakeLists.txt
+++ b/libc/startup/linux/riscv/CMakeLists.txt
@@ -3,7 +3,7 @@ add_startup_object(
SRC
start.cpp
DEPENDS
- libc.config.linux.app_h
+ libc.config.linux.app
libc.include.sys_mman
libc.include.sys_syscall
libc.src.__support.threads.thread
diff --git a/libc/startup/linux/riscv/start.cpp b/libc/startup/linux/riscv/start.cpp
index 5b6e5bde8da81d..c6beab17de7602 100644
--- a/libc/startup/linux/riscv/start.cpp
+++ b/libc/startup/linux/riscv/start.cpp
@@ -32,8 +32,6 @@ static constexpr long MMAP_SYSCALL_NUMBER = SYS_mmap;
#error "mmap and mmap2 syscalls not available."
#endif
-AppProperties app;
-
static ThreadAttributes main_thread_attrib;
void init_tls(TLSDescriptor &tls_descriptor) {
diff --git a/libc/startup/linux/x86_64/CMakeLists.txt b/libc/startup/linux/x86_64/CMakeLists.txt
index aac5a0626a176a..59932b72700cb0 100644
--- a/libc/startup/linux/x86_64/CMakeLists.txt
+++ b/libc/startup/linux/x86_64/CMakeLists.txt
@@ -3,7 +3,7 @@ add_startup_object(
SRC
start.cpp
DEPENDS
- libc.config.linux.app_h
+ libc.config.linux.app
libc.include.sys_mman
libc.include.sys_syscall
libc.include.unistd
diff --git a/libc/startup/linux/x86_64/start.cpp b/libc/startup/linux/x86_64/start.cpp
index c98f58a4ac0aff..937ff8a53d7e91 100644
--- a/libc/startup/linux/x86_64/start.cpp
+++ b/libc/startup/linux/x86_64/start.cpp
@@ -40,8 +40,6 @@ static constexpr long MMAP_SYSCALL_NUMBER = SYS_mmap;
#error "mmap and mmap2 syscalls not available."
#endif
-AppProperties app;
-
static ThreadAttributes main_thread_attrib;
// TODO: The function is x86_64 specific. Move it to config/linux/app.h
>From ffdb3d93aa4e586d179f4bc8135e6b61514bc929 Mon Sep 17 00:00:00 2001
From: Schrodinger ZHU Yifan <yifanzhu at rochester.edu>
Date: Mon, 18 Dec 2023 17:22:59 -0500
Subject: [PATCH 2/2] address CR
---
libc/config/linux/app.h | 8 ++++----
1 file changed, 4 insertions(+), 4 deletions(-)
diff --git a/libc/config/linux/app.h b/libc/config/linux/app.h
index 9c59523bbaed6b..57eb039aa30368 100644
--- a/libc/config/linux/app.h
+++ b/libc/config/linux/app.h
@@ -9,8 +9,8 @@
#ifndef LLVM_LIBC_CONFIG_LINUX_APP_H
#define LLVM_LIBC_CONFIG_LINUX_APP_H
+#include "src/__support/macros/attributes.h"
#include "src/__support/macros/properties/architectures.h"
-
#include <stdint.h>
namespace LIBC_NAMESPACE {
@@ -34,7 +34,7 @@ struct TLSImage {
// value is a power of 2.
uintptr_t align = 0;
- constexpr TLSImage() = default;
+ LIBC_INLINE constexpr TLSImage() = default;
};
#if defined(LIBC_TARGET_ARCH_IS_X86_64) || \
@@ -94,7 +94,7 @@ struct AppProperties {
// Auxiliary vector data.
AuxEntry *auxv_ptr = nullptr;
- constexpr AppProperties() = default;
+ LIBC_INLINE constexpr AppProperties() = default;
};
extern AppProperties app;
@@ -113,7 +113,7 @@ struct TLSDescriptor {
// same as |addr| or something else.
uintptr_t tp = 0;
- constexpr TLSDescriptor() = default;
+ LIBC_INLINE constexpr TLSDescriptor() = default;
};
// Create and initialize the TLS area for the current thread. Should not
More information about the libc-commits
mailing list