Stop the linker from loosing the entry point for COFF/PE code when compiling with LTO enabled.

  PR 30300
  * emultempl/pep.em (set_entry_point): Add an undefined reference to the entry point if it has been constructed heuristically.
  * emultempl/pe.em (set_entry_point): Likewise.
diff --git a/ld/ChangeLog b/ld/ChangeLog
index dcdf27c..121bdfd 100644
--- a/ld/ChangeLog
+++ b/ld/ChangeLog
@@ -1,3 +1,10 @@
+2023-05-04  Nick Clifton  <nickc@redhat.com>
+
+	PR 30300
+	* emultempl/pep.em (set_entry_point): Add an undefined reference
+	to the entry point if it has been constructed heuristically.
+	* emultempl/pe.em (set_entry_point): Likewise.
+
 2023-05-04  Dimitar Dimitrov  <dimitar@dinux.eu>
 
 	* scripttempl/pru.sc (OUTPUT_SECTION_ALIGN): New helper variable
diff --git a/ld/emultempl/pe.em b/ld/emultempl/pe.em
index 55412d6..1f2a5f3 100644
--- a/ld/emultempl/pe.em
+++ b/ld/emultempl/pe.em
@@ -659,6 +659,9 @@
     }
 
   lang_default_entry (entry);
+
+  if (bfd_link_executable (&link_info) && ! entry_from_cmdline)
+    ldlang_add_undef (entry, false);  
 }
 
 static void
diff --git a/ld/emultempl/pep.em b/ld/emultempl/pep.em
index 2a3fd0e..ca4acae 100644
--- a/ld/emultempl/pep.em
+++ b/ld/emultempl/pep.em
@@ -631,6 +631,9 @@
     }
 
   lang_default_entry (entry);
+
+  if (bfd_link_executable (&link_info) && ! entry_from_cmdline)
+    ldlang_add_undef (entry, false);  
 }
 
 static void