From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1752214AbbCZQNQ (ORCPT ); Thu, 26 Mar 2015 12:13:16 -0400 Received: from smtprelay0158.hostedemail.com ([216.40.44.158]:44715 "EHLO smtprelay.hostedemail.com" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S1751212AbbCZQNO (ORCPT ); Thu, 26 Mar 2015 12:13:14 -0400 X-Session-Marker: 6A6F6540706572636865732E636F6D X-Spam-Summary: 50,0,0,,d41d8cd98f00b204,joe@perches.com,:::::::::,RULES_HIT:41:355:379:541:599:960:967:973:988:989:1260:1263:1277:1311:1313:1314:1345:1359:1373:1437:1515:1516:1518:1534:1542:1593:1594:1711:1730:1747:1777:1792:2393:2525:2561:2564:2682:2685:2692:2828:2859:2902:2933:2937:2939:2942:2945:2947:2951:2954:3022:3138:3139:3140:3141:3142:3315:3355:3622:3865:3867:3870:3871:3872:3873:3874:3934:3936:3938:3941:3944:3947:3950:3953:3956:3959:4321:4605:5007:6117:6119:6261:7903:7904:8599:8957:9025:9040:10004:10400:10450:10455:10848:11232:11658:11914:12043:12517:12519:12555:12740:14096:14097:19904:19999:21080,0,RBL:none,CacheIP:none,Bayesian:0.5,0.5,0.5,Netcheck:none,DomainCache:0,MSF:not bulk,SPF:fn,MSBL:0,DNSBL:none,Custom_rules:0:0:0 X-HE-Tag: seat15_390b8e85bf702 X-Filterd-Recvd-Size: 3703 Message-ID: <1427386390.15849.13.camel@perches.com> Subject: Re: String literals in __init functions From: Joe Perches To: Mason Cc: Linux ARM , LKML , Ingo Molnar , Mathias Krause Date: Thu, 26 Mar 2015 09:13:10 -0700 In-Reply-To: <5513FE2F.3040306@free.fr> References: <5512F6C6.1020304@free.fr> <1427306517.2717.0.camel@perches.com> <5513FE2F.3040306@free.fr> Content-Type: text/plain; charset="ISO-8859-1" X-Mailer: Evolution 3.12.10-0ubuntu1~14.10.1 Mime-Version: 1.0 Content-Transfer-Encoding: 7bit Sender: linux-kernel-owner@vger.kernel.org List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Thu, 2015-03-26 at 13:40 +0100, Mason wrote: > On 25/03/2015 19:01, Joe Perches wrote: > > On Wed, 2015-03-25 at 18:56 +0100, Mason wrote: > > > >> AFAIU, functions only used at system init are tagged __init to have > >> the linker store them in a separate .init.text section, so memory can > >> be reclaimed once initialization is complete. Is that correct? > >> > >> The corresponding tag for data is __initdata (section .init.data) > >> > >> I started wondering if the string literals used in an __init functions > >> were automatically marked __initdata. > >> > >> Looking at the objdump output, I see that the string literals are, > >> in fact, stored in the .rodata section. I suppose that .rodata is NOT > >> reclaimed after init? > >> > >> This way seems to work: > >> > >> static char XyZa[] __initdata = KERN_ALERT "foo"; > >> static const char XyZb[] __initconst = KERN_ALERT "bar"; > >> void __init XyZc(void) { printk(XyZa); printk(XyZb); } > >> > >> $ arm-linux-gnueabihf-objdump -xd arch/arm/mach-tangox/time.o | grep XyZ > >> 00000000 l O .init.data 00000006 XyZa > >> 00000000 l O .init.rodata 00000006 XyZb > >> 00000000 g F .init.text 00000028 XyZc > >> 00000000 : > >> > >> $ arm-linux-gnueabihf-objdump -xd vmlinux | grep XyZ > >> c021e360 l O .init.data 00000006 XyZa > >> c0220090 l O .init.data 00000006 XyZb > >> c020d928 g F .init.text 00000028 XyZc > >> c020d928 : > >> > >> c020d928 : > >> c020d928: e1a0c00d mov ip, sp > >> c020d92c: e92dd800 push {fp, ip, lr, pc} > >> c020d930: e24cb004 sub fp, ip, #4 > >> c020d934: e30e0360 movw r0, #58208 ; 0xe360 > >> c020d938: e34c0021 movt r0, #49185 ; 0xc021 > >> c020d93c: ebfe00c9 bl c018dc68 > >> c020d940: e3000090 movw r0, #144 ; 0x90 > >> c020d944: e34c0022 movt r0, #49186 ; 0xc022 > >> c020d948: ebfe00c6 bl c018dc68 > >> c020d94c: e89da800 ldm sp, {fp, sp, pc} > >> > >> Did I miss something in init.h? > >> Or should it be done like above to reclaim string literals? > > > > No, you didn't miss anything. > > > > One proposal: > > > > https://lkml.org/lkml/2014/8/21/255 > > Thanks for the link! > > Here's the equivalent gmane link for my own reference: > http://thread.gmane.org/gmane.linux.kernel/1771969 > > Basically, if I understand correctly, Ingo NAKed the patch, saying > this should be done automatically by the toolchain. That would make > for an interesting side-project... True. It's probably not feasible though. Tracking string deduplication/reuse would be pretty difficult.