From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 18290 invoked by alias); 14 May 2004 23:15:42 -0000 Mailing-List: contact libc-hacker-help@sources.redhat.com; run by ezmlm Precedence: bulk List-Subscribe: List-Archive: List-Post: List-Help: , Sender: libc-hacker-owner@sources.redhat.com Received: (qmail 18274 invoked from network); 14 May 2004 23:15:42 -0000 Received: from unknown (HELO sunsite.ms.mff.cuni.cz) (195.113.15.26) by sourceware.org with SMTP; 14 May 2004 23:15:42 -0000 Received: from sunsite.ms.mff.cuni.cz (sunsite.mff.cuni.cz [127.0.0.1]) by sunsite.ms.mff.cuni.cz (8.12.8/8.12.8) with ESMTP id i4EL2r3j030357 for ; Fri, 14 May 2004 23:02:54 +0200 Received: (from jakub@localhost) by sunsite.ms.mff.cuni.cz (8.12.8/8.12.8/Submit) id i4EL2rAN030355 for libc-hacker@sources.redhat.com; Fri, 14 May 2004 23:02:53 +0200 Resent-Message-Id: <200405142102.i4EL2rAN030355@sunsite.ms.mff.cuni.cz> Date: Fri, 14 May 2004 23:15:00 -0000 From: Jakub Jelinek To: Ulrich Drepper Cc: Glibc hackers , tcallawa@redhat.com Subject: [PATCH] Fix TLS handling in ld.so on i386/sh/sparc32 Message-ID: <20040514200749.GF5191@sunsite.ms.mff.cuni.cz> Reply-To: Jakub Jelinek Mime-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline User-Agent: Mutt/1.4i Resent-From: jakub@sunsite.ms.mff.cuni.cz Resent-Date: Fri, 14 May 2004 23:02:53 +0200 Resent-To: Glibc hackers X-SW-Source: 2004-05/txt/msg00028.txt.bz2 Hi! When attempting to add TLS support for prelink on SPARC, I have noticed ld.so segfaults. CHECK_STATIC_TLS must never be called if sym_map == NULL (which is iff sym == NULL). Looking around revealed the same problem on SH and in i386 RELA handling (I have added 2 new testcases to prelink where one of them fails on i386 unless this patch is in). 2004-05-14 Jakub Jelinek * sysdeps/sparc/sparc32/dl-machine.h (elf_machine_rela): Only CHECK_STATIC_TLS if sym != NULL. * sysdeps/sh/dl-machine.h (elf_machine_rela): Likewise. * sysdeps/i386/dl-machine.h (elf_machine_rela): Likewise. --- libc/sysdeps/sparc/sparc32/dl-machine.h.jj 2004-04-21 10:06:11.000000000 +0200 +++ libc/sysdeps/sparc/sparc32/dl-machine.h 2004-05-14 23:37:55.412726806 +0200 @@ -521,22 +521,27 @@ elf_machine_rela (struct link_map *map, /* We know the offset of object the symbol is contained in. It is a negative value which will be added to the thread pointer. */ - CHECK_STATIC_TLS (map, sym_map); - *reloc_addr - = (sym == NULL ? 0 : sym->st_value - sym_map->l_tls_offset) - + reloc->r_addend; + if (sym != NULL) + { + CHECK_STATIC_TLS (map, sym_map); + *reloc_addr = sym->st_value - sym_map->l_tls_offset + + reloc->r_addend; + } break; # ifndef RTLD_BOOTSTRAP case R_SPARC_TLS_LE_HIX22: case R_SPARC_TLS_LE_LOX10: - CHECK_STATIC_TLS (map, sym_map); - value = (sym == NULL ? 0 : sym->st_value - sym_map->l_tls_offset) - + reloc->r_addend; - if (r_type == R_SPARC_TLS_LE_HIX22) - *reloc_addr = (*reloc_addr & 0xffc00000) | ((~value) >> 10); - else - *reloc_addr = (*reloc_addr & 0xffffe000) | (value & 0x3ff) - | 0x1c00; + if (sym != NULL) + { + CHECK_STATIC_TLS (map, sym_map); + value = sym->st_value - sym_map->l_tls_offset + + reloc->r_addend; + if (r_type == R_SPARC_TLS_LE_HIX22) + *reloc_addr = (*reloc_addr & 0xffc00000) | ((~value) >> 10); + else + *reloc_addr = (*reloc_addr & 0xffffe000) | (value & 0x3ff) + | 0x1c00; + } break; # endif #endif --- libc/sysdeps/sh/dl-machine.h.jj 2004-03-11 11:10:19.000000000 +0100 +++ libc/sysdeps/sh/dl-machine.h 2004-05-14 23:36:13.157052354 +0200 @@ -580,10 +580,12 @@ elf_machine_rela (struct link_map *map, It is a positive value which will be added to the thread pointer. To get the variable position in the TLS block we add the offset from that of the TLS block. */ - CHECK_STATIC_TLS (map, sym_map); - *reloc_addr - = ((sym == NULL ? 0 : sym_map->l_tls_offset + sym->st_value) - + reloc->r_addend); + if (sym != NULL) + { + CHECK_STATIC_TLS (map, sym_map); + *reloc_addr = sym_map->l_tls_offset + sym->st_value + + reloc->r_addend; + } # endif break; #endif /* use TLS */ --- libc/sysdeps/i386/dl-machine.h.jj 2004-03-09 10:58:16.000000000 +0100 +++ libc/sysdeps/i386/dl-machine.h 2004-05-14 23:35:10.295317995 +0200 @@ -587,20 +587,24 @@ elf_machine_rela (struct link_map *map, It is a positive value which will be subtracted from the thread pointer. To get the variable position in the TLS block we subtract the offset from that of the TLS block. */ - CHECK_STATIC_TLS (map, sym_map); - *reloc_addr - = (sym == NULL ? 0 : sym_map->l_tls_offset - sym->st_value) - + reloc->r_addend; + if (sym != NULL) + { + CHECK_STATIC_TLS (map, sym_map); + *reloc_addr = sym_map->l_tls_offset - sym->st_value + + reloc->r_addend; + } break; case R_386_TLS_TPOFF: /* The offset is negative, forward from the thread pointer. */ /* We know the offset of object the symbol is contained in. It is a negative value which will be added to the thread pointer. */ - CHECK_STATIC_TLS (map, sym_map); - *reloc_addr - = (sym == NULL ? 0 : sym->st_value - sym_map->l_tls_offset) - + reloc->r_addend; + if (sym != NULL) + { + CHECK_STATIC_TLS (map, sym_map); + *reloc_addr = sym->st_value - sym_map->l_tls_offset + + reloc->r_addend; + } break; # endif /* use TLS */ case R_386_COPY: Jakub From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 27545 invoked by alias); 15 May 2004 00:31:05 -0000 Mailing-List: contact libc-hacker-help@sources.redhat.com; run by ezmlm Precedence: bulk List-Subscribe: List-Archive: List-Post: List-Help: , Sender: libc-hacker-owner@sources.redhat.com Received: (qmail 27516 invoked from network); 15 May 2004 00:31:04 -0000 Received: from unknown (HELO sunsite.ms.mff.cuni.cz) (195.113.15.26) by sourceware.org with SMTP; 15 May 2004 00:31:04 -0000 Received: from sunsite.ms.mff.cuni.cz (sunsite.mff.cuni.cz [127.0.0.1]) by sunsite.ms.mff.cuni.cz (8.12.8/8.12.8) with ESMTP id i4EMIG3l012367; Sat, 15 May 2004 00:18:17 +0200 Received: (from jakub@localhost) by sunsite.ms.mff.cuni.cz (8.12.8/8.12.8/Submit) id i4EK7ogi029644; Fri, 14 May 2004 22:07:50 +0200 Date: Sat, 15 May 2004 07:50:00 -0000 From: Jakub Jelinek To: Ulrich Drepper Cc: Glibc hackers , tcallawa@redhat.com Subject: [PATCH] Fix TLS handling in ld.so on i386/sh/sparc32 Message-ID: <20040514200749.GF5191@sunsite.ms.mff.cuni.cz> Reply-To: Jakub Jelinek Mime-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline User-Agent: Mutt/1.4i X-SW-Source: 2004-05/txt/msg00029.txt.bz2 Message-ID: <20040515075000.ppyt7ybvhwjrM9WeD0QsfQuD6e8KXaHcm2hUtNxxze4@z> Hi! When attempting to add TLS support for prelink on SPARC, I have noticed ld.so segfaults. CHECK_STATIC_TLS must never be called if sym_map == NULL (which is iff sym == NULL). Looking around revealed the same problem on SH and in i386 RELA handling (I have added 2 new testcases to prelink where one of them fails on i386 unless this patch is in). 2004-05-14 Jakub Jelinek * sysdeps/sparc/sparc32/dl-machine.h (elf_machine_rela): Only CHECK_STATIC_TLS if sym != NULL. * sysdeps/sh/dl-machine.h (elf_machine_rela): Likewise. * sysdeps/i386/dl-machine.h (elf_machine_rela): Likewise. --- libc/sysdeps/sparc/sparc32/dl-machine.h.jj 2004-04-21 10:06:11.000000000 +0200 +++ libc/sysdeps/sparc/sparc32/dl-machine.h 2004-05-14 23:37:55.412726806 +0200 @@ -521,22 +521,27 @@ elf_machine_rela (struct link_map *map, /* We know the offset of object the symbol is contained in. It is a negative value which will be added to the thread pointer. */ - CHECK_STATIC_TLS (map, sym_map); - *reloc_addr - = (sym == NULL ? 0 : sym->st_value - sym_map->l_tls_offset) - + reloc->r_addend; + if (sym != NULL) + { + CHECK_STATIC_TLS (map, sym_map); + *reloc_addr = sym->st_value - sym_map->l_tls_offset + + reloc->r_addend; + } break; # ifndef RTLD_BOOTSTRAP case R_SPARC_TLS_LE_HIX22: case R_SPARC_TLS_LE_LOX10: - CHECK_STATIC_TLS (map, sym_map); - value = (sym == NULL ? 0 : sym->st_value - sym_map->l_tls_offset) - + reloc->r_addend; - if (r_type == R_SPARC_TLS_LE_HIX22) - *reloc_addr = (*reloc_addr & 0xffc00000) | ((~value) >> 10); - else - *reloc_addr = (*reloc_addr & 0xffffe000) | (value & 0x3ff) - | 0x1c00; + if (sym != NULL) + { + CHECK_STATIC_TLS (map, sym_map); + value = sym->st_value - sym_map->l_tls_offset + + reloc->r_addend; + if (r_type == R_SPARC_TLS_LE_HIX22) + *reloc_addr = (*reloc_addr & 0xffc00000) | ((~value) >> 10); + else + *reloc_addr = (*reloc_addr & 0xffffe000) | (value & 0x3ff) + | 0x1c00; + } break; # endif #endif --- libc/sysdeps/sh/dl-machine.h.jj 2004-03-11 11:10:19.000000000 +0100 +++ libc/sysdeps/sh/dl-machine.h 2004-05-14 23:36:13.157052354 +0200 @@ -580,10 +580,12 @@ elf_machine_rela (struct link_map *map, It is a positive value which will be added to the thread pointer. To get the variable position in the TLS block we add the offset from that of the TLS block. */ - CHECK_STATIC_TLS (map, sym_map); - *reloc_addr - = ((sym == NULL ? 0 : sym_map->l_tls_offset + sym->st_value) - + reloc->r_addend); + if (sym != NULL) + { + CHECK_STATIC_TLS (map, sym_map); + *reloc_addr = sym_map->l_tls_offset + sym->st_value + + reloc->r_addend; + } # endif break; #endif /* use TLS */ --- libc/sysdeps/i386/dl-machine.h.jj 2004-03-09 10:58:16.000000000 +0100 +++ libc/sysdeps/i386/dl-machine.h 2004-05-14 23:35:10.295317995 +0200 @@ -587,20 +587,24 @@ elf_machine_rela (struct link_map *map, It is a positive value which will be subtracted from the thread pointer. To get the variable position in the TLS block we subtract the offset from that of the TLS block. */ - CHECK_STATIC_TLS (map, sym_map); - *reloc_addr - = (sym == NULL ? 0 : sym_map->l_tls_offset - sym->st_value) - + reloc->r_addend; + if (sym != NULL) + { + CHECK_STATIC_TLS (map, sym_map); + *reloc_addr = sym_map->l_tls_offset - sym->st_value + + reloc->r_addend; + } break; case R_386_TLS_TPOFF: /* The offset is negative, forward from the thread pointer. */ /* We know the offset of object the symbol is contained in. It is a negative value which will be added to the thread pointer. */ - CHECK_STATIC_TLS (map, sym_map); - *reloc_addr - = (sym == NULL ? 0 : sym->st_value - sym_map->l_tls_offset) - + reloc->r_addend; + if (sym != NULL) + { + CHECK_STATIC_TLS (map, sym_map); + *reloc_addr = sym->st_value - sym_map->l_tls_offset + + reloc->r_addend; + } break; # endif /* use TLS */ case R_386_COPY: Jakub