From patchwork Tue Jul 18 22:33:28 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Thomas Garnier X-Patchwork-Id: 9850075 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 D517C60392 for ; Tue, 18 Jul 2017 22:37:19 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id C0428285CD for ; Tue, 18 Jul 2017 22:37:19 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id B47C9285E4; Tue, 18 Jul 2017 22:37:19 +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 2302D285D8 for ; Tue, 18 Jul 2017 22:37:19 +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 1dXb4j-0000rL-85; Tue, 18 Jul 2017 22:34:41 +0000 Received: from mail6.bemta3.messagelabs.com ([195.245.230.39]) by lists.xenproject.org with esmtp (Exim 4.84_2) (envelope-from ) id 1dXb4h-0000oa-UU for xen-devel@lists.xenproject.org; Tue, 18 Jul 2017 22:34:40 +0000 Received: from [85.158.137.68] by server-8.bemta-3.messagelabs.com id 81/AC-02176-FFC8E695; Tue, 18 Jul 2017 22:34:39 +0000 X-Brightmail-Tracker: H4sIAAAAAAAAA+NgFtrCIsWRWlGSWpSXmKPExsXiVRusrfuvJy/ S4PtpGYvvWyYzOTB6HP5whSWAMYo1My8pvyKBNWP2rJvMBS9VK/a9msjewHhaoYuRi0NIYAaj xNYbx9lBHBaBVywSC/8uZAJxJAT6WSVWztzI2sXICeTEScxb8pUFwq6S6Pl4nQ3EFhJQkti6Y SkzxKh/jBKfds4Ea2AT0JLY0zAfbJKIwGwOicVdZ1hAHAGBj2wSN7YcBmthFmhhknjybxsTSI uwgJPE8Rvv2EFsFgFViZ8Lt4GN4hWwklh3fhfQPg6g3cYSf7/og5icQOHl93kgrrCU6O1tYJn AKLiAkWEVo0ZxalFZapGukaVeUlFmekZJbmJmjq6hgbFebmpxcWJ6ak5iUrFecn7uJkZg2NUz MDDuYGza63eIUZKDSUmUd6tyXqQQX1J+SmVGYnFGfFFpTmrxIUYZDg4lCd5D3UA5waLU9NSKt MwcYATApCU4eJREeH1A0rzFBYm5xZnpEKlTjMYckw5s/8LE8WrC/29MQix5+XmpUuK8C0BKBU BKM0rz4AbBIvMSo6yUMC8jAwODEE9BalFuZgmq/CtGcQ5GJWFedmCcC/Fk5pXA7XsFdAoT0Cn Cvjkgp5QkIqSkGhi5Dr9tfOa94FPO874VXqs5b+xMaWGscVQNEt81vXhfpELSc4kpEpreix92 Mtie2DVjNUNI3YqWLiWbn1caSjt+v+3IPuNhs8dKkT/l7YK/h9U+b9zdkZ/K+KpOfl/MtLvtW gFHTX+UeDBWXPbwsFew7fnJLXL9WeX8H68Z+DZZXuZRO8225bUSS3FGoqEWc1FxIgCw7Bgfxw IAAA== X-Env-Sender: thgarnie@google.com X-Msg-Ref: server-5.tower-31.messagelabs.com!1500417276!102822278!1 X-Originating-IP: [74.125.83.43] X-SpamReason: No, hits=0.0 required=7.0 tests= X-StarScan-Received: X-StarScan-Version: 9.4.25; banners=-,-,- X-VirusChecked: Checked Received: (qmail 43034 invoked from network); 18 Jul 2017 22:34:38 -0000 Received: from mail-pg0-f43.google.com (HELO mail-pg0-f43.google.com) (74.125.83.43) by server-5.tower-31.messagelabs.com with AES128-GCM-SHA256 encrypted SMTP; 18 Jul 2017 22:34:38 -0000 Received: by mail-pg0-f43.google.com with SMTP id 123so20061420pgj.1 for ; Tue, 18 Jul 2017 15:34:38 -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=mAJv5V6I2lZ1xUFrgT12JDfH7dk1gDucWD68g8iaoDo=; b=N+cTED2dovvk2LYq3nUPFlASpyKY3zeoyYBSqKvMYAD4ptUkuPtPY1OsOMCCGFB3QI 3rFX94jJFnV4Wu0tVVi3xrCkgm79vsSyjFIQ0/92pb4VcseNI74jrfgx2zqtN42IXmDI Kn5CYrDNLfeJ2O0M46n4CNO3pf06ggQHp+SEv7k8fKNk0ofYomWoETc7g8NdxkSYqANo wQ8q69QQ9lhwrEYFaugKu7+lS4OzfzwCUVtzXoxFbZySCPNVE+pSq5hR6Jdd7UOwXwW5 hul620SI0JFBy9hui8g0kVDm3IZiBqD0SKH8OyjVVswzm1jXTnMmgbgnvn/mWsCYwOz6 PvRA== 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=mAJv5V6I2lZ1xUFrgT12JDfH7dk1gDucWD68g8iaoDo=; b=RNqsWsudQ77U0KMz0ohgtvU/GiuoEqegAm3Lx1hFbcvDnTzHEtqBiMxvX/drsDOIbg XMjJV+FUoq6O4UZyRPQYVJvhH9Pu82i9u+oUfGa+XD2lMt0tJuD4cKztJBFVJZKmu9ew 9WGeW96kgsmh7EvqYAzsEeHV0ph9/KuvYUPpnnOqtu4PDSL1KEdwA0agi8CZJTnGTEUI 1hnNQ2GKhQ6WDzN4b9JHBML+a4qPPfVRlCPcwd2JgXxhh+QtDYej+lX0+1KR/+CJvf7j umG/6hVvaK7bp4b1lnwPvrsZNn3ZOMqVCheRNBo8kX0EItwOIam++RyRCYaP8y0roA/i 6zQg== X-Gm-Message-State: AIVw112oPzMm1Y3r2S5Kkki7HcV4po2bNhzmuVG9pJQf7meC2/RVfVZK mvhq62Ae3OiHzA70 X-Received: by 10.101.91.203 with SMTP id o11mr4025020pgr.206.1500417276104; Tue, 18 Jul 2017 15:34:36 -0700 (PDT) Received: from skynet.sea.corp.google.com ([100.100.206.164]) by smtp.gmail.com with ESMTPSA id b6sm6444242pgn.67.2017.07.18.15.34.34 (version=TLS1_2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Tue, 18 Jul 2017 15:34:35 -0700 (PDT) From: Thomas Garnier To: Herbert Xu , "David S . Miller" , Thomas Gleixner , Ingo Molnar , "H . Peter Anvin" , Peter Zijlstra , Josh Poimboeuf , Thomas Garnier , Arnd Bergmann , Matthias Kaehlcke , Boris Ostrovsky , Juergen Gross , Paolo Bonzini , =?UTF-8?q?Radim=20Kr=C4=8Dm=C3=A1=C5=99?= , Joerg Roedel , Andy Lutomirski , Borislav Petkov , "Kirill A . Shutemov" , Brian Gerst , Borislav Petkov , Christian Borntraeger , "Rafael J . Wysocki" , Len Brown , Pavel Machek , Tejun Heo , Christoph Lameter , Kees Cook , Paul Gortmaker , Chris Metcalf , "Paul E . McKenney" , Andrew Morton , Christopher Li , Dou Liyang , Masahiro Yamada , Daniel Borkmann , Markus Trippelsdorf , Peter Foley , Steven Rostedt , Tim Chen , Ard Biesheuvel , Catalin Marinas , Matthew Wilcox , Michal Hocko , Rob Landley , Jiri Kosina , "H . J . Lu" , Paul Bolle , Baoquan He , Daniel Micay Date: Tue, 18 Jul 2017 15:33:28 -0700 Message-Id: <20170718223333.110371-18-thgarnie@google.com> X-Mailer: git-send-email 2.13.2.932.g7449e964c-goog In-Reply-To: <20170718223333.110371-1-thgarnie@google.com> References: <20170718223333.110371-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 17/22] 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 e4585a393965..f3ffad82bdc0 100644 --- a/arch/x86/include/asm/setup.h +++ b/arch/x86/include/asm/setup.h @@ -66,7 +66,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 eca8ad75e28b..876b827fe4a7 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 4fb5d6fc2c4f..a93626d40355 100644 --- a/init/Kconfig +++ b/init/Kconfig @@ -1635,6 +1635,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) {