Hi!

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)

ChangeLog:

    * gcc/config/host-netbsd.cc (netbsd_gt_pch_use_address): update for pch/71934

Testing:

For the reasons outlined in pch/71934, the new code has been tested manually by temporarily arranging for the first call to mmap() to map the compiled header at a different address from the one supplied.

GCC was bootstrapped on NetBSD/amd64 (x86_64-unknown-netbsd11.0) and the tests for gcc, g++ and gfortran were run.  The results are below:

                === gcc Summary ===

# of expected passes            205468
# of unexpected failures        1131
# of unexpected successes       1
# of expected failures          1332
# of unresolved testcases       643
# of unsupported tests          4241

                === g++ Summary ===

# of expected passes            233216
# of unexpected failures        10471
# of unexpected successes       9
# of expected failures          2270
# of unresolved testcases       1219
# of unsupported tests          2065

(and in particular the PCH tests g++.dg/pch all pass)

                === gfortran Summary ===

# of expected passes            73055
# of unexpected failures        93
# of expected failures          343
# of unsupported tests          91


many thanks

kalvis

diff --git a/gcc/config/host-netbsd.cc b/gcc/config/host-netbsd.cc
index 6dd39e80695f..40dfed0b264d 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;
 }
 
 

Reply via email to