[compiler-rt] [compiler-rt] Add a prefix on the windows mmap symbols (PR #78037)

Martin Storsjö via llvm-commits llvm-commits at lists.llvm.org
Sat Jan 13 15:33:21 PST 2024


https://github.com/mstorsjo updated https://github.com/llvm/llvm-project/pull/78037

>From c63207e91e5dc32e5db0b2e0c67a7560fc9745bf Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Martin=20Storsj=C3=B6?= <martin at martin.st>
Date: Sat, 13 Jan 2024 16:04:14 +0200
Subject: [PATCH] [compiler-rt] Add a prefix on the windows mmap symbols

For Windows, the compiler-rt profile library contains a polyfill
reimplementation of the mmap family of functions.

Previously, the runtime library exposed those symbols like,
"mmap", in the user symbol namespace. This could cause
misdetections by configure scripts that check for the "mmap"
function just by linking, without including headers.

Add a prefix on the symbols, and make an undeclared function
static.

This fixes such an issue reported at
https://github.com/mstorsjo/llvm-mingw/issues/390.
---
 compiler-rt/lib/profile/WindowsMMap.c | 3 +--
 compiler-rt/lib/profile/WindowsMMap.h | 6 ++++++
 2 files changed, 7 insertions(+), 2 deletions(-)

diff --git a/compiler-rt/lib/profile/WindowsMMap.c b/compiler-rt/lib/profile/WindowsMMap.c
index 07c0a689feaeae..9d7da835b1ed38 100644
--- a/compiler-rt/lib/profile/WindowsMMap.c
+++ b/compiler-rt/lib/profile/WindowsMMap.c
@@ -124,8 +124,7 @@ int madvise(void *addr, size_t length, int advice)
   return 0;
 }
 
-COMPILER_RT_VISIBILITY
-int lock(HANDLE handle, DWORD lockType, BOOL blocking) {
+static int lock(HANDLE handle, DWORD lockType, BOOL blocking) {
   DWORD flags = lockType;
   if (!blocking)
     flags |= LOCKFILE_FAIL_IMMEDIATELY;
diff --git a/compiler-rt/lib/profile/WindowsMMap.h b/compiler-rt/lib/profile/WindowsMMap.h
index 68b8de2398d606..1df1a0be0b02bd 100644
--- a/compiler-rt/lib/profile/WindowsMMap.h
+++ b/compiler-rt/lib/profile/WindowsMMap.h
@@ -60,6 +60,12 @@
 # define DWORD_LO(x) (x)
 #endif
 
+#define mmap __llvm_profile_mmap
+#define munmap __llvm_profile_munmap
+#define msync __llvm_profile_msync
+#define madvise __llvm_profile_madvise
+#define flock __llvm_profile_flock
+
 void *mmap(void *start, size_t length, int prot, int flags, int fd,
            off_t offset);
 



More information about the llvm-commits mailing list