summaryrefslogtreecommitdiff
path: root/ld/ldlang.c
diff options
context:
space:
mode:
authorAlan Modra <amodra@gmail.com>2022-01-12 12:37:27 +1030
committerAlan Modra <amodra@gmail.com>2022-01-12 12:55:17 +1030
commitb02db37812bef6e12772bfbddd004e50534eaed1 (patch)
tree775ed5bbacbb532774161bd54e4e34b89f7c2f71 /ld/ldlang.c
parent295114a64ff50cc79e4510b8be935ebccda2900a (diff)
downloadbinutils-gdb-b02db37812bef6e12772bfbddd004e50534eaed1.tar.gz
Set SEC_ELF_REVERSE_COPY earlier
For the sake of DT_RELR. bfd/ * elflink.c (elf_link_input_bfd): Don't set SEC_ELF_REVERSE_COPY here. Move sanity checks to reverse copying code. ld/ * ldlang.c (lang_add_section): Set SEC_ELF_REVERSE_COPY for .ctors/.dtors in .init_array/.fini_array.
Diffstat (limited to 'ld/ldlang.c')
-rw-r--r--ld/ldlang.c10
1 files changed, 10 insertions, 0 deletions
diff --git a/ld/ldlang.c b/ld/ldlang.c
index 9dbc8752f87..0af6c60bce5 100644
--- a/ld/ldlang.c
+++ b/ld/ldlang.c
@@ -2701,6 +2701,16 @@ lang_add_section (lang_statement_list_type *ptr,
output->block_value = 128;
}
+ /* When a .ctors section is placed in .init_array it must be copied
+ in reverse order. Similarly for .dtors. Set that up. */
+ if (bfd_get_flavour (link_info.output_bfd) == bfd_target_elf_flavour
+ && ((startswith (section->name, ".ctors")
+ && strcmp (output->bfd_section->name, ".init_array") == 0)
+ || (startswith (section->name, ".dtors")
+ && strcmp (output->bfd_section->name, ".fini_array") == 0))
+ && (section->name[6] == 0 || section->name[6] == '.'))
+ section->flags |= SEC_ELF_REVERSE_COPY;
+
if (section->alignment_power > output->bfd_section->alignment_power)
output->bfd_section->alignment_power = section->alignment_power;