From a7346857934d6cecb21ddbd4100bbac1ce73cafc Mon Sep 17 00:00:00 2001 From: Khem Raj Date: Fri, 25 Aug 2023 10:43:00 -0700 Subject: [PATCH] [llvm-exegesis] Use mmap2 when mmap is unavailable to fix riscv32 build Some 32-bit architectures don't have mmap and define mmap2 instead. E.g. on riscv32 we may get ``` | /mnt/b/yoe/master/build/tmp/work-shared/llvm-project-source-17.0.0-r0/git/llvm/tools/llvm-exegesis/lib/X86/Target.cpp:1116:19: error: use of undeclared identifier 'SYS_mmap' | 1116 | generateSyscall(SYS_mmap, MmapCode); | | ^ | /mnt/b/yoe/master/build/tmp/work-shared/llvm-project-source-17.0.0-r0/git/llvm/tools/llvm-exegesis/lib/X86/Target.cpp:1134:19: error: use of undeclared identifier 'SYS_mmap' | 1134 | generateSyscall(SYS_mmap, GeneratedCode); | | ^ | 1 warning and 2 errors generated. ``` Co-Authored-By: Fangrui Song Differential Revision: https://reviews.llvm.org/D158375 (cherry picked from commit 01a92f06f23585f15b3e83b7c378d0df2d91e06b) --- llvm/tools/llvm-exegesis/lib/X86/Target.cpp | 10 +++++----- llvm/unittests/tools/llvm-exegesis/X86/TargetTest.cpp | 10 +++++----- 2 files changed, 10 insertions(+), 10 deletions(-) diff --git a/llvm/tools/llvm-exegesis/lib/X86/Target.cpp b/llvm/tools/llvm-exegesis/lib/X86/Target.cpp index e690089fec565..b3d40800aef63 100644 --- a/llvm/tools/llvm-exegesis/lib/X86/Target.cpp +++ b/llvm/tools/llvm-exegesis/lib/X86/Target.cpp @@ -1083,11 +1083,11 @@ ExegesisX86Target::generateExitSyscall(unsigned ExitCode) const { #define MAP_FIXED_NOREPLACE MAP_FIXED #endif -// 32 bit ARM doesn't have mmap and uses mmap2 instead. The only difference -// between the two syscalls is that mmap2's offset parameter is in terms 4096 -// byte offsets rather than individual bytes, so for our purposes they are -// effectively the same as all ofsets here are set to 0. -#ifdef __arm__ +// Some 32-bit architectures don't have mmap and define mmap2 instead. The only +// difference between the two syscalls is that mmap2's offset parameter is in +// terms 4096 byte offsets rather than individual bytes, so for our purposes +// they are effectively the same as all ofsets here are set to 0. +#if defined(SYS_mmap2) && !defined(SYS_mmap) #define SYS_mmap SYS_mmap2 #endif diff --git a/llvm/unittests/tools/llvm-exegesis/X86/TargetTest.cpp b/llvm/unittests/tools/llvm-exegesis/X86/TargetTest.cpp index aa5d525f24eb7..c001c693cc146 100644 --- a/llvm/unittests/tools/llvm-exegesis/X86/TargetTest.cpp +++ b/llvm/unittests/tools/llvm-exegesis/X86/TargetTest.cpp @@ -635,11 +635,11 @@ TEST_F(X86Core2TargetTest, GenerateExitSyscallTest) { #define MAP_FIXED_NOREPLACE MAP_FIXED #endif -// 32 bit ARM doesn't have mmap and uses mmap2 instead. The only difference -// between the two syscalls is that mmap2's offset parameter is in terms 4096 -// byte offsets rather than individual bytes, so for our purposes they are -// effectively the same as all ofsets here are set to 0. -#ifdef __arm__ +// Some 32-bit architectures don't have mmap and define mmap2 instead. The only +// difference between the two syscalls is that mmap2's offset parameter is in +// terms 4096 byte offsets rather than individual bytes, so for our purposes +// they are effectively the same as all ofsets here are set to 0. +#if defined(SYS_mmap2) && !defined(SYS_mmap) #define SYS_mmap SYS_mmap2 #endif