+2020-02-06 H.J. Lu <hongjiu.lu@intel.com>
+
+ PR ld/25022
+ * emultempl/aix.em (ld_${EMULATION_NAME}_emulation): Add
+ before_place_orphans_default.
+ * emultempl/armcoff.em (ld_${EMULATION_NAME}_emulation): Likewise.
+ * emultempl/beos.em (ld_${EMULATION_NAME}_emulation): Likewise.
+ * emultempl/generic.em (ld_${EMULATION_NAME}_emulation): Likewise.
+ * emultempl/linux.em (ld_${EMULATION_NAME}_emulation): Likewise.
+ * emultempl/msp430.em (ld_${EMULATION_NAME}_emulation): Likewise.
+ * emultempl/pe.em (ld_${EMULATION_NAME}_emulation): Likewise.
+ * emultempl/pep.em (ld_${EMULATION_NAME}_emulation): Likewise.
+ * emultempl/ticoff.em (ld_${EMULATION_NAME}_emulation): Likewise.
+ * emultempl/vanilla.em (ld_${EMULATION_NAME}_emulation): Likewise.
+ * emultempl/elf.em (ld_${EMULATION_NAME}_emulation): Use
+ ldelf_before_place_orphans.
+ * ldelf.c (ldelf_before_place_orphans): New.
+ * ldelf.h (ldelf_before_place_orphans): Likewise.
+ * ldemul.c (ldemul_before_place_orphans): Likewise.
+ (before_place_orphans_default): Likewise.
+ * ldemul.h (ldemul_before_place_orphans): Likewise.
+ (before_place_orphans_default): Likewise.
+ (ld_emulation_xfer_struct): Add before_place_orphans.
+ * ldlang.c (lang_process): Call ldemul_before_place_orphans
+ before lang_place_orphans.
+ * testsuite/ld-elf/pr25022.d: New file.
+ * testsuite/ld-elf/pr25022.s: Likewise.
+ * testsuite/ld-elf/pr25022.t: Likewise.
+
2020-02-06 H.J. Lu <hongjiu.lu@intel.com>
PR ld/25490
after_parse_default,
gld${EMULATION_NAME}_after_open,
after_check_relocs_default,
+ before_place_orphans_default,
after_allocation_default,
gld${EMULATION_NAME}_set_output_arch,
gld${EMULATION_NAME}_choose_target,
after_parse_default,
gld${EMULATION_NAME}_after_open,
after_check_relocs_default,
+ before_place_orphans_default,
after_allocation_default,
set_output_arch_default,
ldemul_default_target,
after_parse_default,
gld_${EMULATION_NAME}_after_open,
after_check_relocs_default,
+ before_place_orphans_default,
after_allocation_default,
set_output_arch_default,
ldemul_default_target,
${LDEMUL_AFTER_PARSE-ldelf_after_parse},
${LDEMUL_AFTER_OPEN-gld${EMULATION_NAME}_after_open},
${LDEMUL_AFTER_CHECK_RELOCS-after_check_relocs_default},
+ ${LDEMUL_BEFORE_PLACE_ORPHANS-ldelf_before_place_orphans},
${LDEMUL_AFTER_ALLOCATION-gld${EMULATION_NAME}_after_allocation},
${LDEMUL_SET_OUTPUT_ARCH-set_output_arch_default},
${LDEMUL_CHOOSE_TARGET-ldemul_default_target},
${LDEMUL_AFTER_PARSE-after_parse_default},
${LDEMUL_AFTER_OPEN-after_open_default},
${LDEMUL_AFTER_CHECK_RELOCS-after_check_relocs_default},
+ ${LDEMUL_BEFORE_PLACE_ORPHANS-before_place_orphans_default},
${LDEMUL_AFTER_ALLOCATION-after_allocation_default},
${LDEMUL_SET_OUTPUT_ARCH-set_output_arch_default},
${LDEMUL_CHOOSE_TARGET-ldemul_default_target},
after_parse_default,
after_open_default,
after_check_relocs_default,
+ before_place_orphans_default,
after_allocation_default,
set_output_arch_default,
ldemul_default_target,
${LDEMUL_AFTER_PARSE-after_parse_default},
msp430_elf_after_open,
after_check_relocs_default,
+ before_place_orphans_default,
msp430_elf_after_allocation,
${LDEMUL_SET_OUTPUT_ARCH-set_output_arch_default},
${LDEMUL_CHOOSE_TARGET-ldemul_default_target},
gld_${EMULATION_NAME}_after_parse,
gld_${EMULATION_NAME}_after_open,
after_check_relocs_default,
+ before_place_orphans_default,
after_allocation_default,
set_output_arch_default,
ldemul_default_target,
gld_${EMULATION_NAME}_after_parse,
gld_${EMULATION_NAME}_after_open,
after_check_relocs_default,
+ before_place_orphans_default,
after_allocation_default,
set_output_arch_default,
ldemul_default_target,
after_parse_default,
after_open_default,
after_check_relocs_default,
+ before_place_orphans_default,
after_allocation_default,
set_output_arch_default,
ldemul_default_target,
after_parse_default,
after_open_default,
after_check_relocs_default,
+ before_place_orphans_default,
after_allocation_default,
vanilla_set_output_arch,
ldemul_default_target,
return lang_insert_orphan (s, secname, constraint, after, place, NULL, NULL);
}
+
+void
+ldelf_before_place_orphans (void)
+{
+ bfd *abfd;
+
+ for (abfd = link_info.input_bfds;
+ abfd != (bfd *) NULL; abfd = abfd->link.next)
+ if (bfd_get_flavour (abfd) == bfd_target_elf_flavour
+ && bfd_count_sections (abfd) != 0
+ && !bfd_input_just_syms (abfd))
+ {
+ asection *isec;
+ for (isec = abfd->sections; isec != NULL; isec = isec->next)
+ {
+ /* Discard a section if any of its linked-to section has
+ been discarded. */
+ asection *linked_to_sec;
+ for (linked_to_sec = elf_linked_to_section (isec);
+ linked_to_sec != NULL;
+ linked_to_sec = elf_linked_to_section (linked_to_sec))
+ if (discarded_section (linked_to_sec))
+ {
+ isec->output_section = bfd_abs_section_ptr;
+ break;
+ }
+ }
+ }
+}
(const char *, search_dirs_type *, lang_input_statement_type *);
extern lang_output_section_statement_type *ldelf_place_orphan
(asection *, const char *, int);
+extern void ldelf_before_place_orphans (void);
ld_emulation->after_check_relocs ();
}
+void
+ldemul_before_place_orphans (void)
+{
+ ld_emulation->before_place_orphans ();
+}
+
void
ldemul_after_allocation (void)
{
{
}
+void
+before_place_orphans_default (void)
+{
+}
+
void
after_allocation_default (void)
{
(void);
extern void ldemul_after_check_relocs
(void);
+extern void ldemul_before_place_orphans
+ (void);
extern void ldemul_after_allocation
(void);
extern void ldemul_before_allocation
(void);
extern void after_check_relocs_default
(void);
+extern void before_place_orphans_default
+ (void);
extern void after_allocation_default
(void);
extern void before_allocation_default
/* Run after checking relocations. */
void (*after_check_relocs) (void);
+ /* Run before placing orphans. */
+ void (*before_place_orphans) (void);
+
/* Run after allocating output sections. */
void (*after_allocation) (void);
output statement, so that it isn't reordered. */
process_insert_statements (&lang_os_list.head->header.next);
+ ldemul_before_place_orphans ();
+
/* Find any sections not attached explicitly and handle them. */
lang_place_orphans ();
--- /dev/null
+#ld: -T pr25022.t
+#readelf: -SW
+#xfail: msp*-*
+# msp* doesn't use ldelf_before_place_orphans.
+
+#failif
+#...
+ +\[ *[0-9]+\] \.(bar|moo|zed) +.*
+#...
--- /dev/null
+ .section .foo,"a"
+ .dc.a 0
+
+ .section .moo,"ao",%progbits,.zed
+ .dc.a 0
+
+ .section .bar,"ao",%progbits,.foo
+ .dc.a 0
+
+ .section .zed,"ao",%progbits,.foo
+ .dc.a 0
--- /dev/null
+SECTIONS { /DISCARD/ : { *(.foo) } }