From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [63.128.21.124]) by sourceware.org (Postfix) with ESMTP id 4D5A7386F435 for ; Tue, 29 Sep 2020 15:13:07 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.3.2 sourceware.org 4D5A7386F435 Received: from mimecast-mx01.redhat.com (mimecast-mx01.redhat.com [209.132.183.4]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-244-xSAhjcoFOeCtFp7IbYFJ2Q-1; Tue, 29 Sep 2020 11:13:02 -0400 X-MC-Unique: xSAhjcoFOeCtFp7IbYFJ2Q-1 Received: from smtp.corp.redhat.com (int-mx02.intmail.prod.int.phx2.redhat.com [10.5.11.12]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id 9D26310A7AE6 for ; Tue, 29 Sep 2020 15:13:01 +0000 (UTC) Received: from comet.redhat.com (ovpn-112-148.ams2.redhat.com [10.36.112.148]) by smtp.corp.redhat.com (Postfix) with ESMTPS id EB4E465F5E for ; Tue, 29 Sep 2020 15:13:00 +0000 (UTC) From: Nick Clifton To: binutils@sourceware.org Subject: RFC: New gas directive: .attach_to_group Date: Tue, 29 Sep 2020 16:12:58 +0100 Message-ID: <87pn647h1h.fsf@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.12 X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Type: multipart/mixed; boundary="=-=-=" X-Spam-Status: No, score=-11.7 required=5.0 tests=BAYES_00, DKIMWL_WL_HIGH, DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, DKIM_VALID_EF, GIT_PATCH_0, RCVD_IN_DNSWL_NONE, RCVD_IN_MSPIKE_H5, RCVD_IN_MSPIKE_WL, SPF_HELO_NONE, SPF_PASS, TXREP autolearn=ham autolearn_force=no version=3.4.2 X-Spam-Checker-Version: SpamAssassin 3.4.2 (2018-09-13) on server2.sourceware.org X-BeenThere: binutils@sourceware.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Binutils mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Tue, 29 Sep 2020 15:13:08 -0000 --=-=-= Content-Type: text/plain Hi Guys, I am planning on applying the attached patch, but I wondered if anyone had any comments or thoughts first. The patch adds a new gas directive: ".attach_to_group " which can be used to attach the current section to a named group. I need this functionality for the annobin plugin for gcc. The plugin creates new note sections and it wants to place them into section groups with their associated code section. (So the .annobin.text section is grouped with the .text section, the .annobin.text.hot section is grouped with the .text.hot section and so on). The problem is that the compiler creates the .section directives for (most of) these code sections, and it does not add a group section to their declaration. So I need a way to retroactively add a section to a group. Hence the new directive. Tested with a wide variety of different configurations and no problems. Thoughts ? Cheers Nick gas/ * 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. --=-=-= Content-Type: text/x-patch Content-Disposition: inline; filename=attach-to-group.patch diff --git a/gas/NEWS b/gas/NEWS index 7ae58506ec..0ef33ab60e 100644 --- a/gas/NEWS +++ b/gas/NEWS @@ -1,4 +1,7 @@ -*- text -*- +* Add a .attach-to_group directive which allows a section to added to a group + even after the section has been created. + * Add support for Intel TDX instructions. * Add support for Intel Key Locker instructions. diff --git a/gas/config/obj-elf.c b/gas/config/obj-elf.c index b1c99020a3..5f61204bce 100644 --- a/gas/config/obj-elf.c +++ b/gas/config/obj-elf.c @@ -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) { diff --git a/gas/doc/as.texi b/gas/doc/as.texi index b88c1f9997..c0baa94536 100644 --- a/gas/doc/as.texi +++ b/gas/doc/as.texi @@ -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/elf.exp b/gas/testsuite/gas/elf/elf.exp index 135ade24ec..5ce9691b38 100644 --- a/gas/testsuite/gas/elf/elf.exp +++ b/gas/testsuite/gas/elf/elf.exp @@ -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*-*-* { } --- /dev/null 2020-09-29 09:19:37.528268715 +0100 +++ current/gas/testsuite/gas/elf/attach-1.s 2020-09-29 14:30:06.242727518 +0100 @@ -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 --- /dev/null 2020-09-29 09:19:37.528268715 +0100 +++ current/gas/testsuite/gas/elf/attach-1.d 2020-09-29 15:53:50.914680109 +0100 @@ -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 + \[ .\] [P|\.text] + \[ .\] foo +#pass + --- /dev/null 2020-09-29 09:19:37.528268715 +0100 +++ current/gas/testsuite/gas/elf/attach-2.d 2020-09-29 14:56:01.546024741 +0100 @@ -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 + --- /dev/null 2020-09-29 09:19:37.528268715 +0100 +++ current/gas/testsuite/gas/elf/attach-2.s 2020-09-29 14:53:25.041006132 +0100 @@ -0,0 +1,9 @@ + .section bar + .nop + .attach_to_group foo.group + + .section foo, "G", %note , foo.group + .word 0 + + .section bar + .nop --- /dev/null 2020-09-29 09:19:37.528268715 +0100 +++ current/gas/testsuite/gas/elf/attach-err.d 2020-09-29 14:48:14.501953361 +0100 @@ -0,0 +1,3 @@ +#name: Errors generated by .attach_to_group +#source: attach-err.s +#error_output: attach-err.err --- /dev/null 2020-09-29 09:19:37.528268715 +0100 +++ current/gas/testsuite/gas/elf/attach-err.err 2020-09-29 15:54:35.415401125 +0100 @@ -0,0 +1,4 @@ +.*: Assembler messages: +.*:4: Warning: section [P|\.text] already has a group \(does\.not\.exist\) +.*:5: Error: missing name +.*:5: Warning: group name not parseable --- /dev/null 2020-09-29 09:19:37.528268715 +0100 +++ current/gas/testsuite/gas/elf/attach-err.s 2020-09-29 14:45:34.540949111 +0100 @@ -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. */ --=-=-=--