From patchwork Thu Aug 10 17:26:09 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Thomas Garnier X-Patchwork-Id: 9894309 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 0F21260236 for ; Thu, 10 Aug 2017 17:28:51 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id E9F2D286CF for ; Thu, 10 Aug 2017 17:28:50 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id DD6D1288A7; Thu, 10 Aug 2017 17:28:50 +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.1 required=2.0 tests=BAYES_00, DKIM_ADSP_CUSTOM_MED, DKIM_SIGNED, RCVD_IN_DNSWL_MED, T_DKIM_INVALID 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 66127286CF for ; Thu, 10 Aug 2017 17:28:50 +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 1dfrEn-000812-Ow; Thu, 10 Aug 2017 17:27:13 +0000 Received: from mail6.bemta3.messagelabs.com ([195.245.230.39]) by lists.xenproject.org with esmtp (Exim 4.84_2) (envelope-from ) id 1dfrEm-0007xe-7D for xen-devel@lists.xenproject.org; Thu, 10 Aug 2017 17:27:12 +0000 Received: from [85.158.137.68] by server-13.bemta-3.messagelabs.com id A9/79-01862-F679C895; Thu, 10 Aug 2017 17:27:11 +0000 X-Brightmail-Tracker: H4sIAAAAAAAAA+NgFlrLIsWRWlGSWpSXmKPExsVyMfTAet286T2 RBq+my1l83zKZyYHR4/CHKywBjFGsmXlJ+RUJrBk3NhQXvFKtePnvK1sD4xmFLkYuDiGBGYwS 3/4uYgZxWAResUgcftgI5kgI9LNKrJt7mK2LkRPIiZOYO+c9lF0lsWf9OhYQW0hASWLrhqXME KP+MUo8397JBJJgE9CS2NMwnwkkISKwVFDiZOs1RhCHWaCFSeLJv21gVcICrhKH700DG8UioC rRPu03axcjBwevgKXEvrleENtMJJ60TmIEsTmBwtOWzWSG2GwhMfXXSqYJjAILGBlWMWoUpxa VpRbpGproJRVlpmeU5CZm5ugaGhjr5aYWFyemp+YkJhXrJefnbmIEBhcDEOxgXLHd8xCjJAeT kihv8afuSCG+pPyUyozE4oz4otKc1OJDjDIcHEoSvPzTeiKFBItS01Mr0jJzgGEOk5bg4FES4 d06FSjNW1yQmFucmQ6ROsVoyXHlyrovTBxTDmwHkq8m/P/GJMSSl5+XKiXOaw0yTwCkIaM0D2 4cLBYvMcpKCfMyAh0oxFOQWpSbWYIq/4pRnINRSZjXFWQKT2ZeCdzWV0AHMQEdFOHbCXJQSSJ CSqqBcZluruyVlKs3JDjLS8J/Nyz6/OblK/HeHzc7/P++dXka+9khsCtIcPLVD87RJ50up7at OpJ9j71l3bXp3Ql75av3n7lafFh5e9SVZ5t8ihgW9SzPDdj33nrK14lZLxY9MJ253aZGj33Sz CBt3TPCpWEtW+b8aI7/yvG/SLJfu+/G/53qk4QYGJRYijMSDbWYi4oTAUvWiCLAAgAA X-Env-Sender: thgarnie@google.com X-Msg-Ref: server-7.tower-31.messagelabs.com!1502386028!101935325!1 X-Originating-IP: [209.85.192.175] X-SpamReason: No, hits=0.0 required=7.0 tests= X-StarScan-Received: X-StarScan-Version: 9.4.45; banners=-,-,- X-VirusChecked: Checked Received: (qmail 32776 invoked from network); 10 Aug 2017 17:27:10 -0000 Received: from mail-pf0-f175.google.com (HELO mail-pf0-f175.google.com) (209.85.192.175) by server-7.tower-31.messagelabs.com with AES128-GCM-SHA256 encrypted SMTP; 10 Aug 2017 17:27:10 -0000 Received: by mail-pf0-f175.google.com with SMTP id h68so5710723pfk.0 for ; Thu, 10 Aug 2017 10:27:10 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20161025; h=from:to:cc:subject:date:message-id:in-reply-to:references; bh=qeWBd9fpVdJrATwMSYU3g/RNfkLZduWYfvBfWT0lkys=; b=mXornKlprFTcjhDkrHKlp7FRhKflx3dDTwof/IWz/p1LKA8IysQN1PbQ5njCNVi9xJ DkplGngDx5gJ+1apiDosyZl/YntN6sMZBbMrTz++98nGRf1oh6aruWfdFQazIQ7ch2lL YSP3OtRE4rvuv5dRU/yiHNgKot8V+8PgBSUDS7WX5/deg8KPPpjN4DQJJwbJAz0Q7xvj 5Pe553rjr2AxE7ikBJc4X62eosh/I924e1zzp53OigMFYgL2FylH+KqJ47H9YW/PkIGF hsUSsH0mKf/MkH/BdYa0NxdFp7eWci9IO9ustm5BaIXGI6wzDdkCE0UKZkHAeqdDyfzz ejVQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references; bh=qeWBd9fpVdJrATwMSYU3g/RNfkLZduWYfvBfWT0lkys=; b=FAhjASix0TXSWMpGwf3l2UnrmEdq2iGT41qPctXjliGSKKgkmdZz8vaPOYQUqt8y5k 893vAV/3OoIf7mWT/CMk/MtFb0im8GWfr8MnySnezsy3g1xbIIkr+jIIAewgG5Vferxy CmmxhlNDJqibS8N/Ff9B5Ogh3yPZuvyeiNEjiJVFW0lt7kTgDMcW3rIaJVifDlZ1iYu3 gAuJdB0hZgFo6zgWFzURcV1g3Sq6KOdQojDPcp3nmhqxol3efmfvBUf6p5gGeB50nOER KNZKB4LykbfAHwH+xYH5pkuj1Xi8G14z4K2Zn8IVwzqEfXcEiVK0CiOlRHlIR//pcd55 on4g== X-Gm-Message-State: AHYfb5gzPaIqPoQaCfKWOUHuFaKkyC8g9pV+WKiuTasNcRheFuh282ba TUCDr1pDSGOf5qD5 X-Received: by 10.99.120.68 with SMTP id t65mr12489023pgc.415.1502386027635; Thu, 10 Aug 2017 10:27:07 -0700 (PDT) Received: from skynet.sea.corp.google.com ([172.31.92.33]) by smtp.gmail.com with ESMTPSA id p77sm11894925pfi.153.2017.08.10.10.27.06 (version=TLS1_2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Thu, 10 Aug 2017 10:27:06 -0700 (PDT) From: Thomas Garnier To: Herbert Xu , "David S . Miller" , Thomas Gleixner , Ingo Molnar , "H . Peter Anvin" , Peter Zijlstra , Josh Poimboeuf , Arnd Bergmann , Thomas Garnier , Matthias Kaehlcke , Boris Ostrovsky , Juergen Gross , Paolo Bonzini , =?UTF-8?q?Radim=20Kr=C4=8Dm=C3=A1=C5=99?= , Joerg Roedel , Tom Lendacky , Andy Lutomirski , Borislav Petkov , Brian Gerst , "Kirill A . Shutemov" , "Rafael J . Wysocki" , Len Brown , Pavel Machek , Tejun Heo , Christoph Lameter , Paul Gortmaker , Chris Metcalf , Andrew Morton , "Paul E . McKenney" , Nicolas Pitre , Christopher Li , "Rafael J . Wysocki" , Lukas Wunner , Mika Westerberg , Dou Liyang , Daniel Borkmann , Alexei Starovoitov , Masahiro Yamada , Markus Trippelsdorf , Steven Rostedt , Kees Cook , Rik van Riel , David Howells , Waiman Long , Kyle Huey , Peter Foley , Tim Chen , Catalin Marinas , Ard Biesheuvel , Michal Hocko , Matthew Wilcox , "H . J . Lu" , Paul Bolle , Rob Landley , Baoquan He , Daniel Micay Date: Thu, 10 Aug 2017 10:26:09 -0700 Message-Id: <20170810172615.51965-18-thgarnie@google.com> X-Mailer: git-send-email 2.14.0.434.g98096fd7a8-goog In-Reply-To: <20170810172615.51965-1-thgarnie@google.com> References: <20170810172615.51965-1-thgarnie@google.com> Cc: linux-arch@vger.kernel.org, kvm@vger.kernel.org, linux-pm@vger.kernel.org, x86@kernel.org, linux-kernel@vger.kernel.org, linux-sparse@vger.kernel.org, linux-crypto@vger.kernel.org, kernel-hardening@lists.openwall.com, xen-devel@lists.xenproject.org Subject: [Xen-devel] [RFC v2 17/23] compiler: Option to default to hidden 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 Provide an option to default visibility to hidden except for key symbols. This option is disabled by default and will be used by x86_64 PIE support to remove errors between compilation units. Signed-off-by: Thomas Garnier --- arch/x86/boot/boot.h | 2 +- arch/x86/include/asm/setup.h | 2 +- include/asm-generic/sections.h | 6 ++++++ include/linux/compiler.h | 8 ++++++++ init/Kconfig | 7 +++++++ kernel/kallsyms.c | 16 ++++++++-------- 6 files changed, 31 insertions(+), 10 deletions(-) diff --git a/arch/x86/boot/boot.h b/arch/x86/boot/boot.h index ef5a9cc66fb8..d726c35bdd96 100644 --- a/arch/x86/boot/boot.h +++ b/arch/x86/boot/boot.h @@ -193,7 +193,7 @@ static inline bool memcmp_gs(const void *s1, addr_t s2, size_t len) } /* Heap -- available for dynamic lists. */ -extern char _end[]; +extern char _end[] __default_visibility; extern char *HEAP; extern char *heap_end; #define RESET_HEAP() ((void *)( HEAP = _end )) diff --git a/arch/x86/include/asm/setup.h b/arch/x86/include/asm/setup.h index a65cf544686a..7e0b54f605c6 100644 --- a/arch/x86/include/asm/setup.h +++ b/arch/x86/include/asm/setup.h @@ -67,7 +67,7 @@ static inline void x86_ce4100_early_setup(void) { } * This is set up by the setup-routine at boot-time */ extern struct boot_params boot_params; -extern char _text[]; +extern char _text[] __default_visibility; static inline bool kaslr_enabled(void) { diff --git a/include/asm-generic/sections.h b/include/asm-generic/sections.h index 532372c6cf15..27c12f6dd6e2 100644 --- a/include/asm-generic/sections.h +++ b/include/asm-generic/sections.h @@ -28,6 +28,9 @@ * __entry_text_start, __entry_text_end * __ctors_start, __ctors_end */ +#ifdef CONFIG_DEFAULT_HIDDEN +#pragma GCC visibility push(default) +#endif extern char _text[], _stext[], _etext[]; extern char _data[], _sdata[], _edata[]; extern char __bss_start[], __bss_stop[]; @@ -42,6 +45,9 @@ extern char __start_rodata[], __end_rodata[]; /* Start and end of .ctors section - used for constructor calls. */ extern char __ctors_start[], __ctors_end[]; +#ifdef CONFIG_DEFAULT_HIDDEN +#pragma GCC visibility pop +#endif extern __visible const void __nosave_begin, __nosave_end; diff --git a/include/linux/compiler.h b/include/linux/compiler.h index dfaaeec4a32e..3a79b536cef8 100644 --- a/include/linux/compiler.h +++ b/include/linux/compiler.h @@ -78,6 +78,14 @@ extern void __chk_io_ptr(const volatile void __iomem *); #include #endif +/* Useful for Position Independent Code to reduce global references */ +#ifdef CONFIG_DEFAULT_HIDDEN +#pragma GCC visibility push(hidden) +#define __default_visibility __attribute__((visibility ("default"))) +#else +#define __default_visibility +#endif + /* * Generic compiler-dependent macros required for kernel * build go below this comment. Actual compiler/compiler version diff --git a/init/Kconfig b/init/Kconfig index 482a18a88fb9..a886d73993db 100644 --- a/init/Kconfig +++ b/init/Kconfig @@ -1640,6 +1640,13 @@ config PROFILING config TRACEPOINTS bool +# +# Default to hidden visibility for all symbols. +# Useful for Position Independent Code to reduce global references. +# +config DEFAULT_HIDDEN + bool + source "arch/Kconfig" endmenu # General setup diff --git a/kernel/kallsyms.c b/kernel/kallsyms.c index 127e7cfafa55..252019c8c3a9 100644 --- a/kernel/kallsyms.c +++ b/kernel/kallsyms.c @@ -32,24 +32,24 @@ * These will be re-linked against their real values * during the second link stage. */ -extern const unsigned long kallsyms_addresses[] __weak; -extern const int kallsyms_offsets[] __weak; -extern const u8 kallsyms_names[] __weak; +extern const unsigned long kallsyms_addresses[] __weak __default_visibility; +extern const int kallsyms_offsets[] __weak __default_visibility; +extern const u8 kallsyms_names[] __weak __default_visibility; /* * Tell the compiler that the count isn't in the small data section if the arch * has one (eg: FRV). */ extern const unsigned long kallsyms_num_syms -__attribute__((weak, section(".rodata"))); +__attribute__((weak, section(".rodata"))) __default_visibility; extern const unsigned long kallsyms_relative_base -__attribute__((weak, section(".rodata"))); +__attribute__((weak, section(".rodata"))) __default_visibility; -extern const u8 kallsyms_token_table[] __weak; -extern const u16 kallsyms_token_index[] __weak; +extern const u8 kallsyms_token_table[] __weak __default_visibility; +extern const u16 kallsyms_token_index[] __weak __default_visibility; -extern const unsigned long kallsyms_markers[] __weak; +extern const unsigned long kallsyms_markers[] __weak __default_visibility; static inline int is_kernel_inittext(unsigned long addr) {