From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from smtp.gentoo.org (woodpecker.gentoo.org [IPv6:2001:470:ea4a:1:5054:ff:fec7:86e4]) by sourceware.org (Postfix) with ESMTP id 2344F385E83F for ; Wed, 16 Mar 2022 08:30:44 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.1 sourceware.org 2344F385E83F Authentication-Results: sourceware.org; dmarc=pass (p=none dis=none) header.from=gentoo.org Authentication-Results: sourceware.org; spf=pass smtp.mailfrom=gentoo.org Received: by smtp.gentoo.org (Postfix, from userid 559) id 4B780342BA0; Wed, 16 Mar 2022 08:30:03 +0000 (UTC) Date: Wed, 16 Mar 2022 04:30:11 -0400 From: Mike Frysinger To: "R. Diez" Cc: Richard Earnshaw , newlib@sourceware.org Subject: Re: [PATCH v2] newlib: fix build with Mail-Followup-To: "R. Diez" , Richard Earnshaw , newlib@sourceware.org References: <20220314032559.24535-1-vapier@gentoo.org> <20220315032550.16502-1-vapier@gentoo.org> <2c68b0f8-03ad-d93d-dd35-002a66576ff8@foss.arm.com> MIME-Version: 1.0 Content-Type: multipart/signed; micalg=pgp-sha256; protocol="application/pgp-signature"; boundary="v+meJfllnMoMb9CW" Content-Disposition: inline In-Reply-To: X-Spam-Status: No, score=-5.6 required=5.0 tests=BAYES_00, KAM_DMARC_STATUS, SPF_HELO_PASS, SPF_PASS, TXREP, T_SCC_BODY_TEXT_LINE autolearn=ham autolearn_force=no version=3.4.4 X-Spam-Checker-Version: SpamAssassin 3.4.4 (2020-01-24) on server2.sourceware.org X-BeenThere: newlib@sourceware.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Newlib mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Wed, 16 Mar 2022 08:30:45 -0000 --v+meJfllnMoMb9CW Content-Type: text/plain; charset=utf-8 Content-Disposition: inline Content-Transfer-Encoding: quoted-printable On 16 Mar 2022 08:12, R. Diez wrote: > > __builtin_mul_overflow showed up with gcc-5, so stub it out for older > > versions. > > [...] > > +#if !__GNUC_PREREQ__(5, 0) > > +#define __builtin_mul_overflow(a, b, size) ({ *(size) =3D (a) * (b); 0= ; }) >=20 > I do not understand why Newlib needs to "stub it out" like this. because the builtin doesn't exist, and attempting to use it leads to undefined functions, and the resulting libc.a can't link anything. > According to the GCC documentation, this kind of built-in routines allow = the caller to check whether the operations overflowes. But the code above p= erforms no overflow checking at all. >=20 > Therefore, compiling your code with GCC < 5 will silently break your appl= ication. After all, the only reason to use __builtin_mul_overflow() is that= you need to check for overflow, is it? practically speaking, i don't think this is a big deal. newlib gained these checks only "recently" (<2 years ago). newlib has been around for much much longer, and the world didn't notice. yes, if an app starts trying to alloc= ate huge amounts of memory such that it triggers 32-bit overflows when calculat= ing, the new size, it will probably internally allocate fewer bytes than request= ed, and things will get corrupted. but like, don't do that :p. such applicati= ons probably will have other problems already. -mike --v+meJfllnMoMb9CW Content-Type: application/pgp-signature; name="signature.asc" -----BEGIN PGP SIGNATURE----- iQIzBAABCAAdFiEEuQK1JxMl+JKsJRrUQWM7n+g39YEFAmIxoBMACgkQQWM7n+g3 9YHzMhAAzN3v8LWOAd2S4h39teKYZv1uCfqTg+vwqHsHY+z5e5Jm4Y4dkVmU7TMl M8U0PqYfdwGMHVqB7Tb+4FYpOLeB2/HfxOL+NY7c4zh/anpqF23Iuegi62soAhSh mP+U7czqDvEdfulqy1oNfDnRQWP1uODjxmkrRrW8Ckq0RbvFIuc6e1u9X+h/3YYo dInupseHmISwRByIgWB4aNNLTtYsNwovDTvfR8hpJ3hRPGEfMWt7yT/FPgbQWgBd vqNhkEiR1WVBQ5AHh1nZQmU3onKJI9u0eTdvSuHXyEDrmSKcUawwYm/XtdfDj5a+ L2akOu84rQPO3dRrP4MzR3MvoPkVzen+aMdcvFKWy88T2VxKNZ2101XN0Q1P7LDt MIQMeM/OvDO5Coga9zErynGIf9B/yGlOLgihH8aWvXi0nOXgU1u1fm1JG5O0loRN xyPxfs3d0aUyyq0tf0E30A+eSLqvRMAwocpihN6fHhmfk/YVerFtmIPuVArRfay9 2JjxkjxQ6L4sNip6ZgLxCF6hTbNwjDYfcjfkWzjEj2p0nGcmY6WmR2GkKcg7XHWl 38Rgohh69iT8sy8H2TFtGbj1MMy9E856WQgsILlE1ALilpOswCpcK0rF/qo9Uowb KeL/P9YLbQXCz3vmlEPpEKBAmCK81enK1WwGaEHRqZWa6OkfrB8= =MJXN -----END PGP SIGNATURE----- --v+meJfllnMoMb9CW--