[gcc r16-6485] [PATCH v2]: pch, target: update host hooks for NetBSD and OpenBSD
Jeff Law
law@gcc.gnu.org
Sun Jan 4 17:56:56 GMT 2026
https://gcc.gnu.org/g:1a2b5eeb5d24a44db9cb757906bd06912af15379
commit r16-6485-g1a2b5eeb5d24a44db9cb757906bd06912af15379
Author: Kalvis Duckmanton <kalvisd@gmail.com>
Date: Sun Jan 4 10:54:48 2026 -0700
[PATCH v2]: pch, target: update host hooks for NetBSD and OpenBSD
The PCH use_address hooks for NetBSD hosts have not yet been updated to allow
compiled headers to be loaded at an address different from their preferred
address.
This change updates host-netbsd.cc:netbsd_gt_pch_use_address() thus: if a
compiled header cannot be mapped at its preferred address, a region of memory
is allocated and the base address of this region is passed back to the caller
(ggc-common.cc:gt_pch_restore() I believe). Note that in this case the return
value is 0, allowing gt_pch_restore() to load the header. In this respect the
behaviour is slightly different from that of the use_address hook for other
hosts (e.g. Linux).
This change against GCC 15.2.0 builds on the work in pch/71934 (and
target/58937)
gcc/
* config/host-netbsd.cc (netbsd_gt_pch_use_address): Support PCH
loading at addresses other than its preferred address.
* config/host-openbsd.cc (openbsd_gt_pch_use_address): Likewise.
Diff:
---
gcc/config/host-netbsd.cc | 16 +++++++++++++++-
gcc/config/host-openbsd.cc | 16 +++++++++++++++-
2 files changed, 30 insertions(+), 2 deletions(-)
diff --git a/gcc/config/host-netbsd.cc b/gcc/config/host-netbsd.cc
index a6f12d0ecf0d..a5b449944939 100644
--- a/gcc/config/host-netbsd.cc
+++ b/gcc/config/host-netbsd.cc
@@ -78,7 +78,21 @@ netbsd_gt_pch_use_address (void *&base, size_t size, int fd, size_t offset)
addr = mmap (base, size, PROT_READ | PROT_WRITE, MAP_PRIVATE | MAP_FIXED, fd, offset);
- return addr == base ? 1 : -1;
+ if (addr == base)
+ return 1;
+
+ if (addr != (void *) MAP_FAILED)
+ munmap(addr, size);
+
+ addr = mmap (base, size, PROT_READ | PROT_WRITE, MAP_PRIVATE | MAP_ANONYMOUS, -1, 0);
+
+ if (addr == (void *) MAP_FAILED)
+ return -1;
+
+ /* Signal to the caller that whilst memory has been allocated, it
+ must read the PCH data */
+ base = addr;
+ return 0;
}
diff --git a/gcc/config/host-openbsd.cc b/gcc/config/host-openbsd.cc
index ee09df361820..ac5f913ed914 100644
--- a/gcc/config/host-openbsd.cc
+++ b/gcc/config/host-openbsd.cc
@@ -78,7 +78,21 @@ openbsd_gt_pch_use_address (void *&base, size_t size, int fd, size_t offset)
addr = mmap (base, size, PROT_READ | PROT_WRITE, MAP_PRIVATE, fd, offset);
- return addr == base ? 1 : -1;
+ if (addr == base)
+ return 1;
+
+ if (addr != (void *) MAP_FAILED)
+ munmap(addr, size);
+
+ addr = mmap (base, size, PROT_READ | PROT_WRITE, MAP_PRIVATE | MAP_ANONYMOUS, -1, 0);
+
+ if (addr == (void *) MAP_FAILED)
+ return -1;
+
+ /* Signal to the caller that whilst memory has been allocated, it
+ must read the PCH data */
+ base = addr;
+ return 0;
}
More information about the Gcc-cvs
mailing list