Date: Fri, 18 Jan 2013 07:29:39 +0200 From: Konstantin Belousov <kostikbel@gmail.com> To: Steve Kiernan <stevek@juniper.net> Cc: Jason Evans <jasone@canonware.com>, freebsd-arch@freebsd.org Subject: Re: [JNPR] Proposal to add weak symbols for malloc, realloc, and free to libc Message-ID: <20130118052939.GV2522@kib.kiev.ua> In-Reply-To: <20130117232850.1b69bfc0@stevek-ubuntu> References: <20130117161311.4c15c7c4@stevek-ubuntu> <E4A1FEFD-B267-422B-8051-443B1F8519E1@canonware.com> <20130117184654.06f8e330@stevek-ubuntu> <20130118040933.GU2522@kib.kiev.ua> <20130117232850.1b69bfc0@stevek-ubuntu>
next in thread | previous in thread | raw e-mail | index | archive | help
--Pbi2MkfjSbXbI4MN Content-Type: text/plain; charset=us-ascii Content-Disposition: inline Content-Transfer-Encoding: quoted-printable On Thu, Jan 17, 2013 at 11:28:50PM -0500, Steve Kiernan wrote: > On Fri, 18 Jan 2013 06:09:33 +0200 > Konstantin Belousov <kostikbel@gmail.com> wrote: >=20 > > On Thu, Jan 17, 2013 at 06:46:54PM -0500, Steve Kiernan wrote: > > > On Thu, 17 Jan 2013 15:42:19 -0800 > > > Jason Evans <jasone@canonware.com> wrote: > > >=20 > > > > On Jan 17, 2013, at 1:13 PM, Steve Kiernan wrote: > > > > > When libc was changed to use jemalloc, the weak symbols for mallo= c, realloc, and free ended up being removed. > > > > > This makes it a bit difficult for an application to replace (or a= ugment) the malloc implementation. > > > > >=20 > > > > > This proposal is to add back the weak symbols similar to how they= existed in libc prior to jemalloc introduction. > > > > >=20 > > > > > See the following patch for the changes: > > > > > http://people.freebsd.org/~marcel/Juniper/weak-malloc.diff > > > > >=20 > > > > > I'm not sure if the the symbols are in the proper place in the Sy= mbol.map file and would welcome comments. > > > >=20 > > > > What about calloc(), posix_memalign(), and malloc_usable_size()? S= imilarly, I think the *allocm() functions in -current may need the same tre= atment. > > >=20 > > > I think you are correct and those would probably be necessary, as wel= l, yes. > > >=20 > > > It looked like previously, calloc was not made weak because it was im= plemented in terms of malloc, but since that is not the case in jemalloc, i= t will need to be addressed. > > >=20 > > > I'll update the patch. > >=20 > > New symbols should be added to the current version, which is FBSD_1.3 > > for the 10.0. >=20 > Okay, great. Thank you for the information. >=20 > > That said, what are the difficulties you experiencing with the malloc > > interposing ? According to the normal ELF symbol lookup rules, the > > definitions from any object which is loaded before libc overrides the > > libc symbols. >=20 > The problem is when one want to augment the calls. For example, say > you want to do some leak detection or keep track of statistics that > the malloc library does not. One would need to still call the original > call after replacing the malloc/realloc/free/etc. with their own. > Without having the __malloc/__realloc/__free/etc. that _used_ to be > in libc, one cannot do so. Well, the standard technique is to do void *libc_handle =3D dlopen("libc.so"); void *(*libc_malloc)(size_t) =3D dlsym(libc_handle, "malloc"); if you know exactly that you want malloc from libc. If you want just any previous interposer for the malloc, then the right technique is to do dlsym(RTLD_NEXT, "malloc") from your malloc wrapper. Still I think that your patch, with additions noted by Jason, is useful. --Pbi2MkfjSbXbI4MN Content-Type: application/pgp-signature -----BEGIN PGP SIGNATURE----- Version: GnuPG v2.0.19 (FreeBSD) iQIcBAEBAgAGBQJQ+N3DAAoJEJDCuSvBvK1BG9oQAJOs5GYCya1p6vp19k3ZgUmn tfC3QNm2olwWsNv4NCUxoJGYPtA2D048UoxaEjgToRcLdwjD2fmj716LkLhQOIei Ugy/HHWmQdaTWZ9gqIh5ZZsneEt5WEGJ0pRmyFLTBco975+SNX4E0RNhJcpirM8t nbqIMNHN26JacWeo+LZFXqgbIOvTJVB9mV2sA+GJ9c96mFC1uwQOk+dOoywnEJ29 WSM+91naZaowEueXSldJu7uORi0Xs1uFeHJZTeKZOsWuW0G2cwSLr4zMszSNvt9o 6/znom+JMWSKQwHZBC+U3FK7VZiEpAWghCb16f7qdXZZ1en0fpX4VtZuERF79C2d 4992Shsyz4D8f7ltuI+z95Pq74Ok8rEphr989CH9xoha5mQZIA1IYAIabuy7Qz7H Eug4yLFhR0VnB1aiD0SzD6BzLvjDc8e4lcAVSqmuw/0jQXb9cpIWzQ1iXEZ65jWu K+oBo1mw1QK6rFYfBPS+fq48qqAnHtGaYQIIPp+xp7HypHIYQGrKt0MzKFYQ0ElQ fX7FJmW4unSfEmoJgJYurLhDuYi2JOD9vdoeLGs/nzcE5lgiPzGdM1kYag8c3Aaz yDI4qCXAqgJV5VMrjObR9tj4TcAxJ6AAO9USZXVIx5NS+DuPi7q1XdXSDnwgIdRZ 9RasAT7Ew/65hIAw2b7C =wUb0 -----END PGP SIGNATURE----- --Pbi2MkfjSbXbI4MN--
Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?20130118052939.GV2522>