PR 34450 SEGV in elf_orphan_compatible

Message ID arJudh3E8gU_Q0O5@squeak.grove.modra.org
State New
Headers
Series PR 34450 SEGV in elf_orphan_compatible |

Checks

Context Check Description
linaro-tcwg-bot/tcwg_binutils_build--master-arm fail Patch failed to apply
linaro-tcwg-bot/tcwg_binutils_build--master-aarch64 fail Patch failed to apply

Commit Message

Alan Modra Sept. 22, 2026, 12:03 p.m. UTC
  Don't trust that SHF_LINK_ORDER set means linked_to is non-NULL.

	* ldelf.c (elf_orphan_compatible): Sanity check linked_to before
	dereferencing.
  

Patch

diff --git a/ld/ldelf.c b/ld/ldelf.c
index c1f29608c6d..0fe69784e08 100644
--- a/ld/ldelf.c
+++ b/ld/ldelf.c
@@ -2129,6 +2129,7 @@  elf_orphan_compatible (asection *in, asection *out)
 	  || ((elf_section_flags (in) & SHF_LINK_ORDER) != 0
 	      && (elf_section_flags (out) & SHF_LINK_ORDER) != 0
 	      && elf_linked_to_section (in) != NULL
+	      && elf_linked_to_section (out) != NULL
 	      && (elf_linked_to_section (in)->output_section
 		  != elf_linked_to_section (out)->output_section))
 	  || ((elf_section_flags (out) ^ elf_section_flags (in))