handle-aux-at_base.patch (1214B)
1 This is required to make the gcompat ELF interpreter stub work with some 2 packed binaries. 3 4 diff --git a/src/env/__init_tls.c b/src/env/__init_tls.c 5 index b125eb1..616c6a6 100644 6 --- a/src/env/__init_tls.c 7 +++ b/src/env/__init_tls.c 8 @@ -66,8 +66,10 @@ void *__copy_tls(unsigned char *mem) 9 } 10 11 #if ULONG_MAX == 0xffffffff 12 +typedef Elf32_Ehdr Ehdr; 13 typedef Elf32_Phdr Phdr; 14 #else 15 +typedef Elf64_Ehdr Ehdr; 16 typedef Elf64_Phdr Phdr; 17 #endif 18 19 @@ -77,15 +79,23 @@ extern const size_t _DYNAMIC[]; 20 static void static_init_tls(size_t *aux) 21 { 22 unsigned char *p; 23 - size_t n; 24 + size_t n, e; 25 Phdr *phdr, *tls_phdr=0; 26 size_t base = 0; 27 void *mem; 28 29 - for (p=(void *)aux[AT_PHDR],n=aux[AT_PHNUM]; n; n--,p+=aux[AT_PHENT]) { 30 + if (aux[AT_BASE]) { 31 + Ehdr *ehdr = (void *)aux[AT_BASE]; 32 + p = (unsigned char *)aux[AT_BASE] + ehdr->e_phoff; 33 + n = ehdr->e_phnum; 34 + e = ehdr->e_phentsize; 35 + } else { 36 + p = (void *)aux[AT_PHDR]; 37 + n = aux[AT_PHNUM]; 38 + e = aux[AT_PHENT]; 39 + } 40 + for (; n; n--, p+=e) { 41 phdr = (void *)p; 42 - if (phdr->p_type == PT_PHDR) 43 - base = aux[AT_PHDR] - phdr->p_vaddr; 44 if (phdr->p_type == PT_DYNAMIC && _DYNAMIC) 45 base = (size_t)_DYNAMIC - phdr->p_vaddr; 46 if (phdr->p_type == PT_TLS)