From: Daniel Jacobowitz <dan@debian.org>
To: Carsten Langgaard <carstenl@mips.com>
Cc: "Maciej W. Rozycki" <macro@ds2.pg.gda.pl>,
linux-mips@fnet.fr, linux-mips@oss.sgi.com
Subject: Re: [patch] linux: RFC: elf_check_arch() rework
Date: Wed, 24 Jul 2002 15:31:17 -0400 [thread overview]
Message-ID: <20020724193117.GA22820@nevyn.them.org> (raw)
In-Reply-To: <3D3EFC14.D8D690F0@mips.com>
On Wed, Jul 24, 2002 at 09:12:20PM +0200, Carsten Langgaard wrote:
> We at MIPS are in the process of making an ABI spec for all this,
> which is the intention that should be used by the tool-vendors. So
> please don't change the ELF header defines. I don't see that is wrong
Well, if so you'd better be using the ones Maciej changed them to, not
the ones they used to be. Check binutils/include/elf/mips.h for the
current definitions of these flags; the kernel was just wrong.
> with checking the ISA level, I rather have an error telling me that I
> can't execute a certain ISA level than eventually getting a reserved
> instruction or something worse like something unpredictable. You are
I agree with Maciej on this. It is perfectly reasonable to build a
binary which can operate safely at a different ISA level (either above
or below) that which it is linked at; and rather than arguing about the
semantics of that, as he also pointed out, this routine is specifically
supposed to be checking architecture and not ISA level; consistency
across platforms has high advantages.
> obviously right about the elf_check_arch in the 64-bit part of the
> kernel is broken. It's probably just be copied from the 32-bit part
> without changes, like a lot of the code in the 64-bit kernel is.
>
> Hope that makes some sense.
> /Carsten
>
>
> "Maciej W. Rozycki" wrote:
>
> > Hello,
> >
> > After noticing I cannot run a trivial ELF64 program because of the
> > EF_MIPS_ARCH_3 flag (quite a reasonable setting for a 64-bit executable,
> > isn't it?), I concluded a considerable rework of elf_check_arch() is
> > needed as what we currently have is inadequate.
> >
> > Here is my proposal. I think binfmt_elf.c for mips and binfmt_elf32.c
> > for mips64 should accept all ELF32 binaries either with no ABI mark (as
> > produced by most versions of binutils) or with a 32 (aka o32) ABI one and
> > binfmt_elf.c for mips64 should accept all ELF32 binaries with an n32 ABI
> > mark and all ELF64 ones (which essentially means the 64 aka n64 ABI).
> > Everything else (i.e. o64 and EABIs) is rejected. The patch adds
> > necessary ELF file header flag definitions and synchronizes a few wrong
> > ones to the binutils' definitions as well.
> >
> > It removes the bogus check of architecture flags as they are really
> > irrelevant -- the code is intended to handle executable formats and not
> > execution of code. If a user incorporates unsupported opcodes, he'll just
> > get SIGILL at one moment. We may actually check if an architecture is
> > supported even no other Linux port seems to care, but then the comparison
> > should be against mips_cpu.isa_level and not against hardcoded constants.
> >
> > Note, this is an RFC at this stage -- I haven't tested the code
> > adequately for an immediate inclusion, even if it looks obvious. There
> > should be no problems with code made with old binutils as unset flags are
> > treated as (o)32.
> >
> > Maciej
> >
> > --
> > + Maciej W. Rozycki, Technical University of Gdansk, Poland +
> > +--------------------------------------------------------------+
> > + e-mail: macro@ds2.pg.gda.pl, PGP key available +
> >
> > patch-mips-2.4.19-rc1-20020719-mips64-elf-2
> > diff -up --recursive --new-file linux-mips-2.4.19-rc1-20020719.macro/arch/mips64/kernel/binfmt_elf32.c linux-mips-2.4.19-rc1-20020719/arch/mips64/kernel/binfmt_elf32.c
> > --- linux-mips-2.4.19-rc1-20020719.macro/arch/mips64/kernel/binfmt_elf32.c 2002-06-29 03:01:44.000000000 +0000
> > +++ linux-mips-2.4.19-rc1-20020719/arch/mips64/kernel/binfmt_elf32.c 2002-07-23 23:15:27.000000000 +0000
> > @@ -27,8 +27,26 @@ typedef elf_greg_t elf_gregset_t[ELF_NGR
> > typedef double elf_fpreg_t;
> > typedef elf_fpreg_t elf_fpregset_t[ELF_NFPREG];
> >
> > -#define elf_check_arch(x) \
> > - ((x)->e_machine == EM_MIPS)
> > +/*
> > + * 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 (__h->e_machine != EM_MIPS) \
> > + __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; \
> > + \
> > + __res; \
> > +})
> >
> > #define TASK32_SIZE 0x80000000UL
> > #undef ELF_ET_DYN_BASE
> > diff -up --recursive --new-file linux-mips-2.4.19-rc1-20020719.macro/include/asm-mips/elf.h linux-mips-2.4.19-rc1-20020719/include/asm-mips/elf.h
> > --- linux-mips-2.4.19-rc1-20020719.macro/include/asm-mips/elf.h 2002-04-25 02:57:43.000000000 +0000
> > +++ linux-mips-2.4.19-rc1-20020719/include/asm-mips/elf.h 2002-07-23 22:50:48.000000000 +0000
> > @@ -16,10 +16,11 @@
> > #define EF_MIPS_ARCH_3 0x20000000 /* -mips3 code. */
> > #define EF_MIPS_ARCH_4 0x30000000 /* -mips4 code. */
> > #define EF_MIPS_ARCH_5 0x40000000 /* -mips5 code. */
> > -#define EF_MIPS_ARCH_32 0x60000000 /* MIPS32 code. */
> > -#define EF_MIPS_ARCH_64 0x70000000 /* MIPS64 code. */
> > -#define EF_MIPS_ARCH_32R2 0x80000000 /* MIPS32 code. */
> > -#define EF_MIPS_ARCH_64R2 0x90000000 /* MIPS64 code. */
> > +#define EF_MIPS_ARCH_32 0x50000000 /* MIPS32 code. */
> > +#define EF_MIPS_ARCH_64 0x60000000 /* MIPS64 code. */
> > +/* The ABI of the file. */
> > +#define EF_MIPS_ABI_O32 0x00001000 /* O32 ABI. */
> > +#define EF_MIPS_ABI_O64 0x00002000 /* O32 extended for 64 bit. */
> >
> > typedef unsigned long elf_greg_t;
> > typedef elf_greg_t elf_gregset_t[ELF_NGREG];
> > @@ -37,10 +38,12 @@ typedef elf_fpreg_t elf_fpregset_t[ELF_N
> > \
> > if (__h->e_machine != EM_MIPS) \
> > __res = 0; \
> > - if (((__h->e_flags & EF_MIPS_ARCH) != EF_MIPS_ARCH_1) && \
> > - ((__h->e_flags & EF_MIPS_ARCH) != EF_MIPS_ARCH_2) && \
> > - ((__h->e_flags & EF_MIPS_ARCH) != EF_MIPS_ARCH_32) && \
> > - ((__h->e_flags & EF_MIPS_ARCH) != EF_MIPS_ARCH_32R2)) \
> > + 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; \
> > \
> > __res; \
> > diff -up --recursive --new-file linux-mips-2.4.19-rc1-20020719.macro/include/asm-mips64/elf.h linux-mips-2.4.19-rc1-20020719/include/asm-mips64/elf.h
> > --- linux-mips-2.4.19-rc1-20020719.macro/include/asm-mips64/elf.h 2002-07-22 08:49:30.000000000 +0000
> > +++ linux-mips-2.4.19-rc1-20020719/include/asm-mips64/elf.h 2002-07-23 23:12:28.000000000 +0000
> > @@ -9,21 +9,23 @@
> > #include <asm/ptrace.h>
> > #include <asm/user.h>
> >
> > -#ifndef ELF_ARCH
> > -/* ELF register definitions */
> > -#define ELF_NGREG 45
> > -#define ELF_NFPREG 33
> > -
> > -/* ELF header e_flags defines. MIPS architecture level. */
> > +/* ELF header e_flags defines. */
> > +/* MIPS architecture level. */
> > #define EF_MIPS_ARCH_1 0x00000000 /* -mips1 code. */
> > #define EF_MIPS_ARCH_2 0x10000000 /* -mips2 code. */
> > #define EF_MIPS_ARCH_3 0x20000000 /* -mips3 code. */
> > #define EF_MIPS_ARCH_4 0x30000000 /* -mips4 code. */
> > #define EF_MIPS_ARCH_5 0x40000000 /* -mips5 code. */
> > -#define EF_MIPS_ARCH_32 0x60000000 /* MIPS32 code. */
> > -#define EF_MIPS_ARCH_64 0x70000000 /* MIPS64 code. */
> > -#define EF_MIPS_ARCH_32R2 0x80000000 /* MIPS32 code. */
> > -#define EF_MIPS_ARCH_64R2 0x90000000 /* MIPS64 code. */
> > +#define EF_MIPS_ARCH_32 0x50000000 /* MIPS32 code. */
> > +#define EF_MIPS_ARCH_64 0x60000000 /* MIPS64 code. */
> > +/* The ABI of the file. */
> > +#define EF_MIPS_ABI_O32 0x00001000 /* O32 ABI. */
> > +#define EF_MIPS_ABI_O64 0x00002000 /* O32 extended for 64 bit. */
> > +
> > +#ifndef ELF_ARCH
> > +/* ELF register definitions */
> > +#define ELF_NGREG 45
> > +#define ELF_NFPREG 33
> >
> > typedef unsigned long elf_greg_t;
> > typedef elf_greg_t elf_gregset_t[ELF_NGREG];
> > @@ -41,14 +43,9 @@ typedef elf_fpreg_t elf_fpregset_t[ELF_N
> > \
> > if (__h->e_machine != EM_MIPS) \
> > __res = 0; \
> > - if (sizeof(elf_caddr_t) == 8 && \
> > - __h->e_ident[EI_CLASS] == ELFCLASS32) \
> > - __res = 0; \
> > - if (((__h->e_flags & EF_MIPS_ARCH) != EF_MIPS_ARCH_1) && \
> > - ((__h->e_flags & EF_MIPS_ARCH) != EF_MIPS_ARCH_2) && \
> > - ((__h->e_flags & EF_MIPS_ARCH) != EF_MIPS_ARCH_32) && \
> > - ((__h->e_flags & EF_MIPS_ARCH) != EF_MIPS_ARCH_32R2)) \
> > - __res = 0; \
> > + if ((__h->e_ident[EI_CLASS] == ELFCLASS32) && \
> > + ((__h->e_flags & EF_MIPS_ABI2) == 0)) \
> > + __res = 0; \
> > \
> > __res; \
> > })
> > diff -up --recursive --new-file linux-mips-2.4.19-rc1-20020719.macro/include/linux/elf.h linux-mips-2.4.19-rc1-20020719/include/linux/elf.h
> > --- linux-mips-2.4.19-rc1-20020719.macro/include/linux/elf.h 2002-07-22 08:49:30.000000000 +0000
> > +++ linux-mips-2.4.19-rc1-20020719/include/linux/elf.h 2002-07-23 22:18:54.000000000 +0000
> > @@ -37,6 +37,9 @@ typedef __s64 Elf64_Sxword;
> > #define EF_MIPS_NOREORDER 0x00000001
> > #define EF_MIPS_PIC 0x00000002
> > #define EF_MIPS_CPIC 0x00000004
> > +#define EF_MIPS_ABI2 0x00000020
> > +#define EF_MIPS_32BITMODE 0x00000100
> > +#define EF_MIPS_ABI 0x0000f000
> > #define EF_MIPS_ARCH 0xf0000000
> >
> > /* These constants define the different elf file types */
>
>
--
Daniel Jacobowitz Carnegie Mellon University
MontaVista Software Debian GNU/Linux Developer
next prev parent reply other threads:[~2002-07-24 19:34 UTC|newest]
Thread overview: 21+ messages / expand[flat|nested] mbox.gz Atom feed top
2002-07-24 17:05 [patch] linux: RFC: elf_check_arch() rework Maciej W. Rozycki
2002-07-24 18:08 ` Daniel Jacobowitz
2002-07-24 19:12 ` Carsten Langgaard
2002-07-24 19:31 ` Daniel Jacobowitz [this message]
2002-07-25 11:10 ` Maciej W. Rozycki
2002-07-25 13:29 ` Carsten Langgaard
2002-07-25 14:12 ` Maciej W. Rozycki
2002-07-25 15:26 ` PATCH: Update E_MIP_ARCH_XXX (Re: [patch] linux: RFC: elf_check_arch() rework) H. J. Lu
[not found] ` <mailpost.1027610779.9546@news-sj1-1>
2002-07-25 17:49 ` cgd
2002-07-25 18:50 ` David Anderson
2002-07-26 16:53 ` cgd
2002-07-26 17:12 ` Paul Koning
2002-07-29 7:47 ` PATCH: Update E_MIP_ARCH_XXX (Re: [patch] linux: RFC:elf_check_arch() rework) Carsten Langgaard
2002-07-29 7:47 ` Carsten Langgaard
2002-07-30 14:09 ` Dan Temple
2002-07-30 14:09 ` Dan Temple
2002-07-30 15:07 ` Maciej W. Rozycki
[not found] ` <mailpost.1028038253.3155@news-sj1-1>
2002-07-30 19:20 ` PATCH: Update E_MIP_ARCH_XXX (Re: [patch] linux: RFC: elf_check_arch() rework) cgd
2002-07-30 19:26 ` Geoff Keating
2002-07-30 19:27 ` cgd
2002-07-30 20:03 ` Eric Christopher
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20020724193117.GA22820@nevyn.them.org \
--to=dan@debian.org \
--cc=carstenl@mips.com \
--cc=linux-mips@fnet.fr \
--cc=linux-mips@oss.sgi.com \
--cc=macro@ds2.pg.gda.pl \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox