diff mbox series

Fix iconv build with GCC mainline

Message ID alpine.DEB.2.22.394.2108191655530.350860@digraph.polyomino.org.uk
State New
Headers show
Series Fix iconv build with GCC mainline | expand

Commit Message

Joseph Myers Aug. 19, 2021, 4:56 p.m. UTC
Current GCC mainline produces -Wstringop-overflow errors building some
iconv converters, as discussed at
<https://gcc.gnu.org/pipermail/gcc/2021-July/236943.html>.  Add an
__builtin_unreachable call as suggested so that GCC can see the case
that would involve a buffer overflow is unreachable; because the
unreachability depends on valid conversion state being passed into the
function from previous conversion steps, it's not something the
compiler can reasonably deduce on its own.

Tested with build-many-glibcs.py that, together with
<https://sourceware.org/pipermail/libc-alpha/2021-August/130244.html>,
it restores the glibc build for powerpc-linux-gnu.

Comments

Joseph Myers Aug. 23, 2021, 3:46 p.m. UTC | #1
Ping.  This patch 
<https://sourceware.org/pipermail/libc-alpha/2021-August/130315.html> is 
pending review.
Andreas Schwab Aug. 23, 2021, 4:09 p.m. UTC | #2
On Aug 19 2021, Joseph Myers wrote:

> Current GCC mainline produces -Wstringop-overflow errors building some
> iconv converters, as discussed at
> <https://gcc.gnu.org/pipermail/gcc/2021-July/236943.html>.  Add an
> __builtin_unreachable call as suggested so that GCC can see the case
> that would involve a buffer overflow is unreachable; because the
> unreachability depends on valid conversion state being passed into the
> function from previous conversion steps, it's not something the
> compiler can reasonably deduce on its own.

Ok.

Andreas.
diff mbox series

Patch

diff --git a/iconv/loop.c b/iconv/loop.c
index 062cc1b868..560a5f6394 100644
--- a/iconv/loop.c
+++ b/iconv/loop.c
@@ -436,6 +436,12 @@  SINGLE(LOOPFCT) (struct __gconv_step *step,
     return __GCONV_FULL_OUTPUT;
 
   /*  Now add characters from the normal input buffer.  */
+  if (inlen >= MAX_NEEDED_INPUT)
+    /* Avoid a -Wstringop-overflow= warning when this loop is
+       unrolled.  The compiler cannot otherwise see that this is
+       unreachable because it depends on (state->__count & 7) not
+       being too large after a previous conversion step.  */
+    __builtin_unreachable ();
   do
     bytebuf[inlen++] = *inptr++;
   while (inlen < MAX_NEEDED_INPUT && inptr < inend);