index | | raw e-mail
diff --git a/libexec/rtld-elf/map_object.c b/libexec/rtld-elf/map_object.c
index 06be8c02137e..d8583cb67e5a 100644
--- a/libexec/rtld-elf/map_object.c
+++ b/libexec/rtld-elf/map_object.c
@@ -60,7 +60,7 @@ phdr_in_zero_page(const Elf_Ehdr *hdr)
* 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;
@@ -314,8 +314,12 @@ map_object(int fd, const char *path, const struct stat *sb)
if (phinterp != NULL)
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.c b/libexec/rtld-elf/rtld.c
index 1a5cb0a6fce9..a7fdc153eca8 100644
--- a/libexec/rtld-elf/rtld.c
+++ b/libexec/rtld-elf/rtld.c
@@ -765,7 +765,7 @@ _rtld(Elf_Addr *sp, func_ptr_type *exit_proc, Obj_Entry **objp)
*/
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();
@@ -2897,7 +2897,7 @@ do_load_object(int fd, const char *name, char *path, struct stat *sbp,
}
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);
diff --git a/libexec/rtld-elf/rtld.h b/libexec/rtld-elf/rtld.h
index 527ecf9d84e7..b51bbb427a79 100644
--- a/libexec/rtld-elf/rtld.h
+++ b/libexec/rtld-elf/rtld.h
@@ -390,7 +390,7 @@ enum {
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 *);
help
