This is the mail archive of the gcc-patches@gcc.gnu.org mailing list for the GCC project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

Re: PCH support on Solaris


> Yes, that's why Geoff suggested to first make sure that we can safely pass
> MAP_FIXED by using OS-specific hooks.

The problem is not that MAP_FIXED is not portable, it is that it is dangerous.  It's
too easy to get a crash if MAP_FIXED is too zealous in getting the address you asked
for: in my experience I had segfaults and SIGILLs in libgcc, which were even dependant
on the system libraries, for instance on the file sizes and on what libc mmap-ed at
startup.  This weird behavior is not good for gcc where bugs are seeked to be as easily
reproducible as possible.

I was attempting to make it safer. Knowing more about how the code's work, I can detail
more about my suggestion.

- when loading the pre-compiled header, you first ask the OS for memory for the PCH,
preferrably at the base address that the PCH was translated to, with

#ifndef MAP_NORESERVE
#define MAP_NORESERVE 0
#endif

guess = mmap (mmi.preferred_base, mmi.size, PROT_NONE,
        MAP_PRIVATE|MAP_ANON|MAP_NORESERVE, -1, 0);

if (guess == (caddr_t) -1)
    {
        warning ("PCH not usable");
        return;
    }

_If getting that area is not possible, the OS will not unmap anything!_

- then if the OS likes the position, you are sure that mapping the file at that
location is not risky, so you can use MAP_FIXED like

addr = mmap (guess, mmi.size, PROT_READ | PROT_WRITE,
        MAP_PRIVATE|MAP_FIXED, fileno (f), mmi.offset);

if (addr != guess || addr != mmi.preferred_base)
   {
        munmap (guess, mmi.size);
        assert (addr == (caddr_t) -1);    /* else MAP_FIXED did not work! */
        warning ("PCH not usable");
        return;
    }

/* ok, PCH was mmap-ed */

With this approach you have no OS dependent heuristic, you just ask the OS in advance
whether what you want can be achieved with the current memory layout.

Paolo



Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]