[PATCH 2/4] Add a signal-safe malloc replacement
Ondřej Bílka
neleai@seznam.cz
Fri Dec 20 16:09:00 GMT 2013
On Fri, Dec 20, 2013 at 01:59:25PM +0100, Thomas Schwinge wrote:
> Hi!
>
...
> This causes a link failure on Hurd, because to resolve the mmap and
> munmap symbols it tries to pull in object files that are not meant to be
> pulled in:
>
> gcc-4.7 -nostdlib -nostartfiles -r -o [...]/elf/librtld.map.o '-Wl,-(' [...]/elf/dl-allobjs.os [...]/libc_pic.a [...]/mach/libmachuser_pic.a [...]/hurd/libhurduser_pic.a -lgcc '-Wl,-)' -Wl,-Map,[...]/elf/librtld.mapT
> [...]/libc_pic.a(init-first.os):(.data+0x0): multiple definition of `__libc_multiple_libcs'
> [...]/elf/dl-allobjs.os:[...]/elf/rtld.c:797: first defined here
> [...]/libc_pic.a(_itoa.os): In function `_itoa':
> [...]/stdio-common/_itoa.c:199: multiple definition of `_itoa'
> [...]/elf/dl-allobjs.os:[...]/elf/dl-minimal.c:317: first defined here
> collect2: error: ld returned 1 exit status
> make[2]: *** [[...]/elf/librtld.map] Error 1
>
> OK to fix as follows?
>
OK for me.
> * elf/dl-misc.c (__signal_safe_memalign, __signal_safe_free): Use
> internal symbols for mmap and munmap.
>
> diff --git elf/dl-misc.c elf/dl-misc.c
> index b529af3..0ea4329 100644
> --- elf/dl-misc.c
> +++ elf/dl-misc.c
> @@ -418,8 +418,8 @@ __signal_safe_memalign (size_t boundary, size_t size)
>
>
> size_t actual_size = roundup (padded_size, pg);
> - void *actual = mmap (NULL, actual_size, PROT_READ | PROT_WRITE,
> - MAP_ANONYMOUS | MAP_PRIVATE, -1, 0);
> + void *actual = __mmap (NULL, actual_size, PROT_READ | PROT_WRITE,
> + MAP_ANONYMOUS | MAP_PRIVATE, -1, 0);
> if (actual == MAP_FAILED)
> return NULL;
>
> @@ -435,7 +435,7 @@ __signal_safe_memalign (size_t boundary, size_t size)
> start_pg -= start_pg % boundary_pg;
> if (start_pg > (actual_pg + 1))
> {
> - int ret = munmap (actual, (start_pg - actual_pg - 1) * pg);
> + int ret = __munmap (actual, (start_pg - actual_pg - 1) * pg);
> assert (ret == 0);
> actual = (void *) ((start_pg - 1) * pg);
> }
> @@ -466,7 +466,7 @@ __signal_safe_free (void *ptr)
>
> struct __signal_safe_a
More information about the Libc-alpha
mailing list