diff --git a/libexec/rtld-elf/map_object.c b/libexec/rtld-elf/map_object.c --- a/libexec/rtld-elf/map_object.c +++ b/libexec/rtld-elf/map_object.c @@ -60,7 +60,7 @@ * for the shared object. Returns NULL on failure. */ Obj_Entry * -map_object(int fd, const char *path, const struct stat *sb) +map_object(int fd, const char *path, const struct stat *sb, bool ismain) { Obj_Entry *obj; Elf_Ehdr *hdr; @@ -327,8 +327,12 @@ obj->interp = (const char *)(obj->relocbase + phinterp->p_vaddr); if (phtls != NULL) { - tls_dtv_generation++; - obj->tlsindex = ++tls_max_index; + if (ismain) + obj->tlsindex = 1; + else { + tls_dtv_generation++; + obj->tlsindex = ++tls_max_index; + } obj->tlssize = phtls->p_memsz; obj->tlsalign = phtls->p_align; obj->tlspoffset = phtls->p_offset; diff --git a/libexec/rtld-elf/rtld.h b/libexec/rtld-elf/rtld.h --- a/libexec/rtld-elf/rtld.h +++ b/libexec/rtld-elf/rtld.h @@ -380,7 +380,7 @@ void _rtld_error(const char *, ...) __printflike(1, 2) __exported; void rtld_die(void) __dead2; const char *rtld_strerror(int); -Obj_Entry *map_object(int, const char *, const struct stat *); +Obj_Entry *map_object(int, const char *, const struct stat *, bool); void *xcalloc(size_t, size_t); void *xmalloc(size_t); char *xstrdup(const char *); diff --git a/libexec/rtld-elf/rtld.c b/libexec/rtld-elf/rtld.c --- a/libexec/rtld-elf/rtld.c +++ b/libexec/rtld-elf/rtld.c @@ -784,7 +784,7 @@ */ if (fd != -1) { /* Load the main program. */ dbg("loading main program"); - obj_main = map_object(fd, argv0, NULL); + obj_main = map_object(fd, argv0, NULL, true); close(fd); if (obj_main == NULL) rtld_die(); @@ -2920,7 +2920,7 @@ } dbg("loading \"%s\"", printable_path(path)); - obj = map_object(fd, printable_path(path), sbp); + obj = map_object(fd, printable_path(path), sbp, false); if (obj == NULL) return (NULL);