Re: [PATCH v2] newlib: fix build with <gcc-5 versions
Mike Frysinger <[email protected]>
| Newsgroups | gmane.comp.lib.newlib |
|---|---|
| Message-ID | <YjKe7JnZNMv8VtEr@vapier> |
On 16 Mar 2022 10:17, R. Diez wrote: > >> 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. > > Such general justifications wouldn't pass quality assurance (if we had one). in your opinion. software is not perfect, it's trade-offs. > > 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. > > You are suggesting that this only affects memory allocation, but the patch is for libc/include/sys/cdefs.h , so those mine traps will be available for everybody. > > People will tend to assume that anything in Newlib is correct, and code has a way to get copied around and re-used. > > There are many ways to mitigate the risk: > > - Require GCC 5. > - Provide a proper implementation of __builtin_mul_overflow(). > - Patch all users of __builtin_mul_overflow() within Newlib, so that they do not use it if the compiler does not provide it. > - Issue a compilation warning for GCC < 5 that the "stub" __builtin_mul_overflow() is broken. > Note that this is not actually a "stub" implementation in the common sense. > - Add an "assert( false ) // fix me" inside the implementation. > - Add a comment stating that the "stub" implementation is not actually correct. any option that prevents correct execution with gcc-4 is not an improvement. if you care this much, feel free to contribute a patch. or use gcc-5+ and not worry about it. -mike
signature.asc
(application/pgp-signature, 833 B)
-----BEGIN PGP SIGNATURE----- iQIzBAABCAAdFiEEuQK1JxMl+JKsJRrUQWM7n+g39YEFAmIyn+YACgkQQWM7n+g3 9YGbRg//c1miuy5+4dh1DMqRPiw2H8o4A8peDpoXsHqC46lc2dD1vq6XDC3RT4/F VKJePv41D0OnLjw3ESVkpKjvHxnudKeNmdXH+6zGXeiJECyugigc9JuMq4pnaa7z cT9Un9EvezM1BBPoGzz1duNXHvhxLWkltOqbUKOXLP+UR1pBDwvTA/qFyRQk+rxE DGvpAZvKMj9Lwa1+V0tS7pA1aHhRwyIA2nR5JfUQ02Uj2G5zODnLfEkJLFWJnt8d lvqb6zwRF1ZfgS2ksBkedzo9KN94fBDC9q9yTUEXigkgcbQxb+NZQ6+UEpN4KYSA 2Hujr0AhMLctt0G2l6qsYnjhFqk2rhsueKn7bUQ3MhxAtqQYZZZi0mTblCsC0qPt zkpK3NHPdLgWm60g9u7WAsd61ZRC8iK7+2qxnl0oaHr1XiUMK8KGpywMg+FDy0z9 ILQ3UtW2ixnaB+rxpigCdEoiGTU8R0Tgnpb9qVHkAuzk9F2Vs8/KeYk4BC7Rwv81 jfdTTOzvAXVp2zhQkjFGFZtf5cwo/a2zSqGxeqqw5MTRMnT/pn3BEUnxnqnwb9TL Xij2K1ZYPnS6RBOWaT4rzsu9JQ2NB0AWebTU8CA0Y7sZa3dtK8f1m+ZRMwHBvrVa JgvWzEammAcKeKjT/1udPxTFFyQFxufIMNssh4+uZ+a8Jq8FtoE= =8Xyq -----END PGP SIGNATURE-----