58725c
--- b/bfd/elf.c	2018-10-31 12:25:51.693217184 +0530
58725c
+++ a/bfd/elf.c	2018-10-31 12:27:54.243952676 +0530
58725c
@@ -1249,13 +1249,19 @@
58725c
   Elf_Internal_Shdr ** oheaders = elf_elfsections (obfd);
58725c
   unsigned int i;
58725c
 
58725c
-  if (section_match (oheaders[hint], iheader))
58725c
+  BFD_ASSERT (iheader != NULL);
58725c
+
58725c
+  /* See PR 20922 for a reproducer of the NULL test.  */
58725c
+  if (oheaders[hint] != NULL
58725c
+      && section_match (oheaders[hint], iheader))
58725c
     return hint;
58725c
 
58725c
   for (i = 1; i < elf_numsections (obfd); i++)
58725c
     {
58725c
       Elf_Internal_Shdr * oheader = oheaders[i];
58725c
 
58725c
+      if (oheader == NULL)
58725c
+	continue;      
58725c
       if (section_match (oheader, iheader))
58725c
 	/* FIXME: Do we care if there is a potential for
58725c
 	   multiple matches ?  */