[PATCH v2] Move libc_freeres_ptrs and libc_subfreeres to hidden/weak functions

Adhemerval Zanella Netto adhemerval.zanella@linaro.org
Tue Dec 13 15:46:26 GMT 2022



On 13/12/22 10:41, Florian Weimer wrote:
> * Adhemerval Zanella:
> 
>> -#define __libc_freeres_fn_section \
>> -  __attribute__ ((__used__, section ("__libc_freeres_fn")))
> 
> I think we could keep __libc_freeres_fn_section for documentation and
> optimization purposes.  A section name such as ".text.__libc_freeres_fn"
> won't need generic linker script support.
> 
>> +#ifdef SHARED
>> +#define set_freeres_declare_ptr(__name, __ptr)			\
>> +  void __name (void)						\
>> +  {								\
>> +    free (__ptr);						\
>> +  }
>> +#else
>> +#define set_freeres_declare_name(__name)			\
>> +  __name ## _aux
>> +#define set_freeres_declare_ptr(__name, __ptr)			\
>> +  void set_freeres_declare_name (__name) (void)			\
>> +  {								\
>> +    if (__ptr != NULL)						\
>> +      free (__ptr);						\
>> +  }								\
>> +  weak_alias (set_freeres_declare_name (__name),  __name)
>> +#endif
> 
> What's the benefit of going through the function, instead of freeing the
> variable directly?
> 
>   if (&ptr != NULL)
>     free (ptr);
> 
> should work for a weak variable, too.

Right, I did not get your suggestion before. I will adjust it.


More information about the Libc-alpha mailing list