#if HAVE_NBTOOL_CONFIG_H
#include "nbtool_config.h"
#endif
#include <sys/types.h>
#include <err.h>
#include <errno.h>
#include <fcntl.h>
#include <unistd.h>
#include <sys/exec_elf.h>
#include <stdio.h>
#include <sys/exec_ecoff.h>
#include <stdlib.h>
#include <string.h>
#include <limits.h>
#define ISLAST(p) (p->n_un.n_name == 0 || p->n_un.n_name[0] == 0)
struct sect {
uint32_t vaddr;
uint32_t len;
};
struct elf_syms {
int nsymbols;
Elf32_Sym *elf_syms;
off_t stringsize;
char *stringtab;
};
struct ecoff_syms {
int nsymbols;
struct ecoff_extsym *ecoff_syms;
off_t stringsize;
char *stringtab;
};
int debug = 0;
#if BYTE_ORDER != BIG_ENDIAN && BYTE_ORDER != LITTLE_ENDIAN
#error "unknown endian"
#endif
static int needswap;
static int phcmp(Elf32_Phdr *, Elf32_Phdr *);
static char *saveRead(int, off_t, off_t, const char *);
static void safewrite(int, const void *, off_t, const char *);
static void copy(int, int, off_t, off_t);
static void combine(struct sect *, struct sect *, int);
static size_t compute_stringsize(const Elf32_Sym *elf_syms, int nsymbols,
const char *elf_stringbase);
static void translate_syms(struct elf_syms *, struct ecoff_syms *);
static void elf_symbol_table_to_ecoff(int, int, struct ecoff32_exechdr *,
off_t, off_t, off_t, off_t);
static int make_ecoff_section_hdrs(struct ecoff32_exechdr *,
struct ecoff32_scnhdr *);
static void write_ecoff_symhdr(int, struct ecoff32_exechdr *,
struct ecoff32_symhdr *, int32_t, int32_t, int32_t, int32_t);
static void pad16(int, int, const char *);
static void bswap32_region(int32_t* , int);
static void elf_read_syms(struct elf_syms *, int, off_t, off_t, off_t,
off_t);
static void
debug_printf(int level, const char *format, ...)
{
if (debug >= level) {
va_list ap;
va_start(ap, format);
vfprintf(stderr, format, ap);
va_end(ap);
}
}
static void
usage(void)
{
fprintf(stderr,
"Usage: %s [-sv] <elf executable> <ECOFF executable>\n",
getprogname());
exit(1);
}
static int
is_mipsel(const Elf32_Ehdr *ex)
{
if (ex->e_ident[EI_DATA] == ELFDATA2LSB)
return 1;
if (ex->e_ident[EI_DATA] == ELFDATA2MSB)
return 0;
errx(1, "invalid ELF byte order %d", ex->e_ident[EI_DATA]);
}
static int
is_different_endianness(const Elf32_Ehdr *ex)
{
const int input_is_mipsel = is_mipsel(ex);
const int runtime_is_mipsel = (BYTE_ORDER == LITTLE_ENDIAN);
return input_is_mipsel != runtime_is_mipsel;
}
int
main(int argc, char **argv)
{
Elf32_Ehdr ex;
Elf32_Phdr *ph;
Elf32_Shdr *sh;
char *shstrtab;
int strtabix, symtabix;
size_t i;
int pad;
struct sect text, data, bss;
struct ecoff32_exechdr ep;
struct ecoff32_scnhdr esecs[6];
struct ecoff32_symhdr symhdr;
int infile, outfile;
uint32_t cur_vma = UINT32_MAX;
int nsecs = 0;
int mipsel;
text.len = data.len = bss.len = 0;
text.vaddr = data.vaddr = bss.vaddr = 0;
int ch;
while ((ch = getopt(argc, argv, "sv")) != -1) {
switch (ch) {
case 'v':
debug++;
break;
case 's':
case '?':
default:
usage();
}
}
argv += optind;
argc -= optind;
if (argc != 2) {
usage();
}
if ((infile = open(argv[0], O_RDONLY)) < 0)
err(1, "Can't open %s for read", argv[0]);
i = read(infile, &ex, sizeof ex);
if (i != sizeof ex)
err(1, "Short header read from %s", argv[0]);
if (ex.e_ident[EI_DATA] == ELFDATA2LSB)
mipsel = 1;
else if (ex.e_ident[EI_DATA] == ELFDATA2MSB)
mipsel = 0;
else
errx(1, "invalid ELF byte order %d", ex.e_ident[EI_DATA]);
needswap = is_different_endianness(&ex);
if (needswap) {
ex.e_type = bswap16(ex.e_type);
ex.e_machine = bswap16(ex.e_machine);
ex.e_version = bswap32(ex.e_version);
ex.e_entry = bswap32(ex.e_entry);
ex.e_phoff = bswap32(ex.e_phoff);
ex.e_shoff = bswap32(ex.e_shoff);
ex.e_flags = bswap32(ex.e_flags);
ex.e_ehsize = bswap16(ex.e_ehsize);
ex.e_phentsize = bswap16(ex.e_phentsize);
ex.e_phnum = bswap16(ex.e_phnum);
ex.e_shentsize = bswap16(ex.e_shentsize);
ex.e_shnum = bswap16(ex.e_shnum);
ex.e_shstrndx = bswap16(ex.e_shstrndx);
}
ph = (Elf32_Phdr *) saveRead(infile, ex.e_phoff,
ex.e_phnum * sizeof(Elf32_Phdr), "ph");
if (needswap)
bswap32_region((int32_t*)ph, sizeof(Elf32_Phdr) * ex.e_phnum);
sh = (Elf32_Shdr *) saveRead(infile, ex.e_shoff,
ex.e_shnum * sizeof(Elf32_Shdr), "sh");
if (needswap)
bswap32_region((int32_t*)sh, sizeof(Elf32_Shdr) * ex.e_shnum);
shstrtab = saveRead(infile, sh[ex.e_shstrndx].sh_offset,
sh[ex.e_shstrndx].sh_size, "shstrtab");
symtabix = 0;
strtabix = 0;
for (i = 0; i < ex.e_shnum; i++) {
char *name = shstrtab + sh[i].sh_name;
if (!strcmp(name, ".symtab"))
symtabix = i;
else
if (!strcmp(name, ".strtab"))
strtabix = i;
}
qsort(ph, ex.e_phnum, sizeof(Elf32_Phdr),
(int (*) (const void *, const void *)) phcmp);
for (i = 0; i < ex.e_phnum; i++) {
switch (ph[i].p_type) {
case PT_NOTE:
case PT_NULL:
case PT_PHDR:
case PT_MIPS_ABIFLAGS:
case PT_MIPS_REGINFO:
debug_printf(1, " skipping PH %zu type %#x "
"flags %#x\n", i, ph[i].p_type, ph[i].p_flags);
continue;
default:
if (ph[i].p_type != PT_LOAD)
errx(1, "Program header %zu type %#x can't be "
"converted", i, ph[i].p_type);
}
if (ph[i].p_flags & PF_W) {
struct sect ndata, nbss;
ndata.vaddr = ph[i].p_vaddr;
ndata.len = ph[i].p_filesz;
nbss.vaddr = ph[i].p_vaddr + ph[i].p_filesz;
nbss.len = ph[i].p_memsz - ph[i].p_filesz;
debug_printf(1, " combining PH %zu type %d flags %#x "
"with data, ndata = %d, nbss = %d\n", i,
ph[i].p_type, ph[i].p_flags, ndata.len, nbss.len);
combine(&data, &ndata, 0);
combine(&bss, &nbss, 1);
} else {
struct sect ntxt;
ntxt.vaddr = ph[i].p_vaddr;
ntxt.len = ph[i].p_filesz;
debug_printf(1, " combining PH %zu type %d flags %#x "
"with text, len = %d\n", i, ph[i].p_type,
ph[i].p_flags, ntxt.len);
combine(&text, &ntxt, 0);
}
if (ph[i].p_vaddr < cur_vma)
cur_vma = ph[i].p_vaddr;
}
if (text.vaddr > data.vaddr || data.vaddr > bss.vaddr ||
text.vaddr + text.len > data.vaddr ||
data.vaddr + data.len > bss.vaddr)
errx(1, "Sections ordering prevents a.out conversion");
if (data.len && text.len == 0) {
text = data;
data.vaddr = text.vaddr + text.len;
data.len = 0;
}
if (text.vaddr + text.len < data.vaddr)
text.len = data.vaddr - text.vaddr;
ep.a.magic = ECOFF_OMAGIC;
ep.a.vstamp = 2 * 256 + 10;
ep.a.tsize = text.len;
ep.a.dsize = data.len;
ep.a.bsize = bss.len;
ep.a.entry = ex.e_entry;
ep.a.text_start = text.vaddr;
ep.a.data_start = data.vaddr;
ep.a.bss_start = bss.vaddr;
ep.a.gprmask = 0xf3fffffe;
memset(&ep.a.cprmask, 0, sizeof ep.a.cprmask);
ep.a.gp_value = 0;
if (mipsel)
ep.f.f_magic = ECOFF_MAGIC_MIPSEL;
else
ep.f.f_magic = ECOFF_MAGIC_MIPSEB;
ep.f.f_nscns = 6;
ep.f.f_timdat = 0;
ep.f.f_symptr = 0;
ep.f.f_nsyms = sizeof(struct ecoff32_symhdr);
ep.f.f_opthdr = sizeof ep.a;
ep.f.f_flags = 0x100f;
memset(esecs, 0, sizeof(esecs));
make_ecoff_section_hdrs(&ep, esecs);
nsecs = ep.f.f_nscns;
if (needswap) {
ep.f.f_magic = bswap16(ep.f.f_magic);
ep.f.f_nscns = bswap16(ep.f.f_nscns);
ep.f.f_timdat = bswap32(ep.f.f_timdat);
ep.f.f_symptr = bswap32(ep.f.f_symptr);
ep.f.f_nsyms = bswap32(ep.f.f_nsyms);
ep.f.f_opthdr = bswap16(ep.f.f_opthdr);
ep.f.f_flags = bswap16(ep.f.f_flags);
ep.a.magic = bswap16(ep.a.magic);
ep.a.vstamp = bswap16(ep.a.vstamp);
ep.a.tsize = bswap32(ep.a.tsize);
ep.a.dsize = bswap32(ep.a.dsize);
ep.a.bsize = bswap32(ep.a.bsize);
ep.a.entry = bswap32(ep.a.entry);
ep.a.text_start = bswap32(ep.a.text_start);
ep.a.data_start = bswap32(ep.a.data_start);
ep.a.bss_start = bswap32(ep.a.bss_start);
ep.a.gprmask = bswap32(ep.a.gprmask);
bswap32_region((int32_t*)ep.a.cprmask, sizeof(ep.a.cprmask));
ep.a.gp_value = bswap32(ep.a.gp_value);
for (i = 0; i < sizeof(esecs) / sizeof(esecs[0]); i++) {
esecs[i].s_paddr = bswap32(esecs[i].s_paddr);
esecs[i].s_vaddr = bswap32(esecs[i].s_vaddr);
esecs[i].s_size = bswap32(esecs[i].s_size);
esecs[i].s_scnptr = bswap32(esecs[i].s_scnptr);
esecs[i].s_relptr = bswap32(esecs[i].s_relptr);
esecs[i].s_lnnoptr = bswap32(esecs[i].s_lnnoptr);
esecs[i].s_nreloc = bswap16(esecs[i].s_nreloc);
esecs[i].s_nlnno = bswap16(esecs[i].s_nlnno);
esecs[i].s_flags = bswap32(esecs[i].s_flags);
}
}
if ((outfile = open(argv[1], O_WRONLY | O_CREAT, 0777)) < 0)
err(1, "Unable to create %s", argv[1]);
if (ftruncate(outfile, 0)) {
warn("ftruncate %s", argv[1]);
}
safewrite(outfile, &ep.f, sizeof(ep.f), "ep.f: write");
debug_printf(1, "wrote %zu byte file header.\n", sizeof(ep.f));
safewrite(outfile, &ep.a, sizeof(ep.a), "ep.a: write");
debug_printf(1, "wrote %zu byte a.out header.\n", sizeof(ep.a));
safewrite(outfile, &esecs, sizeof(esecs[0]) * nsecs, "esecs: write");
debug_printf(1, "wrote %zu bytes of section headers.\n",
sizeof(esecs[0]) * nsecs);
pad = ((sizeof ep.f + sizeof ep.a + sizeof esecs) & 15);
if (pad) {
pad = 16 - pad;
pad16(outfile, pad, "ipad: write");
debug_printf(1, "wrote %d byte pad.\n", pad);
}
for (i = 0; i < ex.e_phnum; i++) {
if (ph[i].p_type == PT_LOAD && ph[i].p_filesz) {
if (cur_vma != ph[i].p_vaddr) {
uint32_t gap = ph[i].p_vaddr - cur_vma;
char obuf[1024];
if (gap > 65536)
errx(1, "Intersegment gap (%d bytes) "
"too large", gap);
debug_printf(1, "Warning: %d byte "
"intersegment gap.\n", gap);
memset(obuf, 0, sizeof obuf);
while (gap) {
int count = write(outfile, obuf,
(gap > sizeof obuf
? sizeof obuf : gap));
if (count < 0)
err(1, "Error writing gap");
gap -= count;
}
}
debug_printf(1, "writing %d bytes...\n",
ph[i].p_filesz);
copy(outfile, infile, ph[i].p_offset, ph[i].p_filesz);
cur_vma = ph[i].p_vaddr + ph[i].p_filesz;
}
}
uint32_t symptr = needswap ? bswap32(ep.f.f_symptr) : ep.f.f_symptr;
debug_printf(1, "writing symhdr at offset %#x, syms at offset %#x\n",
symptr, (uint32_t)(symptr + sizeof(symhdr)));
elf_symbol_table_to_ecoff(outfile, infile, &ep,
sh[symtabix].sh_offset, sh[symtabix].sh_size,
sh[strtabix].sh_offset, sh[strtabix].sh_size);
{
char obuf[4096];
memset(obuf, 0, sizeof obuf);
if (write(outfile, obuf, sizeof(obuf)) != sizeof(obuf))
err(1, "Error writing PROM padding");
}
return 0;
}
static void
copy(int out, int in, off_t offset, off_t size)
{
char ibuf[4096];
size_t remaining, cur, count;
if (lseek(in, offset, SEEK_SET) < 0)
err(1, "copy: lseek");
remaining = size;
while (remaining) {
cur = remaining;
if (cur > sizeof ibuf)
cur = sizeof ibuf;
remaining -= cur;
if ((count = read(in, ibuf, cur)) != cur)
err(1, "copy: short read");
safewrite(out, ibuf, cur, "copy: write");
}
}
static void
combine(struct sect *base, struct sect *new, int pad)
{
if (base->len == 0)
*base = *new;
else
if (new->len) {
if (base->vaddr + base->len != new->vaddr) {
if (pad)
base->len = new->vaddr - base->vaddr;
else
errx(1, "Non-contiguous data can't be "
"converted");
}
base->len += new->len;
}
}
static int
phcmp(Elf32_Phdr *h1, Elf32_Phdr *h2)
{
if (h1->p_vaddr > h2->p_vaddr)
return 1;
else
if (h1->p_vaddr < h2->p_vaddr)
return -1;
else
return 0;
}
static char *
saveRead(int file, off_t offset, off_t len, const char *name)
{
char *tmp;
int count;
off_t off;
if ((off = lseek(file, offset, SEEK_SET)) < 0)
err(1, "%s: fseek", name);
if ((tmp = malloc(len)) == NULL)
err(1, "%s: Can't allocate %jd bytes", name, (intmax_t)len);
count = read(file, tmp, len);
if (count != len)
err(1, "%s: short read", name);
return tmp;
}
static void
safewrite(int outfile, const void *buf, off_t len, const char *msg)
{
ssize_t written;
debug_printf(2, "writing %u bytes at offset 0x%x [%s]\n",
(uint32_t)len, (uint32_t)lseek(outfile, 0, SEEK_CUR), msg);
written = write(outfile, buf, len);
if (written != len)
err(1, "%s", msg);
}
static int
make_ecoff_section_hdrs(struct ecoff32_exechdr *ep, struct ecoff32_scnhdr *esecs)
{
ep->f.f_nscns = 6;
strcpy(esecs[0].s_name, ".text");
strcpy(esecs[1].s_name, ".data");
strcpy(esecs[2].s_name, ".bss");
esecs[0].s_paddr = esecs[0].s_vaddr = ep->a.text_start;
esecs[1].s_paddr = esecs[1].s_vaddr = ep->a.data_start;
esecs[2].s_paddr = esecs[2].s_vaddr = ep->a.bss_start;
esecs[0].s_size = ep->a.tsize;
esecs[1].s_size = ep->a.dsize;
esecs[2].s_size = ep->a.bsize;
esecs[0].s_scnptr = ECOFF32_TXTOFF(ep);
esecs[1].s_scnptr = ECOFF32_DATOFF(ep);
#if 0
esecs[2].s_scnptr = esecs[1].s_scnptr +
ECOFF_ROUND(esecs[1].s_size, ECOFF32_SEGMENT_ALIGNMENT(ep));
#endif
esecs[0].s_relptr = esecs[1].s_relptr = esecs[2].s_relptr = 0;
esecs[0].s_lnnoptr = esecs[1].s_lnnoptr = esecs[2].s_lnnoptr = 0;
esecs[0].s_nreloc = esecs[1].s_nreloc = esecs[2].s_nreloc = 0;
esecs[0].s_nlnno = esecs[1].s_nlnno = esecs[2].s_nlnno = 0;
esecs[1].s_flags = 0x100;
esecs[3].s_flags = 0x200;
esecs[4].s_flags = 0x400;
ep->f.f_symptr = esecs[1].s_scnptr + esecs[1].s_size;
return (ep->f.f_nscns);
}
static void
write_ecoff_symhdr(int out, struct ecoff32_exechdr *ep,
struct ecoff32_symhdr *symhdrp, int32_t nesyms,
int32_t extsymoff, int32_t extstroff, int32_t strsize)
{
uint32_t symptr = needswap ? bswap32(ep->f.f_symptr) : ep->f.f_symptr;
debug_printf(1, "writing symhdr for %d entries at offset %#x\n",
nesyms, symptr);
memset(symhdrp, 0, sizeof(*symhdrp));
symhdrp->esymMax = nesyms;
symhdrp->magic = 0x7009;
symhdrp->cbExtOffset = extsymoff;
symhdrp->cbSsExtOffset = extstroff;
symhdrp->issExtMax = strsize;
debug_printf(1, "ECOFF symhdr: symhdr %zx, strsize %x, symsize %zx\n",
sizeof(*symhdrp), strsize, (nesyms * sizeof(struct ecoff32_extsym)));
if (needswap) {
bswap32_region(&symhdrp->ilineMax,
sizeof(*symhdrp) - sizeof(symhdrp->magic) -
sizeof(symhdrp->vstamp));
symhdrp->magic = bswap16(symhdrp->magic);
symhdrp->vstamp = bswap16(symhdrp->vstamp);
}
safewrite(out, symhdrp, sizeof(*symhdrp),
"writing symbol header");
}
static void
elf_read_syms(struct elf_syms *elfsymsp, int in, off_t symoff, off_t symsize,
off_t stroff, off_t strsize)
{
int nsyms;
int i;
nsyms = symsize / sizeof(Elf32_Sym);
elfsymsp->elf_syms = (Elf32_Sym *)
saveRead(in, symoff, nsyms * sizeof(Elf32_Sym),
"ELF symboltable");
elfsymsp->nsymbols = nsyms;
if (needswap) {
for (i = 0; i < nsyms; i++) {
Elf32_Sym *s = &elfsymsp->elf_syms[i];
s->st_name = bswap32(s->st_name);
s->st_value = bswap32(s->st_value);
s->st_size = bswap32(s->st_size);
s->st_shndx = bswap16(s->st_shndx);
}
}
elfsymsp->stringtab = (char *)
saveRead(in, stroff, strsize, "ELF string table");
elfsymsp->stringsize = strsize;
}
static void
elf_symbol_table_to_ecoff(int out, int in, struct ecoff32_exechdr *ep,
off_t symoff, off_t symsize, off_t stroff, off_t strsize)
{
struct elf_syms elfsymtab;
struct ecoff_syms ecoffsymtab;
uint32_t ecoff_symhdr_off, symtaboff, stringtaboff;
uint32_t nextoff, symtabsize, ecoff_strsize;
int nsyms, i;
struct ecoff32_symhdr symhdr;
int align, padding;
elf_read_syms(&elfsymtab, in, symoff, symsize, stroff, strsize);
translate_syms(&elfsymtab, &ecoffsymtab);
nsyms = ecoffsymtab.nsymbols;
ecoff_symhdr_off = needswap ? bswap32(ep->f.f_symptr) : ep->f.f_symptr;
align = needswap ? (bswap16(ep->a.vstamp) < 23 ? 8 : 16) :
ECOFF32_SEGMENT_ALIGNMENT(ep);
nextoff = ecoff_symhdr_off + sizeof(struct ecoff_symhdr);
stringtaboff = nextoff;
ecoff_strsize = ECOFF_ROUND(ecoffsymtab.stringsize, align);
nextoff = stringtaboff + ecoff_strsize;
symtaboff = nextoff;
symtabsize = nsyms * sizeof(struct ecoff_extsym);
symtabsize = ECOFF_ROUND(symtabsize, align);
write_ecoff_symhdr(out, ep, &symhdr, nsyms, symtaboff,
stringtaboff, ecoffsymtab.stringsize);
padding = ecoff_strsize - ecoffsymtab.stringsize;
safewrite(out, ecoffsymtab.stringtab, ecoffsymtab.stringsize,
"string table: write");
if (padding)
pad16(out, padding, "string table: padding");
padding = symtabsize - (nsyms * sizeof(struct ecoff_extsym));
if (needswap) {
for (i = 0; i < nsyms; i++) {
struct ecoff_extsym *es = &ecoffsymtab.ecoff_syms[i];
es->es_flags = bswap16(es->es_flags);
es->es_ifd = bswap16(es->es_ifd);
bswap32_region(&es->es_strindex,
sizeof(*es) - sizeof(es->es_flags) -
sizeof(es->es_ifd));
}
}
safewrite(out, ecoffsymtab.ecoff_syms,
nsyms * sizeof(struct ecoff_extsym),
"symbol table: write");
if (padding)
pad16(out, padding, "symbols: padding");
}
static size_t
compute_stringsize(const Elf32_Sym *elf_syms, int nsyms,
const char *stringbase)
{
size_t stringsize = 0;
int i;
for (i = 0; i < nsyms; i++) {
const Elf32_Sym *esym = &elf_syms[i];
const char *name;
if (ELF32_ST_BIND(esym->st_info) == STB_LOCAL)
continue;
name = stringbase + esym->st_name;
stringsize += strlen(name) + 1;
}
if (stringsize == 0)
stringsize = 1;
return stringsize;
}
static void
translate_syms(struct elf_syms *elfp, struct ecoff_syms *ecoffp)
{
int i;
char *oldstringbase;
char *newstrings, *nsp;
size_t stringsize;
int nsyms, idx;
nsyms = elfp->nsymbols;
oldstringbase = elfp->stringtab;
memset(ecoffp, 0, sizeof(*ecoffp));
ecoffp->nsymbols = 0;
ecoffp->ecoff_syms = malloc(sizeof(struct ecoff_extsym) * nsyms);
stringsize = compute_stringsize(elfp->elf_syms, nsyms, oldstringbase);
debug_printf(1, "%zu (0x%zx) bytes ELF string table\n",
(size_t)elfp->stringsize, (size_t)elfp->stringsize);
debug_printf(1, "%zu (0x%zx) bytes required for ECOFF string table\n",
stringsize, stringsize);
newstrings = malloc(stringsize);
if (newstrings == NULL)
errx(1, "No memory for new string table");
nsp = newstrings;
idx = 0;
for (i = 0; i < nsyms; i++) {
const Elf32_Sym *esym = &elfp->elf_syms[i];
const char *name;
size_t namelen;
if (ELF32_ST_BIND(esym->st_info) == STB_LOCAL)
continue;
name = oldstringbase + esym->st_name;
namelen = strlen(name) + 1;
if (nsp + namelen > newstrings + stringsize)
errx(1, "ECOFF string table overflow");
strcpy(nsp, name);
ecoffp->ecoff_syms[idx].es_strindex = nsp - newstrings;
nsp += namelen;
ecoffp->ecoff_syms[idx].es_type = 1;
ecoffp->ecoff_syms[idx].es_class = 5;
ecoffp->ecoff_syms[idx].es_value = esym->st_value;
ecoffp->ecoff_syms[idx].es_symauxindex = 0xfffff;
idx++;
}
ecoffp->nsymbols = idx;
ecoffp->stringtab = newstrings;
ecoffp->stringsize = nsp - newstrings;
debug_printf(1, "%zu (0x%zx) bytes used for ECOFF string table\n",
(size_t)ecoffp->stringsize, (size_t)ecoffp->stringsize);
}
static void
pad16(int fd, int size, const char *msg)
{
safewrite(fd, "\0\0\0\0\0\0\0\0\0\0\0\0\0\0", size, msg);
}
static void
bswap32_region(int32_t* p, int len)
{
size_t i;
for (i = 0; i < len / sizeof(int32_t); i++, p++)
*p = bswap32(*p);
}