public inbox for binutils@sourceware.org
 help / color / mirror / Atom feed
* PR26483, ASAN: ppc_elf_link_params elf32-ppc.c:2314
@ 2020-08-24 16:37 Alan Modra
  2020-08-24 17:18 ` Alan Modra
  0 siblings, 1 reply; 2+ messages in thread
From: Alan Modra @ 2020-08-24 16:37 UTC (permalink / raw)
  To: binutils

	PR 26483
	* elf32-ppc.c (ppc_elf_hash_table): Test is_elf_hash_table before
	accessing elf_hash_table_id.

diff --git a/bfd/elf32-ppc.c b/bfd/elf32-ppc.c
index 43c0e18896..d5b8a6627a 100644
--- a/bfd/elf32-ppc.c
+++ b/bfd/elf32-ppc.c
@@ -2230,8 +2230,9 @@ struct ppc_elf_link_hash_table
 /* Get the PPC ELF linker hash table from a link_info structure.  */
 
 #define ppc_elf_hash_table(p) \
-  (elf_hash_table_id ((struct elf_link_hash_table *) ((p)->hash)) \
-  == PPC32_ELF_DATA ? ((struct ppc_elf_link_hash_table *) ((p)->hash)) : NULL)
+  ((is_elf_hash_table ((p)->hash)					\
+    && elf_hash_table_id (elf_hash_table (p)) == PPC32_ELF_DATA)	\
+   ? ((struct ppc_elf_link_hash_table *) ((p)->hash)) : NULL)
 
 /* Create an entry in a PPC ELF linker hash table.  */
 

-- 
Alan Modra
Australia Development Lab, IBM

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

* Re: PR26483, ASAN: ppc_elf_link_params elf32-ppc.c:2314
  2020-08-24 16:37 PR26483, ASAN: ppc_elf_link_params elf32-ppc.c:2314 Alan Modra
@ 2020-08-24 17:18 ` Alan Modra
  0 siblings, 0 replies; 2+ messages in thread
From: Alan Modra @ 2020-08-24 17:18 UTC (permalink / raw)
  To: binutils

On Tue, Aug 25, 2020 at 02:07:57AM +0930, Alan Modra wrote:
> 	PR 26483
> 	* elf32-ppc.c (ppc_elf_hash_table): Test is_elf_hash_table before
> 	accessing elf_hash_table_id.

And some more.

	* elf-m10300.c (elf32_mn10300_hash_table): Test is_elf_hash_table
	before accessing elf_hash_table_id.
	* elf32-arc.c (elf_arc_hash_table): Likewise.
	* elf32-arm.c (elf32_arm_hash_table): Likewise.
	* elf32-avr.c (avr_link_hash_table): Likewise.
	* elf32-bfin.c (bfinfdpic_hash_table): Likewise.
	* elf32-cris.c (elf_cris_hash_table): Likewise.
	* elf32-csky.c (csky_elf_hash_table): Likewise.
	* elf32-frv.c (frvfdpic_hash_table): Likewise.
	* elf32-hppa.c (hppa_link_hash_table): Likewise.
	* elf32-lm32.c (lm32_elf_hash_table): Likewise.
	* elf32-m32r.c (m32r_elf_hash_table): Likewise.
	* elf32-m68hc1x.h (m68hc11_elf_hash_table): Likewise.
	* elf32-m68k.c (elf_m68k_hash_table): Likewise.
	* elf32-metag.c (metag_link_hash_table): Likewise.
	* elf32-microblaze.c (elf32_mb_hash_table): Likewise.
	* elf32-nds32.h (nds32_elf_hash_table): Likewise.
	* elf32-or1k.c (or1k_elf_hash_table): Likewise.
	* elf32-s390.c (elf_s390_hash_table): Likewise.
	* elf32-sh.c (sh_elf_hash_table): Likewise.
	* elf32-spu.c (spu_hash_table): Likewise.
	* elf32-tilepro.c (tilepro_elf_hash_table): Likewise.
	* elf32-xtensa.c (elf_xtensa_hash_table): Likewise.
	* elf64-alpha.c (alpha_elf_hash_table): Likewise.
	* elf64-hppa.c (hppa_link_hash_table): Likewise.
	* elf64-ia64-vms.c (elf64_ia64_hash_table): Likewise.
	* elf64-s390.c (elf_s390_hash_table): Likewise.
	* elfnn-ia64.c (elfNN_ia64_hash_table): Likewise.
	* elfnn-riscv.c (riscv_elf_hash_table): Likewise.
	* elfxx-mips.c (mips_elf_hash_table): Likewise.
	* elfxx-sparc.h (_bfd_sparc_elf_hash_table): Likewise.
	* elfxx-tilegx.c (tilegx_elf_hash_table): Likewise.

diff --git a/bfd/elf-m10300.c b/bfd/elf-m10300.c
index 1c436a78d5..ae8cac84e6 100644
--- a/bfd/elf-m10300.c
+++ b/bfd/elf-m10300.c
@@ -128,8 +128,9 @@ struct elf_mn10300_obj_tdata
 /* Get the MN10300 ELF linker hash table from a link_info structure.  */
 
 #define elf32_mn10300_hash_table(p) \
-  (elf_hash_table_id ((struct elf_link_hash_table *) ((p)->hash)) \
-  == MN10300_ELF_DATA ? ((struct elf32_mn10300_link_hash_table *) ((p)->hash)) : NULL)
+  ((is_elf_hash_table ((p)->hash)					\
+    && elf_hash_table_id (elf_hash_table (p)) == MN10300_ELF_DATA)	\
+   ? (struct elf32_mn10300_link_hash_table *) (p)->hash : NULL)
 
 #define elf32_mn10300_link_hash_traverse(table, func, info)		\
   (elf_link_hash_traverse						\
diff --git a/bfd/elf32-arc.c b/bfd/elf32-arc.c
index 4d9d6b9992..7d282f39ac 100644
--- a/bfd/elf32-arc.c
+++ b/bfd/elf32-arc.c
@@ -1939,8 +1939,9 @@ elf_arc_relocate_section (bfd *			  output_bfd,
 }
 
 #define elf_arc_hash_table(p) \
-    (elf_hash_table_id ((struct elf_link_hash_table *) ((p)->hash)) \
-  == ARC_ELF_DATA ? ((struct elf_arc_link_hash_table *) ((p)->hash)) : NULL)
+  ((is_elf_hash_table ((p)->hash)					\
+    && elf_hash_table_id (elf_hash_table (p)) == ARC_ELF_DATA)		\
+   ? (struct elf_arc_link_hash_table *) (p)->hash : NULL)
 
 static bfd_boolean
 elf_arc_check_relocs (bfd *			 abfd,
diff --git a/bfd/elf32-arm.c b/bfd/elf32-arm.c
index 283a614030..66930c0c7d 100644
--- a/bfd/elf32-arm.c
+++ b/bfd/elf32-arm.c
@@ -3255,9 +3255,10 @@ struct elf32_arm_link_hash_entry
     (info)))
 
 /* Get the ARM elf linker hash table from a link_info structure.  */
-#define elf32_arm_hash_table(info) \
-  (elf_hash_table_id ((struct elf_link_hash_table *) ((info)->hash)) \
-  == ARM_ELF_DATA ? ((struct elf32_arm_link_hash_table *) ((info)->hash)) : NULL)
+#define elf32_arm_hash_table(p) \
+  ((is_elf_hash_table ((p)->hash)					\
+    && elf_hash_table_id (elf_hash_table (p)) == ARM_ELF_DATA)		\
+   ? (struct elf32_arm_link_hash_table *) (p)->hash : NULL)
 
 #define arm_stub_hash_lookup(table, string, create, copy) \
   ((struct elf32_arm_stub_hash_entry *) \
diff --git a/bfd/elf32-avr.c b/bfd/elf32-avr.c
index d4ad18c825..9adf627975 100644
--- a/bfd/elf32-avr.c
+++ b/bfd/elf32-avr.c
@@ -106,9 +106,9 @@ struct elf32_avr_link_hash_table
 
 /* Various hash macros and functions.  */
 #define avr_link_hash_table(p) \
-  /* PR 3874: Check that we have an AVR style hash table before using it.  */\
-  (elf_hash_table_id ((struct elf_link_hash_table *) ((p)->hash)) \
-  == AVR_ELF_DATA ? ((struct elf32_avr_link_hash_table *) ((p)->hash)) : NULL)
+  ((is_elf_hash_table ((p)->hash)					\
+    && elf_hash_table_id (elf_hash_table (p)) == AVR_ELF_DATA)		\
+   ? (struct elf32_avr_link_hash_table *) (p)->hash : NULL)
 
 #define avr_stub_hash_entry(ent) \
   ((struct elf32_avr_stub_hash_entry *)(ent))
diff --git a/bfd/elf32-bfin.c b/bfd/elf32-bfin.c
index f6ecc380d8..ab928530db 100644
--- a/bfd/elf32-bfin.c
+++ b/bfd/elf32-bfin.c
@@ -1668,9 +1668,10 @@ struct bfinfdpic_elf_link_hash_table
 
 /* Get the Blackfin ELF linker hash table from a link_info structure.  */
 
-#define bfinfdpic_hash_table(info) \
-  (elf_hash_table_id ((struct elf_link_hash_table *) ((info)->hash)) \
-  == BFIN_ELF_DATA ? ((struct bfinfdpic_elf_link_hash_table *) ((info)->hash)) : NULL)
+#define bfinfdpic_hash_table(p) \
+  ((is_elf_hash_table ((p)->hash)					\
+    && elf_hash_table_id (elf_hash_table (p)) == BFIN_ELF_DATA)		\
+   ? (struct bfinfdpic_elf_link_hash_table *) (p)->hash : NULL)
 
 #define bfinfdpic_got_section(info) \
   (bfinfdpic_hash_table (info)->elf.sgot)
diff --git a/bfd/elf32-cris.c b/bfd/elf32-cris.c
index 4360b5418c..6e5a2d87d6 100644
--- a/bfd/elf32-cris.c
+++ b/bfd/elf32-cris.c
@@ -837,8 +837,9 @@ struct elf_cris_link_hash_table
 /* Get the CRIS ELF linker hash table from a link_info structure.  */
 
 #define elf_cris_hash_table(p) \
-  (elf_hash_table_id ((struct elf_link_hash_table *) ((p)->hash)) \
-  == CRIS_ELF_DATA ? ((struct elf_cris_link_hash_table *) ((p)->hash)) : NULL)
+  ((is_elf_hash_table ((p)->hash)					\
+    && elf_hash_table_id (elf_hash_table (p)) == CRIS_ELF_DATA)		\
+   ? (struct elf_cris_link_hash_table *) (p)->hash : NULL)
 
 /* Get the CRIS ELF linker hash entry from a regular hash entry (the
    "parent class").  The .root reference is just a simple type
diff --git a/bfd/elf32-csky.c b/bfd/elf32-csky.c
index 2998aad205..7806ec7417 100644
--- a/bfd/elf32-csky.c
+++ b/bfd/elf32-csky.c
@@ -1184,11 +1184,10 @@ struct csky_elf_link_hash_entry
     (info)))
 
 /* Get the C-SKY ELF linker hash table from a link_info structure.  */
-#define csky_elf_hash_table(info) \
-  ((elf_hash_table_id  ((struct elf_link_hash_table *) ((info)->hash))	\
-    == CSKY_ELF_DATA)							\
-   ? ((struct csky_elf_link_hash_table *) ((info)->hash))		\
-   : NULL)
+#define csky_elf_hash_table(p) \
+  ((is_elf_hash_table ((p)->hash)					\
+    && elf_hash_table_id (elf_hash_table (p)) == CSKY_ELF_DATA)		\
+   ? (struct csky_elf_link_hash_table *) (p)->hash : NULL)
 
 #define csky_elf_hash_entry(ent)  ((struct csky_elf_link_hash_entry*)(ent))
 
diff --git a/bfd/elf32-frv.c b/bfd/elf32-frv.c
index ad0779b52c..9908c0112a 100644
--- a/bfd/elf32-frv.c
+++ b/bfd/elf32-frv.c
@@ -826,8 +826,9 @@ struct frvfdpic_elf_link_hash_table
 /* Get the FRV ELF linker hash table from a link_info structure.  */
 
 #define frvfdpic_hash_table(p) \
-  (elf_hash_table_id ((struct elf_link_hash_table *) ((p)->hash)) \
-  == FRV_ELF_DATA ? ((struct frvfdpic_elf_link_hash_table *) ((p)->hash)) : NULL)
+  ((is_elf_hash_table ((p)->hash)					\
+    && elf_hash_table_id (elf_hash_table (p)) == FRV_ELF_DATA)		\
+   ? (struct frvfdpic_elf_link_hash_table *) (p)->hash : NULL)
 
 #define frvfdpic_got_section(info) \
   (frvfdpic_hash_table (info)->elf.sgot)
diff --git a/bfd/elf32-hppa.c b/bfd/elf32-hppa.c
index 56284eaf00..b9b1dad1ae 100644
--- a/bfd/elf32-hppa.c
+++ b/bfd/elf32-hppa.c
@@ -296,8 +296,9 @@ struct elf32_hppa_link_hash_table
 
 /* Various hash macros and functions.  */
 #define hppa_link_hash_table(p) \
-  (elf_hash_table_id ((struct elf_link_hash_table *) ((p)->hash)) \
-  == HPPA32_ELF_DATA ? ((struct elf32_hppa_link_hash_table *) ((p)->hash)) : NULL)
+  ((is_elf_hash_table ((p)->hash)					\
+    && elf_hash_table_id (elf_hash_table (p)) == HPPA32_ELF_DATA)	\
+   ? (struct elf32_hppa_link_hash_table *) (p)->hash : NULL)
 
 #define hppa_elf_hash_entry(ent) \
   ((struct elf32_hppa_link_hash_entry *)(ent))
diff --git a/bfd/elf32-lm32.c b/bfd/elf32-lm32.c
index 2be3b92644..1751b66bae 100644
--- a/bfd/elf32-lm32.c
+++ b/bfd/elf32-lm32.c
@@ -67,8 +67,9 @@ struct elf_lm32_link_hash_table
 /* Get the lm32 ELF linker hash table from a link_info structure.  */
 
 #define lm32_elf_hash_table(p) \
-  (elf_hash_table_id ((struct elf_link_hash_table *) ((p)->hash)) \
-  == LM32_ELF_DATA ? ((struct elf_lm32_link_hash_table *) ((p)->hash)) : NULL)
+  ((is_elf_hash_table ((p)->hash)					\
+    && elf_hash_table_id (elf_hash_table (p)) == LM32_ELF_DATA)		\
+   ? (struct elf_lm32_link_hash_table *) (p)->hash : NULL)
 
 #define lm32fdpic_got_section(info) \
   (lm32_elf_hash_table (info)->root.sgot)
diff --git a/bfd/elf32-m32r.c b/bfd/elf32-m32r.c
index 5857c943ae..533d662ee8 100644
--- a/bfd/elf32-m32r.c
+++ b/bfd/elf32-m32r.c
@@ -1509,8 +1509,9 @@ struct elf_m32r_pcrel_relocs_copied
 /* Get the m32r ELF linker hash table from a link_info structure.  */
 
 #define m32r_elf_hash_table(p) \
-  (elf_hash_table_id ((struct elf_link_hash_table *) ((p)->hash)) \
-  == M32R_ELF_DATA ? ((struct elf_link_hash_table *) ((p)->hash)) : NULL)
+  ((is_elf_hash_table ((p)->hash)					\
+    && elf_hash_table_id (elf_hash_table (p)) == M32R_ELF_DATA)		\
+   ? (struct elf_link_hash_table *) (p)->hash : NULL)
 
 /* Create an m32r ELF linker hash table.  */
 
diff --git a/bfd/elf32-m68hc1x.h b/bfd/elf32-m68hc1x.h
index 720c270a59..f88f276772 100644
--- a/bfd/elf32-m68hc1x.h
+++ b/bfd/elf32-m68hc1x.h
@@ -127,8 +127,9 @@ struct m68hc11_elf_link_hash_table
 /* Get the Sparc64 ELF linker hash table from a link_info structure.  */
 
 #define m68hc11_elf_hash_table(p) \
-  (elf_hash_table_id ((struct elf_link_hash_table *) ((p)->hash)) \
-  == M68HC11_ELF_DATA ? ((struct m68hc11_elf_link_hash_table *) ((p)->hash)) : NULL)
+  ((is_elf_hash_table ((p)->hash)					\
+    && elf_hash_table_id (elf_hash_table (p)) == M68HC11_ELF_DATA)	\
+   ? (struct m68hc11_elf_link_hash_table *) (p)->hash : NULL)
 
 /* Create a 68HC11/68HC12 ELF linker hash table.  */
 
diff --git a/bfd/elf32-m68k.c b/bfd/elf32-m68k.c
index 120816f918..b9b8bec6aa 100644
--- a/bfd/elf32-m68k.c
+++ b/bfd/elf32-m68k.c
@@ -910,8 +910,9 @@ struct elf_m68k_link_hash_table
 /* Get the m68k ELF linker hash table from a link_info structure.  */
 
 #define elf_m68k_hash_table(p) \
-  (elf_hash_table_id ((struct elf_link_hash_table *) ((p)->hash)) \
-  == M68K_ELF_DATA ? ((struct elf_m68k_link_hash_table *) ((p)->hash)) : NULL)
+  ((is_elf_hash_table ((p)->hash)					\
+    && elf_hash_table_id (elf_hash_table (p)) == M68K_ELF_DATA)		\
+   ? (struct elf_m68k_link_hash_table *) (p)->hash : NULL)
 
 /* Shortcut to multi-GOT data.  */
 #define elf_m68k_multi_got(INFO) (&elf_m68k_hash_table (INFO)->multi_got_)
diff --git a/bfd/elf32-metag.c b/bfd/elf32-metag.c
index f1122fd71e..e3203b264f 100644
--- a/bfd/elf32-metag.c
+++ b/bfd/elf32-metag.c
@@ -906,8 +906,9 @@ metag_reloc_name_lookup (bfd *abfd ATTRIBUTE_UNUSED,
 
 /* Various hash macros and functions.  */
 #define metag_link_hash_table(p) \
-  (elf_hash_table_id ((struct elf_link_hash_table *) ((p)->hash)) \
-  == METAG_ELF_DATA ? ((struct elf_metag_link_hash_table *) ((p)->hash)) : NULL)
+  ((is_elf_hash_table ((p)->hash)					\
+    && elf_hash_table_id (elf_hash_table (p)) == METAG_ELF_DATA)	\
+   ? (struct elf_metag_link_hash_table *) (p)->hash : NULL)
 
 #define metag_elf_hash_entry(ent) \
   ((struct elf_metag_link_hash_entry *)(ent))
diff --git a/bfd/elf32-microblaze.c b/bfd/elf32-microblaze.c
index 10aa022bee..1b5c2efcd6 100644
--- a/bfd/elf32-microblaze.c
+++ b/bfd/elf32-microblaze.c
@@ -756,9 +756,10 @@ struct elf32_mb_link_hash_table
 
 /* Get the ELF linker hash table from a link_info structure.  */
 
-#define elf32_mb_hash_table(p)				\
-  (elf_hash_table_id ((struct elf_link_hash_table *) ((p)->hash)) \
-  == MICROBLAZE_ELF_DATA ? ((struct elf32_mb_link_hash_table *) ((p)->hash)) : NULL)
+#define elf32_mb_hash_table(p) \
+  ((is_elf_hash_table ((p)->hash)					\
+    && elf_hash_table_id (elf_hash_table (p)) == MICROBLAZE_ELF_DATA)	\
+   ? (struct elf32_mb_link_hash_table *) (p)->hash : NULL)
 
 /* Create an entry in a microblaze ELF linker hash table.  */
 
diff --git a/bfd/elf32-nds32.h b/bfd/elf32-nds32.h
index 83547b2cff..57da1a206a 100644
--- a/bfd/elf32-nds32.h
+++ b/bfd/elf32-nds32.h
@@ -104,10 +104,10 @@ extern void	   bfd_elf32_nds32_set_target_option (struct bfd_link_info *,
 						      int, int, FILE *,
 						      int, int, int);
 
-#define nds32_elf_hash_table(info) \
-  (elf_hash_table_id ((struct elf_link_hash_table *) ((info)->hash)) \
-   == NDS32_ELF_DATA ? \
-   ((struct elf_nds32_link_hash_table *) ((info)->hash)) : NULL)
+#define nds32_elf_hash_table(p) \
+  ((is_elf_hash_table ((p)->hash)					\
+    && elf_hash_table_id (elf_hash_table (p)) == NDS32_ELF_DATA)	\
+   ? (struct elf_nds32_link_hash_table *) (p)->hash : NULL)
 
 #define elf32_nds32_compute_jump_table_size(htab) \
   ((htab)->next_tls_desc_index * 4)
diff --git a/bfd/elf32-or1k.c b/bfd/elf32-or1k.c
index ef78187dce..38406eda3d 100644
--- a/bfd/elf32-or1k.c
+++ b/bfd/elf32-or1k.c
@@ -921,8 +921,9 @@ struct elf_or1k_link_hash_table
 
 /* Get the ELF linker hash table from a link_info structure.  */
 #define or1k_elf_hash_table(p) \
-  (elf_hash_table_id ((struct elf_link_hash_table *) ((p)->hash)) \
-   == OR1K_ELF_DATA ? ((struct elf_or1k_link_hash_table *) ((p)->hash)) : NULL)
+  ((is_elf_hash_table ((p)->hash)					\
+    && elf_hash_table_id (elf_hash_table (p)) == OR1K_ELF_DATA)		\
+   ? (struct elf_or1k_link_hash_table *) (p)->hash : NULL)
 
 static bfd_boolean
 elf_or1k_mkobject (bfd *abfd)
diff --git a/bfd/elf32-s390.c b/bfd/elf32-s390.c
index 530a10d3be..158f909d05 100644
--- a/bfd/elf32-s390.c
+++ b/bfd/elf32-s390.c
@@ -751,8 +751,9 @@ struct elf_s390_link_hash_table
 /* Get the s390 ELF linker hash table from a link_info structure.  */
 
 #define elf_s390_hash_table(p) \
-  (elf_hash_table_id ((struct elf_link_hash_table *) ((p)->hash)) \
-  == S390_ELF_DATA ? ((struct elf_s390_link_hash_table *) ((p)->hash)) : NULL)
+  ((is_elf_hash_table ((p)->hash)					\
+    && elf_hash_table_id (elf_hash_table (p)) == S390_ELF_DATA)		\
+   ? (struct elf_s390_link_hash_table *) (p)->hash : NULL)
 
 #undef ELF64
 #include "elf-s390-common.c"
diff --git a/bfd/elf32-sh.c b/bfd/elf32-sh.c
index 481bed4c4f..04949463eb 100644
--- a/bfd/elf32-sh.c
+++ b/bfd/elf32-sh.c
@@ -2192,8 +2192,9 @@ struct elf_sh_link_hash_table
 /* Get the sh ELF linker hash table from a link_info structure.  */
 
 #define sh_elf_hash_table(p) \
-  (elf_hash_table_id ((struct elf_link_hash_table *) ((p)->hash)) \
-  == SH_ELF_DATA ? ((struct elf_sh_link_hash_table *) ((p)->hash)) : NULL)
+  ((is_elf_hash_table ((p)->hash)					\
+    && elf_hash_table_id (elf_hash_table (p)) == SH_ELF_DATA)		\
+   ? (struct elf_sh_link_hash_table *) (p)->hash : NULL)
 
 /* Create an entry in an sh ELF linker hash table.  */
 
diff --git a/bfd/elf32-spu.c b/bfd/elf32-spu.c
index dcdee26082..13cff2c5e0 100644
--- a/bfd/elf32-spu.c
+++ b/bfd/elf32-spu.c
@@ -371,8 +371,9 @@ struct got_entry
 };
 
 #define spu_hash_table(p) \
-  (elf_hash_table_id ((struct elf_link_hash_table *) ((p)->hash)) \
-  == SPU_ELF_DATA ? ((struct spu_link_hash_table *) ((p)->hash)) : NULL)
+  ((is_elf_hash_table ((p)->hash)					\
+    && elf_hash_table_id (elf_hash_table (p)) == SPU_ELF_DATA)		\
+   ? (struct spu_link_hash_table *) (p)->hash : NULL)
 
 struct call_info
 {
diff --git a/bfd/elf32-tilepro.c b/bfd/elf32-tilepro.c
index e062dc0386..3511466739 100644
--- a/bfd/elf32-tilepro.c
+++ b/bfd/elf32-tilepro.c
@@ -729,9 +729,9 @@ tilepro_elf_mkobject (bfd *abfd)
 
 /* Get the Tilepro ELF linker hash table from a link_info structure.  */
 #define tilepro_elf_hash_table(p) \
-  (elf_hash_table_id ((struct elf_link_hash_table *) ((p)->hash)) \
-  == TILEPRO_ELF_DATA \
-  ? ((struct elf_link_hash_table *) ((p)->hash)) : NULL)
+  ((is_elf_hash_table ((p)->hash)					\
+    && elf_hash_table_id (elf_hash_table (p)) == TILEPRO_ELF_DATA)	\
+   ? (struct elf_link_hash_table *) (p)->hash : NULL)
 
 static reloc_howto_type *
 tilepro_reloc_type_lookup (bfd * abfd ATTRIBUTE_UNUSED,
diff --git a/bfd/elf32-xtensa.c b/bfd/elf32-xtensa.c
index 8928b11fbc..65c6ceb379 100644
--- a/bfd/elf32-xtensa.c
+++ b/bfd/elf32-xtensa.c
@@ -705,8 +705,9 @@ struct elf_xtensa_link_hash_table
 /* Get the Xtensa ELF linker hash table from a link_info structure.  */
 
 #define elf_xtensa_hash_table(p) \
-  (elf_hash_table_id ((struct elf_link_hash_table *) ((p)->hash)) \
-  == XTENSA_ELF_DATA ? ((struct elf_xtensa_link_hash_table *) ((p)->hash)) : NULL)
+  ((is_elf_hash_table ((p)->hash)					\
+    && elf_hash_table_id (elf_hash_table (p)) == XTENSA_ELF_DATA)	\
+   ? (struct elf_xtensa_link_hash_table *) (p)->hash : NULL)
 
 /* Create an entry in an Xtensa ELF linker hash table.  */
 
diff --git a/bfd/elf64-alpha.c b/bfd/elf64-alpha.c
index cb89dfb03f..1976450fa4 100644
--- a/bfd/elf64-alpha.c
+++ b/bfd/elf64-alpha.c
@@ -216,8 +216,9 @@ struct alpha_elf_link_hash_table
 /* Get the Alpha ELF linker hash table from a link_info structure.  */
 
 #define alpha_elf_hash_table(p) \
-  (elf_hash_table_id ((struct elf_link_hash_table *) ((p)->hash)) \
-  == ALPHA_ELF_DATA ? ((struct alpha_elf_link_hash_table *) ((p)->hash)) : NULL)
+  ((is_elf_hash_table ((p)->hash)					\
+    && elf_hash_table_id (elf_hash_table (p)) == ALPHA_ELF_DATA)	\
+   ? (struct alpha_elf_link_hash_table *) (p)->hash : NULL)
 
 /* Get the object's symbols as our own entry type.  */
 
diff --git a/bfd/elf64-hppa.c b/bfd/elf64-hppa.c
index dd52b35118..bf8207e3a7 100644
--- a/bfd/elf64-hppa.c
+++ b/bfd/elf64-hppa.c
@@ -145,8 +145,9 @@ struct elf64_hppa_link_hash_table
 };
 
 #define hppa_link_hash_table(p) \
-  (elf_hash_table_id ((struct elf_link_hash_table *) ((p)->hash)) \
-  == HPPA64_ELF_DATA ? ((struct elf64_hppa_link_hash_table *) ((p)->hash)) : NULL)
+  ((is_elf_hash_table ((p)->hash)					\
+    && elf_hash_table_id (elf_hash_table (p)) == HPPA64_ELF_DATA)	\
+   ? (struct elf64_hppa_link_hash_table *) (p)->hash : NULL)
 
 #define hppa_elf_hash_entry(ent) \
   ((struct elf64_hppa_link_hash_entry *)(ent))
diff --git a/bfd/elf64-ia64-vms.c b/bfd/elf64-ia64-vms.c
index fd001607a3..5ce8775459 100644
--- a/bfd/elf64-ia64-vms.c
+++ b/bfd/elf64-ia64-vms.c
@@ -170,8 +170,9 @@ struct elf64_ia64_allocate_data
 };
 
 #define elf64_ia64_hash_table(p) \
-  (elf_hash_table_id ((struct elf_link_hash_table *) ((p)->hash)) \
-  == IA64_ELF_DATA ? ((struct elf64_ia64_link_hash_table *) ((p)->hash)) : NULL)
+  ((is_elf_hash_table ((p)->hash)					\
+    && elf_hash_table_id (elf_hash_table (p)) == IA64_ELF_DATA)		\
+   ? (struct elf64_ia64_link_hash_table *) (p)->hash : NULL)
 
 struct elf64_ia64_vms_obj_tdata
 {
diff --git a/bfd/elf64-s390.c b/bfd/elf64-s390.c
index c8c691e4b1..0522850a5d 100644
--- a/bfd/elf64-s390.c
+++ b/bfd/elf64-s390.c
@@ -670,8 +670,9 @@ struct elf_s390_link_hash_table
 /* Get the s390 ELF linker hash table from a link_info structure.  */
 
 #define elf_s390_hash_table(p)						\
-  (elf_hash_table_id ((struct elf_link_hash_table *) ((p)->hash))	\
-   == S390_ELF_DATA ? ((struct elf_s390_link_hash_table *) ((p)->hash)) : NULL)
+  ((is_elf_hash_table ((p)->hash)					\
+    && elf_hash_table_id (elf_hash_table (p)) == S390_ELF_DATA)		\
+   ? (struct elf_s390_link_hash_table *) (p)->hash : NULL)
 
 #define ELF64 1
 #include "elf-s390-common.c"
diff --git a/bfd/elfnn-ia64.c b/bfd/elfnn-ia64.c
index e347332aa2..cadf645df9 100644
--- a/bfd/elfnn-ia64.c
+++ b/bfd/elfnn-ia64.c
@@ -166,8 +166,9 @@ struct elfNN_ia64_allocate_data
 };
 
 #define elfNN_ia64_hash_table(p) \
-  (elf_hash_table_id ((struct elf_link_hash_table *) ((p)->hash)) \
-  == IA64_ELF_DATA ? ((struct elfNN_ia64_link_hash_table *) ((p)->hash)) : NULL)
+  ((is_elf_hash_table ((p)->hash)					\
+    && elf_hash_table_id (elf_hash_table (p)) == IA64_ELF_DATA)		\
+   ? (struct elfNN_ia64_link_hash_table *) (p)->hash : NULL)
 
 static struct elfNN_ia64_dyn_sym_info * get_dyn_sym_info
   (struct elfNN_ia64_link_hash_table *ia64_info,
diff --git a/bfd/elfnn-riscv.c b/bfd/elfnn-riscv.c
index fb78c24177..5af1b1c3ff 100644
--- a/bfd/elfnn-riscv.c
+++ b/bfd/elfnn-riscv.c
@@ -120,8 +120,9 @@ struct riscv_elf_link_hash_table
 
 /* Get the RISC-V ELF linker hash table from a link_info structure.  */
 #define riscv_elf_hash_table(p) \
-  (elf_hash_table_id ((struct elf_link_hash_table *) ((p)->hash)) \
-  == RISCV_ELF_DATA ? ((struct riscv_elf_link_hash_table *) ((p)->hash)) : NULL)
+  ((is_elf_hash_table ((p)->hash)					\
+    && elf_hash_table_id (elf_hash_table (p)) == RISCV_ELF_DATA)	\
+   ? (struct riscv_elf_link_hash_table *) (p)->hash : NULL)
 
 static bfd_boolean
 riscv_info_to_howto_rela (bfd *abfd,
diff --git a/bfd/elfxx-mips.c b/bfd/elfxx-mips.c
index a0439041c0..fda653e1af 100644
--- a/bfd/elfxx-mips.c
+++ b/bfd/elfxx-mips.c
@@ -534,8 +534,9 @@ struct mips_elf_link_hash_table
 /* Get the MIPS ELF linker hash table from a link_info structure.  */
 
 #define mips_elf_hash_table(p) \
-  (elf_hash_table_id ((struct elf_link_hash_table *) ((p)->hash)) \
-  == MIPS_ELF_DATA ? ((struct mips_elf_link_hash_table *) ((p)->hash)) : NULL)
+  ((is_elf_hash_table ((p)->hash)					\
+    && elf_hash_table_id (elf_hash_table (p)) == MIPS_ELF_DATA)		\
+   ? (struct mips_elf_link_hash_table *) (p)->hash : NULL)
 
 /* A structure used to communicate with htab_traverse callbacks.  */
 struct mips_htab_traverse_info
diff --git a/bfd/elfxx-sparc.h b/bfd/elfxx-sparc.h
index f09b073259..6fbf237e67 100644
--- a/bfd/elfxx-sparc.h
+++ b/bfd/elfxx-sparc.h
@@ -84,8 +84,9 @@ struct _bfd_sparc_elf_link_hash_table
 /* Get the SPARC ELF linker hash table from a link_info structure.  */
 
 #define _bfd_sparc_elf_hash_table(p) \
-  (elf_hash_table_id ((struct elf_link_hash_table *) ((p)->hash)) \
-  == SPARC_ELF_DATA ? ((struct _bfd_sparc_elf_link_hash_table *) ((p)->hash)) : NULL)
+  ((is_elf_hash_table ((p)->hash)					\
+    && elf_hash_table_id (elf_hash_table (p)) == SPARC_ELF_DATA)	\
+   ? (struct _bfd_sparc_elf_link_hash_table *) (p)->hash : NULL)
 
 extern reloc_howto_type *_bfd_sparc_elf_reloc_type_lookup
   (bfd *, bfd_reloc_code_real_type);
diff --git a/bfd/elfxx-tilegx.c b/bfd/elfxx-tilegx.c
index 2631a0d350..abe344c0c8 100644
--- a/bfd/elfxx-tilegx.c
+++ b/bfd/elfxx-tilegx.c
@@ -840,8 +840,9 @@ struct tilegx_elf_link_hash_table
 
 /* Get the Tile ELF linker hash table from a link_info structure.  */
 #define tilegx_elf_hash_table(p) \
-  (elf_hash_table_id ((struct elf_link_hash_table *) ((p)->hash)) \
-  == TILEGX_ELF_DATA ? ((struct tilegx_elf_link_hash_table *) ((p)->hash)) : NULL)
+  ((is_elf_hash_table ((p)->hash)					\
+    && elf_hash_table_id (elf_hash_table (p)) == TILEGX_ELF_DATA)	\
+   ? (struct tilegx_elf_link_hash_table *) (p)->hash : NULL)
 
 #ifdef BFD64
 static bfd_vma

-- 
Alan Modra
Australia Development Lab, IBM

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

end of thread, other threads:[~2020-08-24 17:18 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2020-08-24 16:37 PR26483, ASAN: ppc_elf_link_params elf32-ppc.c:2314 Alan Modra
2020-08-24 17:18 ` 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).