All of lore.kernel.org
 help / color / mirror / Atom feed
From: imp@bsdimp.com
To: qemu-devel@nongnu.org
Cc: kevans@freebsd.org,
	"Richard Henderson" <richard.henderson@linaro.org>,
	"Philippe Mathieu-Daudé" <f4bug@amsat.org>,
	"Warner Losh" <imp@bsdimp.com>
Subject: [PULL 12/42] bsd-user: remove a.out support
Date: Tue,  7 Sep 2021 15:53:02 -0600	[thread overview]
Message-ID: <20210907215332.30737-13-imp@bsdimp.com> (raw)
In-Reply-To: <20210907215332.30737-1-imp@bsdimp.com>

From: Warner Losh <imp@bsdimp.com>

Remove still-born a.out support. The BSDs switched from a.out to ELF 20+ years
ago. It's out of scope for bsd-user, and what little support there was would
simply wind up at a not-implemented message. Simplify the whole mess by removing
it entirely. Should future support be required, it would be better to start from
scratch.

Signed-off-by: Warner Losh <imp@bsdimp.com>
Reviewed-by: Richard Henderson <richard.henderson@linaro.org>
Reviewed-by: Philippe Mathieu-Daudé <f4bug@amsat.org>
---
 bsd-user/bsdload.c |   9 +---
 bsd-user/elfload.c | 105 ++++++++-------------------------------------
 bsd-user/qemu.h    |   2 +-
 3 files changed, 21 insertions(+), 95 deletions(-)

diff --git a/bsd-user/bsdload.c b/bsd-user/bsdload.c
index 32f7fd5dec..6aefc7a28b 100644
--- a/bsd-user/bsdload.c
+++ b/bsd-user/bsdload.c
@@ -98,7 +98,7 @@ static int prepare_binprm(struct bsd_binprm *bprm)
 
 /* Construct the envp and argv tables on the target stack.  */
 abi_ulong loader_build_argptr(int envc, int argc, abi_ulong sp,
-                              abi_ulong stringp, int push_ptr)
+                              abi_ulong stringp)
 {
     int n = sizeof(abi_ulong);
     abi_ulong envp;
@@ -108,13 +108,6 @@ abi_ulong loader_build_argptr(int envc, int argc, abi_ulong sp,
     envp = sp;
     sp -= (argc + 1) * n;
     argv = sp;
-    if (push_ptr) {
-        /* FIXME - handle put_user() failures */
-        sp -= n;
-        put_user_ual(envp, sp);
-        sp -= n;
-        put_user_ual(argv, sp);
-    }
     sp -= n;
     /* FIXME - handle put_user() failures */
     put_user_ual(argc, sp);
diff --git a/bsd-user/elfload.c b/bsd-user/elfload.c
index e950732978..4f3fa83c2c 100644
--- a/bsd-user/elfload.c
+++ b/bsd-user/elfload.c
@@ -52,25 +52,6 @@
 
 #include "elf.h"
 
-struct exec
-{
-  unsigned int a_info;   /* Use macros N_MAGIC, etc for access */
-  unsigned int a_text;   /* length of text, in bytes */
-  unsigned int a_data;   /* length of data, in bytes */
-  unsigned int a_bss;    /* length of uninitialized data area, in bytes */
-  unsigned int a_syms;   /* length of symbol table data in file, in bytes */
-  unsigned int a_entry;  /* start address */
-  unsigned int a_trsize; /* length of relocation info for text, in bytes */
-  unsigned int a_drsize; /* length of relocation info for data, in bytes */
-};
-
-
-#define N_MAGIC(exec) ((exec).a_info & 0xffff)
-#define OMAGIC 0407
-#define NMAGIC 0410
-#define ZMAGIC 0413
-#define QMAGIC 0314
-
 /* max code+data+bss space allocated to elf interpreter */
 #define INTERP_MAP_SIZE (32 * 1024 * 1024)
 
@@ -82,10 +63,6 @@ struct exec
 #define TARGET_ELF_PAGESTART(_v) ((_v) & ~(unsigned long)(TARGET_ELF_EXEC_PAGESIZE - 1))
 #define TARGET_ELF_PAGEOFFSET(_v) ((_v) & (TARGET_ELF_EXEC_PAGESIZE - 1))
 
-#define INTERPRETER_NONE 0
-#define INTERPRETER_AOUT 1
-#define INTERPRETER_ELF 2
-
 #define DLINFO_ITEMS 12
 
 static inline void memcpy_fromfs(void *to, const void *from, unsigned long n)
@@ -93,8 +70,6 @@ static inline void memcpy_fromfs(void *to, const void *from, unsigned long n)
         memcpy(to, from, n);
 }
 
-static int load_aout_interp(void *exptr, int interp_fd);
-
 #ifdef BSWAP_NEEDED
 static void bswap_ehdr(struct elfhdr *ehdr)
 {
@@ -300,7 +275,7 @@ static abi_ulong create_elf_tables(abi_ulong p, int argc, int envc,
                                    struct elfhdr * exec,
                                    abi_ulong load_addr,
                                    abi_ulong load_bias,
-                                   abi_ulong interp_load_addr, int ibcs,
+                                   abi_ulong interp_load_addr,
                                    struct image_info *info)
 {
         abi_ulong sp;
@@ -330,7 +305,7 @@ static abi_ulong create_elf_tables(abi_ulong p, int argc, int envc,
         size += DLINFO_ARCH_ITEMS * 2;
 #endif
         size += envc + argc + 2;
-        size += (!ibcs ? 3 : 1);        /* argc itself */
+        size += 1;        /* argc itself */
         size *= n;
         if (size & 15)
                 sp -= 16 - (size & 15);
@@ -370,7 +345,7 @@ static abi_ulong create_elf_tables(abi_ulong p, int argc, int envc,
 #endif
 #undef NEW_AUX_ENT
 
-        sp = loader_build_argptr(envc, argc, sp, p, !ibcs);
+        sp = loader_build_argptr(envc, argc, sp, p);
         return sp;
 }
 
@@ -432,7 +407,7 @@ static abi_ulong load_elf_interp(struct elfhdr *interp_elf_ex,
     if (retval < 0) {
         perror("load_elf_interp");
         exit(-1);
-        free (elf_phdata);
+        free(elf_phdata);
         return retval;
     }
 #ifdef BSWAP_NEEDED
@@ -685,11 +660,9 @@ int load_elf_binary(struct bsd_binprm *bprm, struct target_pt_regs *regs,
 {
     struct elfhdr elf_ex;
     struct elfhdr interp_elf_ex;
-    struct exec interp_ex;
     int interpreter_fd = -1; /* avoid warning */
     abi_ulong load_addr, load_bias;
     int load_addr_set = 0;
-    unsigned int interpreter_type = INTERPRETER_NONE;
     int i;
     struct elf_phdr * elf_ppnt;
     struct elf_phdr *elf_phdata;
@@ -702,7 +675,6 @@ int load_elf_binary(struct bsd_binprm *bprm, struct target_pt_regs *regs,
 #ifdef LOW_ELF_STACK
     abi_ulong elf_stack = ~((abi_ulong)0UL);
 #endif
-    char passed_fileno[6];
 
     load_addr = 0;
     load_bias = 0;
@@ -760,7 +732,6 @@ int load_elf_binary(struct bsd_binprm *bprm, struct target_pt_regs *regs,
     end_code = 0;
     start_data = 0;
     end_data = 0;
-    interp_ex.a_info = 0;
 
     for (i = 0;i < elf_ex.e_phnum; i++) {
         if (elf_ppnt->p_type == PT_INTERP) {
@@ -813,7 +784,6 @@ int load_elf_binary(struct bsd_binprm *bprm, struct target_pt_regs *regs,
                 }
             }
             if (retval >= 0) {
-                interp_ex = *((struct exec *) bprm->buf); /* aout exec-header */
                 interp_elf_ex = *((struct elfhdr *) bprm->buf); /* elf exec-header */
             }
             if (retval < 0) {
@@ -830,20 +800,8 @@ int load_elf_binary(struct bsd_binprm *bprm, struct target_pt_regs *regs,
 
     /* Some simple consistency checks for the interpreter */
     if (elf_interpreter) {
-        interpreter_type = INTERPRETER_ELF | INTERPRETER_AOUT;
-
-        /* Now figure out which format our binary is */
-        if ((N_MAGIC(interp_ex) != OMAGIC) && (N_MAGIC(interp_ex) != ZMAGIC) &&
-                (N_MAGIC(interp_ex) != QMAGIC)) {
-            interpreter_type = INTERPRETER_ELF;
-        }
-
         if (interp_elf_ex.e_ident[0] != 0x7f ||
-                strncmp((char *)&interp_elf_ex.e_ident[1], "ELF", 3) != 0) {
-            interpreter_type &= ~INTERPRETER_ELF;
-        }
-
-        if (!interpreter_type) {
+            strncmp((char *)&interp_elf_ex.e_ident[1], "ELF", 3) != 0) {
             free(elf_interpreter);
             free(elf_phdata);
             close(bprm->fd);
@@ -854,24 +812,11 @@ int load_elf_binary(struct bsd_binprm *bprm, struct target_pt_regs *regs,
     /* OK, we are done with that, now set up the arg stuff,
        and then start this sucker up */
 
-    {
-        char *passed_p;
-
-        if (interpreter_type == INTERPRETER_AOUT) {
-            snprintf(passed_fileno, sizeof(passed_fileno), "%d", bprm->fd);
-            passed_p = passed_fileno;
-
-            if (elf_interpreter) {
-                bprm->p = copy_elf_strings(1, &passed_p, bprm->page, bprm->p);
-                bprm->argc++;
-            }
-        }
-        if (!bprm->p) {
-            free(elf_interpreter);
-            free(elf_phdata);
-            close(bprm->fd);
-            return -E2BIG;
-        }
+    if (!bprm->p) {
+        free(elf_interpreter);
+        free(elf_phdata);
+        close(bprm->fd);
+        return -E2BIG;
     }
 
     /* OK, This is the point of no return */
@@ -997,13 +942,8 @@ int load_elf_binary(struct bsd_binprm *bprm, struct target_pt_regs *regs,
     end_data += load_bias;
 
     if (elf_interpreter) {
-        if (interpreter_type & 1) {
-            elf_entry = load_aout_interp(&interp_ex, interpreter_fd);
-        }
-        else if (interpreter_type & 2) {
-            elf_entry = load_elf_interp(&interp_elf_ex, interpreter_fd,
-                                            &interp_load_addr);
-        }
+        elf_entry = load_elf_interp(&interp_elf_ex, interpreter_fd,
+                                    &interp_load_addr);
         reloc_func_desc = interp_load_addr;
 
         close(interpreter_fd);
@@ -1022,19 +962,18 @@ int load_elf_binary(struct bsd_binprm *bprm, struct target_pt_regs *regs,
     if (qemu_log_enabled())
         load_symbols(&elf_ex, bprm->fd);
 
-    if (interpreter_type != INTERPRETER_AOUT) close(bprm->fd);
+    close(bprm->fd);
 
 #ifdef LOW_ELF_STACK
     info->start_stack = bprm->p = elf_stack - 4;
 #endif
     bprm->p = create_elf_tables(bprm->p,
-                    bprm->argc,
-                    bprm->envc,
-                    &elf_ex,
-                    load_addr, load_bias,
-                    interp_load_addr,
-                    (interpreter_type == INTERPRETER_AOUT ? 0 : 1),
-                    info);
+                                bprm->argc,
+                                bprm->envc,
+                                &elf_ex,
+                                load_addr, load_bias,
+                                interp_load_addr,
+                                info);
     info->load_addr = reloc_func_desc;
     info->start_brk = info->brk = elf_brk;
     info->end_code = end_code;
@@ -1063,12 +1002,6 @@ int load_elf_binary(struct bsd_binprm *bprm, struct target_pt_regs *regs,
     return 0;
 }
 
-static int load_aout_interp(void *exptr, int interp_fd)
-{
-    printf("a.out interpreter not yet supported\n");
-    return(0);
-}
-
 void do_init_thread(struct target_pt_regs *regs, struct image_info *infop)
 {
     init_thread(regs, infop);
diff --git a/bsd-user/qemu.h b/bsd-user/qemu.h
index e85c164bab..d1ab58a8eb 100644
--- a/bsd-user/qemu.h
+++ b/bsd-user/qemu.h
@@ -129,7 +129,7 @@ struct bsd_binprm {
 
 void do_init_thread(struct target_pt_regs *regs, struct image_info *infop);
 abi_ulong loader_build_argptr(int envc, int argc, abi_ulong sp,
-                              abi_ulong stringp, int push_ptr);
+                              abi_ulong stringp);
 int loader_exec(const char *filename, char **argv, char **envp,
                 struct target_pt_regs *regs, struct image_info *infop,
                 struct bsd_binprm *bprm);
-- 
2.32.0



  parent reply	other threads:[~2021-09-07 22:03 UTC|newest]

Thread overview: 50+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2021-09-07 21:52 [PULL 00/42] bsd-user updates to run hello world imp
2021-09-07 21:52 ` [PULL 01/42] bsd-user: remove sparc and sparc64 imp
2021-09-07 21:52 ` [PULL 02/42] bsd-user: add copyright header to elfload.c imp
2021-09-07 21:52 ` [PULL 03/42] bsd-user: Add Stacey's copyright to main.c imp
2021-09-07 21:52 ` [PULL 04/42] bsd-user: add license to bsdload.c imp
2021-09-07 21:52 ` [PULL 05/42] bsd-user: style nits: bsdload.c whitespace to qemu standard imp
2021-09-07 21:52 ` [PULL 06/42] bsd-user: Remove all non-x86 code from elfload.c imp
2021-09-07 21:52 ` [PULL 07/42] bsd-user: move arch specific defines out of elfload.c imp
2021-09-07 21:52 ` [PULL 08/42] bsd-user: pass the bsd_param into loader_exec imp
2021-09-07 21:52 ` [PULL 09/42] bsd-user: Fix calculation of size to allocate imp
2021-09-07 21:53 ` [PULL 10/42] bsd-user: implement path searching imp
2021-09-07 21:53 ` [PULL 11/42] bsd-user: Eliminate elf personality imp
2021-09-07 21:53 ` imp [this message]
2021-09-07 21:53 ` [PULL 13/42] bsd-user: TARGET_NGROUPS unused in this file, remove imp
2021-09-07 21:53 ` [PULL 14/42] bsd-user: elfload: simplify bswap a bit imp
2021-09-07 21:53 ` [PULL 15/42] bsd-user: assume pthreads and support of __thread imp
2021-09-07 21:53 ` [PULL 16/42] bsd-user: add host-os.h imp
2021-09-07 21:53 ` [PULL 17/42] bsd-user: Include host-os.h from main imp
2021-09-07 21:53 ` [PULL 18/42] bsd-user: save the path to the qemu emulator imp
2021-09-07 21:53 ` [PULL 19/42] bsd-user: start to move target CPU functions to target_arch* imp
2021-09-07 21:53 ` [PULL 20/42] bsd-user: Move per-cpu code into target_arch_cpu.h imp
2021-09-07 21:53 ` [PULL 21/42] bsd-user: pull in target_arch_thread.h update target_arch_elf.h imp
2021-09-07 21:53 ` [PULL 22/42] bsd-user: Include more things in qemu.h imp
2021-09-07 21:53 ` [PULL 23/42] bsd-user: define max args in terms of pages imp
2021-09-07 21:53 ` [PULL 24/42] bsd-user: Create target specific vmparam.h imp
2021-09-07 21:53 ` [PULL 25/42] bsd-user: Add system independent stack, data and text limiting imp
2021-09-07 21:53 ` [PULL 26/42] bsd-user: *BSD specific siginfo defintions imp
2021-09-07 21:53 ` [PULL 27/42] bsd-user: Implement --seed and initialize random state imp
2021-09-07 21:53 ` [PULL 28/42] bsd-user: Move stack initializtion into a per-os file imp
2021-09-07 21:53 ` [PULL 29/42] bsd-user: Add architecture specific signal tramp code imp
2021-09-07 21:53 ` [PULL 30/42] bsd-user: elf cleanup imp
2021-09-07 21:53 ` [PULL 31/42] bsd-user: Remove dead #ifdefs from elfload.c imp
2021-09-07 21:53 ` [PULL 32/42] bsd-user: Rewrite target system call definintion glue imp
2021-09-07 21:53 ` [PULL 33/42] bsd-user: update debugging in mmap.c imp
2021-09-07 21:53 ` [PULL 34/42] bsd-user: Add target_arch_reg to describe a target's register set imp
2021-09-07 21:53 ` [PULL 35/42] bsd-user: Add target_os_user.h to capture the user/kernel structures imp
2021-09-07 21:53 ` [PULL 36/42] bsd-user: add stubbed out core dump support imp
2021-09-07 21:53 ` [PULL 37/42] bsd-user: elfload.c style catch up patch imp
2021-09-07 21:53 ` [PULL 38/42] bsd-user: Refactor load_elf_sections and is_target_elf_binary imp
2021-09-07 21:53 ` [PULL 39/42] bsd-user: move gemu_log to later in the file imp
2021-09-07 21:53 ` [PULL 40/42] bsd-user: Implement interlock for atomic operations imp
2021-09-07 21:53 ` [PULL 41/42] bsd-user: Add '-0 argv0' option to bsd-user/main.c imp
2021-09-07 21:53 ` [PULL 42/42] bsd-user: Update mapping to handle reserved and starting conditions imp
2021-09-09 15:00 ` [PULL 00/42] bsd-user updates to run hello world Peter Maydell
2021-09-09 15:12   ` Warner Losh
2021-09-09 15:21     ` Daniel P. Berrangé
2021-09-09 16:31     ` Philippe Mathieu-Daudé
2021-09-10 20:35       ` Warner Losh
2021-09-09 16:29 ` Philippe Mathieu-Daudé
2021-09-10 20:31   ` Warner Losh

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=20210907215332.30737-13-imp@bsdimp.com \
    --to=imp@bsdimp.com \
    --cc=f4bug@amsat.org \
    --cc=kevans@freebsd.org \
    --cc=qemu-devel@nongnu.org \
    --cc=richard.henderson@linaro.org \
    /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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.