+2023-08-02  Tom Tromey  <tromey@adacore.com>
+
+       * pei-x86_64.c (PEI_HEADERS): Do not define.
+       * pei-loongarch64.c (PEI_HEADERS): Do not define.
+       * pei-aarch64.c (PEI_HEADERS): Do not define.
+       * pe-x86_64.c (PEI_HEADERS): Do not define.
+       * pe-aarch64.c (PEI_HEADERS): Do not define.
+       * libpei.h (_LIBPEI_H): Add include guard.
+       * coff-x86_64.c (PEI_HEADERS): Do not check.
+       * coff-loongarch64.c (PEI_HEADERS): Do not check.
+       * coff-aarch64.c (PEI_HEADERS): Do not check.
+
 2023-07-24  Johannes Schauer Marin Rodrigues  <josch@debian.org>
 
        * peXXigen.c (_bfd_XXi_only_swap_filehdr_out): If inserting a
 
 #define COFF_WITH_peAArch64
 #endif
 
-/* Note we have to make sure not to include headers twice.
-   Not all headers are wrapped in #ifdef guards, so we define
-   PEI_HEADERS to prevent double including here.  */
-#ifndef PEI_HEADERS
 #include "sysdep.h"
 #include "bfd.h"
 #include "libbfd.h"
 #include "coff/pe.h"
 #include "libcoff.h"
 #include "libiberty.h"
-#endif
-
-#include "libcoff.h"
 
 /* For these howto special functions,
    output_bfd == NULL => final link, or objdump -W and other calls to
 
 #define COFF_WITH_peLoongArch64
 #endif
 
-/* Note we have to make sure not to include headers twice.
-   Not all headers are wrapped in #ifdef guards, so we define
-   PEI_HEADERS to prevent double including here.  */
-#ifndef PEI_HEADERS
 #include "sysdep.h"
 #include "bfd.h"
 #include "libbfd.h"
 #include "coff/pe.h"
 #include "libcoff.h"
 #include "libiberty.h"
-#endif
-
-#include "libcoff.h"
 
 /* The page size is a guess based on ELF.  */
 
 
 
    Written by Kai Tietz, OneVision Software GmbH&CoKg.  */
 
-/* Note we have to make sure not to include headers twice.
-   Not all headers are wrapped in #ifdef guards, so we define
-   PEI_HEADERS to prevent double including here.  */
-#ifndef PEI_HEADERS
 #include "sysdep.h"
 #include "bfd.h"
 #include "libbfd.h"
 #include "coff/internal.h"
 #include "libcoff.h"
 #include "libiberty.h"
-#endif
 
 #define BADMAG(x) AMD64BADMAG(x)
 
 
    Foundation, Inc., 51 Franklin Street - Fifth Floor, Boston,
    MA 02110-1301, USA.  */
 
+#ifndef _LIBPEI_H
+#define _LIBPEI_H
 
 /* Most of this hacked by  Steve Chamberlain,
                        sac@cygnus.com
 bool _bfd_peLoongArch64_print_ce_compressed_pdata (bfd *, void *);
 bool _bfd_pep_print_ce_compressed_pdata (bfd *, void *);
 
+#endif /* _LIBPEI_H */
 
 { COFF_SECTION_NAME_PARTIAL_MATCH (".gnu.linkonce.wi."), \
   COFF_ALIGNMENT_FIELD_EMPTY, COFF_ALIGNMENT_FIELD_EMPTY, 0 }
 
-#define PEI_HEADERS
 #include "sysdep.h"
 #include "bfd.h"
 #include "libbfd.h"
 
 
    Written by Kai Tietz, OneVision Software GmbH&CoKg.  */
 
-#define PEI_HEADERS
 #include "sysdep.h"
 #include "bfd.h"
 #include "libbfd.h"
 
 { COFF_SECTION_NAME_PARTIAL_MATCH (".gnu.linkonce.wi."), \
   COFF_ALIGNMENT_FIELD_EMPTY, COFF_ALIGNMENT_FIELD_EMPTY, 0 }
 
-#define PEI_HEADERS
 #include "sysdep.h"
 #include "bfd.h"
 #include "libbfd.h"
 
 { COFF_SECTION_NAME_PARTIAL_MATCH (".gnu.linkonce.wi."), \
   COFF_ALIGNMENT_FIELD_EMPTY, COFF_ALIGNMENT_FIELD_EMPTY, 0 }
 
-#define PEI_HEADERS
 #include "sysdep.h"
 #include "bfd.h"
 #include "libbfd.h"
 
 { COFF_SECTION_NAME_PARTIAL_MATCH (".gnu.linkonce.wi."), \
   COFF_ALIGNMENT_FIELD_EMPTY, COFF_ALIGNMENT_FIELD_EMPTY, 0 }
 
-/* Note we have to make sure not to include headers twice.
-   Not all headers are wrapped in #ifdef guards, so we define
-   PEI_HEADERS to prevent double including in coff-x86_64.c  */
-#define PEI_HEADERS
 #include "sysdep.h"
 #include "bfd.h"
 #include "libbfd.h"
 
+2023-08-02  Tom Tromey  <tromey@adacore.com>
+
+       * coff/x86_64.h (COFF_X86_64_H): Add include guard.
+       * coff/loongarch64.h (COFF_LOONGARCH64_H): Add include guard.
+       * coff/aarch64.h (COFF_AARCH64_H): Add include guard.
+
 2023-07-30  Jose E. Marchesi  <jose.marchesi@oracle.com>
 
        * elf/bpf.h (EF_BPF_CPUVER): Define.
 
    along with this program; if not, write to the Free Software Foundation,
    Inc., 51 Franklin Street - Fifth Floor, Boston, MA 02110-1301, USA.  */
 
+#ifndef COFF_AARCH64_H
+#define COFF_AARCH64_H
+
 #define COFFAARCH64 1
 
 #define L_LNNO_SIZE 2
 #define IMAGE_REL_ARM64_REL32           0x0011  /* The 32-bit relative address from the byte following the relocation. */
 
 #define ARM_NOTE_SECTION ".note"
+
+#endif /* COFF_AARCH64_H */
 
    along with this program; if not, write to the Free Software Foundation,
    Inc., 51 Franklin Street - Fifth Floor, Boston, MA 02110-1301, USA.  */
 
+#ifndef COFF_LOONGARCH64_H
+#define COFF_LOONGARCH64_H
+
 #define COFFLOONGARCH64 1
 
 #define L_LNNO_SIZE 2
 
 #define RELOC struct external_reloc
 #define RELSZ 14
+
+#endif /* COFF_LOONGARCH64_H */
 
    
    Written by Kai Tietz, OneVision Software GmbH&CoKg.  */
 
+#ifndef COFF_X86_64_H
+#define COFF_X86_64_H
+
 #define L_LNNO_SIZE 2
 #define INCLUDE_COMDAT_FIELDS_IN_AUXENT
 
 #define R_PCRBYTE      18
 #define R_PCRWORD      19
 #define R_PCRLONG      20
+
+#endif /* COFF_X86_64_H */