// SPDX-License-Identifier: GPL-2.0 /* * arch/alpha/boot/tools/objstrip.c * * Strip the object file headers/trailers from an executable (ELF or ECOFF). * * Copyright (C) 1996 David Mosberger-Tang.
*/ /* * Converts an ECOFF or ELF object file into a bootable file. The * object file must be a OMAGIC file (i.e., data and bss follow immediately * behind the text). See DEC "Assembly Language Programmer's Guide" * documentation for details. The SRM boot process is documented in * the Alpha AXP Architecture Reference Manual, Second Edition by * Richard L. Sites and Richard T. Witek.
*/ #include <stdio.h> #include <string.h> #include <stdlib.h> #include <unistd.h>
if (read(fd, buf, sizeof(buf)) < 0) {
perror("read"); exit(1);
}
#ifdef __ELF__
elf = (struct elfhdr *) buf;
if (memcmp(&elf->e_ident[EI_MAG0], ELFMAG, SELFMAG) == 0) { if (elf->e_type != ET_EXEC) {
fprintf(stderr, "%s: %s is not an ELF executable\n",
prog_name, inname); exit(1);
} if (!elf_check_arch(elf)) {
fprintf(stderr, "%s: is not for this processor (e_machine=%d)\n",
prog_name, elf->e_machine); exit(1);
} if (elf->e_phnum != 1) {
fprintf(stderr, "%s: %d program headers (forgot to link with -N?)\n",
prog_name, elf->e_phnum);
}
if (lseek(fd, offset, SEEK_SET) != offset) {
perror("lseek"); exit(1);
}
if (verbose) {
fprintf(stderr, "%s: copying %lu byte from %s\n",
prog_name, (unsignedlong) fil_size, inname);
}
tocopy = fil_size; while (tocopy > 0) {
n = tocopy; if (n > sizeof(buf)) {
n = sizeof(buf);
}
tocopy -= n; if ((size_t) read(fd, buf, n) != n) {
perror("read"); exit(1);
} do {
nwritten = write(ofd, buf, n); if ((ssize_t) nwritten == -1) {
perror("write"); exit(1);
}
n -= nwritten;
} while (n > 0);
}
if (pad) {
mem_size = ((mem_size + pad - 1) / pad) * pad;
}
tocopy = mem_size - fil_size; if (tocopy > 0) {
fprintf(stderr, "%s: zero-filling bss and aligning to %lu with %lu bytes\n",
prog_name, pad, (unsignedlong) tocopy);
memset(buf, 0x00, sizeof(buf)); do {
n = tocopy; if (n > sizeof(buf)) {
n = sizeof(buf);
}
nwritten = write(ofd, buf, n); if ((ssize_t) nwritten == -1) {
perror("write"); exit(1);
}
tocopy -= nwritten;
} while (tocopy > 0);
} return 0;
}
Messung V0.5
¤ Die Informationen auf dieser Webseite wurden
nach bestem Wissen sorgfältig zusammengestellt. Es wird jedoch weder Vollständigkeit, noch Richtigkeit,
noch Qualität der bereit gestellten Informationen zugesichert.0.12Bemerkung:
(vorverarbeitet)
¤
Die Informationen auf dieser Webseite wurden
nach bestem Wissen sorgfältig zusammengestellt. Es wird jedoch weder Vollständigkeit, noch Richtigkeit,
noch Qualität der bereit gestellten Informationen zugesichert.
Bemerkung:
Die farbliche Syntaxdarstellung und die Messung sind noch experimentell.