From patchwork Wed Oct 11 20:30:15 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Thomas Garnier X-Patchwork-Id: 10000559 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 13290603B5 for ; Wed, 11 Oct 2017 20:33:31 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 0760D28B66 for ; Wed, 11 Oct 2017 20:33:31 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id EFC3A28B6B; Wed, 11 Oct 2017 20:33:30 +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=-3.6 required=2.0 tests=BAYES_00, DKIM_ADSP_CUSTOM_MED, DKIM_SIGNED, RCVD_IN_DNSWL_MED, RCVD_IN_SORBS_SPAM, 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 5004828B6A for ; Wed, 11 Oct 2017 20:33:30 +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 1e2NfA-0000cZ-HQ; Wed, 11 Oct 2017 20:31:32 +0000 Received: from mail6.bemta5.messagelabs.com ([195.245.231.135]) by lists.xenproject.org with esmtp (Exim 4.84_2) (envelope-from ) id 1e2Nf9-0000aH-Fm for xen-devel@lists.xenproject.org; Wed, 11 Oct 2017 20:31:31 +0000 Received: from [85.158.139.211] by server-17.bemta-5.messagelabs.com id 47/D9-22397-2AF7ED95; Wed, 11 Oct 2017 20:31:30 +0000 X-Brightmail-Tracker: H4sIAAAAAAAAA+NgFtrNIsWRWlGSWpSXmKPExsVyMfTAKt2F9fc iDX68MLb4vmUykwOjx+EPV1gCGKNYM/OS8isSWDP2nr/DVHDWpqJv3w2mBsYVJl2MXBxCAjMY JZq+bGcCcVgEXrFIXDhxhBXEkRDoZ5WY93seSxcjJ5CTJfGp8QQ7hJ0mMe/eGyYIu0Ji6637Y LaQgJLE1g1LmSHG/mOUuDjtGxtIgk1AS2JPw3ywFSICJ4QlNn34zQjiMAucYZI43neSFaRKWM Bd4s7hVYwgNouAqsT7z5PAxvIKWErs3TiLFWKdhcSxY4fBTuIEin/feIgZYrWFxMpZ51knMAo uYGRYxahRnFpUllqka2Sml1SUmZ5RkpuYmaNraGCql5taXJyYnpqTmFSsl5yfu4kRGHj1DAyM OxhvT/Y7xCjJwaQkyvsw5l6kEF9SfkplRmJxRnxRaU5q8SFGGQ4OJQnepDqgnGBRanpqRVpmD jAGYNISHDxKIrxNIGne4oLE3OLMdIjUKUZLjgt3Lv1h4jiw5xaQ7Lh59w+TEEtefl6qlDhvKU iDAEhDRmke3DhYnF5ilJUS5mVkYGAQ4ilILcrNLEGVf8UozsGoJMx7GGQKT2ZeCdzWV0AHMQE dJJp2B+SgkkSElFQDY+eufqW33BN2/hbeFm824Twbg/Hq/l0JDS7WW2QWHHy27nz1ob07fxxd xnj42C/P1LL5J2XvHOmf8ZxDO1wjbNcmF+nH9Z/LlTvuy6y2sk1UXvZ/sWmsrHLLK4+SXbu33 f3WN6dd3lrfe5XN2o8n5/oxJ9tYy00ILo31e72Ix5OR9de01d8vTFViKc5INNRiLipOBADO6E QWzgIAAA== X-Env-Sender: thgarnie@google.com X-Msg-Ref: server-7.tower-206.messagelabs.com!1507753888!103667546!1 X-Originating-IP: [209.85.192.170] 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 35047 invoked from network); 11 Oct 2017 20:31:29 -0000 Received: from mail-pf0-f170.google.com (HELO mail-pf0-f170.google.com) (209.85.192.170) by server-7.tower-206.messagelabs.com with AES128-GCM-SHA256 encrypted SMTP; 11 Oct 2017 20:31:29 -0000 Received: by mail-pf0-f170.google.com with SMTP id b79so1951789pfk.5 for ; Wed, 11 Oct 2017 13:31:29 -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=yWR6o3ezz47Hymu9Ln49Ej4qtByNKxVldlH0IgJ3hDk=; b=CR76k9V0Yd0kBsxVzzK8pUxOYuZLdgtAPIB1uO1x2Pnwvyv11X3LJZ2FhfW6KUw0id kgaQLffRDqX2/00THCEP5dvu0lBZRozWwcUfcUk1sDGSDXVCD1ar0S1FR0iUUdI3IdkA TrfjMiPd8dIFePsC84yw0+PU3B5STMQagtg8sAbJL3L9xJivsE5iqiNO1y4GdhL1f6RF JqfFDEHX37TLb6OMyFb8WMG9Vv9kW0hUgUf6XZlqsNuZJJlOsfS67d5dnwjxOSYELRth v/03G4MEuVyGF59PrQ9FvipkSN4NxWnfuYooEMF42vhoGUdFdLPsMKyw5AHauCzDQNzK V3kA== 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=yWR6o3ezz47Hymu9Ln49Ej4qtByNKxVldlH0IgJ3hDk=; b=Wn7kbFW3TShzCXpG5hijBIB4l7jcieBMQq6dfpgzT2dMKEf2c3HGju6O8cY5iLSDMt A6C5TzhKfX/reGOElMk0881eeotrXp1w6pD4on8+HslEDPBmHhrIKFu+IoEOnWQBjAZg LdxxR95kEIoX9kEy2HpQ1UKdOcHHx2li70fJFfdff60HNLVvrUQnvJrwezoVRrmzSvwE HaEWj1rISk+BX40FVVFYLwFHamG7+JHEwMTuR3Z9+U4C5vhVzYjmDD9heYqvpbEV6M// 6vst5oZ1op5Vuu/pYYBfq8rxJMj1XeWzQRCgUP9c4073FAJoY3z+ZQAmuib/zT06NYxJ LdLA== X-Gm-Message-State: AMCzsaVOj/kLPF4hwwZwtOQKoHUC9k0985LKfrirwwsT/os81kZAPSVE Oqjcg06cz/rA/jQYZSIeO0LhQw== X-Google-Smtp-Source: AOwi7QAVNtMj68kmaXiQNvuF6zEvWnEkn2u7I7JMiWJwder+/Xk47p8Gf2DxJ52Ge4o3ycqMb2XxCA== X-Received: by 10.84.194.37 with SMTP id g34mr175180pld.139.1507753887761; Wed, 11 Oct 2017 13:31:27 -0700 (PDT) Received: from skynet.sea.corp.google.com ([172.31.92.33]) by smtp.gmail.com with ESMTPSA id n12sm20691913pfb.149.2017.10.11.13.31.26 (version=TLS1_2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Wed, 11 Oct 2017 13:31:27 -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 , Kees Cook , Andrey Ryabinin , Matthias Kaehlcke , Tom Lendacky , Andy Lutomirski , "Kirill A . Shutemov" , Borislav Petkov , "Rafael J . Wysocki" , Len Brown , Pavel Machek , Juergen Gross , Chris Wright , Alok Kataria , Rusty Russell , Tejun Heo , Christoph Lameter , Boris Ostrovsky , Paul Gortmaker , Andrew Morton , Alexey Dobriyan , "Paul E . McKenney" , Nicolas Pitre , Borislav Petkov , "Luis R . Rodriguez" , Greg Kroah-Hartman , Christopher Li , Steven Rostedt , Jason Baron , Mika Westerberg , Dou Liyang , "Rafael J . Wysocki" , Lukas Wunner , Masahiro Yamada , Alexei Starovoitov , Daniel Borkmann , Markus Trippelsdorf , Paolo Bonzini , =?UTF-8?q?Radim=20Kr=C4=8Dm=C3=A1=C5=99?= , Joerg Roedel , Rik van Riel , David Howells , Ard Biesheuvel , Waiman Long , Kyle Huey , Jonathan Corbet , Michal Hocko , Peter Foley , Paul Bolle , Jiri Kosina , "H . J . Lu" , Rob Landley , Baoquan He , =?UTF-8?q?Jan=20H=20=2E=20Sch=C3=B6nherr?= , Daniel Micay Date: Wed, 11 Oct 2017 13:30:15 -0700 Message-Id: <20171011203027.11248-16-thgarnie@google.com> X-Mailer: git-send-email 2.15.0.rc0.271.g36b669edcc-goog In-Reply-To: <20171011203027.11248-1-thgarnie@google.com> References: <20171011203027.11248-1-thgarnie@google.com> Cc: linux-arch@vger.kernel.org, kvm@vger.kernel.org, linux-pm@vger.kernel.org, x86@kernel.org, linux-doc@vger.kernel.org, linux-kernel@vger.kernel.org, virtualization@lists.linux-foundation.org, linux-sparse@vger.kernel.org, linux-crypto@vger.kernel.org, kernel-hardening@lists.openwall.com, xen-devel@lists.xenproject.org Subject: [Xen-devel] [PATCH v1 15/27] 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. The default visibility is also enabled for external symbols that are compared as they maybe equals (start/end of sections). In this case, older versions of GCC will remove the comparison if the symbols are hidden. This issue exists at least on gcc 4.9 and before. Signed-off-by: Thomas Garnier --- arch/x86/boot/boot.h | 2 +- arch/x86/include/asm/setup.h | 2 +- arch/x86/kernel/cpu/microcode/core.c | 4 ++-- drivers/base/firmware_class.c | 4 ++-- include/asm-generic/sections.h | 6 ++++++ include/linux/compiler.h | 8 ++++++++ init/Kconfig | 7 +++++++ kernel/kallsyms.c | 16 ++++++++-------- kernel/trace/trace.h | 4 ++-- lib/dynamic_debug.c | 4 ++-- 10 files changed, 39 insertions(+), 18 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/arch/x86/kernel/cpu/microcode/core.c b/arch/x86/kernel/cpu/microcode/core.c index 86e8f0b2537b..8f021783a929 100644 --- a/arch/x86/kernel/cpu/microcode/core.c +++ b/arch/x86/kernel/cpu/microcode/core.c @@ -144,8 +144,8 @@ static bool __init check_loader_disabled_bsp(void) return *res; } -extern struct builtin_fw __start_builtin_fw[]; -extern struct builtin_fw __end_builtin_fw[]; +extern struct builtin_fw __start_builtin_fw[] __default_visibility; +extern struct builtin_fw __end_builtin_fw[] __default_visibility; bool get_builtin_firmware(struct cpio_data *cd, const char *name) { diff --git a/drivers/base/firmware_class.c b/drivers/base/firmware_class.c index 4b57cf5bc81d..77d4727f6594 100644 --- a/drivers/base/firmware_class.c +++ b/drivers/base/firmware_class.c @@ -45,8 +45,8 @@ MODULE_LICENSE("GPL"); #ifdef CONFIG_FW_LOADER -extern struct builtin_fw __start_builtin_fw[]; -extern struct builtin_fw __end_builtin_fw[]; +extern struct builtin_fw __start_builtin_fw[] __default_visibility; +extern struct builtin_fw __end_builtin_fw[] __default_visibility; static bool fw_get_builtin_firmware(struct firmware *fw, const char *name, void *buf, size_t size) diff --git a/include/asm-generic/sections.h b/include/asm-generic/sections.h index e5da44eddd2f..1aa5d6dac9e1 100644 --- a/include/asm-generic/sections.h +++ b/include/asm-generic/sections.h @@ -30,6 +30,9 @@ * __irqentry_text_start, __irqentry_text_end * __softirqentry_text_start, __softirqentry_text_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[]; @@ -46,6 +49,9 @@ extern char __softirqentry_text_start[], __softirqentry_text_end[]; /* 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 e95a2631e545..6997716f73bf 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 ccb1d8daf241..b640201fcff7 100644 --- a/init/Kconfig +++ b/init/Kconfig @@ -1649,6 +1649,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) { diff --git a/kernel/trace/trace.h b/kernel/trace/trace.h index 652c682707cd..31cb920039a2 100644 --- a/kernel/trace/trace.h +++ b/kernel/trace/trace.h @@ -1742,8 +1742,8 @@ extern int trace_event_enable_disable(struct trace_event_file *file, int enable, int soft_disable); extern int tracing_alloc_snapshot(void); -extern const char *__start___trace_bprintk_fmt[]; -extern const char *__stop___trace_bprintk_fmt[]; +extern const char *__start___trace_bprintk_fmt[] __default_visibility; +extern const char *__stop___trace_bprintk_fmt[] __default_visibility; extern const char *__start___tracepoint_str[]; extern const char *__stop___tracepoint_str[]; diff --git a/lib/dynamic_debug.c b/lib/dynamic_debug.c index da796e2dc4f5..10ed20177354 100644 --- a/lib/dynamic_debug.c +++ b/lib/dynamic_debug.c @@ -37,8 +37,8 @@ #include #include -extern struct _ddebug __start___verbose[]; -extern struct _ddebug __stop___verbose[]; +extern struct _ddebug __start___verbose[] __default_visibility; +extern struct _ddebug __stop___verbose[] __default_visibility; struct ddebug_table { struct list_head link;