This is the mail archive of the
binutils@sourceware.org
mailing list for the binutils project.
Re: [RFC PATCH] gas .section directives with comdat inheritance
Here is a new version of the patch that includes a test case.
Thanks,
Roland
gas/
2010-08-11 Roland McGrath <roland@frob.com>
* config/obj-elf.c (obj_elf_parse_section_letters): Take new
boolean result parameter CLONE; set it if '?' flag letter seen.
(obj_elf_section): Update caller. Handle that flag by copying
the LINKONCE and GROUP_NAME state from NOW_SEG.
* doc/as.texinfo (Section): Document the ? flag.
gas/testsuite/
2010-08-11 Roland McGrath <roland@redhat.com>
* gas/elf/groupauto.s: New file.
* gas/elf/groupautoa.d: New file.
* gas/elf/groupautob.d: New file.
* gas/elf/elf.exp (run_elf_list_test): Use them.
Index: gas/config/obj-elf.c
===================================================================
RCS file: /cvs/src/src/gas/config/obj-elf.c,v
retrieving revision 1.128
diff -b -p -u -r1.128 obj-elf.c
--- gas/config/obj-elf.c 15 Jul 2010 14:34:41 -0000 1.128
+++ gas/config/obj-elf.c 11 Aug 2010 23:07:28 -0000
@@ -741,9 +741,10 @@ obj_elf_change_section (const char *name
}
static bfd_vma
-obj_elf_parse_section_letters (char *str, size_t len)
+obj_elf_parse_section_letters (char *str, size_t len, bfd_boolean *clone)
{
bfd_vma attr = 0;
+ *clone = FALSE;
while (len > 0)
{
@@ -773,6 +774,9 @@ obj_elf_parse_section_letters (char *str
case 'T':
attr |= SHF_TLS;
break;
+ case '?':
+ *clone = TRUE;
+ break;
/* Compatibility. */
case 'm':
if (*(str - 1) == 'a')
@@ -974,13 +978,15 @@ obj_elf_section (int push)
if (*input_line_pointer == '"')
{
+ bfd_boolean clone;
+
beg = demand_copy_C_string (&dummy);
if (beg == NULL)
{
ignore_rest_of_line ();
return;
}
- attr |= obj_elf_parse_section_letters (beg, strlen (beg));
+ attr |= obj_elf_parse_section_letters (beg, strlen (beg), &clone);
SKIP_WHITESPACE ();
if (*input_line_pointer == ',')
@@ -1032,6 +1038,11 @@ obj_elf_section (int push)
attr &= ~SHF_MERGE;
}
+ if ((attr & SHF_GROUP) != 0 && clone)
+ {
+ as_warn (_("? section flag ignored with G present"));
+ clone = FALSE;
+ }
if ((attr & SHF_GROUP) != 0 && *input_line_pointer == ',')
{
++input_line_pointer;
@@ -1051,6 +1062,16 @@ obj_elf_section (int push)
as_warn (_("group name for SHF_GROUP not specified"));
attr &= ~SHF_GROUP;
}
+
+ if (clone)
+ {
+ const char *now_group = elf_group_name (now_seg);
+ if (now_group != NULL)
+ {
+ group_name = xstrdup (now_group);
+ linkonce = (now_seg->flags & SEC_LINK_ONCE) != 0;
+ }
+ }
}
else
{
Index: gas/doc/as.texinfo
===================================================================
RCS file: /cvs/src/src/gas/doc/as.texinfo,v
retrieving revision 1.221
diff -b -p -u -r1.221 as.texinfo
--- gas/doc/as.texinfo 9 Aug 2010 18:08:18 -0000 1.221
+++ gas/doc/as.texinfo 11 Aug 2010 23:07:28 -0000
@@ -5898,6 +5898,8 @@ section contains zero terminated strings
section is a member of a section group
@item T
section is used for thread-local-storage
+@item ?
+section is a member of the previously-current section's group, if any
@end table
The optional @var{type} argument may contain one of the following constants:
@@ -5962,6 +5964,13 @@ the Merge flag should come first, like t
.section @var{name} , "@var{flags}"MG, @@@var{type}, @var{entsize}, @var{GroupName}[, @var{linkage}]
@end smallexample
+If @var{flags} contains the @code{?} symbol then it may not also contain the
+@code{G} symbol and the @var{GroupName} or @var{linkage} fields should not be
+present. Instead, @code{?} says to consider the section that's current before
+this directive. If that section used @code{G}, then the new section will use
+@code{G} with those same @var{GroupName} and @var{linkage} fields implicitly.
+If not, then the @code{?} symbol has no effect.
+
If no flags are specified, the default flags depend upon the section name. If
the section name is not recognized, the default will be for the section to have
none of the above flags: it will not be allocated in memory, nor writable, nor
Index: gas/testsuite/gas/elf/elf.exp
===================================================================
RCS file: /cvs/src/src/gas/testsuite/gas/elf/elf.exp,v
retrieving revision 1.64
diff -b -p -u -r1.64 elf.exp
--- gas/testsuite/gas/elf/elf.exp 3 Aug 2010 10:30:52 -0000 1.64
+++ gas/testsuite/gas/elf/elf.exp 11 Aug 2010 23:07:28 -0000
@@ -106,6 +106,8 @@ if { ([istarget "*-*-*elf*"]
run_dump_test "group0b"
run_dump_test "group1a"
run_dump_test "group1b"
+ run_dump_test "groupautoa"
+ run_dump_test "groupautob"
case $target_triplet in {
{ alpha*-*-* } { }
{ cr16*-*-* } { }
--- /dev/null 2010-08-09 23:10:21.236063375 -0700
+++ gas/testsuite/gas/elf/groupauto.s 2010-08-11 15:50:21.565969577 -0700
@@ -0,0 +1,17 @@
+ .text
+ .byte 1
+ .section .foo,"a?","progbits"
+ .byte 1
+
+ .section .text,"axG",%progbits,some_group,comdat
+ .byte 1
+ .pushsection .note.bar,"?","note"
+ .4byte 1f-0f, 3f-2f, 123
+0: .asciz "somevendor"
+1: .balign 4
+2: .byte 1
+ .uleb128 5f-4f
+3: .balign 4
+ .popsection
+4: .byte 2
+5: .byte 3
--- /dev/null 2010-08-09 23:10:21.236063375 -0700
+++ gas/testsuite/gas/elf/groupautoa.d 2010-08-11 16:00:30.189720744 -0700
@@ -0,0 +1,15 @@
+#readelf: -SW
+#name: automatic section group
+#source: groupauto.s
+
+#...
+[ ]*\[.*\][ ]+some_group[ ]+GROUP.*
+#...
+[ ]*\[.*\][ ]+\.text[ ]+PROGBITS.*[ ]+AX[ ]+.*
+#...
+[ ]*\[.*\][ ]+\.foo[ ]+PROGBITS.*[ ]+A[ ]+.*
+#...
+[ ]*\[.*\][ ]+\.text[ ]+PROGBITS.*[ ]+AXG[ ]+.*
+#...
+[ ]*\[.*\][ ]+\.note.bar[ ]+NOTE.*[ ]+G[ ]+.*
+#pass
--- /dev/null 2010-08-09 23:10:21.236063375 -0700
+++ gas/testsuite/gas/elf/groupautob.d 2010-08-11 16:00:35.945657363 -0700
@@ -0,0 +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