This is the mail archive of the
binutils@sourceware.org
mailing list for the binutils project.
Re: [commiited, PATCH] x86: Add VERIFY_COPY_RELOC
On 10/6/17, Pedro Alves <palves@redhat.com> wrote:
> On 10/06/2017 08:52 AM, H.J. Lu wrote:
>>
>> +/* Verify that the symbol supports copy relocation. */
>> +#define VERIFY_COPY_RELOC(H, HTAB) \
>> + if ((H)->dynindx == -1 \
>> + || ((H)->root.type != bfd_link_hash_defined \
>> + && (H)->root.type != bfd_link_hash_defweak) \
>> + || (HTAB)->elf.srelbss == NULL \
>> + || (HTAB)->elf.sreldynrelro == NULL) \
>> + abort ();
>> +
>
> I'd suggest at least wrapping macros such as this
> one with do/while(0) to avoid potential dangling
> else problems.
>
I am checking in this patch.
--
H.J.
From e0d8f43169368abf354e596c7725dee1dd609cb8 Mon Sep 17 00:00:00 2001
From: "H.J. Lu" <hjl.tools@gmail.com>
Date: Fri, 6 Oct 2017 05:49:48 -0700
Subject: [PATCH] Add "do/while(0);" to COPY_INPUT_RELOC_P/VERIFY_COPY_RELOC
Add "do/while(0);" to COPY_INPUT_RELOC_P/VERIFY_COPY_RELOC to avoid
potential dangling else problems.
* elfxx-x86.h (COPY_INPUT_RELOC_P): Add "do/while(0);".
(VERIFY_COPY_RELOC): Likewise.
---
bfd/ChangeLog | 5 +++++
bfd/elfxx-x86.h | 38 +++++++++++++++++++++++---------------
2 files changed, 28 insertions(+), 15 deletions(-)
diff --git a/bfd/ChangeLog b/bfd/ChangeLog
index 982d29daab..8633071d24 100644
--- a/bfd/ChangeLog
+++ b/bfd/ChangeLog
@@ -1,5 +1,10 @@
2017-10-06 H.J. Lu <hongjiu.lu@intel.com>
+ * elfxx-x86.h (COPY_INPUT_RELOC_P): Add "do/while(0);".
+ (VERIFY_COPY_RELOC): Likewise.
+
+2017-10-06 H.J. Lu <hongjiu.lu@intel.com>
+
* elfxx-x86.h (VERIFY_COPY_RELOC): New.
* elf32-i386.c (elf_i386_finish_dynamic_symbol): Use it.
* elf64-x86-64.c (elf_x86_64_finish_dynamic_symbol): Likewise.
diff --git a/bfd/elfxx-x86.h b/bfd/elfxx-x86.h
index ca270ded0a..5dc21b06bf 100644
--- a/bfd/elfxx-x86.h
+++ b/bfd/elfxx-x86.h
@@ -198,24 +198,32 @@
/* Verify that the symbol has an entry in the procedure linkage table. */
#define VERIFY_PLT_ENTRY(INFO, H, PLT, GOTPLT, RELPLT, LOCAL_UNDEFWEAK) \
- if (((H)->dynindx == -1 \
- && !LOCAL_UNDEFWEAK \
- && !(((H)->forced_local || bfd_link_executable (INFO)) \
- && (H)->def_regular \
- && (H)->type == STT_GNU_IFUNC)) \
- || (PLT) == NULL \
- || (GOTPLT) == NULL \
- || (RELPLT) == NULL) \
- abort ();
+ do \
+ { \
+ if (((H)->dynindx == -1 \
+ && !LOCAL_UNDEFWEAK \
+ && !(((H)->forced_local || bfd_link_executable (INFO)) \
+ && (H)->def_regular \
+ && (H)->type == STT_GNU_IFUNC)) \
+ || (PLT) == NULL \
+ || (GOTPLT) == NULL \
+ || (RELPLT) == NULL) \
+ abort (); \
+ } \
+ while (0);
/* Verify that the symbol supports copy relocation. */
#define VERIFY_COPY_RELOC(H, HTAB) \
- if ((H)->dynindx == -1 \
- || ((H)->root.type != bfd_link_hash_defined \
- && (H)->root.type != bfd_link_hash_defweak) \
- || (HTAB)->elf.srelbss == NULL \
- || (HTAB)->elf.sreldynrelro == NULL) \
- abort ();
+ do \
+ { \
+ if ((H)->dynindx == -1 \
+ || ((H)->root.type != bfd_link_hash_defined \
+ && (H)->root.type != bfd_link_hash_defweak) \
+ || (HTAB)->elf.srelbss == NULL \
+ || (HTAB)->elf.sreldynrelro == NULL) \
+ abort (); \
+ } \
+ while (0);
/* x86 ELF linker hash entry. */
--
2.13.6