Skip to content

Commit ffa0366

Browse files
committed
bsd-user: remove a.out support
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 <[email protected]> Reviewed-by: Richard Henderson <[email protected]> Reviewed-by: Philippe Mathieu-Daudé <[email protected]>
1 parent 7ee0986 commit ffa0366

File tree

3 files changed

+21
-95
lines changed

3 files changed

+21
-95
lines changed

bsd-user/bsdload.c

Lines changed: 1 addition & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -98,7 +98,7 @@ static int prepare_binprm(struct bsd_binprm *bprm)
9898

9999
/* Construct the envp and argv tables on the target stack. */
100100
abi_ulong loader_build_argptr(int envc, int argc, abi_ulong sp,
101-
abi_ulong stringp, int push_ptr)
101+
abi_ulong stringp)
102102
{
103103
int n = sizeof(abi_ulong);
104104
abi_ulong envp;
@@ -108,13 +108,6 @@ abi_ulong loader_build_argptr(int envc, int argc, abi_ulong sp,
108108
envp = sp;
109109
sp -= (argc + 1) * n;
110110
argv = sp;
111-
if (push_ptr) {
112-
/* FIXME - handle put_user() failures */
113-
sp -= n;
114-
put_user_ual(envp, sp);
115-
sp -= n;
116-
put_user_ual(argv, sp);
117-
}
118111
sp -= n;
119112
/* FIXME - handle put_user() failures */
120113
put_user_ual(argc, sp);

bsd-user/elfload.c

Lines changed: 19 additions & 86 deletions
Original file line numberDiff line numberDiff line change
@@ -52,25 +52,6 @@
5252

5353
#include "elf.h"
5454

55-
struct exec
56-
{
57-
unsigned int a_info; /* Use macros N_MAGIC, etc for access */
58-
unsigned int a_text; /* length of text, in bytes */
59-
unsigned int a_data; /* length of data, in bytes */
60-
unsigned int a_bss; /* length of uninitialized data area, in bytes */
61-
unsigned int a_syms; /* length of symbol table data in file, in bytes */
62-
unsigned int a_entry; /* start address */
63-
unsigned int a_trsize; /* length of relocation info for text, in bytes */
64-
unsigned int a_drsize; /* length of relocation info for data, in bytes */
65-
};
66-
67-
68-
#define N_MAGIC(exec) ((exec).a_info & 0xffff)
69-
#define OMAGIC 0407
70-
#define NMAGIC 0410
71-
#define ZMAGIC 0413
72-
#define QMAGIC 0314
73-
7455
/* max code+data+bss space allocated to elf interpreter */
7556
#define INTERP_MAP_SIZE (32 * 1024 * 1024)
7657

@@ -82,19 +63,13 @@ struct exec
8263
#define TARGET_ELF_PAGESTART(_v) ((_v) & ~(unsigned long)(TARGET_ELF_EXEC_PAGESIZE - 1))
8364
#define TARGET_ELF_PAGEOFFSET(_v) ((_v) & (TARGET_ELF_EXEC_PAGESIZE - 1))
8465

85-
#define INTERPRETER_NONE 0
86-
#define INTERPRETER_AOUT 1
87-
#define INTERPRETER_ELF 2
88-
8966
#define DLINFO_ITEMS 12
9067

9168
static inline void memcpy_fromfs(void *to, const void *from, unsigned long n)
9269
{
9370
memcpy(to, from, n);
9471
}
9572

96-
static int load_aout_interp(void *exptr, int interp_fd);
97-
9873
#ifdef BSWAP_NEEDED
9974
static void bswap_ehdr(struct elfhdr *ehdr)
10075
{
@@ -300,7 +275,7 @@ static abi_ulong create_elf_tables(abi_ulong p, int argc, int envc,
300275
struct elfhdr * exec,
301276
abi_ulong load_addr,
302277
abi_ulong load_bias,
303-
abi_ulong interp_load_addr, int ibcs,
278+
abi_ulong interp_load_addr,
304279
struct image_info *info)
305280
{
306281
abi_ulong sp;
@@ -330,7 +305,7 @@ static abi_ulong create_elf_tables(abi_ulong p, int argc, int envc,
330305
size += DLINFO_ARCH_ITEMS * 2;
331306
#endif
332307
size += envc + argc + 2;
333-
size += (!ibcs ? 3 : 1); /* argc itself */
308+
size += 1; /* argc itself */
334309
size *= n;
335310
if (size & 15)
336311
sp -= 16 - (size & 15);
@@ -370,7 +345,7 @@ static abi_ulong create_elf_tables(abi_ulong p, int argc, int envc,
370345
#endif
371346
#undef NEW_AUX_ENT
372347

373-
sp = loader_build_argptr(envc, argc, sp, p, !ibcs);
348+
sp = loader_build_argptr(envc, argc, sp, p);
374349
return sp;
375350
}
376351

@@ -432,7 +407,7 @@ static abi_ulong load_elf_interp(struct elfhdr *interp_elf_ex,
432407
if (retval < 0) {
433408
perror("load_elf_interp");
434409
exit(-1);
435-
free (elf_phdata);
410+
free(elf_phdata);
436411
return retval;
437412
}
438413
#ifdef BSWAP_NEEDED
@@ -685,11 +660,9 @@ int load_elf_binary(struct bsd_binprm *bprm, struct target_pt_regs *regs,
685660
{
686661
struct elfhdr elf_ex;
687662
struct elfhdr interp_elf_ex;
688-
struct exec interp_ex;
689663
int interpreter_fd = -1; /* avoid warning */
690664
abi_ulong load_addr, load_bias;
691665
int load_addr_set = 0;
692-
unsigned int interpreter_type = INTERPRETER_NONE;
693666
int i;
694667
struct elf_phdr * elf_ppnt;
695668
struct elf_phdr *elf_phdata;
@@ -702,7 +675,6 @@ int load_elf_binary(struct bsd_binprm *bprm, struct target_pt_regs *regs,
702675
#ifdef LOW_ELF_STACK
703676
abi_ulong elf_stack = ~((abi_ulong)0UL);
704677
#endif
705-
char passed_fileno[6];
706678

707679
load_addr = 0;
708680
load_bias = 0;
@@ -760,7 +732,6 @@ int load_elf_binary(struct bsd_binprm *bprm, struct target_pt_regs *regs,
760732
end_code = 0;
761733
start_data = 0;
762734
end_data = 0;
763-
interp_ex.a_info = 0;
764735

765736
for (i = 0;i < elf_ex.e_phnum; i++) {
766737
if (elf_ppnt->p_type == PT_INTERP) {
@@ -813,7 +784,6 @@ int load_elf_binary(struct bsd_binprm *bprm, struct target_pt_regs *regs,
813784
}
814785
}
815786
if (retval >= 0) {
816-
interp_ex = *((struct exec *) bprm->buf); /* aout exec-header */
817787
interp_elf_ex = *((struct elfhdr *) bprm->buf); /* elf exec-header */
818788
}
819789
if (retval < 0) {
@@ -830,20 +800,8 @@ int load_elf_binary(struct bsd_binprm *bprm, struct target_pt_regs *regs,
830800

831801
/* Some simple consistency checks for the interpreter */
832802
if (elf_interpreter) {
833-
interpreter_type = INTERPRETER_ELF | INTERPRETER_AOUT;
834-
835-
/* Now figure out which format our binary is */
836-
if ((N_MAGIC(interp_ex) != OMAGIC) && (N_MAGIC(interp_ex) != ZMAGIC) &&
837-
(N_MAGIC(interp_ex) != QMAGIC)) {
838-
interpreter_type = INTERPRETER_ELF;
839-
}
840-
841803
if (interp_elf_ex.e_ident[0] != 0x7f ||
842-
strncmp((char *)&interp_elf_ex.e_ident[1], "ELF", 3) != 0) {
843-
interpreter_type &= ~INTERPRETER_ELF;
844-
}
845-
846-
if (!interpreter_type) {
804+
strncmp((char *)&interp_elf_ex.e_ident[1], "ELF", 3) != 0) {
847805
free(elf_interpreter);
848806
free(elf_phdata);
849807
close(bprm->fd);
@@ -854,24 +812,11 @@ int load_elf_binary(struct bsd_binprm *bprm, struct target_pt_regs *regs,
854812
/* OK, we are done with that, now set up the arg stuff,
855813
and then start this sucker up */
856814

857-
{
858-
char *passed_p;
859-
860-
if (interpreter_type == INTERPRETER_AOUT) {
861-
snprintf(passed_fileno, sizeof(passed_fileno), "%d", bprm->fd);
862-
passed_p = passed_fileno;
863-
864-
if (elf_interpreter) {
865-
bprm->p = copy_elf_strings(1, &passed_p, bprm->page, bprm->p);
866-
bprm->argc++;
867-
}
868-
}
869-
if (!bprm->p) {
870-
free(elf_interpreter);
871-
free(elf_phdata);
872-
close(bprm->fd);
873-
return -E2BIG;
874-
}
815+
if (!bprm->p) {
816+
free(elf_interpreter);
817+
free(elf_phdata);
818+
close(bprm->fd);
819+
return -E2BIG;
875820
}
876821

877822
/* 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,
997942
end_data += load_bias;
998943

999944
if (elf_interpreter) {
1000-
if (interpreter_type & 1) {
1001-
elf_entry = load_aout_interp(&interp_ex, interpreter_fd);
1002-
}
1003-
else if (interpreter_type & 2) {
1004-
elf_entry = load_elf_interp(&interp_elf_ex, interpreter_fd,
1005-
&interp_load_addr);
1006-
}
945+
elf_entry = load_elf_interp(&interp_elf_ex, interpreter_fd,
946+
&interp_load_addr);
1007947
reloc_func_desc = interp_load_addr;
1008948

1009949
close(interpreter_fd);
@@ -1022,19 +962,18 @@ int load_elf_binary(struct bsd_binprm *bprm, struct target_pt_regs *regs,
1022962
if (qemu_log_enabled())
1023963
load_symbols(&elf_ex, bprm->fd);
1024964

1025-
if (interpreter_type != INTERPRETER_AOUT) close(bprm->fd);
965+
close(bprm->fd);
1026966

1027967
#ifdef LOW_ELF_STACK
1028968
info->start_stack = bprm->p = elf_stack - 4;
1029969
#endif
1030970
bprm->p = create_elf_tables(bprm->p,
1031-
bprm->argc,
1032-
bprm->envc,
1033-
&elf_ex,
1034-
load_addr, load_bias,
1035-
interp_load_addr,
1036-
(interpreter_type == INTERPRETER_AOUT ? 0 : 1),
1037-
info);
971+
bprm->argc,
972+
bprm->envc,
973+
&elf_ex,
974+
load_addr, load_bias,
975+
interp_load_addr,
976+
info);
1038977
info->load_addr = reloc_func_desc;
1039978
info->start_brk = info->brk = elf_brk;
1040979
info->end_code = end_code;
@@ -1063,12 +1002,6 @@ int load_elf_binary(struct bsd_binprm *bprm, struct target_pt_regs *regs,
10631002
return 0;
10641003
}
10651004

1066-
static int load_aout_interp(void *exptr, int interp_fd)
1067-
{
1068-
printf("a.out interpreter not yet supported\n");
1069-
return(0);
1070-
}
1071-
10721005
void do_init_thread(struct target_pt_regs *regs, struct image_info *infop)
10731006
{
10741007
init_thread(regs, infop);

bsd-user/qemu.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -129,7 +129,7 @@ struct bsd_binprm {
129129

130130
void do_init_thread(struct target_pt_regs *regs, struct image_info *infop);
131131
abi_ulong loader_build_argptr(int envc, int argc, abi_ulong sp,
132-
abi_ulong stringp, int push_ptr);
132+
abi_ulong stringp);
133133
int loader_exec(const char *filename, char **argv, char **envp,
134134
struct target_pt_regs *regs, struct image_info *infop,
135135
struct bsd_binprm *bprm);

0 commit comments

Comments
 (0)