Re: [PATCH v2] newlib: fix build with <gcc-5 versions

Mike Frysinger <[email protected]>
Newsgroups gmane.comp.lib.newlib
Message-ID <YjGgE0WFwVPT2oh1@vapier>
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) = (a) * (b); 0; })
> 
> 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 performs no overflow checking at all.
> 
> Therefore, compiling your code with GCC < 5 will silently break your application. 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 allocate
huge amounts of memory such that it triggers 32-bit overflows when calculating,
the new size, it will probably internally allocate fewer bytes than requested,
and things will get corrupted.  but like, don't do that :p.  such applications
probably will have other problems already.
-mike
signature.asc (application/pgp-signature, 833 B)
-----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-----
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.