From mboxrd@z Thu Jan 1 00:00:00 1970 X-Spam-Checker-Version: SpamAssassin 3.4.4 (2020-01-24) on inbox.vuxu.org X-Spam-Level: X-Spam-Status: No, score=-1.1 required=5.0 tests=DKIM_SIGNED,DKIM_VALID, DKIM_VALID_AU,MAILING_LIST_MULTI,RCVD_IN_MSPIKE_H2, T_SCC_BODY_TEXT_LINE autolearn=ham autolearn_force=no version=3.4.4 Received: (qmail 8110 invoked from network); 15 Aug 2022 19:02:11 -0000 Received: from second.openwall.net (193.110.157.125) by inbox.vuxu.org with ESMTPUTF8; 15 Aug 2022 19:02:11 -0000 Received: (qmail 1918 invoked by uid 550); 15 Aug 2022 19:02:08 -0000 Mailing-List: contact musl-help@lists.openwall.com; run by ezmlm Precedence: bulk List-Post: List-Help: List-Unsubscribe: List-Subscribe: List-ID: Reply-To: musl@lists.openwall.com Received: (qmail 1886 invoked from network); 15 Aug 2022 19:02:08 -0000 X-Virus-Scanned: SPAM Filter at disroot.org Mime-Version: 1.0 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=disroot.org; s=mail; t=1660590105; bh=u7+0EXKH9sPj2qjFqM3nhCKv0GKVKdRszxJTVcUXnNw=; h=Date:Subject:From:To:References:In-Reply-To; b=dlu9wJL5gBJrwwI6IDM1//r92dFf3LFCkgbZM6aL6VWvpsfoxyFH0r5dJC1uPHNmE 8QgjsbgHvKyUkdpFKYDWtDWHCez3JxS6rieVJAP+kNNe8ZnMYUiE5wrRTcTqcEozcj KoAPonqCmJQwXz7nGfzpKZp1j5eYG9tZZyOCYpl4kTW/vyVBkYc4s/4cfHNRC5HWON Nb678FUPA8pMpE+gFxxcSDr0eQLKoogosXRayNG1j0Ai0/9ReIJJlAKwSwAg2N8Ryt m4jj9LUaqXxNYnJKlWX9LnYvKxI67SpKzgHQWltZfn9Aj2MIRNmZFNXHXWV68cWQda hCPdajL3Ja8yg== Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset=UTF-8 Date: Mon, 15 Aug 2022 16:01:41 -0300 Message-Id: From: =?utf-8?q?=C3=89rico_Nogueira?= To: References: <20220815182110.19039-1-ericonr@disroot.org> <20220815183114.GZ7074@brightrain.aerifal.cx> In-Reply-To: <20220815183114.GZ7074@brightrain.aerifal.cx> Subject: Re: [musl] [PATCH] use __getauxval in mallocng On Mon Aug 15, 2022 at 3:31 PM -03, Rich Felker wrote: > On Mon, Aug 15, 2022 at 03:21:10PM -0300, =C3=89rico Nogueira wrote: > > saves around 20 bytes of .text > > --- > > src/malloc/mallocng/glue.h | 6 +++--- > > 1 file changed, 3 insertions(+), 3 deletions(-) > >=20 > > diff --git a/src/malloc/mallocng/glue.h b/src/malloc/mallocng/glue.h > > index 151c48b8..4b988fb2 100644 > > --- a/src/malloc/mallocng/glue.h > > +++ b/src/malloc/mallocng/glue.h > > @@ -12,6 +12,7 @@ > > #include "libc.h" > > #include "lock.h" > > #include "dynlink.h" > > +#include "sys/auxv.h" > > =20 > > // use macros to appropriately namespace these. > > #define size_classes __malloc_size_classes > > @@ -42,9 +43,8 @@ > > static inline uint64_t get_random_secret() > > { > > uint64_t secret =3D (uintptr_t)&secret * 1103515245; > > - for (size_t i=3D0; libc.auxv[i]; i+=3D2) > > - if (libc.auxv[i]=3D=3DAT_RANDOM) > > - memcpy(&secret, (char *)libc.auxv[i+1]+8, sizeof secret); > > + const char *at_random =3D (void *)__getauxval(AT_RANDOM); > > + if (at_random) memcpy(&secret, at_random+8, sizeof secret); > > return secret; > > } > > =20 > > --=20 > > 2.37.2 > > Hm, this might be worth doing. I'm trying to remember if there was a > reason it wasn't done initially. It wasn't absence of a namespace-safe > version because __getauxval already existed when mallocng was merged. > And it doesn't look like there's an early-use issue before getauxval > is usable either. Might it just be more expensive in the static linked > case where __getauxval isn't otherwise used? That does seem to be the case :/ >From some quick testing, a program calling only malloc and freeing it got ~60 bytes bigger. I don't think there's a good way to get the best outcome in both situations, is there? And 20 bytes in a shared mapping makes more sense. > > Rich