diff options
author | Michael Jones <michaelrj@google.com> | 2023-08-02 16:30:26 -0700 |
---|---|---|
committer | Michael Jones <michaelrj@google.com> | 2023-08-07 15:03:01 -0700 |
commit | f0a3954ef1af274cb0b79a6e0bc51a31e0de540b (patch) | |
tree | 3036b7d657907c56e78214c50fe9b6b736e70b99 /libc/startup | |
parent | f6267d3b98c11b50bf24946f21c6646d2d3f6fa8 (diff) | |
download | llvm-f0a3954ef1af274cb0b79a6e0bc51a31e0de540b.zip llvm-f0a3954ef1af274cb0b79a6e0bc51a31e0de540b.tar.gz llvm-f0a3954ef1af274cb0b79a6e0bc51a31e0de540b.tar.bz2 |
[libc][cleanup] Fix most conversion warnings
This patch is large, but is almost entirely just adding casts to calls
to syscall_impl. Much of the work was done programatically, with human
checking when the syntax or types got confusing.
Reviewed By: mcgrathr
Differential Revision: https://reviews.llvm.org/D156950
Diffstat (limited to 'libc/startup')
-rw-r--r-- | libc/startup/linux/aarch64/start.cpp | 18 | ||||
-rw-r--r-- | libc/startup/linux/riscv64/start.cpp | 18 | ||||
-rw-r--r-- | libc/startup/linux/x86_64/start.cpp | 20 |
3 files changed, 31 insertions, 25 deletions
diff --git a/libc/startup/linux/aarch64/start.cpp b/libc/startup/linux/aarch64/start.cpp index 67253bc..7b94ae6 100644 --- a/libc/startup/linux/aarch64/start.cpp +++ b/libc/startup/linux/aarch64/start.cpp @@ -69,13 +69,13 @@ void init_tls(TLSDescriptor &tls_descriptor) { // We cannot call the mmap function here as the functions set errno on // failure. Since errno is implemented via a thread local variable, we cannot // use errno before TLS is setup. - long mmap_ret_val = __llvm_libc::syscall_impl( + long mmap_ret_val = __llvm_libc::syscall_impl<long>( MMAP_SYSCALL_NUMBER, nullptr, alloc_size, PROT_READ | PROT_WRITE, MAP_ANONYMOUS | MAP_PRIVATE, -1, 0); // We cannot check the return value with MAP_FAILED as that is the return // of the mmap function and not the mmap syscall. if (mmap_ret_val < 0 && static_cast<uintptr_t>(mmap_ret_val) > -app.pageSize) - __llvm_libc::syscall_impl(SYS_exit, 1); + __llvm_libc::syscall_impl<long>(SYS_exit, 1); uintptr_t thread_ptr = uintptr_t(reinterpret_cast<uintptr_t *>(mmap_ret_val)); uintptr_t tls_addr = thread_ptr + size_of_pointers + padding; __llvm_libc::inline_memcpy(reinterpret_cast<char *>(tls_addr), @@ -89,7 +89,7 @@ void init_tls(TLSDescriptor &tls_descriptor) { void cleanup_tls(uintptr_t addr, uintptr_t size) { if (size == 0) return; - __llvm_libc::syscall_impl(SYS_munmap, addr, size); + __llvm_libc::syscall_impl<long>(SYS_munmap, addr, size); } static void set_thread_ptr(uintptr_t val) { __arm_wsr64("tpidr_el0", val); } @@ -134,10 +134,10 @@ struct AuxEntry { }; __attribute__((noinline)) static void do_start() { - auto tid = __llvm_libc::syscall_impl(SYS_gettid); + auto tid = __llvm_libc::syscall_impl<long>(SYS_gettid); if (tid <= 0) - __llvm_libc::syscall_impl(SYS_exit, 1); - __llvm_libc::main_thread_attrib.tid = tid; + __llvm_libc::syscall_impl<long>(SYS_exit, 1); + __llvm_libc::main_thread_attrib.tid = static_cast<int>(tid); // After the argv array, is a 8-byte long NULL value before the array of env // values. The end of the env values is marked by another 8-byte long NULL @@ -200,10 +200,12 @@ __attribute__((noinline)) static void do_start() { __llvm_libc::atexit(&__llvm_libc::call_fini_array_callbacks); __llvm_libc::call_init_array_callbacks( - app.args->argc, reinterpret_cast<char **>(app.args->argv), + static_cast<int>(app.args->argc), + reinterpret_cast<char **>(app.args->argv), reinterpret_cast<char **>(env_ptr)); - int retval = main(app.args->argc, reinterpret_cast<char **>(app.args->argv), + int retval = main(static_cast<int>(app.args->argc), + reinterpret_cast<char **>(app.args->argv), reinterpret_cast<char **>(env_ptr)); // TODO: TLS cleanup should be done after all other atexit callbacks diff --git a/libc/startup/linux/riscv64/start.cpp b/libc/startup/linux/riscv64/start.cpp index 0a78397..9835bc4 100644 --- a/libc/startup/linux/riscv64/start.cpp +++ b/libc/startup/linux/riscv64/start.cpp @@ -56,13 +56,13 @@ void init_tls(TLSDescriptor &tls_descriptor) { // We cannot call the mmap function here as the functions set errno on // failure. Since errno is implemented via a thread local variable, we cannot // use errno before TLS is setup. - long mmap_ret_val = __llvm_libc::syscall_impl( + long mmap_ret_val = __llvm_libc::syscall_impl<long>( MMAP_SYSCALL_NUMBER, nullptr, alloc_size, PROT_READ | PROT_WRITE, MAP_ANONYMOUS | MAP_PRIVATE, -1, 0); // We cannot check the return value with MAP_FAILED as that is the return // of the mmap function and not the mmap syscall. if (mmap_ret_val < 0 && static_cast<uintptr_t>(mmap_ret_val) > -app.pageSize) - __llvm_libc::syscall_impl(SYS_exit, 1); + __llvm_libc::syscall_impl<long>(SYS_exit, 1); uintptr_t thread_ptr = uintptr_t(reinterpret_cast<uintptr_t *>(mmap_ret_val)); uintptr_t tls_addr = thread_ptr + size_of_pointers + padding; __llvm_libc::inline_memcpy(reinterpret_cast<char *>(tls_addr), @@ -76,7 +76,7 @@ void init_tls(TLSDescriptor &tls_descriptor) { void cleanup_tls(uintptr_t addr, uintptr_t size) { if (size == 0) return; - __llvm_libc::syscall_impl(SYS_munmap, addr, size); + __llvm_libc::syscall_impl<long>(SYS_munmap, addr, size); } static void set_thread_ptr(uintptr_t val) { @@ -127,10 +127,10 @@ __attribute__((noinline)) static void do_start() { ".option norelax\n\t" "lla gp, __global_pointer$\n\t" ".option pop\n\t"); - auto tid = __llvm_libc::syscall_impl(SYS_gettid); + auto tid = __llvm_libc::syscall_impl<long>(SYS_gettid); if (tid <= 0) - __llvm_libc::syscall_impl(SYS_exit, 1); - __llvm_libc::main_thread_attrib.tid = tid; + __llvm_libc::syscall_impl<long>(SYS_exit, 1); + __llvm_libc::main_thread_attrib.tid = static_cast<int>(tid); // After the argv array, is a 8-byte long NULL value before the array of env // values. The end of the env values is marked by another 8-byte long NULL @@ -193,10 +193,12 @@ __attribute__((noinline)) static void do_start() { __llvm_libc::atexit(&__llvm_libc::call_fini_array_callbacks); __llvm_libc::call_init_array_callbacks( - app.args->argc, reinterpret_cast<char **>(app.args->argv), + static_cast<int>(app.args->argc), + reinterpret_cast<char **>(app.args->argv), reinterpret_cast<char **>(env_ptr)); - int retval = main(app.args->argc, reinterpret_cast<char **>(app.args->argv), + int retval = main(static_cast<int>(app.args->argc), + reinterpret_cast<char **>(app.args->argv), reinterpret_cast<char **>(env_ptr)); // TODO: TLS cleanup should be done after all other atexit callbacks diff --git a/libc/startup/linux/x86_64/start.cpp b/libc/startup/linux/x86_64/start.cpp index bbcd9ae..2f9dbfd 100644 --- a/libc/startup/linux/x86_64/start.cpp +++ b/libc/startup/linux/x86_64/start.cpp @@ -59,13 +59,13 @@ void init_tls(TLSDescriptor &tls_descriptor) { // We cannot call the mmap function here as the functions set errno on // failure. Since errno is implemented via a thread local variable, we cannot // use errno before TLS is setup. - long mmapRetVal = __llvm_libc::syscall_impl( + long mmapRetVal = __llvm_libc::syscall_impl<long>( mmapSyscallNumber, nullptr, tlsSizeWithAddr, PROT_READ | PROT_WRITE, MAP_ANONYMOUS | MAP_PRIVATE, -1, 0); // We cannot check the return value with MAP_FAILED as that is the return // of the mmap function and not the mmap syscall. if (mmapRetVal < 0 && static_cast<uintptr_t>(mmapRetVal) > -app.pageSize) - __llvm_libc::syscall_impl(SYS_exit, 1); + __llvm_libc::syscall_impl<long>(SYS_exit, 1); uintptr_t *tlsAddr = reinterpret_cast<uintptr_t *>(mmapRetVal); // x86_64 TLS faces down from the thread pointer with the first entry @@ -84,7 +84,7 @@ void init_tls(TLSDescriptor &tls_descriptor) { void cleanup_tls(uintptr_t addr, uintptr_t size) { if (size == 0) return; - __llvm_libc::syscall_impl(SYS_munmap, addr, size); + __llvm_libc::syscall_impl<long>(SYS_munmap, addr, size); } // Sets the thread pointer to |val|. Returns true on success, false on failure. @@ -152,10 +152,10 @@ extern "C" void _start() { __asm__ __volatile__("andq $0xfffffffffffffff0, %rsp\n\t"); __asm__ __volatile__("andq $0xfffffffffffffff0, %rbp\n\t"); - auto tid = __llvm_libc::syscall_impl(SYS_gettid); + auto tid = __llvm_libc::syscall_impl<long>(SYS_gettid); if (tid <= 0) - __llvm_libc::syscall_impl(SYS_exit, 1); - __llvm_libc::main_thread_attrib.tid = tid; + __llvm_libc::syscall_impl<long>(SYS_exit, 1); + __llvm_libc::main_thread_attrib.tid = static_cast<int>(tid); // After the argv array, is a 8-byte long NULL value before the array of env // values. The end of the env values is marked by another 8-byte long NULL @@ -205,7 +205,7 @@ extern "C" void _start() { __llvm_libc::TLSDescriptor tls; __llvm_libc::init_tls(tls); if (tls.size != 0 && !__llvm_libc::set_thread_ptr(tls.tp)) - __llvm_libc::syscall_impl(SYS_exit, 1); + __llvm_libc::syscall_impl<long>(SYS_exit, 1); __llvm_libc::self.attrib = &__llvm_libc::main_thread_attrib; __llvm_libc::main_thread_attrib.atexit_callback_mgr = @@ -218,10 +218,12 @@ extern "C" void _start() { __llvm_libc::atexit(&__llvm_libc::call_fini_array_callbacks); __llvm_libc::call_init_array_callbacks( - app.args->argc, reinterpret_cast<char **>(app.args->argv), + static_cast<int>(app.args->argc), + reinterpret_cast<char **>(app.args->argv), reinterpret_cast<char **>(env_ptr)); - int retval = main(app.args->argc, reinterpret_cast<char **>(app.args->argv), + int retval = main(static_cast<int>(app.args->argc), + reinterpret_cast<char **>(app.args->argv), reinterpret_cast<char **>(env_ptr)); // TODO: TLS cleanup should be done after all other atexit callbacks |