From patchwork Sun Oct 31 14:59:43 2010 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Iain Sandoe X-Patchwork-Id: 69716 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 E863D1007D2 for ; Mon, 1 Nov 2010 02:00:17 +1100 (EST) Received: (qmail 6939 invoked by alias); 31 Oct 2010 15:00:16 -0000 Received: (qmail 6925 invoked by uid 22791); 31 Oct 2010 15:00:14 -0000 X-SWARE-Spam-Status: No, hits=-1.9 required=5.0 tests=AWL, BAYES_00, RCVD_IN_DNSWL_NONE X-Spam-Check-By: sourceware.org Received: from c2beaomr10.btconnect.com (HELO mail.btconnect.com) (213.123.26.188) by sourceware.org (qpsmtpd/0.43rc1) with ESMTP; Sun, 31 Oct 2010 15:00:05 +0000 Received: from host81-138-1-83.in-addr.btopenworld.com (EHLO thor.office) ([81.138.1.83]) by c2beaomr10.btconnect.com with ESMTP id ALX24950; Sun, 31 Oct 2010 14:59:46 +0000 (GMT) Cc: Richard Henderson , GCC Patches Message-Id: <3666E272-5A54-40B0-A8EF-BFC2A1342F75@sandoe-acoustics.co.uk> From: IainS To: Mike Stump In-Reply-To: <4CCC5DDB.8060300@redhat.com> Mime-Version: 1.0 (Apple Message framework v936) Subject: different impl. Re: [Patch darwin, debug] make debug section starts explicit. Date: Sun, 31 Oct 2010 14:59:43 +0000 References: <4CCB3644.2040408@redhat.com> <9A74A8A1-8385-4258-B953-476DEE18E2C0@sandoe-acoustics.co.uk> <4CCC5DDB.8060300@redhat.com> X-Mirapoint-IP-Reputation: reputation=Fair-1, source=Queried, refid=tid=0001.0A0B0301.4CCD8460.00C3, actions=tag X-Junkmail-Signature-Raw: score=unknown, refid=str=0001.0A0B020B.4CCD8463.00D3, ss=1, fgs=0, ip=0.0.0.0, so=2010-07-22 22:03:31, dmn=2009-09-10 00:05:08, mode=single engine X-IsSubscribed: yes 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 30 Oct 2010, at 19:03, Richard Henderson wrote: > On 10/30/2010 01:07 AM, IainS wrote: >> Ah well, something to consider for 4.7 ;-) ... > > This *is* a bug fix, isn't it? If so, you don't have to > wait for stage1 to open up again. You've got 2 months... I had missed the obvious ... that we gained a "darwin_asm_named_section" along with lto... ... this is not as neat as Richard's suggestion... ... but it is entirely local to darwin (and roughly the same amount of work "is it dwarf debug? yes.. did we emit this section yet? if no ... then put a label" ) if Mike is OK with this... , it does the job. OK for trunk? Iain gcc: * config/darwin.c (darwin_asm_named_section): Check for __DWARF sections. (darwin_asm_dwarf_section): New. (darwin_file_start): Remove code emitting dwarf section symbols. Index: gcc/config/darwin.c =================================================================== --- gcc/config/darwin.c (revision 166092) +++ gcc/config/darwin.c (working copy) @@ -1459,6 +1459,11 @@ darwin_asm_lto_end (void) saved_asm_out_file = NULL; } +static void +darwin_asm_dwarf_section (const char *name, unsigned int flags, tree decl); + +/* Called for the TARGET_ASM_NAMED_SECTION hook. */ + void darwin_asm_named_section (const char *name, unsigned int flags, @@ -1495,6 +1500,8 @@ darwin_asm_named_section (const char *name, gcc_assert (lto_section_names_offset > 0 && lto_section_names_offset < ((unsigned) 1 << 31)); } + else if (strncmp (name, "__DWARF,", 8) == 0) + darwin_asm_dwarf_section (name, flags, decl); else fprintf (asm_out_file, "\t.section %s\n", name); } @@ -1675,6 +1682,73 @@ darwin_assemble_visibility (tree decl, int vis) "not supported in this configuration; ignored"); } +/* VEC Used by darwin_asm_dwarf_section. + Maybe a hash tab would be better here - but the intention is that this is + a very short list (fewer than 16 items) and each entry should (ideally, + eventually) only be presented once. + + A structure to hold a dwarf debug section used entry. */ + +typedef struct GTY(()) dwarf_sect_used_entry { + const char *name; + unsigned count; +} +dwarf_sect_used_entry; + +DEF_VEC_O(dwarf_sect_used_entry); +DEF_VEC_ALLOC_O(dwarf_sect_used_entry, gc); + +/* A list of used __DWARF sections. */ +static GTY (()) VEC (dwarf_sect_used_entry, gc) * dwarf_sect_names_table; + +/* This is called when we are asked to assemble a named section and the + name begins with __DWARF,. We keep a list of the section names (without + the __DWARF, prefix) and use this to emit our required start label on the + first switch to each section. */ + +static void +darwin_asm_dwarf_section (const char *name, unsigned int flags, + tree ARG_UNUSED (decl)) +{ + unsigned i; + int namelen; + const char * sname; + dwarf_sect_used_entry *ref; + bool found = false; + gcc_assert ((flags & (SECTION_DEBUG | SECTION_NAMED)) + == (SECTION_DEBUG | SECTION_NAMED)); + /* We know that the name starts with __DWARF, */ + sname = name + 8; + namelen = strchr (sname, ',') - sname; + gcc_assert (namelen); + if (dwarf_sect_names_table == NULL) + dwarf_sect_names_table = VEC_alloc (dwarf_sect_used_entry, gc, 16); + else + for (i = 0; + VEC_iterate (dwarf_sect_used_entry, dwarf_sect_names_table, i, ref); + i++) + { + if (!ref) + break; + if (!strcmp (ref->name, sname)) + { + found = true; + ref->count++; + break; + } + } + + fprintf (asm_out_file, "\t.section %s\n", name); + if (!found) + { + dwarf_sect_used_entry e; + fprintf (asm_out_file, "Lsection%.*s:\n", namelen, sname); + e.count = 1; + e.name = xstrdup (sname); + VEC_safe_push (dwarf_sect_used_entry, gc, dwarf_sect_names_table, &e); + } +} + /* Output a difference of two labels that will be an assembly time constant if the two labels are local. (.long lab1-lab2 will be very different if lab1 is at the boundary between two sections; it @@ -1703,49 +1777,6 @@ darwin_asm_output_dwarf_delta (FILE *file, int siz fprintf (file, "\n\t%s L$set$%d", directive, darwin_dwarf_label_counter++); } -/* Output labels for the start of the DWARF sections if necessary. - Initialize the stuff we need for LTO long section names support. */ -void -darwin_file_start (void) -{ - if (write_symbols == DWARF2_DEBUG) - { - static const char * const debugnames[] = - { - DEBUG_FRAME_SECTION, - DEBUG_INFO_SECTION, - DEBUG_ABBREV_SECTION, - DEBUG_ARANGES_SECTION, - DEBUG_MACINFO_SECTION, - DEBUG_LINE_SECTION, - DEBUG_LOC_SECTION, - DEBUG_PUBNAMES_SECTION, - DEBUG_PUBTYPES_SECTION, - DEBUG_STR_SECTION, - DEBUG_RANGES_SECTION - }; - size_t i; - - for (i = 0; i < ARRAY_SIZE (debugnames); i++) - { - int namelen; - - switch_to_section (get_section (debugnames[i], SECTION_DEBUG, NULL)); - - gcc_assert (strncmp (debugnames[i], "__DWARF,", 8) == 0); - gcc_assert (strchr (debugnames[i] + 8, ',')); - - namelen = strchr (debugnames[i] + 8, ',') - (debugnames[i] + 8); - fprintf (asm_out_file, "Lsection%.*s:\n", namelen, debugnames[i] + 8); - } - } - - /* We fill this obstack with the complete section text for the lto section - names to write in darwin_file_end. */ - obstack_init (<o_section_names_obstack); - lto_section_names_offset = 0; -} - /* Output an offset in a DWARF section on Darwin. On Darwin, DWARF section offsets are not represented using relocs in .o files; either the section never leaves the .o file, or the linker or other tool is @@ -1767,7 +1798,24 @@ darwin_asm_output_dwarf_offset (FILE *file, int si darwin_asm_output_dwarf_delta (file, size, lab, sname); } +/* Called from the within the TARGET_ASM_FILE_START for each target. + Initialize the stuff we need for LTO long section names support. */ + void +darwin_file_start (void) +{ + /* We fill this obstack with the complete section text for the lto section + names to write in darwin_file_end. */ + obstack_init (<o_section_names_obstack); + lto_section_names_offset = 0; +} + +/* Called for the TARGET_ASM_FILE_END hook. + Emit the mach-o pic indirection data, the lto data and, finally a flag + to tell the linker that it can break the file object into sections and + move those around for efficiency. */ + +void darwin_file_end (void) { const char *lto_section_names;