[PATCH 4/7] Move libc_freeres_ptrs and libc_subfreeres to weak functions

Adhemerval Zanella Netto adhemerval.zanella@linaro.org
Mon Dec 12 14:16:16 GMT 2022



On 12/12/22 11:05, Florian Weimer wrote:
> * Adhemerval Zanella Netto:
> 
>>> I think you should consider introducing a call_free_static_weak that
>>> does something like
>>>
>>>   if (&ptr != NULL)
>>>     free (ptr);
>>>
>>> in the static case, and calls
>>>
>>>   free (ptr);
>>>
>>> unconditionally for the dynamic case.  And then add attribute_hidden
>>> variable declarations to a suitable wrapper header under include/.
>>>
>>> This avoids writing all these little helper functions.
>>
>> We already have call_free_static_weak function that does exactly that,
> 
> I don't see call_free_static_weak?
> 
>> maybe you are proposing a something like:
>>
>> # ifdef SHARED
>> #  define declare_libc_freeres (name, ptr) \
>> static void name (void) { free (ptr); }
>> # else 
>> #  define declare_libc_freeres (name, ptr) \
>> static void name (void) { if (ptr != NULL) free (ptr); }
>> # endif
> 
> It has to be &ptr != NULL for the weak case, and you also need to create
> a weak alias.

Right, and do we really need a weak_alias in this fact? Wouldn't weak_function
suffice in this case for !SHARED?



More information about the Libc-alpha mailing list