diff options
author | dfr <dfr@FreeBSD.org> | 2004-08-03 08:51:00 +0000 |
---|---|---|
committer | dfr <dfr@FreeBSD.org> | 2004-08-03 08:51:00 +0000 |
commit | 4e9853427fa3cd90808fd8369e917f588b1ee5c0 (patch) | |
tree | 5493edb6b3a69f88f4154145f1edf0879595204f /libexec/rtld-elf/amd64 | |
parent | 5a48e6bc9fa5e4eb90bf8dc018ec35469df1d4ea (diff) | |
download | FreeBSD-src-4e9853427fa3cd90808fd8369e917f588b1ee5c0.zip FreeBSD-src-4e9853427fa3cd90808fd8369e917f588b1ee5c0.tar.gz |
Add support for Thread Local Storage.
Diffstat (limited to 'libexec/rtld-elf/amd64')
-rw-r--r-- | libexec/rtld-elf/amd64/reloc.c | 130 | ||||
-rw-r--r-- | libexec/rtld-elf/amd64/rtld_machdep.h | 15 |
2 files changed, 145 insertions, 0 deletions
diff --git a/libexec/rtld-elf/amd64/reloc.c b/libexec/rtld-elf/amd64/reloc.c index dcb492c..985b481 100644 --- a/libexec/rtld-elf/amd64/reloc.c +++ b/libexec/rtld-elf/amd64/reloc.c @@ -33,6 +33,7 @@ #include <sys/param.h> #include <sys/mman.h> +#include <machine/sysarch.h> #include <dlfcn.h> #include <err.h> @@ -199,6 +200,111 @@ reloc_non_plt(Obj_Entry *obj, Obj_Entry *obj_rtld) } break; + case R_X86_64_TPOFF64: + { + const Elf_Sym *def; + const Obj_Entry *defobj; + + def = find_symdef(ELF_R_SYM(rela->r_info), obj, &defobj, + false, cache); + if (def == NULL) + goto done; + + /* + * We lazily allocate offsets for static TLS as we + * see the first relocation that references the + * TLS block. This allows us to support (small + * amounts of) static TLS in dynamically loaded + * modules. If we run out of space, we generate an + * error. + */ + if (!defobj->tls_done) { + if (!allocate_tls_offset((Obj_Entry*) defobj)) { + _rtld_error("%s: No space available for static " + "Thread Local Storage", obj->path); + goto done; + } + } + + *where = (Elf_Addr) (def->st_value - defobj->tlsoffset + + rela->r_addend); + } + break; + + case R_X86_64_TPOFF32: + { + const Elf_Sym *def; + const Obj_Entry *defobj; + + def = find_symdef(ELF_R_SYM(rela->r_info), obj, &defobj, + false, cache); + if (def == NULL) + goto done; + + /* + * We lazily allocate offsets for static TLS as we + * see the first relocation that references the + * TLS block. This allows us to support (small + * amounts of) static TLS in dynamically loaded + * modules. If we run out of space, we generate an + * error. + */ + if (!defobj->tls_done) { + if (!allocate_tls_offset((Obj_Entry*) defobj)) { + _rtld_error("%s: No space available for static " + "Thread Local Storage", obj->path); + goto done; + } + } + + *where32 = (Elf32_Addr) (def->st_value - + defobj->tlsoffset + + rela->r_addend); + } + break; + + case R_X86_64_DTPMOD64: + { + const Elf_Sym *def; + const Obj_Entry *defobj; + + def = find_symdef(ELF_R_SYM(rela->r_info), obj, &defobj, + false, cache); + if (def == NULL) + goto done; + + *where += (Elf_Addr) defobj->tlsindex; + } + break; + + case R_X86_64_DTPOFF64: + { + const Elf_Sym *def; + const Obj_Entry *defobj; + + def = find_symdef(ELF_R_SYM(rela->r_info), obj, &defobj, + false, cache); + if (def == NULL) + goto done; + + *where += (Elf_Addr) (def->st_value + rela->r_addend); + } + break; + + case R_X86_64_DTPOFF32: + { + const Elf_Sym *def; + const Obj_Entry *defobj; + + def = find_symdef(ELF_R_SYM(rela->r_info), obj, &defobj, + false, cache); + if (def == NULL) + goto done; + + *where32 += (Elf32_Addr) (def->st_value + rela->r_addend); + } + break; + case R_X86_64_RELATIVE: *where = (Elf_Addr)(obj->relocbase + rela->r_addend); break; @@ -265,3 +371,27 @@ reloc_jmpslots(Obj_Entry *obj) obj->jmpslots_done = true; return 0; } + +void +allocate_initial_tls(Obj_Entry *objs) +{ + /* + * Fix the size of the static TLS block by using the maximum + * offset allocated so far and adding a bit for dynamic modules to + * use. + */ + tls_static_space = tls_last_offset + RTLD_STATIC_TLS_EXTRA; + amd64_set_fsbase(allocate_tls(objs, 0, + 2*sizeof(Elf_Addr), sizeof(Elf_Addr))); +} + +void *__tls_get_addr(tls_index *ti) +{ + Elf_Addr** segbase; + Elf_Addr* dtv; + + __asm __volatile("movq %%fs:0, %0" : "=r" (segbase)); + dtv = segbase[1]; + + return tls_get_addr_common(&segbase[1], ti->ti_module, ti->ti_offset); +} diff --git a/libexec/rtld-elf/amd64/rtld_machdep.h b/libexec/rtld-elf/amd64/rtld_machdep.h index 0fb431b..57bd0de 100644 --- a/libexec/rtld-elf/amd64/rtld_machdep.h +++ b/libexec/rtld-elf/amd64/rtld_machdep.h @@ -58,4 +58,19 @@ reloc_jmpslot(Elf_Addr *where, Elf_Addr target, #define call_initfini_pointer(obj, target) \ (((InitFunc)(target))()) +#define round(size, align) \ + (((size) + (align) - 1) & ~((align) - 1)) +#define calculate_first_tls_offset(size, align) \ + round(size, align) +#define calculate_tls_offset(prev_offset, prev_size, size, align) \ + round((prev_offset) + (size), align) +#define calculate_tls_end(off, size) (off) + +typedef struct { + unsigned long ti_module; + unsigned long ti_offset; +} tls_index; + +extern void *__tls_get_addr(tls_index *ti); + #endif |