diff options
author | rnordier <rnordier@FreeBSD.org> | 2000-11-04 13:02:00 +0000 |
---|---|---|
committer | rnordier <rnordier@FreeBSD.org> | 2000-11-04 13:02:00 +0000 |
commit | 18e0fe6967f684c8adb8dd9db3a8cb24f70e7705 (patch) | |
tree | 796a6ec2a8cda6145d54708de7195fc62b04838a /usr.sbin/kgzip/kgzld.c | |
parent | 2cfec00a84116cb5277eecec357964eb0c113954 (diff) | |
download | FreeBSD-src-18e0fe6967f684c8adb8dd9db3a8cb24f70e7705.zip FreeBSD-src-18e0fe6967f684c8adb8dd9db3a8cb24f70e7705.tar.gz |
Add support for creating a.out output files in addition to ELF.
This allows booting from compressed binaries using older bootstraps.
Thanks to: dwmalone
Diffstat (limited to 'usr.sbin/kgzip/kgzld.c')
-rw-r--r-- | usr.sbin/kgzip/kgzld.c | 28 |
1 files changed, 24 insertions, 4 deletions
diff --git a/usr.sbin/kgzip/kgzld.c b/usr.sbin/kgzip/kgzld.c index a2b0086..3e1d2d1 100644 --- a/usr.sbin/kgzip/kgzld.c +++ b/usr.sbin/kgzip/kgzld.c @@ -36,11 +36,10 @@ #include <string.h> #include <unistd.h> +#include "aouthdr.h" #include "elfhdr.h" #include "kgzip.h" -#define KGZOFF sizeof(struct kgz_elfhdr) - #define align(x, y) (((x) + (y) - 1) & ~((y) - 1)) /* @@ -58,7 +57,23 @@ kgzld(struct kgz_hdr * kh, const char *f1, const char *f2) if (strcmp(kh->ident, "KGZ")) { if ((idi.fd = open(idi.fname = f1, O_RDONLY)) == -1) err(1, "%s", idi.fname); - n = xread(&idi, kh, sizeof(*kh), KGZOFF); + if (!format) { + union { + struct exec ex; + Elf32_Ehdr ee; + } hdr; + n = xread(&idi, &hdr, sizeof(hdr), 0); + if (n >= sizeof(hdr.ee) && IS_ELF(hdr.ee)) + format = F_ELF; + else if (n >= sizeof(hdr.ex) && + N_GETMAGIC(hdr.ex) == OMAGIC) + format = F_AOUT; + if (!format) + errx(1, "%s: Format not supported", idi.fname); + } + n = xread(&idi, kh, sizeof(*kh), + format == F_AOUT ? sizeof(struct kgz_aouthdr0) + : sizeof(struct kgz_elfhdr)); xclose(&idi); if (n != sizeof(*kh) || strcmp(kh->ident, "KGZ")) errx(1, "%s: Invalid format", idi.fname); @@ -68,7 +83,12 @@ kgzld(struct kgz_hdr * kh, const char *f1, const char *f2) case -1: err(1, NULL); case 0: - execlp("ld", "ld", "-Ttext", addr, "-o", f2, loader, f1, NULL); + if (format == F_AOUT) + execlp("ld", "ld", "-aout", "-Z", "-T", addr, "-o", f2, + loader, f1, NULL); + else + execlp("ld", "ld", "-Ttext", addr, "-o", f2, loader, f1, + NULL); warn(NULL); _exit(1); default: |