2010-10-21 Mark Mitchell * config/obj-elf.c (elf_adjust_symtab): New. Move group section processing here from elf_frob_file. Ensure that group signature symbols have the name of the group. (elf_frob_file): Move group section processing to elf_adjust_symtab. * config/obj-elf.h (elf_adjust_symtab): Declare. (obj_adjust_symtab): Define. 2010-10-21 Mark Mitchell * gas/elf/elf.exp: Add group0c test. * gas/elf/group0c.d: New. * gas/elf/group0a.d: Expect ".group" for the name of group sections. * gas/elf/group0b.d: Likewise. * gas/elf/group1a.d: Likewise. * gas/elf/group1b.d: Likewise. * gas/elf/groupautoa.d: Likewise. * gas/elf/groupautob.d: Likewise. * gas/elf/section4.d: Likewise. Index: gas/config/obj-elf.c =================================================================== RCS file: /cvs/src/src/gas/config/obj-elf.c,v retrieving revision 1.131 diff -c -5 -p -r1.131 obj-elf.c *** gas/config/obj-elf.c 16 Sep 2010 23:55:09 -0000 1.131 --- gas/config/obj-elf.c 22 Oct 2010 03:16:59 -0000 *************** static void free_section_idx (const char *** 2079,2114 **** { free ((unsigned int *) val); } void ! elf_frob_file (void) { struct group_list list; unsigned int i; - bfd_map_over_sections (stdoutput, adjust_stab_sections, NULL); - /* Go find section groups. */ list.num_group = 0; list.head = NULL; list.elt_count = NULL; ! list.indexes = hash_new (); bfd_map_over_sections (stdoutput, build_group_lists, &list); ! ! /* Make the SHT_GROUP sections that describe each section group. We ! can't set up the section contents here yet, because elf section ! indices have yet to be calculated. elf.c:set_group_contents does ! the rest of the work. */ for (i = 0; i < list.num_group; i++) { const char *group_name = elf_group_name (list.head[i]); const char *sec_name; asection *s; flagword flags; struct symbol *sy; - int has_sym; bfd_size_type size; flags = SEC_READONLY | SEC_HAS_CONTENTS | SEC_IN_MEMORY | SEC_GROUP; for (s = list.head[i]; s != NULL; s = elf_next_in_group (s)) if ((s->flags ^ flags) & SEC_LINK_ONCE) --- 2079,2109 ---- { free ((unsigned int *) val); } void ! elf_adjust_symtab (void) { struct group_list list; unsigned int i; /* Go find section groups. */ list.num_group = 0; list.head = NULL; list.elt_count = NULL; ! list.indexes = hash_new (); bfd_map_over_sections (stdoutput, build_group_lists, &list); ! ! /* Make sure that the group signature symbol for each group has the ! intended name. */ for (i = 0; i < list.num_group; i++) { const char *group_name = elf_group_name (list.head[i]); const char *sec_name; asection *s; flagword flags; struct symbol *sy; bfd_size_type size; flags = SEC_READONLY | SEC_HAS_CONTENTS | SEC_IN_MEMORY | SEC_GROUP; for (s = list.head[i]; s != NULL; s = elf_next_in_group (s)) if ((s->flags ^ flags) & SEC_LINK_ONCE) *************** elf_frob_file (void) *** 2120,2139 **** group_name); break; } } ! sec_name = group_name; sy = symbol_find_exact (group_name); ! has_sym = 0; ! if (sy != NULL ! && (sy == symbol_lastP ! || (sy->sy_next != NULL ! && sy->sy_next->sy_previous == sy))) { ! has_sym = 1; ! sec_name = ".group"; } s = subseg_force_new (sec_name, 0); if (s == NULL || !bfd_set_section_flags (stdoutput, s, flags) || !bfd_set_section_alignment (stdoutput, s, 2)) --- 2115,2135 ---- group_name); break; } } ! sec_name = ".group"; sy = symbol_find_exact (group_name); ! if (!sy ! || (sy != symbol_lastP ! && (sy->sy_next == NULL ! || sy->sy_next->sy_previous != sy))) { ! /* Create the symbol now. */ ! sy = symbol_new (group_name, now_seg, (valueT) 0, frag_now); ! symbol_get_obj (sy)->local = 1; ! symbol_table_insert (sy); } s = subseg_force_new (sec_name, 0); if (s == NULL || !bfd_set_section_flags (stdoutput, s, flags) || !bfd_set_section_alignment (stdoutput, s, 2)) *************** elf_frob_file (void) *** 2143,2171 **** } elf_section_type (s) = SHT_GROUP; /* Pass a pointer to the first section in this group. */ elf_next_in_group (s) = list.head[i]; ! if (has_sym) ! elf_group_id (s) = sy->bsym; size = 4 * (list.elt_count[i] + 1); bfd_set_section_size (stdoutput, s, size); s->contents = (unsigned char *) frag_more (size); frag_now->fr_fix = frag_now_fix_octets (); frag_wane (frag_now); } - #ifdef elf_tc_final_processing - elf_tc_final_processing (); - #endif - /* Cleanup hash. */ hash_traverse (list.indexes, free_section_idx); hash_die (list.indexes); } /* It removes any unneeded versioned symbols from the symbol table. */ void elf_frob_file_before_adjust (void) { --- 2139,2172 ---- } elf_section_type (s) = SHT_GROUP; /* Pass a pointer to the first section in this group. */ elf_next_in_group (s) = list.head[i]; ! elf_group_id (s) = sy->bsym; size = 4 * (list.elt_count[i] + 1); bfd_set_section_size (stdoutput, s, size); s->contents = (unsigned char *) frag_more (size); frag_now->fr_fix = frag_now_fix_octets (); frag_wane (frag_now); } /* Cleanup hash. */ hash_traverse (list.indexes, free_section_idx); hash_die (list.indexes); } + void + elf_frob_file (void) + { + bfd_map_over_sections (stdoutput, adjust_stab_sections, NULL); + + #ifdef elf_tc_final_processing + elf_tc_final_processing (); + #endif + } + /* It removes any unneeded versioned symbols from the symbol table. */ void elf_frob_file_before_adjust (void) { Index: gas/config/obj-elf.h =================================================================== RCS file: /cvs/src/src/gas/config/obj-elf.h,v retrieving revision 1.37 diff -c -5 -p -r1.37 obj-elf.h *** gas/config/obj-elf.h 13 Jan 2010 14:08:52 -0000 1.37 --- gas/config/obj-elf.h 22 Oct 2010 03:16:59 -0000 *************** void elf_copy_symbol_attributes (symbolS *** 195,204 **** --- 195,209 ---- #ifndef OBJ_COPY_SYMBOL_ATTRIBUTES #define OBJ_COPY_SYMBOL_ATTRIBUTES(DEST, SRC) \ (elf_copy_symbol_attributes (DEST, SRC)) #endif + void elf_adjust_symtab (void); + #ifndef obj_adjust_symtab + #define obj_adjust_symtab elf_adjust_symtab + #endif + #ifndef SEPARATE_STAB_SECTIONS /* Avoid ifndef each separate macro setting by wrapping the whole of the stab group on the assumption that whoever sets SEPARATE_STAB_SECTIONS caters to ECOFF_DEBUGGING and the right setting of INIT_STAB_SECTIONS and OBJ_PROCESS_STAB too, without needing the tweaks below. */ Index: gas/testsuite/gas/elf/elf.exp =================================================================== RCS file: /cvs/src/src/gas/testsuite/gas/elf/elf.exp,v retrieving revision 1.67 diff -c -5 -p -r1.67 elf.exp *** gas/testsuite/gas/elf/elf.exp 20 Sep 2010 16:07:27 -0000 1.67 --- gas/testsuite/gas/elf/elf.exp 22 Oct 2010 03:16:59 -0000 *************** if { ([istarget "*-*-*elf*"] *** 102,111 **** --- 102,112 ---- run_dump_test "file" } } run_dump_test "group0a" run_dump_test "group0b" + run_dump_test "group0c" run_dump_test "group1a" run_dump_test "group1b" run_dump_test "groupautoa" run_dump_test "groupautob" case $target_triplet in { Index: gas/testsuite/gas/elf/group0a.d =================================================================== RCS file: /cvs/src/src/gas/testsuite/gas/elf/group0a.d,v retrieving revision 1.2 diff -c -5 -p -r1.2 group0a.d *** gas/testsuite/gas/elf/group0a.d 25 Nov 2004 00:56:00 -0000 1.2 --- gas/testsuite/gas/elf/group0a.d 22 Oct 2010 03:16:59 -0000 *************** *** 1,10 **** #readelf: -SW #name: group section #source: group0.s #... ! [ ]*\[.*\][ ]+\.foo_group[ ]+GROUP.* #... [ ]*\[.*\][ ]+\.foo[ ]+PROGBITS.*[ ]+AXG[ ]+.* [ ]*\[.*\][ ]+\.bar[ ]+PROGBITS.*[ ]+AG[ ]+.* #pass --- 1,10 ---- #readelf: -SW #name: group section #source: group0.s #... ! [ ]*\[.*\][ ]+\.group[ ]+GROUP.* #... [ ]*\[.*\][ ]+\.foo[ ]+PROGBITS.*[ ]+AXG[ ]+.* [ ]*\[.*\][ ]+\.bar[ ]+PROGBITS.*[ ]+AG[ ]+.* #pass Index: gas/testsuite/gas/elf/group0b.d =================================================================== RCS file: /cvs/src/src/gas/testsuite/gas/elf/group0b.d,v retrieving revision 1.2 diff -c -5 -p -r1.2 group0b.d *** gas/testsuite/gas/elf/group0b.d 25 May 2005 06:30:25 -0000 1.2 --- gas/testsuite/gas/elf/group0b.d 22 Oct 2010 03:16:59 -0000 *************** *** 1,10 **** #readelf: -g #name: group section #source: group0.s #... ! COMDAT group section \[ 1\] `.foo_group' \[.foo_group\] contains 2 sections: [ ]+\[Index\][ ]+Name [ ]+\[.*\][ ]+.foo [ ]+\[.*\][ ]+.bar #pass --- 1,10 ---- #readelf: -g #name: group section #source: group0.s #... ! COMDAT group section \[ 1\] `\.group' \[.foo_group\] contains 2 sections: [ ]+\[Index\][ ]+Name [ ]+\[.*\][ ]+.foo [ ]+\[.*\][ ]+.bar #pass Index: gas/testsuite/gas/elf/group0c.d =================================================================== RCS file: gas/testsuite/gas/elf/group0c.d diff -N gas/testsuite/gas/elf/group0c.d *** /dev/null 1 Jan 1970 00:00:00 -0000 --- gas/testsuite/gas/elf/group0c.d 22 Oct 2010 03:16:59 -0000 *************** *** 0 **** --- 1,7 ---- + #readelf: -sW + #name: group section name + #source: group0.s + + #... + .*NOTYPE[ ]+LOCAL[ ]+DEFAULT[ ]+[0-9]+[ ]+\.foo_group + #pass Index: gas/testsuite/gas/elf/group1a.d =================================================================== RCS file: /cvs/src/src/gas/testsuite/gas/elf/group1a.d,v retrieving revision 1.2 diff -c -5 -p -r1.2 group1a.d *** gas/testsuite/gas/elf/group1a.d 25 Nov 2004 00:56:00 -0000 1.2 --- gas/testsuite/gas/elf/group1a.d 22 Oct 2010 03:16:59 -0000 *************** *** 1,11 **** #readelf: -SW #name: group section with multiple sections of same name #source: group1.s #... ! [ ]*\[.*\][ ]+\.foo_group[ ]+GROUP.* #... [ ]*\[.*\][ ]+\.text[ ]+PROGBITS.*[ ]+AX[ ]+.* #... [ ]*\[.*\][ ]+\.text[ ]+PROGBITS.*[ ]+AXG[ ]+.* #pass --- 1,11 ---- #readelf: -SW #name: group section with multiple sections of same name #source: group1.s #... ! [ ]*\[.*\][ ]+\.group[ ]+GROUP.* #... [ ]*\[.*\][ ]+\.text[ ]+PROGBITS.*[ ]+AX[ ]+.* #... [ ]*\[.*\][ ]+\.text[ ]+PROGBITS.*[ ]+AXG[ ]+.* #pass Index: gas/testsuite/gas/elf/group1b.d =================================================================== RCS file: /cvs/src/src/gas/testsuite/gas/elf/group1b.d,v retrieving revision 1.2 diff -c -5 -p -r1.2 group1b.d *** gas/testsuite/gas/elf/group1b.d 25 May 2005 06:30:25 -0000 1.2 --- gas/testsuite/gas/elf/group1b.d 22 Oct 2010 03:16:59 -0000 *************** *** 1,9 **** #readelf: -g #name: group section with multiple sections of same name #source: group1.s #... ! COMDAT group section \[ 1\] `.foo_group' \[.foo_group\] contains 1 sections: [ ]+\[Index\][ ]+Name [ ]+\[.*\][ ]+.text #pass --- 1,9 ---- #readelf: -g #name: group section with multiple sections of same name #source: group1.s #... ! COMDAT group section \[ 1\] `\.group' \[.foo_group\] contains 1 sections: [ ]+\[Index\][ ]+Name [ ]+\[.*\][ ]+.text #pass Index: gas/testsuite/gas/elf/groupautoa.d =================================================================== RCS file: /cvs/src/src/gas/testsuite/gas/elf/groupautoa.d,v retrieving revision 1.1 diff -c -5 -p -r1.1 groupautoa.d *** gas/testsuite/gas/elf/groupautoa.d 18 Aug 2010 00:43:46 -0000 1.1 --- gas/testsuite/gas/elf/groupautoa.d 22 Oct 2010 03:16:59 -0000 *************** *** 1,11 **** #readelf: -SW #name: automatic section group #source: groupauto.s #... ! [ ]*\[.*\][ ]+some_group[ ]+GROUP.* #... [ ]*\[.*\][ ]+\.text[ ]+PROGBITS.*[ ]+AX[ ]+.* #... [ ]*\[.*\][ ]+\.foo[ ]+PROGBITS.*[ ]+A[ ]+.* #... --- 1,11 ---- #readelf: -SW #name: automatic section group #source: groupauto.s #... ! [ ]*\[.*\][ ]+\.group[ ]+GROUP.* #... [ ]*\[.*\][ ]+\.text[ ]+PROGBITS.*[ ]+AX[ ]+.* #... [ ]*\[.*\][ ]+\.foo[ ]+PROGBITS.*[ ]+A[ ]+.* #... Index: gas/testsuite/gas/elf/groupautob.d =================================================================== RCS file: /cvs/src/src/gas/testsuite/gas/elf/groupautob.d,v retrieving revision 1.1 diff -c -5 -p -r1.1 groupautob.d *** gas/testsuite/gas/elf/groupautob.d 18 Aug 2010 00:43:46 -0000 1.1 --- gas/testsuite/gas/elf/groupautob.d 22 Oct 2010 03:16:59 -0000 *************** *** 1,10 **** #readelf: -g #name: automatic section group #source: groupauto.s #... ! COMDAT group section \[ 1\] `some_group' \[some_group\] contains 2 sections: [ ]+\[Index\][ ]+Name [ ]+\[.*\][ ]+.text [ ]+\[.*\][ ]+.note.bar #pass --- 1,10 ---- #readelf: -g #name: automatic section group #source: groupauto.s #... ! COMDAT group section \[ 1\] `\.group' \[some_group\] contains 2 sections: [ ]+\[Index\][ ]+Name [ ]+\[.*\][ ]+.text [ ]+\[.*\][ ]+.note.bar #pass Index: gas/testsuite/gas/elf/section4.d =================================================================== RCS file: /cvs/src/src/gas/testsuite/gas/elf/section4.d,v retrieving revision 1.2 diff -c -5 -p -r1.2 section4.d *** gas/testsuite/gas/elf/section4.d 25 Nov 2004 00:56:00 -0000 1.2 --- gas/testsuite/gas/elf/section4.d 22 Oct 2010 03:16:59 -0000 *************** *** 1,10 **** #readelf: --sections #name: label arithmetic with multiple same-name sections #... ! [ ]*\[.*\][ ]+foo[ ]+GROUP.* #... [ ]*\[.*\][ ]+\.text[ ]+PROGBITS.* #... [ ]*\[.*\][ ]+\.data[ ]+PROGBITS.* #... --- 1,10 ---- #readelf: --sections #name: label arithmetic with multiple same-name sections #... ! [ ]*\[.*\][ ]+\.group[ ]+GROUP.* #... [ ]*\[.*\][ ]+\.text[ ]+PROGBITS.* #... [ ]*\[.*\][ ]+\.data[ ]+PROGBITS.* #...