From patchwork Tue Mar 29 20:44:35 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Nicolas Pitre X-Patchwork-Id: 64629 Delivered-To: patch@linaro.org Received: by 10.112.199.169 with SMTP id jl9csp2236295lbc; Tue, 29 Mar 2016 13:48:08 -0700 (PDT) X-Received: by 10.98.32.5 with SMTP id g5mr6675702pfg.95.1459284488048; Tue, 29 Mar 2016 13:48:08 -0700 (PDT) Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id tf6si698922pac.233.2016.03.29.13.48.07; Tue, 29 Mar 2016 13:48:08 -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 S1758106AbcC2Ur7 (ORCPT + 29 others); Tue, 29 Mar 2016 16:47:59 -0400 Received: from alt13.smtp-out.videotron.ca ([135.19.0.26]:21422 "EHLO alt12.smtp-out.videotron.ca" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S1754314AbcC2UpK (ORCPT ); Tue, 29 Mar 2016 16:45:10 -0400 Received: from yoda.home ([96.23.157.65]) by Videotron with SMTP id l0VgarjZcF40Ul0VhagX9A; Tue, 29 Mar 2016 16:45:09 -0400 X-Authority-Analysis: v=2.1 cv=SrQwkK60 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=X7ppACSVQOA_6jTZIeQA:9 Received: from xanadu.home (xanadu.home [192.168.2.2]) by yoda.home (Postfix) with ESMTP id EA0362DA0541; Tue, 29 Mar 2016 16:45:07 -0400 (EDT) From: Nicolas Pitre To: Michal Marek Cc: linux-kbuild@vger.kernel.org, linux-kernel@vger.kernel.org Subject: [PATCH v7 1/8] kbuild: record needed exported symbols for modules Date: Tue, 29 Mar 2016 16:44:35 -0400 Message-Id: <1459284282-6676-2-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: MS4wfPzC2xO5lsBf1VJFzbbk5+C1t5Rt2ZfLZ9ApVfUFGQwCC1VvF0IFjUcAsWcczCR8yMgTQEdxRaWjordU8E0M8ptUHFTxNagy9lVvbUEZBlYGsZ07z1Z5 wEB1W/693bmHzzIqH7NS5zHpnxjiRQTNzzfsgDBCoWn9PmAV+7D/jBEYsbBQKa8Oaa0e4OmrBCCHwIA6i/u+sG5l53pauR3lkKhr7DjfJBCOm2qnvTRNRyTK nJ9vaduIAMrnO98ShBhLlg== Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Kernel modules are partially linked object files with some undefined symbols that are expected to be matched with EXPORT_SYMBOL() entries from elsewhere. Each .tmp_versions/*.mod file currently contains two line of text separated by a newline character. The first line has the actual module file name while the second line has a list of object files constituting that module. Those files are parsed by modpost (scripts/mod/sumversion.c), scripts/Makefile.modpost, scripts/Makefile.modsign, etc. Only the modpost utility cares about the second line while the others retrieve only the first line. Therefore we can add a third line to record the list of undefined symbols aka required EXPORT_SYMBOL() entries for each module into that file without breaking anything. Like for the second line, symbols are separated by a blank and the list is terminated with a newline character. To avoid needless build overhead, the undefined symbols extraction is performed only when CONFIG_TRIM_UNUSED_KSYMS is selected. Signed-off-by: Nicolas Pitre Acked-by: Rusty Russell --- scripts/Makefile.build | 13 +++++++++++-- 1 file changed, 11 insertions(+), 2 deletions(-) -- 2.5.5 diff --git a/scripts/Makefile.build b/scripts/Makefile.build index e1bc190709..74556e5e4e 100644 --- a/scripts/Makefile.build +++ b/scripts/Makefile.build @@ -286,6 +286,13 @@ define rule_as_o_S mv -f $(dot-target).tmp $(dot-target).cmd endef +# List module undefined symbols (or empty line if not enabled) +ifdef CONFIG_TRIM_UNUSED_KSYMS +cmd_undef_syms = $(NM) $@ | sed -n 's/^ \+U //p' | xargs echo +else +cmd_undef_syms = echo +endif + # Built-in and composite module parts $(obj)/%.o: $(src)/%.c $(recordmcount_source) $(objtool_obj) FORCE $(call cmd,force_checksrc) @@ -296,7 +303,8 @@ $(obj)/%.o: $(src)/%.c $(recordmcount_source) $(objtool_obj) FORCE $(single-used-m): $(obj)/%.o: $(src)/%.c $(recordmcount_source) $(objtool_obj) FORCE $(call cmd,force_checksrc) $(call if_changed_rule,cc_o_c) - @{ echo $(@:.o=.ko); echo $@; } > $(MODVERDIR)/$(@F:.o=.mod) + @{ echo $(@:.o=.ko); echo $@; \ + $(cmd_undef_syms); } > $(MODVERDIR)/$(@F:.o=.mod) quiet_cmd_cc_lst_c = MKLST $@ cmd_cc_lst_c = $(CC) $(c_flags) -g -c -o $*.o $< && \ @@ -426,7 +434,8 @@ $(call multi_depend, $(multi-used-y), .o, -objs -y) $(multi-used-m): FORCE $(call if_changed,link_multi-m) - @{ echo $(@:.o=.ko); echo $(link_multi_deps); } > $(MODVERDIR)/$(@F:.o=.mod) + @{ echo $(@:.o=.ko); echo $(link_multi_deps); \ + $(cmd_undef_syms); } > $(MODVERDIR)/$(@F:.o=.mod) $(call multi_depend, $(multi-used-m), .o, -objs -y -m) targets += $(multi-used-y) $(multi-used-m)