From 78dff7539bfe825f96e12532ee99a675ce6c3026 Mon Sep 17 00:00:00 2001 From: Yao Zi Date: Tue, 4 Feb 2025 18:51:16 +0000 Subject: [PATCH 1/3] i#3544: RV64: Support RISC-V ELF in module_get_platform() Differing from x86 and ARM, 32-bit and 64-bit variants of RISC-V share the same e_machine constant EM_RISCV, thus additional check against e_ident is required to obtain the bitwidth. This fixes test linux.execve-null on riscv64, where DynamoRIO wrongly assumes an execve call to a RISC-V ELF will fail, thus loses control of the child process. Issue: #3544 --- core/drlibc/drlibc_module_elf.c | 9 +++++++++ suite/tests/CMakeLists.txt | 1 + 2 files changed, 10 insertions(+) diff --git a/core/drlibc/drlibc_module_elf.c b/core/drlibc/drlibc_module_elf.c index 75d0b68c9a3..c4370f7a293 100644 --- a/core/drlibc/drlibc_module_elf.c +++ b/core/drlibc/drlibc_module_elf.c @@ -229,6 +229,15 @@ module_get_platform(file_t f, dr_platform_t *platform, dr_platform_t *alt_platfo #endif *platform = DR_PLATFORM_64BIT; break; +#ifdef EM_RISCV + case EM_RISCV: + switch (elf_header.elf64.e_ident[EI_CLASS]) { + case ELFCLASS32: *platform = DR_PLATFORM_32BIT; break; + case ELFCLASS64: *platform = DR_PLATFORM_64BIT; break; + default: return false; + } + break; +#endif case EM_386: case EM_ARM: *platform = DR_PLATFORM_32BIT; break; default: return false; diff --git a/suite/tests/CMakeLists.txt b/suite/tests/CMakeLists.txt index a5f398e7f30..3748d537666 100644 --- a/suite/tests/CMakeLists.txt +++ b/suite/tests/CMakeLists.txt @@ -6531,6 +6531,7 @@ if (RISCV64) # TODO i#3544: code_api|linux.eintr failed under QEMU # but passed on real hardware. # code_api|linux.eintr + code_api|linux.execve-null code_api|linux.exit code_api|linux.infinite code_api|linux.longjmp From e7c794ecf1d4f20fcd8b5a1e49c3a1ace84bc671 Mon Sep 17 00:00:00 2001 From: Yao Zi Date: Thu, 6 Feb 2025 07:03:09 +0000 Subject: [PATCH 2/3] Keep linux.execve-null disabled in CI as it fails on QEMU --- suite/tests/CMakeLists.txt | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/suite/tests/CMakeLists.txt b/suite/tests/CMakeLists.txt index 3748d537666..0dcec6d1f49 100644 --- a/suite/tests/CMakeLists.txt +++ b/suite/tests/CMakeLists.txt @@ -6531,7 +6531,9 @@ if (RISCV64) # TODO i#3544: code_api|linux.eintr failed under QEMU # but passed on real hardware. # code_api|linux.eintr - code_api|linux.execve-null + # TODO i#3544: code_api|linux.execve-null fails under QEMU but passes on + # real hardware. + # code_api|linux.execve-null code_api|linux.exit code_api|linux.infinite code_api|linux.longjmp From b7a148e4b93ffda64c8ad8502ddf3961008a9745 Mon Sep 17 00:00:00 2001 From: Yao Zi Date: Thu, 6 Feb 2025 19:10:30 +0000 Subject: [PATCH 3/3] Remove unnecessary preprocessing guard --- core/drlibc/drlibc_module_elf.c | 2 -- 1 file changed, 2 deletions(-) diff --git a/core/drlibc/drlibc_module_elf.c b/core/drlibc/drlibc_module_elf.c index c4370f7a293..d78b25026d3 100644 --- a/core/drlibc/drlibc_module_elf.c +++ b/core/drlibc/drlibc_module_elf.c @@ -229,7 +229,6 @@ module_get_platform(file_t f, dr_platform_t *platform, dr_platform_t *alt_platfo #endif *platform = DR_PLATFORM_64BIT; break; -#ifdef EM_RISCV case EM_RISCV: switch (elf_header.elf64.e_ident[EI_CLASS]) { case ELFCLASS32: *platform = DR_PLATFORM_32BIT; break; @@ -237,7 +236,6 @@ module_get_platform(file_t f, dr_platform_t *platform, dr_platform_t *alt_platfo default: return false; } break; -#endif case EM_386: case EM_ARM: *platform = DR_PLATFORM_32BIT; break; default: return false;