Return-Path: Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1753148AbbBMMEx (ORCPT ); Fri, 13 Feb 2015 07:04:53 -0500 Received: from mail-lb0-f180.google.com ([209.85.217.180]:39862 "EHLO mail-lb0-f180.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1752721AbbBMMEv (ORCPT ); Fri, 13 Feb 2015 07:04:51 -0500 From: Rasmus Villemoes To: David Laight Cc: Mark Rustad , "Rustad\, Mark D" , Stanislaw Gruszka , Kalle Valo , "linux-wireless\@vger.kernel.org" , "netdev\@vger.kernel.org" , "linux-kernel\@vger.kernel.org" Subject: Re: [PATCH] iwl4965: Enable checking of format strings Organization: D03 References: <1423695069-23436-1-git-send-email-linux@rasmusvillemoes.dk> <60178C37-F104-430E-92EB-B6DDFAEB2F99@intel.com> <87vbj7zb0e.fsf@rasmusvillemoes.dk> <54DDAE03.4000502@gmail.com> <87y4o2xfgz.fsf@rasmusvillemoes.dk> <063D6719AE5E284EB5DD2968C1650D6D1CAE3325@AcuExch.aculab.com> X-Hashcash: 1:20:150213:netdev@vger.kernel.org::W54T93T6ChDWmtaQ:0000000000000000000000000000000000000000IQr X-Hashcash: 1:20:150213:sgruszka@redhat.com::9XrQzAk/qjp9Q0Tq:0000000000000000000000000000000000000000000FS7 X-Hashcash: 1:20:150213:david.laight@aculab.com::BYc2lMYjtrnwBUrO:000000000000000000000000000000000000001gmd X-Hashcash: 1:20:150213:mrustad@gmail.com::WYaw3viGSPC1Pdu1:000000000000000000000000000000000000000000001cmT X-Hashcash: 1:20:150213:linux-wireless@vger.kernel.org::AhhEWg7/EtG7WTmz:00000000000000000000000000000002bDX X-Hashcash: 1:20:150213:kvalo@codeaurora.org::a8CejpGfGFH2HikT:000000000000000000000000000000000000000005+ha X-Hashcash: 1:20:150213:mark.d.rustad@intel.com::dcKTR0rgOdOB8MHG:000000000000000000000000000000000000006W0k X-Hashcash: 1:20:150213:linux-kernel@vger.kernel.org::C8LcqTJPvyNedOgI:0000000000000000000000000000000005n9e Date: Fri, 13 Feb 2015 13:04:47 +0100 In-Reply-To: <063D6719AE5E284EB5DD2968C1650D6D1CAE3325@AcuExch.aculab.com> (David Laight's message of "Fri, 13 Feb 2015 11:20:47 +0000") Message-ID: <87twyqxbj4.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 Content-Length: 1456 Lines: 35 On Fri, Feb 13 2015, David Laight wrote: > From: Rasmus Villemoes >> Well, probably the linker is allowed to overlap "anonymous" objects >> (string literals) with whatever const char[] (or indeed any const) >> object it finds containing the appropriate byte sequence. But I think >> language lawyers would insist that for >> >> const char foo[] = "a string"; >> const char bar[] = "a string"; > > A quick test shows those are separate strings. > But 'const char *foo = "xxx";' will share. Yes, of course, because in that case you are actually creating two objects, "xxx" which the linker will find some place to put, and foo which is initialized to the address of whereever "xxx" was/will be put. So one is wasting sizeof(const char*). Also, passing foo to a function means the compiler has to load the value of foo and use that, instead of simply passing the compile-time (well, link-time) constant address of "xxx". > You also need -O1 to get the strings into .rodata.str.n so that the linker > can merge them. Sure, optimization has to be turned on, but isn't the kernel always compiled with -O2? ISTR that there are some things which won't even work/compile with -O0. Rasmus -- 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/