Skip to content

Commit 2ed02dd

Browse files
Maciej W. Rozyckiralfbaechle
authored andcommitted
MIPS: Use a union to access the ELF file header
Rewrite `arch_elf_pt_proc' and `arch_check_elf' using a union to access the ELF file header. Signed-off-by: Maciej W. Rozycki <macro@imgtec.com> Cc: Andrew Morton <akpm@linux-foundation.org> Cc: Matthew Fortune <Matthew.Fortune@imgtec.com> Cc: linux-mips@linux-mips.org Cc: linux-kernel@vger.kernel.org Patchwork: https://patchwork.linux-mips.org/patch/11474/ Signed-off-by: Ralf Baechle <ralf@linux-mips.org>
1 parent a0fd81a commit 2ed02dd

1 file changed

Lines changed: 26 additions & 14 deletions

File tree

‎arch/mips/kernel/elf.c‎

Lines changed: 26 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -68,15 +68,23 @@ static struct mode_req none_req = { true, true, false, true, true };
6868
int arch_elf_pt_proc(void *_ehdr, void *_phdr, struct file *elf,
6969
bool is_interp, struct arch_elf_state *state)
7070
{
71-
struct elf32_hdr *ehdr32 = _ehdr;
71+
union {
72+
struct elf32_hdr e32;
73+
struct elf64_hdr e64;
74+
} *ehdr = _ehdr;
7275
struct elf32_phdr *phdr32 = _phdr;
7376
struct elf64_phdr *phdr64 = _phdr;
7477
struct mips_elf_abiflags_v0 abiflags;
78+
bool elf32;
79+
u32 flags;
7580
int ret;
7681

82+
elf32 = ehdr->e32.e_ident[EI_CLASS] == ELFCLASS32;
83+
flags = elf32 ? ehdr->e32.e_flags : ehdr->e64.e_flags;
84+
7785
/* Lets see if this is an O32 ELF */
78-
if (ehdr32->e_ident[EI_CLASS] == ELFCLASS32) {
79-
if (ehdr32->e_flags & EF_MIPS_FP64) {
86+
if (elf32) {
87+
if (flags & EF_MIPS_FP64) {
8088
/*
8189
* Set MIPS_ABI_FP_OLD_64 for EF_MIPS_FP64. We will override it
8290
* later if needed
@@ -123,10 +131,17 @@ int arch_elf_pt_proc(void *_ehdr, void *_phdr, struct file *elf,
123131
int arch_check_elf(void *_ehdr, bool has_interpreter,
124132
struct arch_elf_state *state)
125133
{
126-
struct elf32_hdr *ehdr = _ehdr;
134+
union {
135+
struct elf32_hdr e32;
136+
struct elf64_hdr e64;
137+
} *ehdr = _ehdr;
127138
struct mode_req prog_req, interp_req;
128139
int fp_abi, interp_fp_abi, abi0, abi1, max_abi;
129-
bool is_mips64;
140+
bool elf32;
141+
u32 flags;
142+
143+
elf32 = ehdr->e32.e_ident[EI_CLASS] == ELFCLASS32;
144+
flags = elf32 ? ehdr->e32.e_flags : ehdr->e64.e_flags;
130145

131146
if (!config_enabled(CONFIG_MIPS_O32_FP64_SUPPORT))
132147
return 0;
@@ -142,21 +157,18 @@ int arch_check_elf(void *_ehdr, bool has_interpreter,
142157
abi0 = abi1 = fp_abi;
143158
}
144159

145-
is_mips64 = (ehdr->e_ident[EI_CLASS] == ELFCLASS64) ||
146-
(ehdr->e_flags & EF_MIPS_ABI2);
160+
if (elf32 && !(flags & EF_MIPS_ABI2)) {
161+
/* Default to a mode capable of running code expecting FR=0 */
162+
state->overall_fp_mode = cpu_has_mips_r6 ? FP_FRE : FP_FR0;
147163

148-
if (is_mips64) {
164+
/* Allow all ABIs we know about */
165+
max_abi = MIPS_ABI_FP_64A;
166+
} else {
149167
/* MIPS64 code always uses FR=1, thus the default is easy */
150168
state->overall_fp_mode = FP_FR1;
151169

152170
/* Disallow access to the various FPXX & FP64 ABIs */
153171
max_abi = MIPS_ABI_FP_SOFT;
154-
} else {
155-
/* Default to a mode capable of running code expecting FR=0 */
156-
state->overall_fp_mode = cpu_has_mips_r6 ? FP_FRE : FP_FR0;
157-
158-
/* Allow all ABIs we know about */
159-
max_abi = MIPS_ABI_FP_64A;
160172
}
161173

162174
if ((abi0 > max_abi && abi0 != MIPS_ABI_FP_UNKNOWN) ||

0 commit comments

Comments
 (0)