x86: Silence -fsanitize=undefined

Message ID CAMe9rOpB_HCpfPZ4D87sF34hyOEWBcXiVO7S=uWC1W6rM9M7XA@mail.gmail.com
State New
Headers show
Series
  • x86: Silence -fsanitize=undefined
Related show

Commit Message

H.J. Lu via Binutils June 3, 2020, 1:35 p.m.
On Wed, Jun 3, 2020 at 5:12 AM Alan Modra <amodra@gmail.com> wrote:
>

> On Wed, Jun 03, 2020 at 11:51:30AM +0100, Nick Clifton wrote:

> > Which are all due to:

> >

> >   bfd/elf64-x86-64.c:3233:8: runtime error: member access within null pointer of type 'struct elf_x86_link_hash_entry'

>

> This will be "&(EH)->elf" in elfxx-x86.h:GENERATE_DYNAMIC_RELOCATION_P.

> Fixable by using "(struct elf_link_hash_entry *) (EH)" instead.

>


Thanks.  This is what I am checking in.

-- 
H.J.

Patch

From 433953ffa1a59531a5537327a4e3ce24565e609c Mon Sep 17 00:00:00 2001
From: "H.J. Lu" <hjl.tools@gmail.com>
Date: Wed, 3 Jun 2020 06:32:24 -0700
Subject: [PATCH] x86: Silence -fsanitize=undefined

Replace "&(EH)->elf" with "(struct elf_link_hash_entry *) (EH)" to
silence -fsanitize=undefined.

	* elfxx-x86.h (GENERATE_DYNAMIC_RELOCATION_P): Replace
	"&(EH)->elf" with "(struct elf_link_hash_entry *) (EH)".
---
 bfd/ChangeLog   | 5 +++++
 bfd/elfxx-x86.h | 6 +++---
 2 files changed, 8 insertions(+), 3 deletions(-)

diff --git a/bfd/ChangeLog b/bfd/ChangeLog
index e60cfac5be..2fa19f8130 100644
--- a/bfd/ChangeLog
+++ b/bfd/ChangeLog
@@ -1,3 +1,8 @@ 
+2020-06-03  H.J. Lu  <hongjiu.lu@intel.com>
+
+	* elfxx-x86.h (GENERATE_DYNAMIC_RELOCATION_P): Silence
+	-fsanitize=undefined.
+
 2020-06-03  Alan Modra  <amodra@gmail.com>
 
 	PR 26069
diff --git a/bfd/elfxx-x86.h b/bfd/elfxx-x86.h
index b64c41390a..c717cd16e5 100644
--- a/bfd/elfxx-x86.h
+++ b/bfd/elfxx-x86.h
@@ -133,9 +133,9 @@ 
 	|| ((ELF_ST_VISIBILITY ((EH)->elf.other) == STV_DEFAULT \
 	     && (!(RESOLVED_TO_ZERO) || PC32_RELOC)) \
 	    || (EH)->elf.root.type != bfd_link_hash_undefweak)) \
-    && ((!X86_PCREL_TYPE_P (R_TYPE) \
-	 && !X86_SIZE_TYPE_P (R_TYPE)) \
-	 || ! SYMBOL_CALLS_LOCAL ((INFO), &(EH)->elf))) \
+    && ((!X86_PCREL_TYPE_P (R_TYPE) && !X86_SIZE_TYPE_P (R_TYPE)) \
+	|| ! SYMBOL_CALLS_LOCAL ((INFO), \
+				 (struct elf_link_hash_entry *) (EH)))) \
    || (ELIMINATE_COPY_RELOCS \
        && !bfd_link_pic (INFO) \
        && (EH) != NULL \
-- 
2.26.2