aboutsummaryrefslogtreecommitdiff
path: root/gas
diff options
context:
space:
mode:
Diffstat (limited to 'gas')
-rw-r--r--gas/ChangeLog14
-rw-r--r--gas/NEWS21
-rw-r--r--gas/config/obj-elf.c39
-rw-r--r--gas/config/obj-elf.h10
-rw-r--r--gas/doc/as.texi7
-rw-r--r--gas/testsuite/gas/elf/elf.exp4
-rw-r--r--gas/testsuite/gas/elf/section21.l2
-rw-r--r--gas/testsuite/gas/elf/sh-link-zero.d9
-rw-r--r--gas/testsuite/gas/elf/sh-link-zero.s13
9 files changed, 86 insertions, 33 deletions
diff --git a/gas/ChangeLog b/gas/ChangeLog
index 866a8b4..56796ff 100644
--- a/gas/ChangeLog
+++ b/gas/ChangeLog
@@ -1,3 +1,17 @@
+2020-10-05 Nick Clifton <nickc@redhat.com>
+
+ PR 26253
+ * config/obj-elf.c (obj_elf_section): Accept a numeric value for
+ the "o" section flag. Interpret it as a section index. Allow an
+ index of zero.
+ * doc/as.texi: Document the new behaviour.
+ * NEWS: Mention the new feature. Tidy entries.
+ * testsuite/gas/elf/sh-link-zero.s: New test.
+ * testsuite/gas/elf/sh-link-zero.d: New test driver.
+ * testsuite/gas/elf/elf.exp: Run the new test.
+ * testsuite/gas/elf/section21.l: Updated expected assembler
+ output.
+
2020-10-03 H.J. Lu <hongjiu.lu@intel.com>
PR gas/26685
diff --git a/gas/NEWS b/gas/NEWS
index 8394f74..8f83beb 100644
--- a/gas/NEWS
+++ b/gas/NEWS
@@ -1,21 +1,12 @@
-*- text -*-
-* Add support for Cortex-A78 and Cortex-A78AE for ARM.
+* When setting the link order attribute of ELF sections, it is now possible to
+ use a numeric section index instead of symbol name.
-* Add support for Cortex-A78 and Cortex-A78AE for AArch64.
+* Add support for Cortex-A78, Cortex-A78AE and Cortex-X1 for AArch64 and ARM.
+ Add support for Cortex-R82, Neoverse V1, and Neoverse N2 for ARM.
-* Add support for ETMv4 (Embedded Trace Macrocell) system registers for
- AArch64.
-
-* Add support for ETE (Embedded Trace Extension) system registers for AArch64.
-
-* Add support for TRBE (Trace Buffer Extension) system registers for AArch64.
-
-* Add support for Cortex-X1 for AArch64.
-
-* Add support for Cortex-X1 for ARM.
-
-* Add support for Arm's Cortex-R82, Neoverse V1, and Neoverse N2
- processors.
+* Add support for ETMv4 (Embedded Trace Macrocell), ETE (Embedded Trace
+ Extension) and TRBE (Trace Buffer Extension) system registers for AArch64.
* Add support for Armv8-R AArch64.
diff --git a/gas/config/obj-elf.c b/gas/config/obj-elf.c
index 45de821..f061ea6 100644
--- a/gas/config/obj-elf.c
+++ b/gas/config/obj-elf.c
@@ -519,8 +519,10 @@ struct section_stack
static struct section_stack *section_stack;
+/* Return TRUE iff SEC matches the section info INF. */
+
static bfd_boolean
-get_section (bfd *abfd ATTRIBUTE_UNUSED, asection *sec, void *inf)
+get_section_by_match (bfd *abfd ATTRIBUTE_UNUSED, asection *sec, void *inf)
{
struct elf_section_match *match = (struct elf_section_match *) inf;
const char *gname = match->group_name;
@@ -602,7 +604,7 @@ obj_elf_change_section (const char *name,
previous_section = now_seg;
previous_subsection = now_subseg;
- old_sec = bfd_get_section_by_name_if (stdoutput, name, get_section,
+ old_sec = bfd_get_section_by_name_if (stdoutput, name, get_section_by_match,
(void *) match_p);
if (old_sec)
{
@@ -1076,6 +1078,7 @@ obj_elf_section (int push)
int linkonce;
subsegT new_subsection = -1;
struct elf_section_match match;
+ unsigned long linked_to_section_index = -1UL;
if (flag_mri)
{
@@ -1215,15 +1218,24 @@ obj_elf_section (int push)
if ((attr & SHF_LINK_ORDER) != 0 && *input_line_pointer == ',')
{
- char c;
- unsigned int length;
++input_line_pointer;
SKIP_WHITESPACE ();
- c = get_symbol_name (& beg);
- (void) restore_line_pointer (c);
- length = input_line_pointer - beg;
- if (length)
- match.linked_to_symbol_name = xmemdup0 (beg, length);
+ /* Check for a numeric section index, rather than a symbol name. */
+ if (ISDIGIT (* input_line_pointer))
+ {
+ linked_to_section_index = strtoul (input_line_pointer, & input_line_pointer, 0);
+ }
+ else
+ {
+ char c;
+ unsigned int length;
+
+ c = get_symbol_name (& beg);
+ (void) restore_line_pointer (c);
+ length = input_line_pointer - beg;
+ if (length)
+ match.linked_to_symbol_name = xmemdup0 (beg, length);
+ }
}
if ((attr & SHF_GROUP) != 0 && is_clone)
@@ -1231,6 +1243,7 @@ obj_elf_section (int push)
as_warn (_("? section flag ignored with G present"));
is_clone = FALSE;
}
+
if ((attr & SHF_GROUP) != 0 && *input_line_pointer == ',')
{
++input_line_pointer;
@@ -1289,6 +1302,7 @@ obj_elf_section (int push)
if (*input_line_pointer == ',')
{
char *save = input_line_pointer;
+
++input_line_pointer;
SKIP_WHITESPACE ();
if (strncmp (input_line_pointer, "unique", 6) == 0)
@@ -1394,6 +1408,13 @@ obj_elf_section (int push)
}
elf_section_flags (now_seg) |= gnu_attr;
+ if (linked_to_section_index != -1UL)
+ {
+ elf_section_flags (now_seg) |= SHF_LINK_ORDER;
+ elf_section_data (now_seg)->this_hdr.sh_link = linked_to_section_index;
+ /* FIXME: Should we perform some sanity checking on the section index ? */
+ }
+
if (push && new_subsection != -1)
subseg_set (now_seg, new_subsection);
}
diff --git a/gas/config/obj-elf.h b/gas/config/obj-elf.h
index b39a1a1..4f29572 100644
--- a/gas/config/obj-elf.h
+++ b/gas/config/obj-elf.h
@@ -104,11 +104,11 @@ struct elf_obj_sy
field. */
struct elf_section_match
{
- const char *group_name;
- const char *linked_to_symbol_name;
- unsigned int info;
- unsigned int section_id;
- flagword flags;
+ const char * group_name;
+ const char * linked_to_symbol_name;
+ unsigned int info;
+ unsigned int section_id;
+ flagword flags;
};
#define OBJ_SYMFIELD_TYPE struct elf_obj_sy
diff --git a/gas/doc/as.texi b/gas/doc/as.texi
index c0baa94..2ba101c 100644
--- a/gas/doc/as.texi
+++ b/gas/doc/as.texi
@@ -6728,11 +6728,14 @@ If @var{flags} contains the @code{o} flag, then the @var{type} argument
must be present along with an additional field like this:
@smallexample
-.section @var{name},"@var{flags}"o,@@@var{type},@var{SymbolName}
+.section @var{name},"@var{flags}"o,@@@var{type},@var{SymbolName}|@var{SectionIndex}
@end smallexample
The @var{SymbolName} field specifies the symbol name which the section
-references.
+references. Alternatively a numeric @var{SectionIndex} can be provided. This
+is not generally a good idea as section indicies are rarely known at assembly
+time, but the facility is provided for testing purposes. An index of zero is
+allowed. It indicates that the linked-to section has already been discarded.
Note: If both the @var{M} and @var{o} flags are present, then the fields
for the Merge flag should come first, like this:
diff --git a/gas/testsuite/gas/elf/elf.exp b/gas/testsuite/gas/elf/elf.exp
index 5ce9691..9d75154 100644
--- a/gas/testsuite/gas/elf/elf.exp
+++ b/gas/testsuite/gas/elf/elf.exp
@@ -142,7 +142,7 @@ if { [is_elf_format] } then {
run_dump_test "attach-1"
run_dump_test "attach-err"
-
+
switch -glob $target_triplet {
hppa64*-*-hpux* { }
riscv*-*-* { }
@@ -261,6 +261,8 @@ if { [is_elf_format] } then {
run_dump_test "section19"
run_dump_test "section20"
run_dump_test "section21"
+ run_dump_test "sh-link-zero"
+
run_dump_test "dwarf2-1" $dump_opts
run_dump_test "dwarf2-2" $dump_opts
run_dump_test "dwarf2-3" $dump_opts
diff --git a/gas/testsuite/gas/elf/section21.l b/gas/testsuite/gas/elf/section21.l
index 50342ec..53f0415 100644
--- a/gas/testsuite/gas/elf/section21.l
+++ b/gas/testsuite/gas/elf/section21.l
@@ -1,5 +1,5 @@
[^:]*: Assembler messages:
-[^:]*:11: Error: junk at end of line, first unrecognized character is `1'
+[^:]*:11: Error: junk at end of line, first unrecognized character is `f'
#...
[^:]*: Error: undefined linked-to symbol `bar' on section `__patchable_function_entries'
[^:]*: Error: undefined linked-to symbol `foo' on section `__patchable_function_entries'
diff --git a/gas/testsuite/gas/elf/sh-link-zero.d b/gas/testsuite/gas/elf/sh-link-zero.d
new file mode 100644
index 0000000..243d50c
--- /dev/null
+++ b/gas/testsuite/gas/elf/sh-link-zero.d
@@ -0,0 +1,9 @@
+#readelf: --wide --sections
+#name: Setting the sh_link field to 0
+#source: sh-link-zero.s
+
+#...
+.*\.meta1.*WAL[ ]+0.*
+#...
+.*\.meta2.*WAL[ ]+[1-9].*
+#pass
diff --git a/gas/testsuite/gas/elf/sh-link-zero.s b/gas/testsuite/gas/elf/sh-link-zero.s
new file mode 100644
index 0000000..9e90792
--- /dev/null
+++ b/gas/testsuite/gas/elf/sh-link-zero.s
@@ -0,0 +1,13 @@
+.section .meta1,"awo",%progbits,0
+1:
+ .dc.b 0
+
+.section .meta2,"awo",%progbits,foo
+2:
+ .dc.b 1
+
+.section foo, "aw"
+ .dc.b 2
+
+.section .gc_root,"a",%progbits
+ .dc.a 1b