From patchwork Fri Apr 21 14:12:44 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jiri Slaby X-Patchwork-Id: 9692941 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 8C32C601D4 for ; Fri, 21 Apr 2017 14:15:44 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 7E018285E4 for ; Fri, 21 Apr 2017 14:15:44 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 729B728604; Fri, 21 Apr 2017 14:15:44 +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=ham version=3.3.1 Received: from lists.xenproject.org (lists.xenproject.org [192.237.175.120]) (using TLSv1.2 with cipher AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by mail.wl.linuxfoundation.org (Postfix) with ESMTPS id 32BB7285E4 for ; Fri, 21 Apr 2017 14:15:42 +0000 (UTC) Received: from localhost ([127.0.0.1] helo=lists.xenproject.org) by lists.xenproject.org with esmtp (Exim 4.84_2) (envelope-from ) id 1d1ZJB-0000lq-GL; Fri, 21 Apr 2017 14:13:13 +0000 Received: from mail6.bemta6.messagelabs.com ([193.109.254.103]) by lists.xenproject.org with esmtp (Exim 4.84_2) (envelope-from ) id 1d1ZJA-0000kb-EA for xen-devel@lists.xenproject.org; Fri, 21 Apr 2017 14:13:12 +0000 Received: from [85.158.143.35] by server-11.bemta-6.messagelabs.com id 0F/EB-03587-8731AF85; Fri, 21 Apr 2017 14:13:12 +0000 X-Brightmail-Tracker: H4sIAAAAAAAAA+NgFnrALMWRWlGSWpSXmKPExsVyuP0Ov2658K8 Ig/9vFS2+b5nM5MDocfjDFZYAxijWzLyk/IoE1oy2s4UFne4VK67eYW9g/G7dxcjJISFgJPF2 4j+mLkYuDiGBhYwS608tYAJJsAkoSrScvQZmiwiISBx8uJ0NpIhZYCWLxJXLx1lBEsICzhKn9 05gA7FZBFQltu78xQxi8woYSxzas58dYoO8xNktO4HiHBycAiYSc69FgYSFgEoW7dzLNIGRew EjwypG9eLUorLUIl0LvaSizPSMktzEzBxdQwMzvdzU4uLE9NScxKRiveT83E2MQN8yAMEOxtm X/Q8xSnIwKYnyhvz+GSHEl5SfUpmRWJwRX1Sak1p8iFGGg0NJgveS0K8IIcGi1PTUirTMHGCQ waQlOHiURHiXgqR5iwsSc4sz0yFSpxh1Od4t/fCeSYglLz8vVUqctwukSACkKKM0D24ELOAvM cpKCfMyAh0lxFOQWpSbWYIq/4pRnINRSZi3G2QKT2ZeCdymV0BHMAEdcdbvB8gRJYkIKakGxu VrbhZZnQgXKNOYYXfAv+ST5B0Pm9SbQsyLi2SzDhfc6Jq7MSql19Bs2zXXs6HNDWsWyTZnsE6 XOD971g+W9+yTjx7eUaNUXcYtwDzt0EHpzW8qd8ZvrXI/k/yuJ64vWUzrmsiEJKe7bI9eyE2u 7jUvC1o6u323tsXitww+6pe/6GksYZu+SYmlOCPRUIu5qDgRAIm0WNJzAgAA X-Env-Sender: jslaby@suse.cz X-Msg-Ref: server-9.tower-21.messagelabs.com!1492783991!64607741!1 X-Originating-IP: [195.135.220.15] X-SpamReason: No, hits=0.8 required=7.0 tests=BODY_RANDOM_LONG, MAILTO_TO_SPAM_ADDR,UPPERCASE_25_50 X-StarScan-Received: X-StarScan-Version: 9.4.12; banners=-,-,- X-VirusChecked: Checked Received: (qmail 58067 invoked from network); 21 Apr 2017 14:13:11 -0000 Received: from mx2.suse.de (HELO mx1.suse.de) (195.135.220.15) by server-9.tower-21.messagelabs.com with DHE-RSA-CAMELLIA256-SHA encrypted SMTP; 21 Apr 2017 14:13:11 -0000 X-Virus-Scanned: by amavisd-new at test-mx.suse.de Received: from relay2.suse.de (charybdis-ext.suse.de [195.135.220.254]) by mx1.suse.de (Postfix) with ESMTP id 108DAAEDB; Fri, 21 Apr 2017 14:13:11 +0000 (UTC) From: Jiri Slaby To: mingo@redhat.com Date: Fri, 21 Apr 2017 16:12:44 +0200 Message-Id: <20170421141305.25180-8-jslaby@suse.cz> X-Mailer: git-send-email 2.12.2 In-Reply-To: <20170421141305.25180-1-jslaby@suse.cz> References: <20170421141305.25180-1-jslaby@suse.cz> Cc: Juergen Gross , Len Brown , hpa@zytor.com, Peter Zijlstra , linux-pm@vger.kernel.org, Boris Ostrovsky , Linus Torvalds , x86@kernel.org, "Rafael J. Wysocki" , linux-kernel@vger.kernel.org, Ingo Molnar , Pavel Machek , jpoimboe@redhat.com, xen-devel@lists.xenproject.org, tglx@linutronix.de, Jiri Slaby , Andrew Morton Subject: [Xen-devel] [PATCH v3 08/29] linkage: new macros for assembler symbols X-BeenThere: xen-devel@lists.xen.org X-Mailman-Version: 2.1.18 Precedence: list List-Id: Xen developer discussion List-Unsubscribe: , List-Post: List-Help: List-Subscribe: , MIME-Version: 1.0 Errors-To: xen-devel-bounces@lists.xen.org Sender: "Xen-devel" X-Virus-Scanned: ClamAV using ClamSMTP Introduce new C macros for annotations of functions and data in assembly. There is a long-term mess in macros like ENTRY, END, ENDPROC and similar. They are used in different manners and sometimes incorrectly. So introduce macros with clear use to annotate assembly as follows: a) Support macros SYM_T_FUNC -- type used by assembler to mark functions SYM_T_OBJECT -- type used by assembler to mark data They are defined as STT_FUNC and STT_OBJECT respectively. According to the gas manual, this is the most portable way. I am not sure about other assemblers, so we can switch this back to %function and %object if this turns into a problem. Architectures can also override them by something like ", @function" if need be. SYM_A_ALIGN, SYM_A_NONE -- align the symbol? SYM_V_GLOBAL, SYM_V_WEAK, SYM_V_LOCAL -- visibility of symbols b) Mostly internal annotations, used by the ones below SYM_ENTRY -- use only if you have to for non-paired symbols SYM_START -- use only if you have to SYM_END -- use only if you have to c) Generic annotations d) Annotations for code SYM_FUNC_START_LOCAL_ALIAS -- use where there are two local names for one code SYM_FUNC_START_ALIAS -- use where there are two global names for one code SYM_FUNC_END_ALIAS -- the end of LOCAL_ALIASed or ALIASed code SYM_FUNC_START -- use for global functions SYM_FUNC_START_LOCAL -- use for local functions SYM_FUNC_START_WEAK -- use for weak functions SYM_FUNC_END -- the end of SYM_FUNC_START_LOCAL, SYM_FUNC_START, SYM_FUNC_START_WEAK, ... SYM_FUNC_INNER_LABEL -- only for labels in the middle of functions d) For data SYM_DATA_START -- global data symbol SYM_DATA_END -- the end of SYM_DATA_START symbol SYM_DATA_END_LABEL -- the labeled end of SYM_DATA_START symbol SYM_DATA_SIMPLE -- start+end wrapper around simple global data SYM_DATA_SIMPLE_LOCAL -- start+end wrapper around simple local data ========== Note that SYM_FUNC_START_WEAK aligns symbols now too. The macros allow to pair starts and ends of functions and mark function correctly in the output ELF objects. This will also help a lot to generate DWARF information automatically during build of asm. Finally, all users of the old macros will be converted to use these later. [v2] * use SYM_ prefix and sane names * add SYM_START and SYM_END and parametrize all the macros [v3] * add SYM_DATA_SIMPLE, SYM_DATA_SIMPLE_LOCAL, and SYM_DATA_END_LABEL Signed-off-by: Jiri Slaby Cc: Andrew Morton Cc: Boris Ostrovsky Cc: hpa@zytor.com Cc: Ingo Molnar Cc: jpoimboe@redhat.com Cc: Juergen Gross Cc: Len Brown Cc: Linus Torvalds Cc: linux-kernel@vger.kernel.org Cc: linux-pm@vger.kernel.org Cc: mingo@redhat.com Cc: Pavel Machek Cc: Peter Zijlstra Cc: "Rafael J. Wysocki" Cc: Thomas Gleixner Cc: xen-devel@lists.xenproject.org Cc: x86@kernel.org --- arch/x86/include/asm/linkage.h | 5 +- include/linux/linkage.h | 163 +++++++++++++++++++++++++++++++++++++++-- 2 files changed, 158 insertions(+), 10 deletions(-) diff --git a/arch/x86/include/asm/linkage.h b/arch/x86/include/asm/linkage.h index 0ccb26dda126..de41e51a9ab4 100644 --- a/arch/x86/include/asm/linkage.h +++ b/arch/x86/include/asm/linkage.h @@ -12,9 +12,8 @@ #ifdef __ASSEMBLY__ -#define GLOBAL(name) \ - .globl name; \ - name: +/* deprecated, use SYM_DATA_START, SYM_FUNC_START, or SYM_FUNC_INNER_LABEL */ +#define GLOBAL(name) SYM_ENTRY(name, SYM_V_GLOBAL, SYM_A_NONE) #if defined(CONFIG_X86_64) || defined(CONFIG_X86_ALIGNMENT_16) #define __ALIGN .p2align 4, 0x90 diff --git a/include/linux/linkage.h b/include/linux/linkage.h index a6a42dd02466..31237e9db93f 100644 --- a/include/linux/linkage.h +++ b/include/linux/linkage.h @@ -74,25 +74,46 @@ #ifdef __ASSEMBLY__ +/* SYM_T_FUNC -- type used by assembler to mark functions */ +#ifndef SYM_T_FUNC +#define SYM_T_FUNC STT_FUNC +#endif + +/* SYM_T_OBJECT -- type used by assembler to mark data */ +#ifndef SYM_T_OBJECT +#define SYM_T_OBJECT STT_OBJECT +#endif + +/* SYM_A_* -- align the symbol? */ +#define SYM_A_ALIGN ALIGN +#define SYM_A_NONE /* nothing */ + +/* SYM_V_* -- visibility of symbols */ +#define SYM_V_GLOBAL(name) .globl name +#define SYM_V_WEAK(name) .weak name +#define SYM_V_LOCAL(name) /* nothing */ + #ifndef LINKER_SCRIPT #define ALIGN __ALIGN #define ALIGN_STR __ALIGN_STR +/* === DEPRECATED annotations === */ + #ifndef ENTRY +/* deprecated, use SYM_FUNC_START */ #define ENTRY(name) \ - .globl name ASM_NL \ - ALIGN ASM_NL \ - name: + SYM_FUNC_START(name) #endif #endif /* LINKER_SCRIPT */ #ifndef WEAK +/* deprecated, use SYM_FUNC_START_WEAK */ #define WEAK(name) \ - .weak name ASM_NL \ - name: + SYM_FUNC_START_WEAK(name) #endif #ifndef END +/* deprecated, use SYM_FUNC_END, SYM_DATA_END, or SYM_END */ #define END(name) \ .size name, .-name #endif @@ -102,11 +123,139 @@ * static analysis tools such as stack depth analyzer. */ #ifndef ENDPROC +/* deprecated, use SYM_FUNC_END */ #define ENDPROC(name) \ - .type name, @function ASM_NL \ - END(name) + SYM_FUNC_END(name) +#endif + +/* === generic annotations === */ + +/* SYM_ENTRY -- use only if you have to for non-paired symbols */ +#ifndef SYM_ENTRY +#define SYM_ENTRY(name, visibility, align...) \ + visibility(name) ASM_NL \ + align ASM_NL \ + name: +#endif + +/* SYM_START -- use only if you have to */ +#ifndef SYM_START +#define SYM_START(name, visibility, align...) \ + SYM_ENTRY(name, visibility, align) +#endif + +/* SYM_END -- use only if you have to */ +#ifndef SYM_END +#define SYM_END(name, sym_type) \ + .type name sym_type ASM_NL \ + .size name, .-name +#endif + +/* === code annotations === */ + +/* SYM_FUNC_START_LOCAL_ALIAS -- use where there are two local names for one code */ +#ifndef SYM_FUNC_START_LOCAL_ALIAS +#define SYM_FUNC_START_LOCAL_ALIAS(name) \ + SYM_START(name, SYM_V_LOCAL, SYM_A_ALIGN) +#endif + +/* SYM_FUNC_START_ALIAS -- use where there are two global names for one code */ +#ifndef SYM_FUNC_START_ALIAS +#define SYM_FUNC_START_ALIAS(name) \ + SYM_START(name, SYM_V_GLOBAL, SYM_A_ALIGN) +#endif + +/* SYM_FUNC_START -- use for global functions */ +#ifndef SYM_FUNC_START +/* + * The same as SYM_FUNC_START_ALIAS, but we will need to distinguish these two + * later. + */ +#define SYM_FUNC_START(name) \ + SYM_START(name, SYM_V_GLOBAL, SYM_A_ALIGN) +#endif + +/* SYM_FUNC_START_LOCAL -- use for local functions */ +#ifndef SYM_FUNC_START_LOCAL +/* the same as SYM_FUNC_START_LOCAL_ALIAS, see comment near SYM_FUNC_START */ +#define SYM_FUNC_START_LOCAL(name) \ + SYM_START(name, SYM_V_LOCAL, SYM_A_ALIGN) #endif +/* SYM_FUNC_START_WEAK -- use for weak functions */ +#ifndef SYM_FUNC_START_WEAK +#define SYM_FUNC_START_WEAK(name) \ + SYM_START(name, SYM_V_WEAK, SYM_A_ALIGN) #endif +/* SYM_FUNC_END_ALIAS -- the end of LOCAL_ALIASed or ALIASed code */ +#ifndef SYM_FUNC_END_ALIAS +#define SYM_FUNC_END_ALIAS(name) \ + SYM_END(name, SYM_T_FUNC) +#endif + +/* + * SYM_FUNC_END -- the end of SYM_FUNC_START_LOCAL, SYM_FUNC_START, + * SYM_FUNC_START_WEAK, ... + */ +#ifndef SYM_FUNC_END +/* the same as SYM_FUNC_END_ALIAS, see comment near SYM_FUNC_START */ +#define SYM_FUNC_END(name) \ + SYM_END(name, SYM_T_FUNC) +#endif + +/* SYM_FUNC_INNER_LABEL -- only for labels to the middle of functions */ +#ifndef SYM_FUNC_INNER_LABEL +#define SYM_FUNC_INNER_LABEL(name, visibility) \ + .type name SYM_T_FUNC ASM_NL \ + SYM_ENTRY(name, visibility, SYM_A_NONE) +#endif + +/* === data annotations === */ + +/* SYM_DATA_START -- global data symbol */ +#ifndef SYM_DATA_START +#define SYM_DATA_START(name) \ + SYM_START(name, SYM_V_GLOBAL, SYM_A_NONE) #endif + +/* SYM_DATA_START -- local data symbol */ +#ifndef SYM_DATA_START_LOCAL +#define SYM_DATA_START_LOCAL(name) \ + SYM_START(name, SYM_V_LOCAL, SYM_A_NONE) +#endif + +/* SYM_DATA_END -- the end of SYM_DATA_START symbol */ +#ifndef SYM_DATA_END +#define SYM_DATA_END(name) \ + SYM_END(name, SYM_T_OBJECT) +#endif + +/* SYM_DATA_END_LABEL -- the labeled end of SYM_DATA_START symbol */ +#ifndef SYM_DATA_END_LABEL +#define SYM_DATA_END_LABEL(name, visibility, label) \ + visibility(label) ASM_NL \ + .type label SYM_T_OBJECT ASM_NL \ + label: \ + SYM_END(name, SYM_T_OBJECT) +#endif + +/* SYM_DATA_SIMPLE -- start+end wrapper around simple global data */ +#ifndef SYM_DATA_SIMPLE +#define SYM_DATA_SIMPLE(name, data) \ + SYM_DATA_START(name) ASM_NL \ + data ASM_NL \ + SYM_DATA_END(name) +#endif + +/* SYM_DATA_SIMPLE_LOCAL -- start+end wrapper around simple local data */ +#ifndef SYM_DATA_SIMPLE_LOCAL +#define SYM_DATA_SIMPLE_LOCAL(name, data...) \ + SYM_DATA_START_LOCAL(name) ASM_NL \ + data ASM_NL \ + SYM_DATA_END(name) +#endif + +#endif /* __ASSEMBLY__ */ + +#endif /* _LINUX_LINKAGE_H */