Hi Jeff,

On 6/12/25 16:14, Jeff Law wrote:
On 11/26/25 7:45 PM, Kalvis Duckmanton wrote:
On 26/11/25 11:15, Jeff Law wrote:
On 11/18/25 7:41 PM, Kalvis Duckmanton wrote:
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

Generally it looks sensible.  So my preference would be to fix both NetBSD and OpenBSD at the same time, assuming we think both need the same fix.

Ok.  I will investigate a bit further and try to confirm that the proposed change will also work for OpenBSD.
It'd be hugely appreciated.  I'm an old BSD guy myself and would love to see it better supported these days, but can't really spend any time on it.  In theory this ought to be testable in a VM.

I ended up netbooting OpenBSD/amd64 7.8 and compiling GCC 15.2.0 from source.  In addition to my patch, I also needed to apply the patches from lang/gcc/15 in the OpenBSD ports repository (a converted version of which is at https://github.com/openbsd/ports).

Having updated host-openbsd.cc with the same change as for NetBSD, I tested the change by running cc1plus under lldb.  Using lldb, the first test in openbsd_gt_pch_use_address() (for addr == base) was skipped, and the address returned by the second mmap() call was modified to be 16kB above its original value.  Once cc1plus had finished, the assembly code it produced was inspected.  The output seemed reasonable and it contained values defined in the compiled header, which is encouraging.

I've attached an updated version of the previous patch which updates the use_address hook for NetBSD and for OpenBSD.

cheers

kalvis
diff -cwr a/gcc/config/host-netbsd.cc b/gcc/config/host-netbsd.cc
*** a/gcc/config/host-netbsd.cc	Fri Aug  8 16:51:40 2025
--- b/gcc/config/host-netbsd.cc	Thu Nov 13 12:39:29 2025
***************
*** 78,84 ****
  
    addr = mmap (base, size, PROT_READ | PROT_WRITE, MAP_PRIVATE | MAP_FIXED, fd, offset);
  
!   return addr == base ? 1 : -1;
  }
  
  
--- 78,98 ----
  
    addr = mmap (base, size, PROT_READ | PROT_WRITE, MAP_PRIVATE | MAP_FIXED, fd, offset);
  
!   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 -cwr a/gcc/config/host-openbsd.cc b/gcc/config/host-openbsd.cc
*** a/gcc/config/host-openbsd.cc	Fri Aug  8 16:51:40 2025
--- b/gcc/config/host-openbsd.cc	Sun Dec 21 14:51:12 2025
***************
*** 78,84 ****
  
    addr = mmap (base, size, PROT_READ | PROT_WRITE, MAP_PRIVATE, fd, offset);
  
!   return addr == base ? 1 : -1;
  }
  
  
--- 78,98 ----
  
    addr = mmap (base, size, PROT_READ | PROT_WRITE, MAP_PRIVATE, fd, offset);
  
!   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