From patchwork Thu Aug 19 16:56:19 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Joseph Myers X-Patchwork-Id: 44716 Return-Path: X-Original-To: patchwork@sourceware.org Delivered-To: patchwork@sourceware.org Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id E9B6338930CD for ; Thu, 19 Aug 2021 16:56:46 +0000 (GMT) X-Original-To: libc-alpha@sourceware.org Delivered-To: libc-alpha@sourceware.org Received: from esa1.mentor.iphmx.com (esa1.mentor.iphmx.com [68.232.129.153]) by sourceware.org (Postfix) with ESMTPS id 5DFFE385E44B for ; Thu, 19 Aug 2021 16:56:25 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.1 sourceware.org 5DFFE385E44B Authentication-Results: sourceware.org; dmarc=none (p=none dis=none) header.from=codesourcery.com Authentication-Results: sourceware.org; spf=pass smtp.mailfrom=mentor.com IronPort-SDR: 0ldvh9WimZO0IxYdB+3fp64J6rPv71uob6TOJcPKMolnXoUz1tib0XW8S15lQ0TqcAII9N+ZoT ziDJ2hiAMeMPuu8DTjUi9BohlMfaNyJqTJTH/RJGwhT3WetKowdltzFywTP55GiWPm6tREs82T Aj8k308GI16K04GbRXRnZKNQSRy+PU3pezCkkXL7RKRHX3U1pXINKL/dUm1KxH9dpUQK0H4Usg 5N3iqa9w8wmGCkE3jIRkku1q3f5tBkCoM1ZMAfaFL/6+L0ud52PxIzbo0vJDLigOXcxVo0QTNu pT390vRR8gJQR5EcoiSoqh7D X-IronPort-AV: E=Sophos;i="5.84,335,1620720000"; d="scan'208";a="67397151" Received: from orw-gwy-01-in.mentorg.com ([192.94.38.165]) by esa1.mentor.iphmx.com with ESMTP; 19 Aug 2021 08:56:25 -0800 IronPort-SDR: HUi3Exsu+tWvYQI1n7MpfZXu9abtUBbjFUPiBxP6BT7aMwTT00HQlVC7MXGbIb+YqXEePmgcY7 IbmGoq/BHDpfUoPY3fvnaMW76xYAKwdlD30ZAv45neroMyu6xsIg8s0WaAZBUZ+QyybFMLF9qQ Ivx129hO32XO6oZC7HFAg9pCUIxV/vENDqI/9FUFwmp68Kba8vFX5w5ZMNZC5ujvjW4SAHm+CU 0gYXuBpqYsbq3rSLJM8O5op7t88yVqAodftUPFSEhU/f6rQomaojySaX6UIhRR0OqZ9qbN1LNd 0jM= Date: Thu, 19 Aug 2021 16:56:19 +0000 From: Joseph Myers X-X-Sender: jsm28@digraph.polyomino.org.uk To: Subject: Fix iconv build with GCC mainline Message-ID: User-Agent: Alpine 2.22 (DEB 394 2020-01-19) MIME-Version: 1.0 X-Originating-IP: [137.202.0.90] X-ClientProxiedBy: svr-ies-mbx-01.mgc.mentorg.com (139.181.222.1) To svr-ies-mbx-01.mgc.mentorg.com (139.181.222.1) X-Spam-Status: No, score=-3125.0 required=5.0 tests=BAYES_00, GIT_PATCH_0, HEADER_FROM_DIFFERENT_DOMAINS, KAM_DMARC_STATUS, KAM_SHORT, SPF_HELO_PASS, SPF_PASS, TXREP 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: libc-alpha@sourceware.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Libc-alpha mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: libc-alpha-bounces+patchwork=sourceware.org@sourceware.org Sender: "Libc-alpha" Current GCC mainline produces -Wstringop-overflow errors building some iconv converters, as discussed at . 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 , it restores the glibc build for powerpc-linux-gnu. 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);