public inbox for binutils@sourceware.org
 help / color / mirror / Atom feed
* [PATCH] elf: Check DT_SYMTAB only on non-IR object
@ 2023-08-30 15:55 H.J. Lu
  2023-08-30 23:47 ` Alan Modra
  0 siblings, 1 reply; 2+ messages in thread
From: H.J. Lu @ 2023-08-30 15:55 UTC (permalink / raw)
  To: binutils

Check DT_SYMTAB only on non-IR object of archive member to avoid crash
on LLVM IR object with NULL elf_tdata.

	PR ld/30811
	* elflink.c (elf_link_is_defined_archive_symbol): Check
	DT_SYMTAB only on non-IR object.
---
 bfd/elflink.c | 21 ++++++++++++---------
 1 file changed, 12 insertions(+), 9 deletions(-)

diff --git a/bfd/elflink.c b/bfd/elflink.c
index c4f286e3d90..ca162145f7e 100644
--- a/bfd/elflink.c
+++ b/bfd/elflink.c
@@ -3571,12 +3571,6 @@ elf_link_is_defined_archive_symbol (bfd * abfd, carsym * symdef)
   if (! bfd_check_format (abfd, bfd_object))
     return false;
 
-  if (elf_use_dt_symtab_p (abfd))
-    {
-      bfd_set_error (bfd_error_wrong_format);
-      return false;
-    }
-
   /* Select the appropriate symbol table.  If we don't know if the
      object file is an IR object, give linker LTO plugin a chance to
      get the correct symbol table.  */
@@ -3592,10 +3586,19 @@ elf_link_is_defined_archive_symbol (bfd * abfd, carsym * symdef)
       abfd = abfd->plugin_dummy_bfd;
       hdr = &elf_tdata (abfd)->symtab_hdr;
     }
-  else if ((abfd->flags & DYNAMIC) == 0 || elf_dynsymtab (abfd) == 0)
-    hdr = &elf_tdata (abfd)->symtab_hdr;
   else
-    hdr = &elf_tdata (abfd)->dynsymtab_hdr;
+    {
+      if (elf_use_dt_symtab_p (abfd))
+	{
+	  bfd_set_error (bfd_error_wrong_format);
+	  return false;
+	}
+
+      if ((abfd->flags & DYNAMIC) == 0 || elf_dynsymtab (abfd) == 0)
+	hdr = &elf_tdata (abfd)->symtab_hdr;
+      else
+	hdr = &elf_tdata (abfd)->dynsymtab_hdr;
+    }
 
   symcount = hdr->sh_size / get_elf_backend_data (abfd)->s->sizeof_sym;
 
-- 
2.41.0


^ permalink raw reply	[flat|nested] 2+ messages in thread

* Re: [PATCH] elf: Check DT_SYMTAB only on non-IR object
  2023-08-30 15:55 [PATCH] elf: Check DT_SYMTAB only on non-IR object H.J. Lu
@ 2023-08-30 23:47 ` Alan Modra
  0 siblings, 0 replies; 2+ messages in thread
From: Alan Modra @ 2023-08-30 23:47 UTC (permalink / raw)
  To: H.J. Lu; +Cc: binutils

On Wed, Aug 30, 2023 at 08:55:08AM -0700, H.J. Lu via Binutils wrote:
> Check DT_SYMTAB only on non-IR object of archive member to avoid crash
> on LLVM IR object with NULL elf_tdata.
> 
> 	PR ld/30811
> 	* elflink.c (elf_link_is_defined_archive_symbol): Check
> 	DT_SYMTAB only on non-IR object.

Looks good.  Thanks.

-- 
Alan Modra
Australia Development Lab, IBM

^ permalink raw reply	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2023-08-30 23:47 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2023-08-30 15:55 [PATCH] elf: Check DT_SYMTAB only on non-IR object H.J. Lu
2023-08-30 23:47 ` Alan Modra

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).