From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 17068 invoked by alias); 16 Aug 2017 18:44:18 -0000 Mailing-List: contact gdb-patches-help@sourceware.org; run by ezmlm Precedence: bulk List-Id: List-Subscribe: List-Archive: List-Post: List-Help: , Sender: gdb-patches-owner@sourceware.org Received: (qmail 17037 invoked by uid 89); 16 Aug 2017 18:44:16 -0000 Authentication-Results: sourceware.org; auth=none X-Virus-Found: No X-Spam-SWARE-Status: No, score=-2.4 required=5.0 tests=AWL,BAYES_00,RP_MATCHES_RCVD,SPF_HELO_PASS,SPF_PASS autolearn=ham version=3.3.2 spammy=releasing, visibly, blurred X-HELO: smtp.polymtl.ca Received: from smtp.polymtl.ca (HELO smtp.polymtl.ca) (132.207.4.11) by sourceware.org (qpsmtpd/0.93/v0.84-503-g423c35a) with ESMTP; Wed, 16 Aug 2017 18:44:14 +0000 Received: from simark.ca (simark.ca [158.69.221.121]) (authenticated bits=0) by smtp.polymtl.ca (8.14.7/8.14.7) with ESMTP id v7GIi8lo008328 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT) for ; Wed, 16 Aug 2017 14:44:13 -0400 Received: by simark.ca (Postfix, from userid 112) id 1F8A61EA1D; Wed, 16 Aug 2017 14:44:08 -0400 (EDT) Received: from simark.ca (localhost [127.0.0.1]) by simark.ca (Postfix) with ESMTP id 339A81E5E1; Wed, 16 Aug 2017 14:44:07 -0400 (EDT) MIME-Version: 1.0 Content-Type: text/plain; charset=US-ASCII; format=flowed Content-Transfer-Encoding: 7bit Date: Wed, 16 Aug 2017 18:44:00 -0000 From: Simon Marchi To: Pedro Alves Cc: Simon Marchi , gdb-patches@sourceware.org Subject: Re: [PATCH 0/3] Create arch_lwp_info class hierarchy In-Reply-To: References: <1500892797-7523-1-git-send-email-simon.marchi@ericsson.com> <22f9058d-52de-293a-eef8-6af1572955d0@redhat.com> Message-ID: X-Sender: simon.marchi@polymtl.ca User-Agent: Roundcube Webmail/1.3.0 X-Poly-FromMTA: (simark.ca [158.69.221.121]) at Wed, 16 Aug 2017 18:44:08 +0000 X-IsSubscribed: yes X-SW-Source: 2017-08/txt/msg00325.txt.bz2 On 2017-08-14 13:53, Pedro Alves wrote: > On 08/12/2017 12:29 PM, Simon Marchi wrote: > >> But then I realized that I forgot to include the header for s390, and >> the compiler (when building for a s390 host) didn't warn me. This is >> dangerous and fragile since we end up with two definitions of >> arch_lwp_info (the s390 one and that fallback one), and nothing to >> warn >> about it. > > Not sure whether that's really such a bad problem. It seems like the > sort of thing that'd crash quite visibly/quickly if you actually try to > run the resulting binary. It's not like we're adding ports > every day. :-) How would it crash visibly? I thought it would most likely crash or corrupt memory seemingly randomly. That's irrelevant because of you suggestion below, but I'm asking just for the sake of the discussion. >> So I changed it to listing explicitly the architectures that >> don't defined their own arch_lwp_info: >> >> ... >> #elif defined __alpha__ || defined __powerpc__ || ... >> /* Define a dummy arch_lwp_info for arches that don't define one. */ >> struct arch_lwp_info {}; >> #else >> # error "Missing arch-specific include." >> #endif >> >> That would work, but requires listing all the arches that need the >> fallback definition of arch_lwp_info, so it gets pretty ugly. >> >> Any idea to make this simple but safe? Otherwise, I'll just go with >> the >> current version of the patch. > > There's a 3rd, much simpler option. > > The problem we ran into is one of blurred division of responsibility: > the > arch-specific code is responsible for allocating the arch-specific > arch_lwp_info, which it must be, because it's not possible to allocate > an > incomplete type (must know its size), but we free the object in common > code, > where the type is opaque. > > We can solve the original xfree poisoning problem by simply making the > arch-specific code responsible for releasing arch_lwp_info too, where > the > type is known, just like it is responsible for allocating it. > > See below a proof of concept doing that for the x86 port. Making other > archs do the same should be trivial. Using new/delete/cdtors/in-class > initialization for arch_lwp_info would be a separate, orthogonal change > (and so would class-ification of linux_nat_new_thread, > linux_target_ops, > etc.). Yes, that makes sense. I'll try that. Thanks for the prototype. Simon