From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1755272AbaFYHfy (ORCPT ); Wed, 25 Jun 2014 03:35:54 -0400 Received: from mail-lb0-f170.google.com ([209.85.217.170]:38193 "EHLO mail-lb0-f170.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1755219AbaFYHfl (ORCPT ); Wed, 25 Jun 2014 03:35:41 -0400 From: Rasmus Villemoes To: Mathias Krause Cc: Joe Perches , "linux-kernel\@vger.kernel.org" , Andrew Morton , Greg Kroah-Hartman , Steven Rostedt , "Rafael J. Wysocki" , Thomas Gleixner , Ingo Molnar , "H. Peter Anvin" Subject: Re: [RFC PATCH 0/3] Mark literal strings in __init / __exit code Organization: D03 References: <1403477209-14612-1-git-send-email-minipli@googlemail.com> <1403477762.18747.14.camel@joe-AO725> <1403505219.18747.37.camel@joe-AO725> <87egyeqt03.fsf@rasmusvillemoes.dk> <1403638620.29061.35.camel@joe-AO725> <1403641843.29061.51.camel@joe-AO725> <1403643440.29061.56.camel@joe-AO725> <1403646310.29061.61.camel@joe-AO725> X-Hashcash: 1:20:140625:gregkh@linuxfoundation.org::/JjoELSP4t8OjNLo:000000000000000000000000000000000000OjV X-Hashcash: 1:20:140625:joe@perches.com::kEoyCnECZFNWsRbT:000Iy8 X-Hashcash: 1:20:140625:hpa@zytor.com::7siGke/k2QhFfz5l:00000vPy X-Hashcash: 1:20:140625:minipli@googlemail.com::nKZ54ARkh7KPd3yJ:0000000000000000000000000000000000000001PRx X-Hashcash: 1:20:140625:mingo@redhat.com::IoB/laHC/27/clxC:02q08 X-Hashcash: 1:20:140625:rjw@rjwysocki.net::WiUpeJ5cpXCYepht:000000000000000000000000000000000000000000003+4u X-Hashcash: 1:20:140625:tglx@linutronix.de::Wz2FezmrQUttNHS9:00000000000000000000000000000000000000000003RwG X-Hashcash: 1:20:140625:akpm@linux-foundation.org::PBeH7xItTg5p+xt+:00000000000000000000000000000000000046C9 X-Hashcash: 1:20:140625:linux-kernel@vger.kernel.org::G2ESKd2a+Z4mo2zX:0000000000000000000000000000000005rvz X-Hashcash: 1:20:140625:rostedt@goodmis.org::gOq41nWOoq4Q05q4:0000000000000000000000000000000000000000007MYY Date: Wed, 25 Jun 2014 09:35:36 +0200 In-Reply-To: (Mathias Krause's message of "Wed, 25 Jun 2014 07:55:47 +0200") Message-ID: <877g45qw53.fsf@rasmusvillemoes.dk> User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/24.3 (gnu/linux) MIME-Version: 1.0 Content-Type: text/plain Sender: linux-kernel-owner@vger.kernel.org List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Mathias Krause writes: > On 24 June 2014 16:31, Rasmus Villemoes wrote: >> gcc already seems to contain infrastructure for this kind of thing, so >> maybe it doesn't even require a plugin, but simply a little coordination >> with the gcc folks. This snippet from gcc internals seems relevant: >> >> -- Target Hook: section * TARGET_ASM_FUNCTION_RODATA_SECTION (tree >> DECL) >> Return the readonly data section associated with 'DECL_SECTION_NAME >> (DECL)'. The default version of this function selects >> '.gnu.linkonce.r.name' if the function's section is >> '.gnu.linkonce.t.name', '.rodata.name' if function is in >> '.text.name', and the normal readonly-data section otherwise. >> > > I don't think it's that easy. You cannot simply put all strings into > the .init.rodata section when code currently gets emitted to > .init.text. The reason is because strings used in __init code might be > referenced later on, too. For example, the name passed to > class_create() won't be copied. Right, didn't think about that, so yes, the source would need to be annotated some way or other, or gcc would need to learn the semantics of certain kernel functions. Speaking of dangling pointers: A similar disaster would happen if some code containing pi_* calls gets copy-pasted to some non-__init function. Could checkpatch learn to warn about calling these functions from the wrong context? Mathias Krause writes: > Merging strings across multiple compilation units does not happen, > anyway -- not now, not with the new macros. Certainly string merging seems to happen, at least at -O1 and higher: $ grep . *.c a.c:const char *a(void) { return "654321"; } b.c:const char *b(void) { return "4321"; } c.c:const char *c(void) { return "654321"; } main.c:#include main.c:const char *a(void); main.c:const char *b(void); main.c:const char *c(void); main.c:int main(void) main.c:{ main.c: printf("%p\n", a()); main.c: printf("%p\n", b()); main.c: printf("%p\n", c()); main.c: return 0; main.c:} $ gcc -O1 -c a.c && gcc -O1 -c b.c && gcc -O1 -c c.c $ gcc -O1 main.c a.o b.o c.o $ ./a.out 0x400630 0x400632 0x400630 So not only are identical strings merged; suffixes are also optimized. Rasmus