From: Denys Vlasenko <vda.linux@googlemail.com>
To: Michal Marek <mmarek@suse.cz>,
linux-kbuild <linux-kbuild@vger.kernel.org>,
linux-arch@vger.kernel.org,
Parisc List <linux-parisc@vger.kernel.org>
Cc: lkml <linux-kernel@vger.kernel.org>,
Sam Ravnborg <sam@ravnborg.org>, Tim Abbott <tabbott@ksplice.com>,
Tim Bird <tim.bird@am.sony.com>,
James Bottomley <James.Bottomley@hansenpartnership.com>,
Matt Fleming <matt@console-pimps.org>,
Arnd Bergmann <arnd@arndb.de>, Anders Kaseorg <andersk@mit.edu>,
Andi Kleen <andi@firstfloor.org>,
Stephen Rothwell <sfr@canb.auug.org.au>,
Denys Vlasenko <vda.linux@googlemail.com>
Subject: [PATCH 2/4] module linker script: coalesce function and data sections
Date: Thu, 29 Jul 2010 01:47:54 +0200 [thread overview]
Message-ID: <1280360876-2571-3-git-send-email-vda.linux@googlemail.com> (raw)
In-Reply-To: <1280360876-2571-1-git-send-email-vda.linux@googlemail.com>
gcc -ffunction-sections -fdata-sections places each function foo
into separate section .text.foo, and every data object bar into
separate section .data.bar, .rodata.bar or .bss.bar.
This fix prevents kernel modules from having unnecessarily many
sections and thus prevents module size growth when we pass
-ffunction-sections -fdata-sections to gcc.
Module linker script needs to avoid collecting special kernel sections,
therefore it uses more restrictive patterns like *(.text.[A-Za-z0-9_$^]*)
instead of simplistic *(.text.*): special kernel sections like
.text..page_aligned contain double dots and won't be accidentally
matched by them.
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
Acked-by: Sam Ravnborg <sam@ravnborg.org>
---
scripts/module-common.lds | 23 +++++++++++++++++++++++
1 files changed, 23 insertions(+), 0 deletions(-)
diff --git a/scripts/module-common.lds b/scripts/module-common.lds
index 47a1f9a..4a197e8 100644
--- a/scripts/module-common.lds
+++ b/scripts/module-common.lds
@@ -3,6 +3,29 @@
* Archs are free to supply their own linker scripts. ld will
* combine them automatically.
*/
+
+/* .data.foo are generated by gcc itself with -fdata-sections,
+ * whereas double-dot sections (like .data..percpu) are generated
+ * by kernel's magic macros.
+ *
+ * Since this script does not specify what to do with double-dot sections,
+ * ld -r will coalesce all .data..foo input sections into one .data..foo
+ * output section, all .data..bar input sections into one .data..bar
+ * output section and so on. This is exactly what we want.
+ *
+ * Same goes for .text, .bss and .rodata. In case of .rodata, various
+ * .rodata.foo sections are generated by gcc even without -fdata-sections
+ */
+
SECTIONS {
+
+ /* Coalesce sections produced by gcc -ffunction-sections */
+ .text 0 : AT(0) { *(.text .text.[A-Za-z0-9_$^]*) }
+
+ /* Coalesce sections produced by gcc -fdata-sections */
+ .rodata 0 : AT(0) { *(.rodata .rodata.[A-Za-z0-9_$^]*) }
+ .data 0 : AT(0) { *(.data .data.[A-Za-z0-9_$^]*) }
+ .bss 0 : AT(0) { *(.bss .bss.[A-Za-z0-9_$^]*) }
+
/DISCARD/ : { *(.discard) }
}
--
1.6.2.4
next prev parent reply other threads:[~2010-07-28 23:49 UTC|newest]
Thread overview: 10+ messages / expand[flat|nested] mbox.gz Atom feed top
2010-07-28 23:47 [PATCH 0/4] function/data-sections Denys Vlasenko
2010-07-28 23:47 ` [PATCH 1/4] modpost: support objects with more than 64k sections Denys Vlasenko
2010-07-28 23:47 ` Denys Vlasenko [this message]
2010-07-29 0:25 ` [PATCH 2/4] module linker script: coalesce function and data sections David Howells
2010-07-29 1:24 ` Denys Vlasenko
2010-07-29 9:09 ` David Howells
2010-08-03 13:47 ` Michal Marek
2010-08-06 2:18 ` Denys Vlasenko
2010-07-28 23:47 ` [PATCH 3/4] kernel linker stripts: accomodate " Denys Vlasenko
2010-07-28 23:47 ` [PATCH 4/4] boot " Denys Vlasenko
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=1280360876-2571-3-git-send-email-vda.linux@googlemail.com \
--to=vda.linux@googlemail.com \
--cc=James.Bottomley@hansenpartnership.com \
--cc=andersk@mit.edu \
--cc=andi@firstfloor.org \
--cc=arnd@arndb.de \
--cc=linux-arch@vger.kernel.org \
--cc=linux-kbuild@vger.kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-parisc@vger.kernel.org \
--cc=matt@console-pimps.org \
--cc=mmarek@suse.cz \
--cc=sam@ravnborg.org \
--cc=sfr@canb.auug.org.au \
--cc=tabbott@ksplice.com \
--cc=tim.bird@am.sony.com \
/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