malloc & friends hidden proto issues

Carmelo AMOROSO carmelo.amoroso at st.com
Fri Jul 17 08:19:17 UTC 2009


-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1

Khem Raj wrote:
> On (17/07/09 07:36), Carmelo AMOROSO wrote:
>> -----BEGIN PGP SIGNED MESSAGE-----
>> Hash: SHA1
>>
>> Folks,
>> I've recently added for testing hidden_proto in {m,re,c}alloc functions to
>> ensure that from within the libc we always called the hidden __GI_xxx symbols.
>>
>> Using this uClibc with firefox and bash I found a problem.
>> Both bash and firefox provide a their own implementation of memory allocation
>> functions (bash internally, firefox by libejmalloc.so).
>>
>> Because the dynamic linker will search undefined symbols firstly in the application,
>> any reference to malloc/free functions will be resolved by the application's symbols.
>>
>> If we use the hidden_protos, calls to malloc/free from libc are resolved inside libc itslef
>> at it is expected.
>>
>> Now we have getcwd and strdup that use malloc for allocate memory and return the
>> pointer to the caller. This memory is after freed by the application, calling free(),
>> that is not the libc one implementation, leading to error, sigbus and so on.
>>
>> Do you think it is wrong to use the hidden_protos for this class of functions,
>> or we should think better at how internal symbols are actually used by uClibc ?
> 
Hi Khem,
> IMO when reimplementing malloc by applications, other functions referring to malloc in libc 
> should also be reimplemented in terms of user defined malloc and free.
> 
good point... but the application should know exactly which function has to be
reimplemented.

> bash has --without-bash-malloc which could be there because of such errors.
> 
yes, in fact I used this for bash... firefox could be build without libejmalloc as well,
but for performance reason, it seems the its memory allocator is optimised
for its specific case, so I would like to keep on using libejmalloc.so

> Thx
> 
> -Khem
> 
Carmelo

-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.4.9 (GNU/Linux)
Comment: Using GnuPG with Fedora - http://enigmail.mozdev.org

iEYEARECAAYFAkpgNAUACgkQoRq/3BrK1s/q2gCfbJR1/6WRhLXmbUuPmM8ItLQ0
mRcAoLfjibA9csVyyZ35qhWAvoK9cD+Q
=AiVI
-----END PGP SIGNATURE-----


More information about the uClibc mailing list