This is the mail archive of the
gcc-patches@gcc.gnu.org
mailing list for the GCC project.
Re: Fix a bug in emutls
- From: Jakub Jelinek <jakub at redhat dot com>
- To: Jie Zhang <jie dot zhang at analog dot com>
- Cc: GCC Patches <gcc-patches at gcc dot gnu dot org>
- Date: Fri, 13 Feb 2009 13:16:07 +0100
- Subject: Re: Fix a bug in emutls
- References: <499545B4.6070401@analog.com>
- Reply-to: Jakub Jelinek <jakub at redhat dot com>
On Fri, Feb 13, 2009 at 06:04:36PM +0800, Jie Zhang wrote:
> The number of the elements of data[] in struct __emutls_array is (size -
> 1), not size. I found this when I was looking at several FAILs in
> libgomp testsuite for Blackfin, which uses emutls to emulate TLS. This
> patch fixes it. OK?
I'd say the bug is elsewhere, there is no need to not use the whole
allocated area. Later on we access arr->data[offset - 1], so there is
no problem not reallocating when offset == arr->size, arr->data[offset - 1]
is still valid.
Completely untested.
2009-02-13 Jakub Jelinek <jakub@redhat.com>
* emutls.c (__emutls_get_address): Only reallocate if
offset is bigger than arr->size.
--- gcc/emutls.c 2008-12-16 09:48:41.000000000 +0100
+++ gcc/emutls.c 2009-02-13 13:12:46.000000000 +0100
@@ -166,7 +166,7 @@ __emutls_get_address (struct __emutls_ob
arr->size = size;
__gthread_setspecific (emutls_key, (void *) arr);
}
- else if (__builtin_expect (offset >= arr->size, 0))
+ else if (__builtin_expect (offset > arr->size, 0))
{
pointer orig_size = arr->size;
pointer size = orig_size * 2;
@@ -176,7 +176,7 @@ __emutls_get_address (struct __emutls_ob
if (arr == NULL)
abort ();
arr->size = size;
- memset (arr->data + orig_size - 1, 0,
+ memset (arr->data + orig_size, 0,
(size - orig_size) * sizeof (void *));
__gthread_setspecific (emutls_key, (void *) arr);
}
Jakub