Subject: Re: warning: src/x11 broken
To: Matthias Scheler <tron@zhadum.de>
From: Frank van der Linden <fvdl@netbsd.org>
List: port-amd64
Date: 04/11/2004 11:29:08
On Sun, Apr 11, 2004 at 08:37:17AM +0000, Matthias Scheler wrote:
> So IIUC the loader doesn't work if the address returned by mmap() is
> above 4GB. Correct?

Yeah, because it does direct address fixups on non-PIC objects. And
by default, text and data are referenced using 32bit-values in
generated object files on AMD64 (small model). But mmap and malloc
do, of course, use the full range available in 64bit values. So
if mmap returns a value > 2G (they can be relative values), you're
screwed.


> A possible fix would be a change like this to
> "xfree/xc/programs/Xserver/hw/xfree86/loader/loader.c":
> 
> #if defined(__NetBSD__) && (__AMD64__)
> 	static char *mm_addr = (char *)(1L << 30);
> #else
> 	char *mm_addr = NULL;
> #endif
> 
>     ret = (unsigned long)mmap(mm_addr, new_size, MMAP_PROT, MAP_PRIVATE
> #  if !defined(_NetBSD__) && defined(__AMD64__)
>                               | MAP_32BIT
> #  endif
>                               , fd, new_off);
>     if (ret == -1)
>         FatalError("mmap() failed: %s\n", strerror(errno));
> #if defined(__NetBSD__) && (__AMD64__)
>     mm_addr += new_size;
> #endif
> 
>     return (void *)(ret + new_off_bias);

That's not a bad idea.. a few changes I would make:

#define LOADER_MMAP_AREA_SIZE	(256*1024*1024)
#define LOADER_MMAP_AREA_START	((2*1024*1024*1024) - LOADER_MMAP_AREA_SIZE)

...

	static char *mm_addr = LOADER_MMAP_AREA_START;

...

	mm_addr += roundup(new_size, PAGE_SIZE);
...


I think this might work.. I have no time to try it for a few days, though.

- Frank