Add new directive to GAS: .attach_to_group.
authorNick Clifton <nickc@redhat.com>
Thu, 1 Oct 2020 15:34:05 +0000 (16:34 +0100)
committerNick Clifton <nickc@redhat.com>
Thu, 1 Oct 2020 15:34:05 +0000 (16:34 +0100)
* config/obj-elf (elf_pseudo_table): Add attach_to_group.
        (obj_elf_attach_to_group): New function.
        * doc/as.texi: Document the new directive.
* NEWS: Mention the new feature.
        * testsuite/gas/elf/attach-1.s: New test.
        * testsuite/gas/elf/attach-1.d: New test driver.
        * testsuite/gas/elf/attach-2.s: New test.
        * testsuite/gas/elf/attach-2.d: New test driver.
        * testsuite/gas/elf/attach-err.s: New test.
        * testsuite/gas/elf/attach-err.d: New test driver.
        * testsuite/gas/elf/attach-err.err: New test error output.
        * testsuite/gas/elf/elf.exp: Run the new tests.

gas/ChangeLog
gas/config/obj-elf.c
gas/doc/as.texi
gas/testsuite/gas/elf/attach-1.d [new file with mode: 0644]
gas/testsuite/gas/elf/attach-1.s [new file with mode: 0644]
gas/testsuite/gas/elf/attach-2.d [new file with mode: 0644]
gas/testsuite/gas/elf/attach-2.s [new file with mode: 0644]
gas/testsuite/gas/elf/attach-err.d [new file with mode: 0644]
gas/testsuite/gas/elf/attach-err.err [new file with mode: 0644]
gas/testsuite/gas/elf/attach-err.s [new file with mode: 0644]
gas/testsuite/gas/elf/elf.exp

index f12a18a72d1a7b1b55932d9e1c4d1c47a5e01a32..6662b1c6adebfb9e52ac65d1c18e3476e5d680ac 100644 (file)
@@ -1,3 +1,18 @@
+2020-10-01  Nick Clifton  <nickc@redhat.com>
+
+       * config/obj-elf (elf_pseudo_table): Add attach_to_group.
+        (obj_elf_attach_to_group): New function.
+        * doc/as.texi: Document the new directive.
+       * NEWS: Mention the new feature.
+        * testsuite/gas/elf/attach-1.s: New test.
+        * testsuite/gas/elf/attach-1.d: New test driver.
+        * testsuite/gas/elf/attach-2.s: New test.
+        * testsuite/gas/elf/attach-2.d: New test driver.
+        * testsuite/gas/elf/attach-err.s: New test.
+        * testsuite/gas/elf/attach-err.d: New test driver.
+        * testsuite/gas/elf/attach-err.err: New test error output.
+        * testsuite/gas/elf/elf.exp: Run the new tests.
+
 2020-09-16  H.J. Lu  <hongjiu.lu@intel.com>
 
        PR gas/26685
index cd457abe5ebce89b872e94320677c4893635e165..45de821495e3d2dbddb7ba2d30a19586bf45153a 100644 (file)
@@ -78,9 +78,11 @@ static void obj_elf_gnu_attribute (int);
 static void obj_elf_tls_common (int);
 static void obj_elf_lcomm (int);
 static void obj_elf_struct (int);
+static void obj_elf_attach_to_group (int);
 
 static const pseudo_typeS elf_pseudo_table[] =
 {
+  {"attach_to_group", obj_elf_attach_to_group, 0},
   {"comm", obj_elf_common, 0},
   {"common", obj_elf_common, 1},
   {"ident", obj_elf_ident, 0},
@@ -1040,6 +1042,28 @@ obj_elf_section_name (void)
   return name;
 }
 
+static void
+obj_elf_attach_to_group (int dummy ATTRIBUTE_UNUSED)
+{
+  const char * gname = obj_elf_section_name ();
+
+  if (gname == NULL)
+    {
+      as_warn (_("group name not parseable"));
+      return;
+    }
+
+  if (elf_group_name (now_seg))
+    {
+      as_warn (_("section %s already has a group (%s)"),
+              bfd_section_name (now_seg), elf_group_name (now_seg));
+      return;
+    }
+
+  elf_group_name (now_seg) = xstrdup (gname);
+  elf_section_flags (now_seg) |= SHF_GROUP;
+}
+
 void
 obj_elf_section (int push)
 {
index b88c1f999797c491de28131ac497bea1ca26a0f8..c0baa945360b99b8f2211cb430da2c0c559340bb 100644 (file)
@@ -4362,6 +4362,7 @@ Some machine configurations provide additional directives.
 * Altmacro::                    @code{.altmacro}
 * Ascii::                       @code{.ascii "@var{string}"}@dots{}
 * Asciz::                       @code{.asciz "@var{string}"}@dots{}
+* Attach_to_group::             @code{.attach_to_group @var{name}}
 * Balign::                      @code{.balign [@var{abs-expr}[, @var{abs-expr}]]}
 * Bundle directives::           @code{.bundle_align_mode @var{abs-expr}}, etc
 * Byte::                        @code{.byte @var{expressions}}
@@ -4663,6 +4664,13 @@ trailing zero byte) into consecutive addresses.
 @code{.asciz} is just like @code{.ascii}, but each string is followed by
 a zero byte.  The ``z'' in @samp{.asciz} stands for ``zero''.
 
+@node Attach_to_group
+@section @code{.attach_to_group @var{name}}
+Attaches the current section to the named group.  This is like declaring
+the section with the @code{G} attribute, but can be done after the section
+has been created.  Note if the group section  does not exist at the point that
+this directive is used then it will be created.
+
 @node Balign
 @section @code{.balign[wl] [@var{abs-expr}[, @var{abs-expr}[, @var{abs-expr}]]]}
 
@@ -6663,7 +6671,9 @@ a few exceptions to this rule however.  Processor and application specific
 flags can be added to an already defined section.  The @code{.interp},
 @code{.strtab} and @code{.symtab} sections can have the allocate flag
 (@code{a}) set after they are initially defined, and the @code{.note-GNU-stack}
-section may have the executable (@code{x}) flag added.
+section may have the executable (@code{x}) flag added.  Also note that the
+@code{.attach_to_group} directive can be used to add a section to a group even
+if the section was not originally declared to be part of that group.
 
 The optional @var{type} argument may contain one of the following constants:
 
diff --git a/gas/testsuite/gas/elf/attach-1.d b/gas/testsuite/gas/elf/attach-1.d
new file mode 100644 (file)
index 0000000..053783e
--- /dev/null
@@ -0,0 +1,11 @@
+#readelf: --section-groups
+#name: Attaching a section to a group
+#source: attach-1.s
+
+#...
+group section \[    1\] `\.group' \[foo\.group\] contains . sections:
+   \[Index\]    Name
+   \[    .\]   .*
+   \[    .\]   foo
+#pass
+
diff --git a/gas/testsuite/gas/elf/attach-1.s b/gas/testsuite/gas/elf/attach-1.s
new file mode 100644 (file)
index 0000000..aa69fff
--- /dev/null
@@ -0,0 +1,11 @@
+       .text
+       .nop
+       
+       .section foo, "G", %progbits , foo.group
+       .word 0
+
+       .text
+       /* This is the intended use of the .attach_to_group directive.
+          It attaches a previously defined section (.text) to a
+          previously defined group (foo.group).  */
+       .attach_to_group foo.group
diff --git a/gas/testsuite/gas/elf/attach-2.d b/gas/testsuite/gas/elf/attach-2.d
new file mode 100644 (file)
index 0000000..4aa5211
--- /dev/null
@@ -0,0 +1,11 @@
+#readelf: --section-groups
+#name: Attaching a section to a non-existant group
+#source: attach-2.s
+
+#...
+group section \[    1\] `\.group' \[foo\.group\] contains 2 sections:
+   \[Index\]    Name
+   \[    .\]   bar
+   \[    .\]   foo
+#pass
+
diff --git a/gas/testsuite/gas/elf/attach-2.s b/gas/testsuite/gas/elf/attach-2.s
new file mode 100644 (file)
index 0000000..4a5663f
--- /dev/null
@@ -0,0 +1,9 @@
+       .section bar
+       .nop
+       .attach_to_group foo.group
+       
+       .section foo, "G", %note , foo.group
+       .word 0
+
+       .section bar
+       .nop
diff --git a/gas/testsuite/gas/elf/attach-err.d b/gas/testsuite/gas/elf/attach-err.d
new file mode 100644 (file)
index 0000000..3028d72
--- /dev/null
@@ -0,0 +1,3 @@
+#name: Errors generated by .attach_to_group
+#source: attach-err.s
+#error_output: attach-err.err
diff --git a/gas/testsuite/gas/elf/attach-err.err b/gas/testsuite/gas/elf/attach-err.err
new file mode 100644 (file)
index 0000000..7385467
--- /dev/null
@@ -0,0 +1,4 @@
+.*: Assembler messages:
+.*:4: Warning: section .* already has a group \(does\.not\.exist\)
+.*:5: Error: missing name
+.*:5: Warning: group name not parseable
diff --git a/gas/testsuite/gas/elf/attach-err.s b/gas/testsuite/gas/elf/attach-err.s
new file mode 100644 (file)
index 0000000..40597e9
--- /dev/null
@@ -0,0 +1,5 @@
+
+       /* Test the error messages that should be generated.  */
+       .attach_to_group does.not.exist  /* This is OK, the group does not have to exist.  */
+       .attach_to_group foo.group  /* Already attached.  */
+       .attach_to_group  /* Missing group name.  */
index 135ade24ec9f4d2802824c42dabaa6d48c8a34e8..5ce9691b389c7d3e8b8502c0cade696d6ad66e7a 100644 (file)
@@ -139,6 +139,10 @@ if { [is_elf_format] } then {
     run_dump_test "group1b"
     run_dump_test "group2"
     run_dump_test "group3"
+
+    run_dump_test "attach-1"
+    run_dump_test "attach-err"
+    
     switch -glob $target_triplet {
        hppa64*-*-hpux* { }
        riscv*-*-* { }
This page took 0.036216 seconds and 4 git commands to generate.