Skip to content

Commit

Permalink
[llvm-exegesis] Use mmap2 when mmap is unavailable to fix riscv32 build
Browse files Browse the repository at this point in the history
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 <i@maskray.me>
Differential Revision: https://reviews.llvm.org/D158375

(cherry picked from commit 01a92f0)
  • Loading branch information
kraj authored and tru committed Aug 30, 2023
1 parent 9fbdf9f commit a734685
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 10 deletions.
10 changes: 5 additions & 5 deletions llvm/tools/llvm-exegesis/lib/X86/Target.cpp
Expand Up @@ -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

Expand Down
10 changes: 5 additions & 5 deletions llvm/unittests/tools/llvm-exegesis/X86/TargetTest.cpp
Expand Up @@ -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

Expand Down

0 comments on commit a734685

Please sign in to comment.