[llvm] 4cdfdb5 - [llvm-exegesis] Define MAP_FIXED_NOREPLACE if not available

Aiden Grossman via llvm-commits llvm-commits at lists.llvm.org
Mon Jun 26 13:43:39 PDT 2023


Author: Aiden Grossman
Date: 2023-06-26T20:43:26Z
New Revision: 4cdfdb5e7cf83c327fa42f8706164a1f8a60ff35

URL: https://github.com/llvm/llvm-project/commit/4cdfdb5e7cf83c327fa42f8706164a1f8a60ff35
DIFF: https://github.com/llvm/llvm-project/commit/4cdfdb5e7cf83c327fa42f8706164a1f8a60ff35.diff

LOG: [llvm-exegesis] Define MAP_FIXED_NOREPLACE if not available

Some builders are currently failing as they don't have
MAP_FIXED_NOREPLACE available. This patch checks if MAP_FIXED_NOREPLACE
is available and if it isn't, it is simply defined as MAP_FIXED.

Added: 
    

Modified: 
    llvm/tools/llvm-exegesis/lib/X86/Target.cpp
    llvm/unittests/tools/llvm-exegesis/X86/TargetTest.cpp

Removed: 
    


################################################################################
diff  --git a/llvm/tools/llvm-exegesis/lib/X86/Target.cpp b/llvm/tools/llvm-exegesis/lib/X86/Target.cpp
index 8a498e2713b42..04e753b3e12c6 100644
--- a/llvm/tools/llvm-exegesis/lib/X86/Target.cpp
+++ b/llvm/tools/llvm-exegesis/lib/X86/Target.cpp
@@ -1072,6 +1072,13 @@ ExegesisX86Target::generateExitSyscall(unsigned ExitCode) const {
   return ExitCallCode;
 }
 
+// Before kernel 4.17, Linux did not support MAP_FIXED_NOREPLACE, so if it is
+// not available, simplfy define it as MAP_FIXED which performs the same
+// function but does not guarantee existing mappings won't get clobbered.
+#ifndef MAP_FIXED_NOREPLACE
+#define MAP_FIXED_NOREPLACE MAP_FIXED
+#endif
+
 std::vector<MCInst>
 ExegesisX86Target::generateMmap(intptr_t Address, size_t Length,
                                 intptr_t FileDescriptorAddress) const {

diff  --git a/llvm/unittests/tools/llvm-exegesis/X86/TargetTest.cpp b/llvm/unittests/tools/llvm-exegesis/X86/TargetTest.cpp
index 05879f141c59e..baee336a9f00c 100644
--- a/llvm/unittests/tools/llvm-exegesis/X86/TargetTest.cpp
+++ b/llvm/unittests/tools/llvm-exegesis/X86/TargetTest.cpp
@@ -620,6 +620,13 @@ TEST_F(X86Core2TargetTest, GenerateExitSyscallTest) {
                           OpcodeIs(X86::SYSCALL)));
 }
 
+// Before kernel 4.17, Linux did not support MAP_FIXED_NOREPLACE, so if it is
+// not available, simplfy define it as MAP_FIXED which performs the same
+// function but does not guarantee existing mappings won't get clobbered.
+#ifndef MAP_FIXED_NOREPLACE
+#define MAP_FIXED_NOREPLACE MAP_FIXED
+#endif
+
 TEST_F(X86Core2TargetTest, GenerateMmapTest) {
   EXPECT_THAT(State.getExegesisTarget().generateMmap(0x1000, 4096, 0x2000),
               ElementsAre(IsMovImmediate(X86::MOV64ri, X86::RDI, 0x1000),


        


More information about the llvm-commits mailing list