From patchwork Mon Feb 4 20:24:41 2013 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jack Howarth X-Patchwork-Id: 218060 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Received: from sourceware.org (server1.sourceware.org [209.132.180.131]) by ozlabs.org (Postfix) with SMTP id 5E26F2C02E9 for ; Tue, 5 Feb 2013 07:25:04 +1100 (EST) Comment: DKIM? See http://www.dkim.org DKIM-Signature: v=1; a=rsa-sha1; c=relaxed/relaxed; d=gcc.gnu.org; s=default; x=1360614305; h=Comment: DomainKey-Signature:Received:Received:Received:Received:Received: Date:From:To:Cc:Subject:Message-ID:References:MIME-Version: Content-Type:Content-Disposition:In-Reply-To:User-Agent: Mailing-List:Precedence:List-Id:List-Unsubscribe:List-Archive: List-Post:List-Help:Sender:Delivered-To; bh=KbVpexiEBdEdTfqF1yc+ Cts55hA=; b=yr4+8nswc9UrSRhkAMiHIgfLlVg9W/xQ9otsQ5SgvHjAgMhuW+jw nsA+EMSuuM60vzk/kFO5VO55GxvV6vb+c6kCDG1ZlsaFamyA6gBFGbyMDJf+YV7O L5l9qKCThbnaHbH6YL9WQ6TL9FlnBcCwzTEn5uebg05of1k4SZWXEhI= Comment: DomainKeys? See http://antispam.yahoo.com/domainkeys DomainKey-Signature: a=rsa-sha1; q=dns; c=nofws; s=default; d=gcc.gnu.org; h=Received:Received:X-SWARE-Spam-Status:X-Spam-Check-By:Received:Received:Received:Date:From:To:Cc:Subject:Message-ID:References:MIME-Version:Content-Type:Content-Disposition:In-Reply-To:User-Agent:Mailing-List:Precedence:List-Id:List-Unsubscribe:List-Archive:List-Post:List-Help:Sender:Delivered-To; b=xnN6cO6twx3ibb5ohQAiI0A1D3Rnp49d/lYpsHTQd49JCzoXz25yh1P6kGL2iJ z4M2QBxBEHoZYmvUhwmg3GxXgc/cvI1aEvYhN5dHZwBjVd1c8L8rLatMfIerr7Ih h8wKlUFpS3aXTmfAUGmUBbvCUuoxBNrCJSGq0hUyxmzCo=; Received: (qmail 13977 invoked by alias); 4 Feb 2013 20:24:55 -0000 Received: (qmail 13959 invoked by uid 22791); 4 Feb 2013 20:24:50 -0000 X-SWARE-Spam-Status: No, hits=-1.7 required=5.0 tests=AWL, BAYES_00, RP_MATCHES_RCVD, SARE_SUB_OBFU_Q1 X-Spam-Check-By: sourceware.org Received: from bromo.med.uc.edu (HELO bromo.med.uc.edu) (129.137.3.146) by sourceware.org (qpsmtpd/0.43rc1) with ESMTP; Mon, 04 Feb 2013 20:24:43 +0000 Received: from bromo.med.uc.edu (localhost.localdomain [127.0.0.1]) by bromo.med.uc.edu (Postfix) with ESMTP id C1EB7B0011; Mon, 4 Feb 2013 15:24:42 -0500 (EST) Received: (from howarth@localhost) by bromo.med.uc.edu (8.14.3/8.14.3/Submit) id r14KOfgh024856; Mon, 4 Feb 2013 15:24:41 -0500 Date: Mon, 4 Feb 2013 15:24:41 -0500 From: Jack Howarth To: Mike Stump Cc: gcc-patches@gcc.gnu.org, jakub@redhat.com, glider@google.com, dodji@redhat.com, kcc@google.com, dvyukov@google.com, iain@codesourcery.com Subject: Re: [PATCH] fix PR sanitizer/55617 via qsort Message-ID: <20130204202441.GA24850@bromo.med.uc.edu> References: <20130204172259.GA23606@bromo.med.uc.edu> MIME-Version: 1.0 Content-Disposition: inline In-Reply-To: User-Agent: Mutt/1.5.18 (2008-05-17) Mailing-List: contact gcc-patches-help@gcc.gnu.org; run by ezmlm Precedence: bulk List-Id: List-Unsubscribe: List-Archive: List-Post: List-Help: Sender: gcc-patches-owner@gcc.gnu.org Delivered-To: mailing list gcc-patches@gcc.gnu.org On Mon, Feb 04, 2013 at 12:12:36PM -0800, Mike Stump wrote: > On Feb 4, 2013, at 11:23 AM, Mike Stump wrote: > > On Feb 4, 2013, at 9:22 AM, Jack Howarth wrote: > >> Currently darwin is unable to utilize libasan with constructors due to the lack of > >> constructor priority support on that target. > > > >> Okay for gcc trunk? > > > > Since asan doesn't need cross translation unit priorities, the patch is sufficient to fix all of the semantics needed for asan. > > > Ok. > > Committed revision 195735. > > Note, this doesn't have the test case in it. Please repost just the test case, thanks. Mike, Sorry about that. Complete patch with testcase attached. I am currently testing the dtors sorting. Jack /gcc 2013-02-04 Alexander Potapenko Jack Howarth Jakub Jelinek PR sanitizer/55617 * config/darwin.c (sort_ctor_records): Stabilized qsort on constructor priority by using original position. (finalize_ctors): New routine to sort constructors by priority before use in assemble_integer. (machopic_asm_out_constructor): Use finalize_ctors if needed. /gcc/testsuite 2013-02-04 Alexander Potapenko Jack Howarth Jakub Jelinek PR sanitizer/55617 * g++.dg/asan/pr55617.C: New test. Index: gcc/config/darwin.c =================================================================== --- gcc/config/darwin.c (revision 195685) +++ gcc/config/darwin.c (working copy) @@ -83,6 +83,14 @@ along with GCC; see the file COPYING3. kernel) the stubs might still be required, and this will be set true. */ int darwin_emit_branch_islands = false; +typedef struct GTY(()) ctor_record { + rtx symbol; + int priority; /* constructor priority */ + int position; /* original position */ +} ctor_record; + +static GTY(()) vec *ctors = NULL; + /* A flag to determine whether we are running c++ or obj-c++. This has to be settable from non-c-family contexts too (i.e. we can't use the c_dialect_ functions). */ @@ -1708,15 +1716,48 @@ machopic_select_rtx_section (enum machin void machopic_asm_out_constructor (rtx symbol, int priority ATTRIBUTE_UNUSED) { + ctor_record new_elt = {symbol, priority, vec_safe_length (ctors)}; + + vec_safe_push (ctors, new_elt); + + if (! MACHOPIC_INDIRECT) + fprintf (asm_out_file, ".reference .constructors_used\n"); +} + +static int +sort_ctor_records (const void * a, const void * b) +{ + const ctor_record *ca = (const ctor_record *)a; + const ctor_record *cb = (const ctor_record *)b; + if (ca->priority > cb->priority) + return 1; + if (ca->priority < cb->priority) + return -1; + if (ca->position > cb->position) + return 1; + if (ca->position < cb->position) + return -1; + return 0; +} + +static void +finalize_ctors() +{ + unsigned int i; + ctor_record *elt; + if (MACHOPIC_INDIRECT) switch_to_section (darwin_sections[mod_init_section]); else switch_to_section (darwin_sections[constructor_section]); - assemble_align (POINTER_SIZE); - assemble_integer (symbol, POINTER_SIZE / BITS_PER_UNIT, POINTER_SIZE, 1); - if (! MACHOPIC_INDIRECT) - fprintf (asm_out_file, ".reference .constructors_used\n"); + if (vec_safe_length (ctors) > 1) + ctors->qsort (sort_ctor_records); + FOR_EACH_VEC_SAFE_ELT (ctors, i, elt) + { + assemble_align (POINTER_SIZE); + assemble_integer (elt->symbol, POINTER_SIZE / BITS_PER_UNIT, POINTER_SIZE, 1); + } } void @@ -2762,6 +2803,8 @@ darwin_file_start (void) void darwin_file_end (void) { + if (!vec_safe_is_empty (ctors)) + finalize_ctors(); machopic_finish (asm_out_file); if (strcmp (lang_hooks.name, "GNU C++") == 0) { --- /dev/null 2013-02-02 10:53:51.000000000 -0500 +++ gcc/testsuite/g++.dg/asan/pr55617.C 2013-02-02 10:22:17.000000000 -0500 @@ -0,0 +1,8 @@ +// { dg-do run { target { i?86-*-darwin* x86_64-*-darwin* } } } + +struct c18 { + virtual void bar() { } +}; +c18 ret; +int main () { +}