+2020-10-05 Nick Clifton <nickc@redhat.com>
+
+ PR 26253
+ * elf.c (_bfd_elf_setup_sections): Do not complain about an
+ sh_link value of zero when the SLF_LINK_ORDER flag is set.
+ (assign_section_numbers): Likewise.
+
2020-10-02 H.J. Lu <hongjiu.lu@intel.com>
PR 26681
if ((this_hdr->sh_flags & SHF_LINK_ORDER) != 0)
{
unsigned int elfsec = this_hdr->sh_link;
- /* FIXME: The old Intel compiler and old strip/objcopy may
- not set the sh_link or sh_info fields. Hence we could
- get the situation where elfsec is 0. */
+ /* An sh_link value of 0 is now allowed. It indicates that linked
+ to section has already been discarded, but that the current
+ section has been retained for some other reason. This linking
+ section is still a candidate for later garbage collection
+ however. */
if (elfsec == 0)
{
- const struct elf_backend_data *bed = get_elf_backend_data (abfd);
- bed->link_order_error_handler
- /* xgettext:c-format */
- (_("%pB: warning: sh_link not set for section `%pA'"),
- abfd, s);
+ elf_linked_to_section (s) = NULL;
}
else
{
if ((d->this_hdr.sh_flags & SHF_LINK_ORDER) != 0)
{
s = elf_linked_to_section (sec);
+ /* We can now have a NULL linked section pointer.
+ This happens when the sh_link field is 0, which is done
+ when a linked to section is discarded but the linking
+ section has been retained for some reason. */
if (s)
{
/* Check discarded linkonce section. */
s = s->output_section;
d->this_hdr.sh_link = elf_section_data (s)->this_idx;
}
- else
- {
- /* PR 290:
- The Intel C compiler generates SHT_IA_64_UNWIND with
- SHF_LINK_ORDER. But it doesn't set the sh_link or
- sh_info fields. Hence we could get the situation
- where s is NULL. */
- const struct elf_backend_data *bed
- = get_elf_backend_data (abfd);
- bed->link_order_error_handler
- /* xgettext:c-format */
- (_("%pB: warning: sh_link not set for section `%pA'"),
- abfd, sec);
- }
}
switch (d->this_hdr.sh_type)
+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
-*- 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.
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;
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)
{
int linkonce;
subsegT new_subsection = -1;
struct elf_section_match match;
+ unsigned long linked_to_section_index = -1UL;
if (flag_mri)
{
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)
as_warn (_("? section flag ignored with G present"));
is_clone = FALSE;
}
+
if ((attr & SHF_GROUP) != 0 && *input_line_pointer == ',')
{
++input_line_pointer;
if (*input_line_pointer == ',')
{
char *save = input_line_pointer;
+
++input_line_pointer;
SKIP_WHITESPACE ();
if (strncmp (input_line_pointer, "unique", 6) == 0)
}
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);
}
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
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:
run_dump_test "attach-1"
run_dump_test "attach-err"
-
+
switch -glob $target_triplet {
hppa64*-*-hpux* { }
riscv*-*-* { }
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
[^:]*: 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'
--- /dev/null
+#readelf: --wide --sections
+#name: Setting the sh_link field to 0
+#source: sh-link-zero.s
+
+#...
+.*\.meta1.*WAL[ ]+0.*
+#...
+.*\.meta2.*WAL[ ]+[1-9].*
+#pass
--- /dev/null
+.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