public inbox for binutils@sourceware.org
 help / color / mirror / Atom feed
From: Alan Modra <amodra@gmail.com>
To: binutils@sourceware.org
Subject: PR30198, Assertion and segfault when linking x86_64 elf and coff
Date: Mon, 6 Mar 2023 14:02:45 +1030	[thread overview]
Message-ID: <ZAVe3UuTbz+f5v74@squeak.grove.modra.org> (raw)

	PR 30198
	* coff-x86_64.c (coff_amd64_reloc): Set *error_message when
	returning bfd_reloc_dangerous.  Also check that __ImageBase is
	defined before accessing h->u.def.

diff --git a/bfd/coff-x86_64.c b/bfd/coff-x86_64.c
index 13061cdacff..822504a339b 100644
--- a/bfd/coff-x86_64.c
+++ b/bfd/coff-x86_64.c
@@ -139,15 +139,19 @@ coff_amd64_reloc (bfd *abfd,
 	  break;
 	case bfd_target_elf_flavour:
 	  /* Subtract __ImageBase.  */
+	  h = NULL;
 	  link_info = _bfd_get_link_info (obfd);
-	  if (link_info == NULL)
-	    return bfd_reloc_dangerous;
-	  h = bfd_link_hash_lookup (link_info->hash, "__ImageBase",
-				    false, false, false);
-	  if (h == NULL)
-	    return bfd_reloc_dangerous;
-	  while (h->type == bfd_link_hash_indirect)
-	    h = h->u.i.link;
+	  if (link_info != NULL)
+	    h = bfd_link_hash_lookup (link_info->hash, "__ImageBase",
+				      false, false, true);
+	  if (h == NULL
+	      || (h->type != bfd_link_hash_defined
+		  && h->type != bfd_link_hash_defweak))
+	    {
+	      *error_message
+		= (char *) _("R_AMD64_IMAGEBASE with __ImageBase undefined");
+	      return bfd_reloc_dangerous;
+	    }
 	  /* ELF symbols in relocatable files are section relative,
 	     but in nonrelocatable files they are virtual addresses.  */
 	  diff -= (h->u.def.value

-- 
Alan Modra
Australia Development Lab, IBM

                 reply	other threads:[~2023-03-06  3:32 UTC|newest]

Thread overview: [no followups] expand[flat|nested]  mbox.gz  Atom feed

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=ZAVe3UuTbz+f5v74@squeak.grove.modra.org \
    --to=amodra@gmail.com \
    --cc=binutils@sourceware.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
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).