From patchwork Tue Mar 29 20:44:36 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Nicolas Pitre X-Patchwork-Id: 64623 Delivered-To: patch@linaro.org Received: by 10.112.199.169 with SMTP id jl9csp2235419lbc; Tue, 29 Mar 2016 13:45:45 -0700 (PDT) X-Received: by 10.98.87.5 with SMTP id l5mr6608763pfb.7.1459284345037; Tue, 29 Mar 2016 13:45:45 -0700 (PDT) Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id r18si728087pfi.140.2016.03.29.13.45.44; Tue, 29 Mar 2016 13:45:45 -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; dmarc=fail (p=NONE dis=NONE) header.from=linaro.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1758129AbcC2UpR (ORCPT + 29 others); Tue, 29 Mar 2016 16:45:17 -0400 Received: from alt13.smtp-out.videotron.ca ([135.19.0.26]:5114 "EHLO alt12.smtp-out.videotron.ca" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S1754228AbcC2UpK (ORCPT ); Tue, 29 Mar 2016 16:45:10 -0400 Received: from yoda.home ([96.23.157.65]) by Videotron with SMTP id l0VgaIpSAkaTMl0Vhabbk1; Tue, 29 Mar 2016 16:45:09 -0400 X-Authority-Analysis: v=2.1 cv=D8PnUqlj c=1 sm=1 tr=0 a=keA3yYpnlypCNW5BNWqu+w==:117 a=keA3yYpnlypCNW5BNWqu+w==:17 a=L9H7d07YOLsA:10 a=9cW_t1CCXrUA:10 a=s5jvgZ67dGcA:10 a=7OsogOcEt9IA:10 a=KKAkSRfTAAAA:8 a=Tty9oNO6AAAA:8 a=V4Nnv2rFfRtn8YTrWvgA:9 Received: from xanadu.home (xanadu.home [192.168.2.2]) by yoda.home (Postfix) with ESMTP id 067D82DA0577; Tue, 29 Mar 2016 16:45:08 -0400 (EDT) From: Nicolas Pitre To: Michal Marek Cc: linux-kbuild@vger.kernel.org, linux-kernel@vger.kernel.org Subject: [PATCH v7 2/8] export.h: allow for per-symbol configurable EXPORT_SYMBOL() Date: Tue, 29 Mar 2016 16:44:36 -0400 Message-Id: <1459284282-6676-3-git-send-email-nicolas.pitre@linaro.org> X-Mailer: git-send-email 2.5.5 In-Reply-To: <1459284282-6676-1-git-send-email-nicolas.pitre@linaro.org> References: <1459284282-6676-1-git-send-email-nicolas.pitre@linaro.org> X-CMAE-Envelope: MS4wfHBS/e6gwAYgKsckvsz2F0WAVFBnje47rKjfLbtPwT5idxYdIE4irlIQFco2ci1k0j2qKlLsDpugrMSrecMop2jzBCeIETfjNHvgmJm1MoBJ1p8xoumP 1jlM1WSrUk6LhT4I4WR/YjtbB2ptDRpH2o1E5fKTqySNnoZ3IQUYvByiHdXaA0K0r+KwfuSSjmkF+QrVo9xMk2YeNzk9HhkDHlbhcjKX+yDJ3/1Qsej5YnwN mk7P0r4Yk+K5bdf+aVTPYg== Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Similar to include/generated/autoconf.h, include/generated/autoksyms.h will contain a list of defines for each EXPORT_SYMBOL() that we want active. The format is: #define __KSYM_ 1 This list will be auto-generated with another patch. For now we only include the preprocessor magic to automatically create or omit the corresponding struct kernel_symbol declaration. Given the content of include/generated/autoksyms.h may not be known in advance, an empty file is created early on to let the build proceed. Signed-off-by: Nicolas Pitre Acked-by: Rusty Russell --- Makefile | 2 ++ include/linux/export.h | 22 ++++++++++++++++++++-- 2 files changed, 22 insertions(+), 2 deletions(-) -- 2.5.5 diff --git a/Makefile b/Makefile index 916b26e999..451acbebee 100644 --- a/Makefile +++ b/Makefile @@ -998,6 +998,8 @@ prepare2: prepare3 outputmakefile asm-generic prepare1: prepare2 $(version_h) include/generated/utsrelease.h \ include/config/auto.conf $(cmd_crmodverdir) + $(Q)test -e include/generated/autoksyms.h || \ + touch include/generated/autoksyms.h archprepare: archheaders archscripts prepare1 scripts_basic diff --git a/include/linux/export.h b/include/linux/export.h index 96e45ea463..77afdb2a25 100644 --- a/include/linux/export.h +++ b/include/linux/export.h @@ -38,7 +38,7 @@ extern struct module __this_module; #ifdef CONFIG_MODULES -#ifndef __GENKSYMS__ +#if defined(__KERNEL__) && !defined(__GENKSYMS__) #ifdef CONFIG_MODVERSIONS /* Mark the CRC weak since genksyms apparently decides not to * generate a checksums for some symbols */ @@ -53,7 +53,7 @@ extern struct module __this_module; #endif /* For every exported symbol, place a struct in the __ksymtab section */ -#define __EXPORT_SYMBOL(sym, sec) \ +#define ___EXPORT_SYMBOL(sym, sec) \ extern typeof(sym) sym; \ __CRC_SYMBOL(sym, sec) \ static const char __kstrtab_##sym[] \ @@ -65,6 +65,24 @@ extern struct module __this_module; __attribute__((section("___ksymtab" sec "+" #sym), unused)) \ = { (unsigned long)&sym, __kstrtab_##sym } +#ifdef CONFIG_TRIM_UNUSED_KSYMS + +#include +#include + +#define __EXPORT_SYMBOL(sym, sec) \ + __cond_export_sym(sym, sec, config_enabled(__KSYM_##sym)) +#define __cond_export_sym(sym, sec, conf) \ + ___cond_export_sym(sym, sec, conf) +#define ___cond_export_sym(sym, sec, enabled) \ + __cond_export_sym_##enabled(sym, sec) +#define __cond_export_sym_1(sym, sec) ___EXPORT_SYMBOL(sym, sec) +#define __cond_export_sym_0(sym, sec) /* nothing */ + +#else +#define __EXPORT_SYMBOL ___EXPORT_SYMBOL +#endif + #define EXPORT_SYMBOL(sym) \ __EXPORT_SYMBOL(sym, "")