From patchwork Mon Oct 17 18:38:07 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Will Deacon X-Patchwork-Id: 9380181 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork.web.codeaurora.org (Postfix) with ESMTP id A6FA7607D4 for ; Mon, 17 Oct 2016 18:40:18 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 9F8F929397 for ; Mon, 17 Oct 2016 18:40:18 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 936A22939A; Mon, 17 Oct 2016 18:40:18 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-4.2 required=2.0 tests=BAYES_00, RCVD_IN_DNSWL_MED autolearn=unavailable version=3.3.1 Received: from bombadil.infradead.org (bombadil.infradead.org [198.137.202.9]) (using TLSv1.2 with cipher AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by mail.wl.linuxfoundation.org (Postfix) with ESMTPS id 45FC029397 for ; Mon, 17 Oct 2016 18:40:17 +0000 (UTC) Received: from localhost ([127.0.0.1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.85_2 #1 (Red Hat Linux)) id 1bwCnt-00072Y-6f; Mon, 17 Oct 2016 18:38:29 +0000 Received: from foss.arm.com ([217.140.101.70]) by bombadil.infradead.org with esmtp (Exim 4.85_2 #1 (Red Hat Linux)) id 1bwCnq-00070H-Gy for linux-arm-kernel@lists.infradead.org; Mon, 17 Oct 2016 18:38:27 +0000 Received: from usa-sjc-imap-foss1.foss.arm.com (unknown [10.72.51.249]) by usa-sjc-mx-foss1.foss.arm.com (Postfix) with ESMTP id EE57829; Mon, 17 Oct 2016 11:38:05 -0700 (PDT) Received: from edgewater-inn.cambridge.arm.com (usa-sjc-imap-foss1.foss.arm.com [10.72.51.249]) by usa-sjc-imap-foss1.foss.arm.com (Postfix) with ESMTPA id C181C3F3D6; Mon, 17 Oct 2016 11:38:05 -0700 (PDT) Received: by edgewater-inn.cambridge.arm.com (Postfix, from userid 1000) id 0BE2B1AE3BDB; Mon, 17 Oct 2016 19:38:07 +0100 (BST) Date: Mon, 17 Oct 2016 19:38:07 +0100 From: Will Deacon To: linux-arm-kernel@lists.infradead.org Subject: Build failure with v4.9-rc1 and GCC trunk -- compiler weirdness Message-ID: <20161017183806.GG5601@arm.com> MIME-Version: 1.0 Content-Disposition: inline User-Agent: Mutt/1.5.23 (2014-03-12) X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20161017_113826_608921_797E3FEC X-CRM114-Status: GOOD ( 12.59 ) X-BeenThere: linux-arm-kernel@lists.infradead.org X-Mailman-Version: 2.1.20 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: ard.biesheuvel@linaro.org, peterz@infradead.org, sboyd@codeaurora.org, linux-kernel@vger.kernel.org, james.greenhalgh@arm.com, gregory.clement@free-electrons.com, torvalds@linux-foundation.org, mingo@kernel.org Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+patchwork-linux-arm=patchwork.kernel.org@lists.infradead.org X-Virus-Scanned: ClamAV using ClamSMTP Hi all, I'm seeing an arm64 build failure with -rc1 and GCC trunk, although I believe that the new compiler behaviour at the heart of the problem has the potential to affect other architectures and other pieces of kernel code relying on dead-code elimination to remove deliberately undefined functions. The failure looks like: | drivers/built-in.o: In function `armada_3700_add_composite_clk': | | linux/drivers/clk/mvebu/armada-37xx-periph.c:351: | undefined reference to `____ilog2_NaN' | | linux/drivers/clk/mvebu/armada-37xx-periph.c:351:(.text+0xc72e0): | relocation truncated to fit: R_AARCH64_CALL26 against undefined symbol | `____ilog2_NaN' | | make: *** [vmlinux] Error 1 and if we look at the source for armada_3700_add_composite_clk, we see that this is caused by: int table_size = 0; rate->reg = reg + (u64)rate->reg; for (clkt = rate->table; clkt->div; clkt++) table_size++; rate->width = order_base_2(table_size); order_base_2 calls ilog2, which has the ____ilog2_NaN call: #define ilog2(n) \ ( \ __builtin_constant_p(n) ? ( \ (n) < 1 ? ____ilog2_NaN() : \ This is because we're in a curious case where GCC has emitted a special-cased version of armada_3700_add_composite_clk, with table_size effectively constant-folded as 0. Whilst we shouldn't see this in a non-buggy kernel (hence the deliberate call to the undefined function ____ilog2_NaN), it means that the final link fails because we have a ____ilog2_NaN in the code, with a runtime check on table_size. In other words, __builtin_constant_p appears to be weaker than we've been assuming. Talking to the compiler guys here, this is due to the "jump-threading" optimisation pass, so the patch below disables that. A simpler example is: int foo(); int bar(); int count(int *argc) { int table_size = 0; for (; *argc; argc++) table_size++; if (__builtin_constant_p(table_size)) return table_size == 0 ? foo() : bar(); return bar(); } which compiles to: count: ldr w0, [x0] cbz w0, .L4 b bar .p2align 3 .L4: b foo and, with the "optimisation" disabled: count: b bar Thoughts? It feels awfully fragile disabling passes like this, but with GCC transforming the code like this, I can't immediately think of a way to preserve the intended behaviour of the code. Will --->8 diff --git a/Makefile b/Makefile index 512e47a53e9a..750873d6d11e 100644 --- a/Makefile +++ b/Makefile @@ -641,6 +641,11 @@ endif # Tell gcc to never replace conditional load with a non-conditional one KBUILD_CFLAGS += $(call cc-option,--param=allow-store-data-races=0) +# Stop gcc from converting switches into a form that defeats dead code +# elimination and can subsequently lead to calls to intentionally +# undefined functions appearing in the final link. +KBUILD_CFLAGS += $(call cc-option,--param=max-fsm-thread-path-insns=1) + include scripts/Makefile.gcc-plugins ifdef CONFIG_READABLE_ASM