Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Cygwin] Cygwin general 1 #74941

Closed
wants to merge 1 commit into from
Closed

Conversation

xu-chiheng
Copy link

@xu-chiheng xu-chiheng commented Dec 9, 2023

Remove some uses of macro CYGWIN .

I have build scripts and patches at https://github.com/xu-chiheng/Note .
I can use the build scripts and patches to build and bootstrap GCC(start from 13.0.0) and Clang/LLVM(start from 16.0.0), using GCC or Clang, on Cygwin and MinGW.
If you have interests, you can look at my other PRs at https://github.com/llvm/llvm-project/pulls/xu-chiheng .

Most patches come from upstream at

https://cygwin.com/git-cygwin-packages/
https://cygwin.com/git-cygwin-packages/?p=git/cygwin-packages/clang.git;a=summary
git://cygwin.com/git/cygwin-packages/clang.git
https://cygwin.com/git-cygwin-packages/?p=git/cygwin-packages/llvm.git;a=summary
git://cygwin.com/git/cygwin-packages/llvm.git

https://github.com/msys2/MINGW-packages/tree/master/mingw-w64-clang
https://github.com/msys2/MINGW-packages/blob/master/mingw-w64-clang/PKGBUILD

https://src.fedoraproject.org/rpms/llvm.git

@llvmbot
Copy link
Collaborator

llvmbot commented Dec 9, 2023

@llvm/pr-subscribers-platform-windows

Author: 徐持恒 Xu Chiheng (xu-chiheng)

Changes

Override Cygwin's buggy getpagesize() to Win32 computePageSize().


Full diff: https://github.com/llvm/llvm-project/pull/74941.diff

3 Files Affected:

  • (modified) llvm/lib/Support/Process.cpp (+19)
  • (modified) llvm/lib/Support/Unix/Process.inc (+3-1)
  • (modified) llvm/lib/Support/Windows/Process.inc (-13)
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/Unix/Process.inc b/llvm/lib/Support/Unix/Process.inc
index 2babf07944bf7b..2bf53ae188ebd3 100644
--- a/llvm/lib/Support/Unix/Process.inc
+++ b/llvm/lib/Support/Unix/Process.inc
@@ -76,7 +76,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);
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;

@llvmbot
Copy link
Collaborator

llvmbot commented Dec 9, 2023

@llvm/pr-subscribers-llvm-support

Author: 徐持恒 Xu Chiheng (xu-chiheng)

Changes

Override Cygwin's buggy getpagesize() to Win32 computePageSize().


Full diff: https://github.com/llvm/llvm-project/pull/74941.diff

3 Files Affected:

  • (modified) llvm/lib/Support/Process.cpp (+19)
  • (modified) llvm/lib/Support/Unix/Process.inc (+3-1)
  • (modified) llvm/lib/Support/Windows/Process.inc (-13)
diff --git a/llvm/lib/Support/Process.cpp b/llvm/lib/Support/Process.cpp
index 30c64d3ed9ed1..6d4a7275f5fa6 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/Unix/Process.inc b/llvm/lib/Support/Unix/Process.inc
index 2babf07944bf7..2bf53ae188ebd 100644
--- a/llvm/lib/Support/Unix/Process.inc
+++ b/llvm/lib/Support/Unix/Process.inc
@@ -76,7 +76,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);
diff --git a/llvm/lib/Support/Windows/Process.inc b/llvm/lib/Support/Windows/Process.inc
index a54c06d46870b..9addfa6ec805e 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;

Copy link
Collaborator

@asl asl left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This requires more description. At least some rationale why this is not necessary anymore

@xu-chiheng xu-chiheng changed the title [Cygwin] Cygwin general [Cygwin] Cygwin general 1 Jan 5, 2024
@xu-chiheng xu-chiheng closed this Apr 2, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants