Return-Path: Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1756732Ab0G1XtG (ORCPT ); Wed, 28 Jul 2010 19:49:06 -0400 Received: from mail-fx0-f46.google.com ([209.85.161.46]:33096 "EHLO mail-fx0-f46.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1752508Ab0G1XsR (ORCPT ); Wed, 28 Jul 2010 19:48:17 -0400 DomainKey-Signature: a=rsa-sha1; c=nofws; d=googlemail.com; s=gamma; h=from:to:cc:subject:date:message-id:x-mailer:in-reply-to:references; b=iS0s8917TVLBBIOinlFXnQdLZA6zc7onc2TgpNJcvu4M56ruHTtYRTkYvZS25886uh d/lBijZAYeBXKLs849J728I0ujhx0JnUbvdJsoSNyCk2PMBDXw37z0D1ct2+W7aMD78v soun2N+recsj5RlGq5YlUYxn4CwibJlO70TY8= From: Denys Vlasenko To: Michal Marek , linux-kbuild , linux-arch@vger.kernel.org, Parisc List Cc: lkml , Sam Ravnborg , Tim Abbott , Tim Bird , James Bottomley , Matt Fleming , Arnd Bergmann , Anders Kaseorg , Andi Kleen , Stephen Rothwell , Denys Vlasenko Subject: [PATCH 2/4] module linker script: coalesce function and data sections Date: Thu, 29 Jul 2010 01:47:54 +0200 Message-Id: <1280360876-2571-3-git-send-email-vda.linux@googlemail.com> X-Mailer: git-send-email 1.6.2.5 In-Reply-To: <1280360876-2571-1-git-send-email-vda.linux@googlemail.com> References: <1280360876-2571-1-git-send-email-vda.linux@googlemail.com> Sender: linux-kernel-owner@vger.kernel.org List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Length: 2391 Lines: 62 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 Acked-by: Sam Ravnborg --- 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 -- To unsubscribe from this list: send the line "unsubscribe linux-kernel" in the body of a message to majordomo@vger.kernel.org More majordomo info at http://vger.kernel.org/majordomo-info.html Please read the FAQ at http://www.tux.org/lkml/