diff options
author | Iain Sandoe <iains@gcc.gnu.org> | 2010-11-02 11:14:42 +0000 |
---|---|---|
committer | Iain Sandoe <iains@gcc.gnu.org> | 2010-11-02 11:14:42 +0000 |
commit | de4df14c7d6e8f5db942804e6fdc37033b46c3bb (patch) | |
tree | fc0bcf1ab9f91c1c880b1927fa764bec68f6d1a2 | |
parent | 47afeed5cc59235c41c17f0c9fc7991ffc73ea1a (diff) | |
download | gcc-de4df14c7d6e8f5db942804e6fdc37033b46c3bb.zip gcc-de4df14c7d6e8f5db942804e6fdc37033b46c3bb.tar.gz gcc-de4df14c7d6e8f5db942804e6fdc37033b46c3bb.tar.bz2 |
improve darwin section ordering between debug/non-debug cases.
gcc:
* config/darwin.c (darwin_asm_named_section): Check for __DWARF
sections and call darwin_asm_dwarf_section() to handle them.
(darwin_asm_dwarf_section): New.
(darwin_file_start): Remove code emitting dwarf section symbols.
testsuite:
* g++.dg/debug/dwarf2/pubnames-1.C: Amend to check for only one instance
of debug_pubnames on darwin.
From-SVN: r166174
-rw-r--r-- | gcc/ChangeLog | 7 | ||||
-rw-r--r-- | gcc/config/darwin.c | 134 | ||||
-rw-r--r-- | gcc/testsuite/ChangeLog | 5 | ||||
-rw-r--r-- | gcc/testsuite/g++.dg/debug/dwarf2/pubnames-1.C | 7 |
4 files changed, 104 insertions, 49 deletions
diff --git a/gcc/ChangeLog b/gcc/ChangeLog index 4e1faee..a94206d 100644 --- a/gcc/ChangeLog +++ b/gcc/ChangeLog @@ -1,3 +1,10 @@ +2010-11-02 Iain Sandoe <iains@gcc.gnu.org> + + * config/darwin.c (darwin_asm_named_section): Check for __DWARF + sections and call darwin_asm_dwarf_section() to handle them. + (darwin_asm_dwarf_section): New. + (darwin_file_start): Remove code emitting dwarf section symbols. + 2010-11-02 Chung-Lin Tang <cltang@codesourcery.com> * Makefile.in (LIBGCC2_CFLAGS): Add -fno-stack-protector, to diff --git a/gcc/config/darwin.c b/gcc/config/darwin.c index 37be79f..210421c 100644 --- a/gcc/config/darwin.c +++ b/gcc/config/darwin.c @@ -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 size, 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,6 +1798,23 @@ darwin_asm_output_dwarf_offset (FILE *file, int size, const char * lab, 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) { diff --git a/gcc/testsuite/ChangeLog b/gcc/testsuite/ChangeLog index 8fc1d6b..9d56097 100644 --- a/gcc/testsuite/ChangeLog +++ b/gcc/testsuite/ChangeLog @@ -1,3 +1,8 @@ +2010-11-02 Iain Sandoe <iains@gcc.gnu.org> + + * g++.dg/debug/dwarf2/pubnames-1.C: Amend to check for only one instance + of debug_pubnames on darwin. + 2010-11-01 Jason Merrill <jason@redhat.com> Benjamin Kosnik <bkoz@redhat.com> diff --git a/gcc/testsuite/g++.dg/debug/dwarf2/pubnames-1.C b/gcc/testsuite/g++.dg/debug/dwarf2/pubnames-1.C index 8884842..63e04e4 100644 --- a/gcc/testsuite/g++.dg/debug/dwarf2/pubnames-1.C +++ b/gcc/testsuite/g++.dg/debug/dwarf2/pubnames-1.C @@ -4,12 +4,7 @@ // { dg-options "-g -dA -fno-merge-debug-strings" } // // There should be one debug_pubnames section generated. -// On Darwin though, there is also a label pointing at the begining of the -// debug_pubnames section. The assembly code of that label adds an occurence -// of section declaration assembly. So on Darwin, we need to check for two -// occurences of the debug_pubnames section declaration. -// { dg-final { scan-assembler-times "\.section\[\t \]\[^\n\]*debug_pubnames" 1 { target { ! *-*-darwin* } } } } -// { dg-final { scan-assembler-times "\.section\[\t \]\[^\n\]*debug_pubnames" 2 { target { *-*-darwin* } } } } +// { dg-final { scan-assembler-times "\.section\[\t \]\[^\n\]*debug_pubnames" 1 } } // // Then check of the presence of the names we are interested in. // { dg-final { scan-assembler-times "\"main.0\"\[^\n\]*external name" 1 } } |