Hi!

Linux has a EXEC_PAGESIZE macro, exposed in asm/param.h, typically
accessed via linux/param.h, then sys/param.h.  This is now taken for
granted in glibc:

    commit 02d46fc4b969e25e4ba0c54aa95fa98d7279bd05
    Author: Ulrich Drepper <drep...@gmail.com>
    Date:   Sat Sep 10 21:47:36 2011 -0400
    
        Simplify malloc initialization
        
        Singificantly reduce the code needed at malloc initialization.  In
        the process getpagesize is simplified by always initializing
        GLRO(dl_pagesize).
    
    diff --git a/elf/rtld.c b/elf/rtld.c
    [...]
    @@ -161,6 +161,7 @@ struct rtld_global_ro _rtld_global_ro attribute_relro =
         ._dl_lazy = 1,
         ._dl_fpu_control = _FPU_DEFAULT,
         ._dl_pointer_guard = 1,
    +    ._dl_pagesize = EXEC_PAGESIZE,

And:

    commit 32b4c8393f6db8b0bbf9c87a09461111a423a433
    Author: Ulrich Drepper <drep...@gmail.com>
    Date:   Sun Sep 11 11:25:51 2011 -0400
    
        Provide static initializer for _dl_pagesize in statically linked code
    
    diff --git a/elf/dl-support.c b/elf/dl-support.c
    [...]
    +#include <sys/param.h>
    [...]
    -size_t _dl_pagesize;
    +size_t _dl_pagesize = EXEC_PAGESIZE;

Hurd (or specifically: Mach) doesn't have a EXEC_PAGESIZE macro, but
handles this in the mach/mach_init.c startup code with the host_page_size
RPC and stores the retrieved value in __vm_page_size/vm_page_size.

In my understanding, these two, _rtld_global_ro._dl_pagesize and plain
_dl_pagesize is what is accessed in a lot of places all over glibc by
using GLRO(dl_pagesize) for the shared vs. static case.  This used to
be/still is initialized from the auxv (if available) in elf/dl-support.c
and elf/dl-sysdep.c, or otherwise from a __getpagesize call in the latter
file.  For Hurd it is always initialized from a __getpagesize call
(returning vm_page_size) in sysdeps/mach/hurd/dl-sysdep.c, right after
__mach_init.

Isn't all this due for some cleanup; also the Linux code with assignment
From EXEC_PAGESIZE vs. assignment from auxv?

For the Hurd, can I wrap the two above assignments with #ifdef
EXEC_PAGESIZE, and it'll be enough for us to set GLRO(dl_pagesize) in
sysdeps/mach/hurd/dl-sysdep.c:_dl_sysdep_start, as it used to be?  But
then, malloc won't work before, right (due to commit 02d46fc4)?

And why do we need a __vm_page_size plus vm_page_size weak alias, and
don't only use GLRO(dl_pagesize)?


Then, additionally in libio/libioP.h, I found this bit of code:

    #if _G_HAVE_MMAP
    [...]
    # include <sys/param.h>
    [...]
    # if !defined(MAP_ANONYMOUS) || !defined(EXEC_PAGESIZE)
    #  undef _G_HAVE_MMAP
    #  define _G_HAVE_MMAP 0
    # endif

This means, we don't get to use mmap/munmap but instead use malloc/free.
I will check/fix this later on.


Grüße,
 Thomas

Attachment: pgpk7xE3VM7Nw.pgp
Description: PGP signature

Reply via email to