Make a reference to _pei386_runtime_relocator before LTO recompilation.
This is done regardless of whether such a reference will be used,
because it can't be known whether it is needed before LTO.
I also found it necessary to enable long section names for the bfd
created in make_runtime_pseudo_reloc, because otherwise when writing
it out to the bfd-in-memory we get the section written as .rdata_r
which when read back in leads to a linker warning ".rdata_r: section
below image base" and likely runtime misbehaviour.
PR 30343
* emultempl/pe.em (make_runtime_ref): New function.
(gld${EMULATION_NAME}_before_plugin_all_symbols_read): New function.
(LDEMUL_BEFORE_PLUGIN_ALL_SYMBOLS_READ): Define.
* emultempl/pep.em: Similarly to pe.em.
* pe-dll.c (make_runtime_pseudo_reloc): Set long section names.
pe_create_import_fixup (rel, s, _addend, name, symname);
}
+static void
+make_runtime_ref (void)
+{
+ const char *rr = U ("_pei386_runtime_relocator");
+ struct bfd_link_hash_entry *h
+ = bfd_wrapped_link_hash_lookup (link_info.output_bfd, &link_info,
+ rr, true, false, true);
+ if (!h)
+ einfo (_("%F%P: bfd_link_hash_lookup failed: %E\n"));
+ else
+ {
+ if (h->type == bfd_link_hash_new)
+ {
+ h->type = bfd_link_hash_undefined;
+ h->u.undef.abfd = NULL;
+ if (h->u.undef.next == NULL && h != link_info.hash->undefs_tail)
+ bfd_link_add_undef (link_info.hash, h);
+ }
+ h->non_ir_ref_regular = true;
+ }
+}
+
static bool
pr_sym (struct bfd_hash_entry *h, void *inf ATTRIBUTE_UNUSED)
{
return false;
}
+static void
+gld${EMULATION_NAME}_before_plugin_all_symbols_read (void)
+{
+#ifdef DLL_SUPPORT
+ if (link_info.lto_plugin_active
+ && link_info.pei386_auto_import)
+ make_runtime_ref ();
+#endif
+}
+
static void
gld${EMULATION_NAME}_after_open (void)
{
fi
LDEMUL_AFTER_PARSE=gld${EMULATION_NAME}_after_parse
+LDEMUL_BEFORE_PLUGIN_ALL_SYMBOLS_READ=gld${EMULATION_NAME}_before_plugin_all_symbols_read
LDEMUL_AFTER_OPEN=gld${EMULATION_NAME}_after_open
LDEMUL_BEFORE_ALLOCATION=gld${EMULATION_NAME}_before_allocation
LDEMUL_FINISH=gld${EMULATION_NAME}_finish
pep_create_import_fixup (rel, s, _addend, name, symname);
}
+static void
+make_runtime_ref (void)
+{
+ const char *rr = U ("_pei386_runtime_relocator");
+ struct bfd_link_hash_entry *h
+ = bfd_wrapped_link_hash_lookup (link_info.output_bfd, &link_info,
+ rr, true, false, true);
+ if (!h)
+ einfo (_("%F%P: bfd_link_hash_lookup failed: %E\n"));
+ else
+ {
+ if (h->type == bfd_link_hash_new)
+ {
+ h->type = bfd_link_hash_undefined;
+ h->u.undef.abfd = NULL;
+ if (h->u.undef.next == NULL && h != link_info.hash->undefs_tail)
+ bfd_link_add_undef (link_info.hash, h);
+ }
+ h->non_ir_ref_regular = true;
+ }
+}
+
static bool
pr_sym (struct bfd_hash_entry *h, void *inf ATTRIBUTE_UNUSED)
{
return false;
}
+static void
+gld${EMULATION_NAME}_before_plugin_all_symbols_read (void)
+{
+#ifdef DLL_SUPPORT
+ if (link_info.lto_plugin_active
+ && link_info.pei386_auto_import) /* -1=warn or 1=enable */
+ make_runtime_ref ();
+#endif
+}
+
static void
gld${EMULATION_NAME}_after_open (void)
{
fi
LDEMUL_AFTER_PARSE=gld${EMULATION_NAME}_after_parse
+LDEMUL_BEFORE_PLUGIN_ALL_SYMBOLS_READ=gld${EMULATION_NAME}_before_plugin_all_symbols_read
LDEMUL_AFTER_OPEN=gld${EMULATION_NAME}_after_open
LDEMUL_BEFORE_ALLOCATION=gld${EMULATION_NAME}_before_allocation
LDEMUL_FINISH=gld${EMULATION_NAME}_finish
rt_rel
= quick_section (abfd, ".rdata_runtime_pseudo_reloc", SEC_HAS_CONTENTS, 2);
+ bfd_coff_set_long_section_names (abfd, true);
quick_symbol (abfd, "", fixup_name, "", UNDSEC, BSF_GLOBAL, 0);