This is the mail archive of the
libc-alpha@sourceware.org
mailing list for the glibc project.
Re: [PATCH] BZ #14545: Always check dtv before freeing dtv[-1]
On Thu, Sep 6, 2012 at 4:11 PM, Roland McGrath <roland@hack.frob.com> wrote:
>> I don't see how
>>
>> #ifndef SHARED
>> # define EXTERN extern
>> # define GL(name) _##name
>> #else
>>
>> #ifndef SHARED
>> # define _dl_initial_dtv ((void *) &_dl_static_dtv[1])
>> #endif
>>
>> will work since GL(dl_initial_dtv)) will be expanded to
>> -(void *) &_dl_static_dtv[1]).
>
> Huh? Did you try it?
>
> GL(dl_initial_dtv) becomes _dl_initial_dtv and then that
> becomes ((void *) &_dl_static_dtv[1]). No problem.
>
> Even translating what I presume were your typos to:
> _((void *) &_dl_static_dtv[1])
> your expectation of that result indicates either a misunderstanding of
> cpp semantics so thorough I can't quite imagine what you think they are,
> or just a braino.
You are right. Fixed it with
diff --git a/elf/dl-tls.c b/elf/dl-tls.c
index 9d896b7..c3a3d68 100644
--- a/elf/dl-tls.c
+++ b/elf/dl-tls.c
@@ -466,9 +466,7 @@ rtld_hidden_def (_dl_allocate_tls)
#ifndef SHARED
extern dtv_t _dl_static_dtv[];
-# define DL_INITIAL_DTV (&_dl_static_dtv[1])
-#else
-# define DL_INITIAL_DTV GL(dl_initial_dtv)
+# define _dl_initial_dtv (&_dl_static_dtv[1])
#endif
void
@@ -484,7 +482,7 @@ _dl_deallocate_tls (void *tcb, bool dealloc_tcb)
free (dtv[1 + cnt].pointer.val);
/* The array starts with dtv[-1]. */
- if (dtv != DL_INITIAL_DTV)
+ if (dtv != GL(dl_initial_dtv))
free (dtv - 1);
if (dealloc_tcb)
--
H.J.