[llvm] [Cygwin] Cygwin general (PR #74944)

εΎζŒζ’ Xu Chiheng via llvm-commits llvm-commits at lists.llvm.org
Sun Dec 31 12:51:34 PST 2023


https://github.com/xu-chiheng updated https://github.com/llvm/llvm-project/pull/74944

>From c45d72169925906ed3604e71e2897a9e38ab6d22 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?=E5=BE=90=E6=8C=81=E6=81=92=20Xu=20Chiheng?=
 <chiheng.xu at gmail.com>
Date: Sun, 10 Dec 2023 02:17:58 +0800
Subject: [PATCH 1/5] 1

---
 llvm/lib/Support/Process.cpp         | 19 +++++++++++++++++++
 llvm/lib/Support/Windows/Process.inc | 13 -------------
 2 files changed, 19 insertions(+), 13 deletions(-)

diff --git a/llvm/lib/Support/Process.cpp b/llvm/lib/Support/Process.cpp
index 30c64d3ed9ed17..6d4a7275f5fa61 100644
--- a/llvm/lib/Support/Process.cpp
+++ b/llvm/lib/Support/Process.cpp
@@ -23,6 +23,10 @@
 #include <optional>
 #include <stdlib.h> // for _Exit
 
+#if defined(_WIN32) || defined(__CYGWIN__)
+#include <windows.h>
+#endif
+
 using namespace llvm;
 using namespace sys;
 
@@ -102,6 +106,21 @@ bool Process::AreCoreFilesPrevented() { return coreFilesPrevented; }
     ::exit(RetCode);
 }
 
+#if defined(_WIN32) || defined(__CYGWIN__)
+// This function retrieves the page size using GetNativeSystemInfo() and is
+// present solely so it can be called once to initialize the self_process member
+// below.
+static unsigned computePageSize() {
+  // GetNativeSystemInfo() provides the physical page size which may differ
+  // from GetSystemInfo() in 32-bit applications running under WOW64.
+  SYSTEM_INFO info;
+  GetNativeSystemInfo(&info);
+  // FIXME: FileOffset in MapViewOfFile() should be aligned to not dwPageSize,
+  // but dwAllocationGranularity.
+  return static_cast<unsigned>(info.dwPageSize);
+}
+#endif
+
 // Include the platform-specific parts of this class.
 #ifdef LLVM_ON_UNIX
 #include "Unix/Process.inc"
diff --git a/llvm/lib/Support/Windows/Process.inc b/llvm/lib/Support/Windows/Process.inc
index a54c06d46870b5..9addfa6ec805e3 100644
--- a/llvm/lib/Support/Windows/Process.inc
+++ b/llvm/lib/Support/Windows/Process.inc
@@ -50,19 +50,6 @@ Process::Pid Process::getProcessId() {
   return Pid(::GetCurrentProcessId());
 }
 
-// This function retrieves the page size using GetNativeSystemInfo() and is
-// present solely so it can be called once to initialize the self_process member
-// below.
-static unsigned computePageSize() {
-  // GetNativeSystemInfo() provides the physical page size which may differ
-  // from GetSystemInfo() in 32-bit applications running under WOW64.
-  SYSTEM_INFO info;
-  GetNativeSystemInfo(&info);
-  // FIXME: FileOffset in MapViewOfFile() should be aligned to not dwPageSize,
-  // but dwAllocationGranularity.
-  return static_cast<unsigned>(info.dwPageSize);
-}
-
 Expected<unsigned> Process::getPageSize() {
   static unsigned Ret = computePageSize();
   return Ret;

>From f7995e113fe56e99fccc970ab2f0012f9275fbe7 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?=E5=BE=90=E6=8C=81=E6=81=92=20Xu=20Chiheng?=
 <chiheng.xu at gmail.com>
Date: Sun, 10 Dec 2023 02:29:03 +0800
Subject: [PATCH 2/5] 1

---
 llvm/lib/Support/Process.cpp | 25 +++++++++++++------------
 1 file changed, 13 insertions(+), 12 deletions(-)

diff --git a/llvm/lib/Support/Process.cpp b/llvm/lib/Support/Process.cpp
index 6d4a7275f5fa61..88c23adb3da239 100644
--- a/llvm/lib/Support/Process.cpp
+++ b/llvm/lib/Support/Process.cpp
@@ -23,10 +23,6 @@
 #include <optional>
 #include <stdlib.h> // for _Exit
 
-#if defined(_WIN32) || defined(__CYGWIN__)
-#include <windows.h>
-#endif
-
 using namespace llvm;
 using namespace sys;
 
@@ -106,6 +102,19 @@ bool Process::AreCoreFilesPrevented() { return coreFilesPrevented; }
     ::exit(RetCode);
 }
 
+// Include the platform-specific parts of this class.
+#ifdef LLVM_ON_UNIX
+#include "Unix/Process.inc"
+#endif
+#ifdef _WIN32
+#include "Windows/Process.inc"
+#endif
+
+
+#if defined(_WIN32) || defined(__CYGWIN__)
+#include <windows.h>
+#endif
+
 #if defined(_WIN32) || defined(__CYGWIN__)
 // This function retrieves the page size using GetNativeSystemInfo() and is
 // present solely so it can be called once to initialize the self_process member
@@ -120,11 +129,3 @@ static unsigned computePageSize() {
   return static_cast<unsigned>(info.dwPageSize);
 }
 #endif
-
-// Include the platform-specific parts of this class.
-#ifdef LLVM_ON_UNIX
-#include "Unix/Process.inc"
-#endif
-#ifdef _WIN32
-#include "Windows/Process.inc"
-#endif

>From 7dc14f2ed888467b7fd78d8aa2c62de251fa4267 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?=E5=BE=90=E6=8C=81=E6=81=92=20Xu=20Chiheng?=
 <chiheng.xu at gmail.com>
Date: Sun, 10 Dec 2023 02:31:12 +0800
Subject: [PATCH 3/5] 1

---
 llvm/lib/Support/Process.cpp | 6 ++++--
 1 file changed, 4 insertions(+), 2 deletions(-)

diff --git a/llvm/lib/Support/Process.cpp b/llvm/lib/Support/Process.cpp
index 88c23adb3da239..9e07e086f5661d 100644
--- a/llvm/lib/Support/Process.cpp
+++ b/llvm/lib/Support/Process.cpp
@@ -102,6 +102,10 @@ bool Process::AreCoreFilesPrevented() { return coreFilesPrevented; }
     ::exit(RetCode);
 }
 
+#if defined(_WIN32) || defined(__CYGWIN__)
+static unsigned computePageSize();
+#endif
+
 // Include the platform-specific parts of this class.
 #ifdef LLVM_ON_UNIX
 #include "Unix/Process.inc"
@@ -113,9 +117,7 @@ bool Process::AreCoreFilesPrevented() { return coreFilesPrevented; }
 
 #if defined(_WIN32) || defined(__CYGWIN__)
 #include <windows.h>
-#endif
 
-#if defined(_WIN32) || defined(__CYGWIN__)
 // This function retrieves the page size using GetNativeSystemInfo() and is
 // present solely so it can be called once to initialize the self_process member
 // below.

>From c63c4ae9f5f067233c9ad8183b91a66ea0780b5c Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?=E5=BE=90=E6=8C=81=E6=81=92=20Xu=20Chiheng?=
 <chiheng.xu at gmail.com>
Date: Sun, 10 Dec 2023 02:35:22 +0800
Subject: [PATCH 4/5] 1

---
 llvm/lib/Support/Process.cpp | 1 -
 1 file changed, 1 deletion(-)

diff --git a/llvm/lib/Support/Process.cpp b/llvm/lib/Support/Process.cpp
index 9e07e086f5661d..d0323be2ec057e 100644
--- a/llvm/lib/Support/Process.cpp
+++ b/llvm/lib/Support/Process.cpp
@@ -114,7 +114,6 @@ static unsigned computePageSize();
 #include "Windows/Process.inc"
 #endif
 
-
 #if defined(_WIN32) || defined(__CYGWIN__)
 #include <windows.h>
 

>From 43f2f7d4ae397238e46a2da06307a653e9f5e103 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?=E5=BE=90=E6=8C=81=E6=81=92=20Xu=20Chiheng?=
 <chiheng.xu at gmail.com>
Date: Sun, 10 Dec 2023 03:14:06 +0800
Subject: [PATCH 5/5] 1

---
 llvm/lib/Support/MemoryBuffer.cpp | 8 --------
 llvm/lib/Support/Unix/Process.inc | 4 +++-
 2 files changed, 3 insertions(+), 9 deletions(-)

diff --git a/llvm/lib/Support/MemoryBuffer.cpp b/llvm/lib/Support/MemoryBuffer.cpp
index 4cc4fe019b75b1..8184b32575f21b 100644
--- a/llvm/lib/Support/MemoryBuffer.cpp
+++ b/llvm/lib/Support/MemoryBuffer.cpp
@@ -384,14 +384,6 @@ static bool shouldUseMmap(sys::fs::file_t FD,
   if ((FileSize & (PageSize -1)) == 0)
     return false;
 
-#if defined(__CYGWIN__)
-  // Don't try to map files that are exactly a multiple of the physical page size
-  // if we need a null terminator.
-  // FIXME: We should reorganize again getPageSize() on Win32.
-  if ((FileSize & (4096 - 1)) == 0)
-    return false;
-#endif
-
   return true;
 }
 
diff --git a/llvm/lib/Support/Unix/Process.inc b/llvm/lib/Support/Unix/Process.inc
index 551f0d7f0f029d..e1c4d964db3fa8 100644
--- a/llvm/lib/Support/Unix/Process.inc
+++ b/llvm/lib/Support/Unix/Process.inc
@@ -78,7 +78,9 @@ Process::Pid Process::getProcessId() {
 // On Cygwin, getpagesize() returns 64k(AllocationGranularity) and
 // offset in mmap(3) should be aligned to the AllocationGranularity.
 Expected<unsigned> Process::getPageSize() {
-#if defined(HAVE_GETPAGESIZE)
+#if defined(__CYGWIN__)
+  static const int page_size = computePageSize();
+#elif defined(HAVE_GETPAGESIZE)
   static const int page_size = ::getpagesize();
 #elif defined(HAVE_SYSCONF)
   static long page_size = ::sysconf(_SC_PAGE_SIZE);



More information about the llvm-commits mailing list