use load address from elf header if possible
authorRich Felker <dalias@aerifal.cx>
Tue, 28 Jun 2011 18:20:41 +0000 (14:20 -0400)
committerRich Felker <dalias@aerifal.cx>
Tue, 28 Jun 2011 18:20:41 +0000 (14:20 -0400)
this is mostly useless for shared libs (though it could help for
prelink-like purposes); the intended use case is for adding support
for calling the dynamic linker directly to run a program, as in:
./libc.so ./a.out foo

this usage is not yet supported.

src/ldso/dynlink.c

index 82aaeec..527b36b 100644 (file)
@@ -189,7 +189,7 @@ static void *map_library(int fd, size_t *lenp, unsigned char **basep, size_t *dy
         * the length of the file. This is okay because we will not
         * use the invalid part; we just need to reserve the right
         * amount of virtual address space to map over later. */
         * the length of the file. This is okay because we will not
         * use the invalid part; we just need to reserve the right
         * amount of virtual address space to map over later. */
-       map = mmap(0, map_len, prot, MAP_PRIVATE, fd, off_start);
+       map = mmap((void *)addr_min, map_len, prot, MAP_PRIVATE, fd, off_start);
        if (map==MAP_FAILED) return 0;
        base = map - addr_min;
        ph = (void *)((char *)buf + eh->e_phoff);
        if (map==MAP_FAILED) return 0;
        base = map - addr_min;
        ph = (void *)((char *)buf + eh->e_phoff);