This is a response to https://gcc.gnu.org/bugzilla/show_bug.cgi?id=14940#c57
The patch was submitted to MSYS2 for testing in 2022-5. No issue reports have been received so far:* https://github.com/msys2/MINGW-packages/blob/455762a45250642b90e9ff34020d001c1be09015/mingw-w64-gcc/0021-PR14940-Allow-a-PCH-to-be-mapped-to-a-different-addr.patch
-- Best regards, LIU Hao From 5239275bb4df0e79bc4b2af57d90c2d10ad44863 Mon Sep 17 00:00:00 2001 From: LIU Hao <lh_mo...@126.com> Date: Wed, 11 May 2022 22:42:53 +0800 Subject: [PATCH] Allow a PCH to be mapped to a different address First, try mapping the PCH to its original address. If that fails, try letting the system choose one; the PCH can be relocated thereafter. Reference: https://gcc.gnu.org/pipermail/gcc-patches/2022-May/594556.html 2022-05-11 LIU Hao <lh_mo...@126.com> PR pch/14940 * config/i386/host-mingw32.cc (mingw32_gt_pch_use_address): Replace the loop that attempted to map the PCH only to its original address with more adaptive operations --- gcc/config/i386/host-mingw32.cc | 32 +++++++++++++++----------------- 1 file changed, 15 insertions(+), 17 deletions(-) diff --git a/gcc/config/i386/host-mingw32.cc b/gcc/config/i386/host-mingw32.cc index e083f49f3da7..87804a5bb755 100644 --- a/gcc/config/i386/host-mingw32.cc +++ b/gcc/config/i386/host-mingw32.cc @@ -135,7 +135,6 @@ mingw32_gt_pch_use_address (void *&addr, size_t size, int fd, and earlier, backslashes are invalid in object name. So, we need to check if we are on Windows2000 or higher. */ OSVERSIONINFO version_info; - int r; version_info.dwOSVersionInfoSize = sizeof (version_info); @@ -169,25 +168,24 @@ mingw32_gt_pch_use_address (void *&addr, size_t size, int fd, return -1; } - /* Retry five times, as here might occure a race with multiple gcc's - instances at same time. */ - for (r = 0; r < 5; r++) - { - mmap_addr = MapViewOfFileEx (mmap_handle, FILE_MAP_COPY, 0, offset, - size, addr); - if (mmap_addr == addr) - break; - if (r != 4) - Sleep (500); - } - - if (mmap_addr != addr) + /* Try mapping the file at `addr`. */ + mmap_addr = MapViewOfFileEx (mmap_handle, FILE_MAP_COPY, 0, offset, + size, addr); + if (mmap_addr == NULL) { - w32_error (__FUNCTION__, __FILE__, __LINE__, "MapViewOfFileEx"); - CloseHandle(mmap_handle); - return -1; + /* We could not map the file at its original address, so let the + system choose a different one. The PCH can be relocated later. */ + mmap_addr = MapViewOfFileEx (mmap_handle, FILE_MAP_COPY, 0, offset, + size, NULL); + if (mmap_addr == NULL) + { + w32_error (__FUNCTION__, __FILE__, __LINE__, "MapViewOfFileEx"); + CloseHandle(mmap_handle); + return -1; + } } + addr = mmap_addr; return 1; } -- 2.48.1
From 5239275bb4df0e79bc4b2af57d90c2d10ad44863 Mon Sep 17 00:00:00 2001 From: LIU Hao <lh_mo...@126.com> Date: Wed, 11 May 2022 22:42:53 +0800 Subject: [PATCH] Allow a PCH to be mapped to a different address First, try mapping the PCH to its original address. If that fails, try letting the system choose one; the PCH can be relocated thereafter. Reference: https://gcc.gnu.org/pipermail/gcc-patches/2022-May/594556.html 2022-05-11 LIU Hao <lh_mo...@126.com> PR pch/14940 * config/i386/host-mingw32.cc (mingw32_gt_pch_use_address): Replace the loop that attempted to map the PCH only to its original address with more adaptive operations --- gcc/config/i386/host-mingw32.cc | 32 +++++++++++++++----------------- 1 file changed, 15 insertions(+), 17 deletions(-) diff --git a/gcc/config/i386/host-mingw32.cc b/gcc/config/i386/host-mingw32.cc index e083f49f3da7..87804a5bb755 100644 --- a/gcc/config/i386/host-mingw32.cc +++ b/gcc/config/i386/host-mingw32.cc @@ -135,7 +135,6 @@ mingw32_gt_pch_use_address (void *&addr, size_t size, int fd, and earlier, backslashes are invalid in object name. So, we need to check if we are on Windows2000 or higher. */ OSVERSIONINFO version_info; - int r; version_info.dwOSVersionInfoSize = sizeof (version_info); @@ -169,25 +168,24 @@ mingw32_gt_pch_use_address (void *&addr, size_t size, int fd, return -1; } - /* Retry five times, as here might occure a race with multiple gcc's - instances at same time. */ - for (r = 0; r < 5; r++) - { - mmap_addr = MapViewOfFileEx (mmap_handle, FILE_MAP_COPY, 0, offset, - size, addr); - if (mmap_addr == addr) - break; - if (r != 4) - Sleep (500); - } - - if (mmap_addr != addr) + /* Try mapping the file at `addr`. */ + mmap_addr = MapViewOfFileEx (mmap_handle, FILE_MAP_COPY, 0, offset, + size, addr); + if (mmap_addr == NULL) { - w32_error (__FUNCTION__, __FILE__, __LINE__, "MapViewOfFileEx"); - CloseHandle(mmap_handle); - return -1; + /* We could not map the file at its original address, so let the + system choose a different one. The PCH can be relocated later. */ + mmap_addr = MapViewOfFileEx (mmap_handle, FILE_MAP_COPY, 0, offset, + size, NULL); + if (mmap_addr == NULL) + { + w32_error (__FUNCTION__, __FILE__, __LINE__, "MapViewOfFileEx"); + CloseHandle(mmap_handle); + return -1; + } } + addr = mmap_addr; return 1; } -- 2.48.1
OpenPGP_signature.asc
Description: OpenPGP digital signature