From patchwork Fri Feb 12 21:26:42 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Arnd Bergmann X-Patchwork-Id: 102787 Delivered-To: patch@linaro.org Received: by 10.112.43.199 with SMTP id y7csp1072786lbl; Fri, 12 Feb 2016 13:27:43 -0800 (PST) X-Received: by 10.98.19.205 with SMTP id 74mr5330765pft.31.1455312462902; Fri, 12 Feb 2016 13:27:42 -0800 (PST) Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id wf3si22236279pac.218.2016.02.12.13.27.42; Fri, 12 Feb 2016 13:27:42 -0800 (PST) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1751333AbcBLV1k (ORCPT + 30 others); Fri, 12 Feb 2016 16:27:40 -0500 Received: from mout.kundenserver.de ([212.227.17.24]:62797 "EHLO mout.kundenserver.de" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1750966AbcBLV1j (ORCPT ); Fri, 12 Feb 2016 16:27:39 -0500 Received: from wuerfel.lan. ([78.42.132.4]) by mrelayeu.kundenserver.de (mreue104) with ESMTPA (Nemesis) id 0MC1A0-1aLZnZ2rp2-008r1I; Fri, 12 Feb 2016 22:27:01 +0100 From: Arnd Bergmann To: linux-kernel@vger.kernel.org Cc: linux-arm-kernel@lists.infradead.org, Arnd Bergmann , Nicolas Pitre , Mauro Carvalho Chehab , Steven Rostedt , Ingo Molnar Subject: [PATCH] branch tracer: fix freak link error Date: Fri, 12 Feb 2016 22:26:42 +0100 Message-Id: <1455312410-1058841-1-git-send-email-arnd@arndb.de> X-Mailer: git-send-email 2.7.0 X-Provags-ID: V03:K0:pLUNuk5p6DPBT95p5eCbY+EsAOLXDuCLV7poncc2aws2SWWAbiz G2zru+L8satc8q/qINCKSPyYlHJaeZXyxqr3D+2vS5nUBS3GQ8OVp2CNU5HZMCiCpwpBnry /MYp8KBmakrjSO+sUbaFIZWzbTfYvzVCZeh/r119Oh1pxTwZvYAz12NXTQEbSVNdZftXa/I rk5WAGCXk369XWCusko6Q== X-UI-Out-Filterresults: notjunk:1; V01:K0:NzOxG969Ruc=:cC72llOZE/TwZo8XCfuz8q hOXIDyU8ZFP3nmKGSAwrWmBrHc/KXW0PzCVOsqo7jM9b1G9ToIx61cM18oTeDh6fgksQG6ViB X16Ns3rBFpoAvKG/vixkvJfZY+8GfWBrWqC/2cKTenNffiXnpz9SYV8McjyIjjAoIcT2kcJ4U PrSjl32iSB9P1xULPsA29E6JQWTRY5+w99gPF7xW5/h3NP3ztlfa82EIs1H/J2F1sSvCxWIZ3 VoIBjEVisKzqUrNhRDHP9F46Doom68Lpz8Rfq50wVu15+fYHcmOorZpmo4BLSLyqATnCqx9Tw x8j29ZzPQh0I/YgGOfv4yp2spq6P5+AaZMd0NxgjJROyNo1U8E8kjWfWSdcVw768PY18idEdx ZcoIeIL47ZXRayxmPGU4d5XRg32M+K1Fjyh2UJ4wDyTlvTIzIgT7FRkN14ML6wJI03T842Al4 G9aMjW31sK2evOZQ0UzQwwNppnt9ctu0+XEfywQ042eNU5IHCxrrQoq1G9GjVeeE0B9hQg5v7 UxUPxYDyFV3Ye9thdwULSUdbiW5++183soZd4q7nATbqZqdp6scZHTQV04yqS25aZ47KrOw4k nOGWypjeUC9kg3IYMuntvLfTZYisMMaD7nBXRJEJ9E1y23A6ZRWIO4rbyOpefATO3e8lUQEzc Mkxjru0sO6X1NVcTj2AlTPXyD02BD1OAe2AuX3KIMUCZV6JEJJFJ9+Etr5VtcYKFMccM= Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org In my randconfig tests, I came across a bug that involves several components: * gcc-4.9 through at least 5.3 * CONFIG_GCOV_PROFILE_ALL enabling -fprofile-arcs for all files * CONFIG_PROFILE_ALL_BRANCHES overriding every if() * The optimized implementation of do_div() that tries to replace a library call with an division by multiplication * code in drivers/media/dvb-frontends/zl10353.c doing u32 adc_clock = 450560; /* 45.056 MHz */ if (state->config.adc_clock) adc_clock = state->config.adc_clock; do_div(value, adc_clock); In this case, gcc fails to determine whether the divisor in do_div() is __builtin_constant_p(). In particular, it concludes that __builtin_constant_p(adc_clock) is false, while __builtin_constant_p(!!adc_clock) is true. That in turn throws off the logic in do_div() that also uses __builtin_constant_p(), and instead of picking either the constant- optimized division, and the code in ilog2() that uses __builtin_constant_p() to figure out whether it knows the answer at compile time. The result is a link error from failing to find multiple symbols that should never have been called based on the __builtin_constant_p(): dvb-frontends/zl10353.c:138: undefined reference to `____ilog2_NaN' dvb-frontends/zl10353.c:138: undefined reference to `__aeabi_uldivmod' ERROR: "____ilog2_NaN" [drivers/media/dvb-frontends/zl10353.ko] undefined! ERROR: "__aeabi_uldivmod" [drivers/media/dvb-frontends/zl10353.ko] undefined! This patch avoids the problem by changing __trace_if() to check whether the condition is known at compile-time to be nonzero, rather than checking whether it is actually a constant. I see this one link error in roughly one out of 1600 randconfig builds on ARM, and the patch fixes all known instances. Signed-off-by: Arnd Bergmann Fixes: ab3c9c686e22 ("branch tracer, intel-iommu: fix build with CONFIG_BRANCH_TRACER=y") --- include/linux/compiler.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) -- 2.7.0 diff --git a/include/linux/compiler.h b/include/linux/compiler.h index b5acbb404854..b5ff9881bef8 100644 --- a/include/linux/compiler.h +++ b/include/linux/compiler.h @@ -148,7 +148,7 @@ void ftrace_likely_update(struct ftrace_branch_data *f, int val, int expect); */ #define if(cond, ...) __trace_if( (cond , ## __VA_ARGS__) ) #define __trace_if(cond) \ - if (__builtin_constant_p((cond)) ? !!(cond) : \ + if (__builtin_constant_p(!!(cond)) ? !!(cond) : \ ({ \ int ______r; \ static struct ftrace_branch_data \