mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
From: Jeff Arnold <jbarnold@MIT.EDU>
To: Andrew Morton <akpm@linux-foundation.org>
Cc: linux-kernel@vger.kernel.org,
	Denys Vlasenko <vda.linux@googlemail.com>,
	Tim Abbott <tabbott@MIT.EDU>, Anders Kaseorg <andersk@MIT.EDU>,
	Waseem Daher <wdaher@MIT.EDU>,
	Nikanth Karthikesan <knikanth@suse.de>
Subject: [PATCH 2/7] x86: Add an option to compile with -ffunction-sections -fdata-sections
Date: Fri,  5 Dec 2008 19:03:55 -0500	[thread overview]
Message-ID: <1228521840-3886-3-git-send-email-jbarnold@mit.edu> (raw)
In-Reply-To: <1228521840-3886-2-git-send-email-jbarnold@mit.edu>

From: Waseem Daher <wdaher@mit.edu>

This patch makes it possible to link and boot an x86 kernel with
-ffunction-sections and -fdata-sections enabled.

Modpost currently warns whenever it sees a section with a name
matching [.][0-9]+$ because they are often caused by section flag
mismatch errors.  When compiling with -ffunction-sections
-fdata-sections, gcc places various classes of local symbols in
sections with names such as .rodata.__func__.12345, causing these
warnings to be printed spuriously.  The simplest fix is to disable the
warning when CONFIG_FUNCTION_DATA_SECTIONS is enabled.

Signed-off-by: Waseem Daher <wdaher@mit.edu>
[tabbott@mit.edu: modpost support]
Signed-off-by: Tim Abbott <tabbott@mit.edu>
---
 Makefile                          |    4 ++++
 arch/x86/kernel/vmlinux_32.lds.S  |    1 +
 arch/x86/kernel/vmlinux_64.lds.S  |    1 +
 include/asm-generic/vmlinux.lds.h |    2 ++
 lib/Kconfig.debug                 |    9 +++++++++
 scripts/Makefile.modpost          |    1 +
 scripts/mod/modpost.c             |   10 ++++++++--
 7 files changed, 26 insertions(+), 2 deletions(-)

diff --git a/Makefile b/Makefile
index 9a49960..d3d6fa4 100644
--- a/Makefile
+++ b/Makefile
@@ -540,6 +540,10 @@ ifdef CONFIG_FUNCTION_TRACER
 KBUILD_CFLAGS	+= -pg
 endif
 
+ifdef CONFIG_FUNCTION_DATA_SECTIONS
+KBUILD_CFLAGS	+= -ffunction-sections -fdata-sections
+endif
+
 # We trigger additional mismatches with less inlining
 ifdef CONFIG_DEBUG_SECTION_MISMATCH
 KBUILD_CFLAGS += $(call cc-option, -fno-inline-functions-called-once)
diff --git a/arch/x86/kernel/vmlinux_32.lds.S b/arch/x86/kernel/vmlinux_32.lds.S
index 454ab4c..c0c4323 100644
--- a/arch/x86/kernel/vmlinux_32.lds.S
+++ b/arch/x86/kernel/vmlinux_32.lds.S
@@ -193,6 +193,7 @@ SECTIONS
 	__bss_start = .;		/* BSS */
 	*(.bss.kernel.page_aligned)
 	*(.bss)
+	*(.bss.*)
 	. = ALIGN(4);
 	__bss_stop = .;
   	_end = . ;
diff --git a/arch/x86/kernel/vmlinux_64.lds.S b/arch/x86/kernel/vmlinux_64.lds.S
index 6fd4547..ccb74b0 100644
--- a/arch/x86/kernel/vmlinux_64.lds.S
+++ b/arch/x86/kernel/vmlinux_64.lds.S
@@ -222,6 +222,7 @@ SECTIONS
   .bss : AT(ADDR(.bss) - LOAD_OFFSET) {
 	*(.bss.kernel.page_aligned)
 	*(.bss)
+	*(.bss.*)
 	}
   __bss_stop = .;
 
diff --git a/include/asm-generic/vmlinux.lds.h b/include/asm-generic/vmlinux.lds.h
index e8d1bdd..4b5aea8 100644
--- a/include/asm-generic/vmlinux.lds.h
+++ b/include/asm-generic/vmlinux.lds.h
@@ -48,6 +48,7 @@
 /* .data section */
 #define DATA_DATA							\
 	*(.data)							\
+	*(.data.*)							\
 	*(.kernel.data.init.refok)					\
 	*(.ref.data)							\
 	DEV_KEEP(init.data)						\
@@ -235,6 +236,7 @@
 		ALIGN_FUNCTION();					\
 		*(.text.hot)						\
 		*(.text)						\
+		*(.text.*)						\
 		*(.ref.text)						\
 		*(.kernel.text.init.refok)				\
 		*(.kernel.text.exit.refok)				\
diff --git a/lib/Kconfig.debug b/lib/Kconfig.debug
index b0f239e..e121ab7 100644
--- a/lib/Kconfig.debug
+++ b/lib/Kconfig.debug
@@ -557,6 +557,15 @@ config FRAME_POINTER
 	  some architectures or if you use external debuggers.
 	  If you don't debug the kernel, you can say N.
 
+config FUNCTION_DATA_SECTIONS
+	bool "Compile with -ffunction-sections -fdata-sections"
+	depends on !FTRACE
+	help
+	  If you say Y here the compiler will give each function
+	  and data structure its own ELF section.
+
+	  If unsure, say N.
+
 config BOOT_PRINTK_DELAY
 	bool "Delay each boot printk message by N milliseconds"
 	depends on DEBUG_KERNEL && PRINTK && GENERIC_CALIBRATE_DELAY
diff --git a/scripts/Makefile.modpost b/scripts/Makefile.modpost
index f4053dc..a712bb2 100644
--- a/scripts/Makefile.modpost
+++ b/scripts/Makefile.modpost
@@ -87,6 +87,7 @@ modpost = scripts/mod/modpost                    \
  $(if $(CONFIG_DEBUG_SECTION_MISMATCH),,-S)      \
  $(if $(CONFIG_MARKERS),-K $(kernelmarkersfile)) \
  $(if $(CONFIG_MARKERS),-M $(markersfile))	 \
+ $(if $(filter -ffunction-sections -fdata-sections,$(KBUILD_CFLAGS) $(CFLAGS_KERNEL)),-F) \
  $(if $(KBUILD_EXTMOD)$(KBUILD_MODPOST_WARN),-w) \
  $(if $(cross_build),-c)
 
diff --git a/scripts/mod/modpost.c b/scripts/mod/modpost.c
index afe9408..68d9e95 100644
--- a/scripts/mod/modpost.c
+++ b/scripts/mod/modpost.c
@@ -32,6 +32,8 @@ static int warn_unresolved = 0;
 /* How a symbol is exported */
 static int sec_mismatch_count = 0;
 static int sec_mismatch_verbose = 1;
+/* Are we using CONFIG_FUNCTION_DATA_SECTIONS? */
+static int function_data_sections = 0;
 
 enum export {
 	export_plain,      export_unused,     export_gpl,
@@ -736,7 +738,8 @@ static int check_section(const char *modname, const char *sec)
 		/* consume all digits */
 		while (*e && e != sec && isdigit(*e))
 			e--;
-		if (*e == '.' && !strstr(sec, ".linkonce")) {
+		if (*e == '.' && !strstr(sec, ".linkonce") &&
+		    !function_data_sections) {
 			warn("%s (%s): unexpected section name.\n"
 			     "The (.[number]+) following section name are "
 			     "ld generated and not expected.\n"
@@ -2063,7 +2066,7 @@ int main(int argc, char **argv)
 	struct ext_sym_list *extsym_iter;
 	struct ext_sym_list *extsym_start = NULL;
 
-	while ((opt = getopt(argc, argv, "i:I:e:cmsSo:awM:K:")) != -1) {
+	while ((opt = getopt(argc, argv, "i:I:e:cFmsSo:awM:K:")) != -1) {
 		switch (opt) {
 		case 'i':
 			kernel_read = optarg;
@@ -2083,6 +2086,9 @@ int main(int argc, char **argv)
 			extsym_iter->file = optarg;
 			extsym_start = extsym_iter;
 			break;
+		case 'F':
+			function_data_sections = 1;
+			break;
 		case 'm':
 			modversions = 1;
 			break;
-- 
1.5.6.3


  reply	other threads:[~2008-12-06  0:10 UTC|newest]

Thread overview: 43+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2008-12-06  0:03 [PATCH 0/7] Ksplice: Rebootless kernel updates Jeff Arnold
2008-12-06  0:03 ` [PATCH 1/7] Make section names compatible with -ffunction-sections -fdata-sections Jeff Arnold
2008-12-06  0:03   ` Jeff Arnold [this message]
2008-12-06  0:03     ` [PATCH 3/7] Ksplice: Make find_symbol return a struct kernel_symbol Jeff Arnold
2008-12-06  0:03       ` [PATCH 4/7] Ksplice: Add module_data_address (the analogue of module_text_address) Jeff Arnold
2008-12-06  0:03         ` [PATCH 5/7] Ksplice: Add functions for walking kallsyms symbols Jeff Arnold
2008-12-06  0:03           ` [PATCH 6/7] Ksplice: Export symbols needed for Ksplice Jeff Arnold
2008-12-06  0:04             ` [PATCH 7/7] Ksplice: Support updating x86-32 and x86-64 Jeff Arnold
2008-12-17  5:41               ` Theodore Tso
2008-12-18  2:09                 ` Tim Abbott
2009-02-07  2:36               ` Rusty Russell
2009-02-10  1:01                 ` Tim Abbott
2009-02-04 11:35             ` [PATCH 6/7] Ksplice: Export symbols needed for Ksplice Rusty Russell
2009-02-13  1:46               ` Tim Abbott
2009-02-16  7:11                 ` Rusty Russell
2009-02-04 11:30           ` [PATCH 5/7] Ksplice: Add functions for walking kallsyms symbols Rusty Russell
2009-02-04 21:31             ` Anders Kaseorg
2009-02-04 11:21         ` [PATCH 4/7] Ksplice: Add module_data_address (the analogue of module_text_address) Rusty Russell
2009-02-04 20:48           ` Anders Kaseorg
2009-02-07 12:45             ` Rusty Russell
2009-02-04  9:26       ` [PATCH 3/7] Ksplice: Make find_symbol return a struct kernel_symbol Rusty Russell
2009-02-04  8:38     ` [PATCH 2/7] x86: Add an option to compile with -ffunction-sections -fdata-sections Rusty Russell
2009-02-04 10:26       ` Anders Kaseorg
2009-02-04 10:58         ` Rusty Russell
2009-02-04 20:50           ` Anders Kaseorg
2008-12-06  8:46   ` [PATCH 1/7] Make section names compatible " Andi Kleen
2008-12-31 19:18     ` Tim Abbott
2008-12-31 19:52       ` Andi Kleen
2008-12-31 21:59         ` Tim Abbott
2009-01-01 16:32           ` Andrew Morton
2009-01-04 19:20             ` Tim Abbott
2009-01-12 21:51               ` Andrew Morton
2009-01-12 22:11                 ` Andi Kleen
2009-02-04  8:15   ` Rusty Russell
2009-02-05  1:11     ` Anders Kaseorg
2009-02-05  2:00       ` Anders Kaseorg
2008-12-17  2:48 ` [PATCH 0/7] Ksplice: Rebootless kernel updates Tim Abbott
2008-12-17  3:07   ` Andrew Morton
2008-12-17  3:53     ` Dave Jones
2008-12-17 17:19       ` Jeff Arnold
2008-12-17  5:05     ` Tim Abbott
2008-12-17 12:09       ` Ben Collins
2008-12-17 12:06     ` Ben Collins

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=1228521840-3886-3-git-send-email-jbarnold@mit.edu \
    --to=jbarnold@mit.edu \
    --cc=akpm@linux-foundation.org \
    --cc=andersk@MIT.EDU \
    --cc=knikanth@suse.de \
    --cc=linux-kernel@vger.kernel.org \
    --cc=tabbott@MIT.EDU \
    --cc=vda.linux@googlemail.com \
    --cc=wdaher@MIT.EDU \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox

Powered by JetHome