From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from eggs.gnu.org ([2001:4830:134:3::10]:38672) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1ageJa-0001gu-O3 for qemu-devel@nongnu.org; Thu, 17 Mar 2016 16:14:39 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1ageJR-0006Rz-NU for qemu-devel@nongnu.org; Thu, 17 Mar 2016 16:14:38 -0400 Received: from mail-qg0-x235.google.com ([2607:f8b0:400d:c04::235]:34724) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1ageJR-0006Ru-IC for qemu-devel@nongnu.org; Thu, 17 Mar 2016 16:14:29 -0400 Received: by mail-qg0-x235.google.com with SMTP id w104so82327826qge.1 for ; Thu, 17 Mar 2016 13:14:29 -0700 (PDT) Sender: Richard Henderson References: <87wpp4m6n1.fsf@blackfin.pond.sub.org> <20160315133916.GM27203@stefanha-x1.localdomain> <20160315135647.GB11728@work-vm> <20160316182343.GE2012@stefanha-x1.localdomain> <20160316182748.GG2246@work-vm> <20160317112508.GG14062@stefanha-x1.localdomain> <20160317162900.GK5966@work-vm> <56EB03D0.6010209@redhat.com> From: Richard Henderson Message-ID: <56EB1021.5040100@twiddle.net> Date: Thu, 17 Mar 2016 13:14:25 -0700 MIME-Version: 1.0 In-Reply-To: <56EB03D0.6010209@redhat.com> Content-Type: text/plain; charset=windows-1252 Content-Transfer-Encoding: 7bit Subject: Re: [Qemu-devel] Our use of #include is undisciplined, and what to do about it List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , To: Paolo Bonzini , "Dr. David Alan Gilbert" , Stefan Hajnoczi Cc: Peter Maydell , qemu-devel@nongnu.org, Markus Armbruster , =?UTF-8?Q?Llu=c3=ads_Vilanova?= On 03/17/2016 12:21 PM, Paolo Bonzini wrote: > That however makes you waste a lot of cache on trace_events_dstate > (commit 585ec72, "trace: track enabled events in a separate array", > 2016-02-03). I must say I'm not really convinced by that patch, since I don't see that there's much locality between the ID's that would be polled. > Perhaps we get the linker to do compute the id, for example by using a > separate data section and then use te-&te_first to compute the id... > Richard, do you have ideas on how to do this in a reasonably portable > manner? That works for all of the hosts we care about (ELF and MachO). All you need is "crt0"/"crtn" files to force to be first and last, placing symbols in known sections. Then emit all of the "id"s as symbols in those sections. E.g. for an event FOO, generate bool trace_event_FOO_dstate __attribute__((section(".bss.trace_event_dstate"))); TraceEvent trace_event_FOO __attribute__((section(".bss.trace_event"))); For portability, you must put the section attribute on the extern declaration as well, lest the compiler make assumptions about small variables living in ".sbss" or the like, and thus being addressable with gp-relative offsets. See gcc's crtstuff.c for examples of how to write the crt files. Or, if you value your sanity, don't. ;-) r~