qemu-devel.nongnu.org archive mirror
 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: [PATCH v3 12/43] bsd-user: remove a.out support
Date: Thu,  2 Sep 2021 17:46:58 -0600	[thread overview]
Message-ID: <20210902234729.76141-13-imp@bsdimp.com> (raw)
In-Reply-To: <20210902234729.76141-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-03  0:02 UTC|newest]

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

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=20210902234729.76141-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 a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).