From 3033fb72982a3a820de43eb0974227c871b6e581 Mon Sep 17 00:00:00 2001 From: Alexander van der Grinten Date: Wed, 27 Nov 2024 23:48:01 +0100 Subject: [PATCH 1/4] sysdeps/managarm: Make crti.S + crtn.S empty --- sysdeps/managarm/riscv64/crt-src/crti.S | 10 ---------- sysdeps/managarm/riscv64/crt-src/crtn.S | 6 ------ 2 files changed, 16 deletions(-) diff --git a/sysdeps/managarm/riscv64/crt-src/crti.S b/sysdeps/managarm/riscv64/crt-src/crti.S index 69f23ea88f..8b13789179 100644 --- a/sysdeps/managarm/riscv64/crt-src/crti.S +++ b/sysdeps/managarm/riscv64/crt-src/crti.S @@ -1,11 +1 @@ -.section .init -.global _init -_init: - unimp - -.section .fini -.global _fini -_fini: - unimp -.section .note.GNU-stack,"",%progbits diff --git a/sysdeps/managarm/riscv64/crt-src/crtn.S b/sysdeps/managarm/riscv64/crt-src/crtn.S index 525efd6649..8b13789179 100644 --- a/sysdeps/managarm/riscv64/crt-src/crtn.S +++ b/sysdeps/managarm/riscv64/crt-src/crtn.S @@ -1,7 +1 @@ -.section .init - unimp - -.section .fini - unimp -.section .note.GNU-stack,"",%progbits From 2ae7477c50386dc5650c7e1ebd2470c449655f42 Mon Sep 17 00:00:00 2001 From: Alexander van der Grinten Date: Wed, 27 Nov 2024 23:48:59 +0100 Subject: [PATCH 2/4] sysdeps/managarm: Implement sys_tcb_set() on RISC-V --- sysdeps/managarm/rtld-generic/support.cpp | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/sysdeps/managarm/rtld-generic/support.cpp b/sysdeps/managarm/rtld-generic/support.cpp index 895bc3ee74..ce383074bb 100644 --- a/sysdeps/managarm/rtld-generic/support.cpp +++ b/sysdeps/managarm/rtld-generic/support.cpp @@ -176,12 +176,17 @@ HelHandleResult *parseHandle(void *&element) { namespace mlibc { int sys_tcb_set(void *pointer) { -#if defined(__aarch64__) +#if defined(__x86_64__) + HEL_CHECK(helWriteFsBase(pointer)); +#elif defined(__aarch64__) uintptr_t addr = reinterpret_cast(pointer); addr += sizeof(Tcb) - 0x10; asm volatile ("msr tpidr_el0, %0" :: "r"(addr)); +#elif defined(__riscv) && __riscv_xlen == 64 + uintptr_t tp = reinterpret_cast(pointer) + sizeof(Tcb); + asm volatile ("mv tp, %0" : : "r"(tp) : "memory"); #else - HEL_CHECK(helWriteFsBase(pointer)); +#error Unknown architecture #endif return 0; } From 09cd978dfc95ff96fc5d01dc058c60e042b846ff Mon Sep 17 00:00:00 2001 From: Alexander van der Grinten Date: Wed, 27 Nov 2024 23:55:41 +0100 Subject: [PATCH 3/4] sysdeps/linux: Drop crti.S and crtn.S --- sysdeps/linux/meson.build | 35 +++++++++++++++------------- sysdeps/linux/riscv64/crt-src/crti.S | 11 --------- sysdeps/linux/riscv64/crt-src/crtn.S | 7 ------ 3 files changed, 19 insertions(+), 34 deletions(-) delete mode 100644 sysdeps/linux/riscv64/crt-src/crti.S delete mode 100644 sysdeps/linux/riscv64/crt-src/crtn.S diff --git a/sysdeps/linux/meson.build b/sysdeps/linux/meson.build index cebfef51c0..0df9f8559f 100644 --- a/sysdeps/linux/meson.build +++ b/sysdeps/linux/meson.build @@ -112,23 +112,26 @@ if not headers_only install_dir: get_option('libdir') ) - custom_target('crti', - build_by_default: true, - command: c_compiler.cmd_array() + ['-c', '-o', '@OUTPUT@', '@INPUT@'], - input: host_machine.cpu_family() / 'crt-src/crti.S', - output: 'crti.o', - install: true, - install_dir: get_option('libdir') - ) + # On RISC-V, crti.o and crtn.o are provided by GCC. + if host_machine.cpu_family() != 'riscv64' + custom_target('crti', + build_by_default: true, + command: c_compiler.cmd_array() + ['-c', '-o', '@OUTPUT@', '@INPUT@'], + input: host_machine.cpu_family() / 'crt-src/crti.S', + output: 'crti.o', + install: true, + install_dir: get_option('libdir') + ) - custom_target('crtn', - build_by_default: true, - command: c_compiler.cmd_array() + ['-c', '-o', '@OUTPUT@', '@INPUT@'], - input: host_machine.cpu_family() / 'crt-src/crtn.S', - output: 'crtn.o', - install: true, - install_dir: get_option('libdir') - ) + custom_target('crtn', + build_by_default: true, + command: c_compiler.cmd_array() + ['-c', '-o', '@OUTPUT@', '@INPUT@'], + input: host_machine.cpu_family() / 'crt-src/crtn.S', + output: 'crtn.o', + install: true, + install_dir: get_option('libdir') + ) + endif wrapper_conf = configuration_data() wrapper_conf.set('LIBDIR', get_option('libdir')) diff --git a/sysdeps/linux/riscv64/crt-src/crti.S b/sysdeps/linux/riscv64/crt-src/crti.S deleted file mode 100644 index 69f23ea88f..0000000000 --- a/sysdeps/linux/riscv64/crt-src/crti.S +++ /dev/null @@ -1,11 +0,0 @@ -.section .init -.global _init -_init: - unimp - -.section .fini -.global _fini -_fini: - unimp -.section .note.GNU-stack,"",%progbits - diff --git a/sysdeps/linux/riscv64/crt-src/crtn.S b/sysdeps/linux/riscv64/crt-src/crtn.S deleted file mode 100644 index 525efd6649..0000000000 --- a/sysdeps/linux/riscv64/crt-src/crtn.S +++ /dev/null @@ -1,7 +0,0 @@ -.section .init - unimp - -.section .fini - unimp -.section .note.GNU-stack,"",%progbits - From 53c05fade5c55676947eacda7955b23636563459 Mon Sep 17 00:00:00 2001 From: Alexander van der Grinten Date: Thu, 28 Nov 2024 00:02:14 +0100 Subject: [PATCH 4/4] ci: Update Ubuntu image to 22.04 --- .github/workflows/ci.yml | 2 +- .github/workflows/rust-libc.yml | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index dd5451457f..725876f70a 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -16,7 +16,7 @@ jobs: builds: mlibc compiler: clang name: Build mlibc - runs-on: ubuntu-20.04 + runs-on: ubuntu-22.04 container: image: ghcr.io/managarm/mlibc-crossers:latest steps: diff --git a/.github/workflows/rust-libc.yml b/.github/workflows/rust-libc.yml index 07828db423..7d35e56d39 100644 --- a/.github/workflows/rust-libc.yml +++ b/.github/workflows/rust-libc.yml @@ -5,7 +5,7 @@ on: [pull_request, merge_group] jobs: check-bindings: name: Verify bindings generation - runs-on: ubuntu-20.04 + runs-on: ubuntu-22.04 container: image: ghcr.io/managarm/mlibc-crossers:latest steps: