MIPS: ELF: Unify ABI classification macros
authorMaciej W. Rozycki <macro@imgtec.com>
Fri, 13 May 2016 06:21:40 +0000 (07:21 +0100)
committerRalf Baechle <ralf@linux-mips.org>
Fri, 13 May 2016 13:30:25 +0000 (15:30 +0200)
Remove a duplicate o32 `elf_check_arch' implementation, move all macro
variants to <asm/elf.h> and define them unconditionally under indvidual
names, substituting alias `elf_check_arch' definitions in variant code.

Signed-off-by: Maciej W. Rozycki <macro@imgtec.com>
Cc: linux-mips@linux-mips.org
Patchwork: https://patchwork.linux-mips.org/patch/13245/
Signed-off-by: Ralf Baechle <ralf@linux-mips.org>
arch/mips/include/asm/elf.h
arch/mips/kernel/binfmt_elfn32.c
arch/mips/kernel/binfmt_elfo32.c

index 68705a0a8014541ba787e73677712ea4f8195bd7..f5f45717968e6103e54509beeb88c338a245a3d4 100644 (file)
@@ -214,25 +214,7 @@ typedef elf_fpreg_t elf_fpregset_t[ELF_NFPREG];
 /*
  * This is used to ensure we don't load something for the wrong architecture.
  */
-#define elf_check_arch(hdr)                                            \
-({                                                                     \
-       int __res = 1;                                                  \
-       struct elfhdr *__h = (hdr);                                     \
-                                                                       \
-       if (!mips_elf_check_machine(__h))                               \
-               __res = 0;                                              \
-       if (__h->e_ident[EI_CLASS] != ELFCLASS32)                       \
-               __res = 0;                                              \
-       if ((__h->e_flags & EF_MIPS_ABI2) != 0)                         \
-               __res = 0;                                              \
-       if (((__h->e_flags & EF_MIPS_ABI) != 0) &&                      \
-           ((__h->e_flags & EF_MIPS_ABI) != EF_MIPS_ABI_O32))          \
-               __res = 0;                                              \
-       if (__h->e_flags & __MIPS_O32_FP64_MUST_BE_ZERO)                \
-               __res = 0;                                              \
-                                                                       \
-       __res;                                                          \
-})
+#define elf_check_arch elfo32_check_arch
 
 /*
  * These are used to set parameters in the core dumps.
@@ -245,18 +227,7 @@ typedef elf_fpreg_t elf_fpregset_t[ELF_NFPREG];
 /*
  * This is used to ensure we don't load something for the wrong architecture.
  */
-#define elf_check_arch(hdr)                                            \
-({                                                                     \
-       int __res = 1;                                                  \
-       struct elfhdr *__h = (hdr);                                     \
-                                                                       \
-       if (!mips_elf_check_machine(__h))                               \
-               __res = 0;                                              \
-       if (__h->e_ident[EI_CLASS] != ELFCLASS64)                       \
-               __res = 0;                                              \
-                                                                       \
-       __res;                                                          \
-})
+#define elf_check_arch elfn64_check_arch
 
 /*
  * These are used to set parameters in the core dumps.
@@ -294,6 +265,64 @@ typedef elf_fpreg_t elf_fpregset_t[ELF_NFPREG];
 #define vmcore_elf32_check_arch mips_elf_check_machine
 #define vmcore_elf64_check_arch mips_elf_check_machine
 
+/*
+ * Return non-zero if HDR identifies an o32 ELF binary.
+ */
+#define elfo32_check_arch(hdr)                                         \
+({                                                                     \
+       int __res = 1;                                                  \
+       struct elfhdr *__h = (hdr);                                     \
+                                                                       \
+       if (!mips_elf_check_machine(__h))                               \
+               __res = 0;                                              \
+       if (__h->e_ident[EI_CLASS] != ELFCLASS32)                       \
+               __res = 0;                                              \
+       if ((__h->e_flags & EF_MIPS_ABI2) != 0)                         \
+               __res = 0;                                              \
+       if (((__h->e_flags & EF_MIPS_ABI) != 0) &&                      \
+           ((__h->e_flags & EF_MIPS_ABI) != EF_MIPS_ABI_O32))          \
+               __res = 0;                                              \
+       if (__h->e_flags & __MIPS_O32_FP64_MUST_BE_ZERO)                \
+               __res = 0;                                              \
+                                                                       \
+       __res;                                                          \
+})
+
+/*
+ * Return non-zero if HDR identifies an n64 ELF binary.
+ */
+#define elfn64_check_arch(hdr)                                         \
+({                                                                     \
+       int __res = 1;                                                  \
+       struct elfhdr *__h = (hdr);                                     \
+                                                                       \
+       if (!mips_elf_check_machine(__h))                               \
+               __res = 0;                                              \
+       if (__h->e_ident[EI_CLASS] != ELFCLASS64)                       \
+               __res = 0;                                              \
+                                                                       \
+       __res;                                                          \
+})
+
+/*
+ * Return non-zero if HDR identifies an n32 ELF binary.
+ */
+#define elfn32_check_arch(hdr)                                         \
+({                                                                     \
+       int __res = 1;                                                  \
+       struct elfhdr *__h = (hdr);                                     \
+                                                                       \
+       if (!mips_elf_check_machine(__h))                               \
+               __res = 0;                                              \
+       if (__h->e_ident[EI_CLASS] != ELFCLASS32)                       \
+               __res = 0;                                              \
+       if (((__h->e_flags & EF_MIPS_ABI2) == 0) ||                     \
+           ((__h->e_flags & EF_MIPS_ABI) != 0))                        \
+               __res = 0;                                              \
+                                                                       \
+       __res;                                                          \
+})
+
 struct mips_abi;
 
 extern struct mips_abi mips_abi;
index 1b992c6e3d8e212420673fbb697edeff0b6314e3..58ad63d7eb42413ee1259582fd6b666f699faa99 100644 (file)
@@ -30,21 +30,7 @@ typedef elf_fpreg_t elf_fpregset_t[ELF_NFPREG];
 /*
  * This is used to ensure we don't load something for the wrong architecture.
  */
-#define elf_check_arch(hdr)                                            \
-({                                                                     \
-       int __res = 1;                                                  \
-       struct elfhdr *__h = (hdr);                                     \
-                                                                       \
-       if (!mips_elf_check_machine(__h))                               \
-               __res = 0;                                              \
-       if (__h->e_ident[EI_CLASS] != ELFCLASS32)                       \
-               __res = 0;                                              \
-       if (((__h->e_flags & EF_MIPS_ABI2) == 0) ||                     \
-           ((__h->e_flags & EF_MIPS_ABI) != 0))                        \
-               __res = 0;                                              \
-                                                                       \
-       __res;                                                          \
-})
+#define elf_check_arch elfn32_check_arch
 
 #define TASK32_SIZE            0x7fff8000UL
 #undef ELF_ET_DYN_BASE
index ca43eaf1734b081c695829fe2de91eb54f325627..49fb881481f7b6940dfb353dedeb412d2be584bb 100644 (file)
@@ -30,25 +30,7 @@ typedef elf_fpreg_t elf_fpregset_t[ELF_NFPREG];
 /*
  * This is used to ensure we don't load something for the wrong architecture.
  */
-#define elf_check_arch(hdr)                                            \
-({                                                                     \
-       int __res = 1;                                                  \
-       struct elfhdr *__h = (hdr);                                     \
-                                                                       \
-       if (!mips_elf_check_machine(__h))                               \
-               __res = 0;                                              \
-       if (__h->e_ident[EI_CLASS] != ELFCLASS32)                       \
-               __res = 0;                                              \
-       if ((__h->e_flags & EF_MIPS_ABI2) != 0)                         \
-               __res = 0;                                              \
-       if (((__h->e_flags & EF_MIPS_ABI) != 0) &&                      \
-           ((__h->e_flags & EF_MIPS_ABI) != EF_MIPS_ABI_O32))          \
-               __res = 0;                                              \
-       if (__h->e_flags & __MIPS_O32_FP64_MUST_BE_ZERO)                \
-               __res = 0;                                              \
-                                                                       \
-       __res;                                                          \
-})
+#define elf_check_arch elfo32_check_arch
 
 #ifdef CONFIG_KVM_GUEST
 #define TASK32_SIZE            0x3fff8000UL