Received: by 2002:ac0:a594:0:0:0:0:0 with SMTP id m20-v6csp1139091imm; Tue, 15 May 2018 14:29:44 -0700 (PDT) X-Google-Smtp-Source: AB8JxZoZQRlUs1meE+BzpEcrwzivFVe5L6cvPbXTl4uwvGUEwtqI2zy8rxj2l5ylu984TXCYyIwG X-Received: by 2002:a17:902:14cb:: with SMTP id y11-v6mr15787508plg.229.1526419784124; Tue, 15 May 2018 14:29:44 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1526419784; cv=none; d=google.com; s=arc-20160816; b=LeF/YLPNrFxyRAqMQid2guuHTD9OdYOmp/tJrwLpfPrlHozFp4r5L002qFDoldW2hT YNQ1F73LixOdrOghDbl1mJruPIeHysAGwXePvQWHCQeGwJH3aVkB0aS4tT7cKNBeaETD MDevlXkRum1w7te/Vw16GBDaWo5e1VMPjrmd8V+yQZpjXgsP9ZzggD1xMWjcOGtZq8BZ 48TzNGHWJBhV9KYJUEKRteQpWtnNtuJ9tBTaN8S4hXF0aAPhqvj/TeFPX9qoW/DJv0Zp vzKEeOZp3XlaIJn+egQVvF4lLNSlxVEq3N3wQWc/VPojv5ZtflAB3Cd3+unL8FwWWnBw sYRA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:arc-authentication-results; bh=5Z0WW980ZH1ESp//OVLwC3pmUTEzDnXFuR04pcoJizE=; b=VHSqdTvk0wFAVd3iogBJnBYmqD174YKOh+FWsAGSXNXZ+HUfPsTqz1mKMUE36LYWM2 MgtVxk3fizO4Mq1QcGX3rHhd+DG2ZwmMau8fowbNwXFNcrC3mo4k3pD0pbZSytXS7QhZ XUwrjRNp9TMndm6gJRmilu0R1vS9+KeUBTCvVS0aKKtBXTllR6Lpzp3kUU5f5/A6P1TB InnUqdF6eAvGKbYt2bGh4UIs25oTYL/Rfs8X7B6JxDhzUuyWopxR9Sn4yFA9Yy7TKLoA wBqZ/GSeTD+2cs61ScRubCNTnnvsb/ShOjgpLkljriR/yycnIWs5WHIboUgRUCVCPuCN xxYA== ARC-Authentication-Results: i=1; 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 Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id j6-v6si794872pgc.509.2018.05.15.14.29.29; Tue, 15 May 2018 14:29:44 -0700 (PDT) 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 S1752716AbeEOV1i (ORCPT + 99 others); Tue, 15 May 2018 17:27:38 -0400 Received: from ex13-edg-ou-001.vmware.com ([208.91.0.189]:48538 "EHLO EX13-EDG-OU-001.vmware.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1752823AbeEOV0P (ORCPT ); Tue, 15 May 2018 17:26:15 -0400 Received: from sc9-mailhost2.vmware.com (10.113.161.72) by EX13-EDG-OU-001.vmware.com (10.113.208.155) with Microsoft SMTP Server id 15.0.1156.6; Tue, 15 May 2018 14:25:46 -0700 Received: from sc2-haas01-esx0118.eng.vmware.com (sc2-haas01-esx0118.eng.vmware.com [10.172.44.118]) by sc9-mailhost2.vmware.com (Postfix) with ESMTP id 25E02B079B; Tue, 15 May 2018 14:26:11 -0700 (PDT) From: Nadav Amit To: CC: , Nadav Amit , Christopher Li , Subject: [RFC 1/8] x86: objtool: use asm macro for better compiler decisions Date: Tue, 15 May 2018 07:11:17 -0700 Message-ID: <20180515141124.84254-11-namit@vmware.com> X-Mailer: git-send-email 2.17.0 In-Reply-To: <20180515141124.84254-1-namit@vmware.com> References: <20180515141124.84254-1-namit@vmware.com> MIME-Version: 1.0 Content-Type: text/plain Received-SPF: None (EX13-EDG-OU-001.vmware.com: namit@vmware.com does not designate permitted sender hosts) Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org GCC considers the number of statements in inlined assembly blocks, according to new-lines and semicolons, as an indication to the cost of the block in time and space. This data is distorted by the kernel code, which puts information in alternative sections. As a result, the compiler may perform incorrect inlining and branch optimizations. In the case of objtool, this distortion is extreme, since anyhow the annotations of objtool are discarded during linkage. The solution is to set an assembly macro and call it from the inlinedv assembly block. As a result GCC considers the inline assembly block as a single instruction. This patch slightly increases the kernel size. text data bss dec hex filename 18126699 10066728 2936832 31130259 1db0293 ./vmlinux before 18126824 10067268 2936832 31130924 1db052c ./vmlinux after (+665) But allows more aggressive inlining. Static text symbols: Before: 40033 After: 40015 (-18) Cc: Christopher Li Cc: linux-sparse@vger.kernel.org Signed-off-by: Nadav Amit --- include/linux/compiler.h | 29 +++++++++++++++++++++-------- 1 file changed, 21 insertions(+), 8 deletions(-) diff --git a/include/linux/compiler.h b/include/linux/compiler.h index ab4711c63601..369753000541 100644 --- a/include/linux/compiler.h +++ b/include/linux/compiler.h @@ -98,17 +98,30 @@ void ftrace_likely_update(struct ftrace_likely_data *f, int val, * The __COUNTER__ based labels are a hack to make each instance of the macros * unique, to convince GCC not to merge duplicate inline asm statements. */ + +asm ("\n" + ".macro __annotate_reachable counter:req\n" + "\\counter:\n\t" + ".pushsection .discard.reachable\n\t" + ".long \\counter\\()b -.\n\t" + ".popsection\n" + ".endm\n"); + #define annotate_reachable() ({ \ - asm volatile("%c0:\n\t" \ - ".pushsection .discard.reachable\n\t" \ - ".long %c0b - .\n\t" \ - ".popsection\n\t" : : "i" (__COUNTER__)); \ + asm volatile("__annotate_reachable %c0" : : "i" (__COUNTER__)); \ }) + +asm ("\n" + ".macro __annotate_unreachable counter:req\n" + "\\counter:\n\t" + ".pushsection .discard.unreachable\n\t" + ".long \\counter\\()b -.\n\t" + ".popsection\n" + ".endm"); + #define annotate_unreachable() ({ \ - asm volatile("%c0:\n\t" \ - ".pushsection .discard.unreachable\n\t" \ - ".long %c0b - .\n\t" \ - ".popsection\n\t" : : "i" (__COUNTER__)); \ + asm volatile("__annotate_unreachable %c0" : : \ + "i" (__COUNTER__)); \ }) #define ASM_UNREACHABLE \ "999:\n\t" \ -- 2.17.0