Exemple #1
0
static void
elf_x86_x86_write_proghead(unsigned char **bufpp,
                           elf_offset secthead_addr,
                           unsigned long secthead_count,
                           elf_section_index shstrtab_index)
{
    unsigned char *bufp = *bufpp;
    unsigned char *buf = bufp-4;
    YASM_WRITE_8(bufp, ELFCLASS32);         /* elf class */
    YASM_WRITE_8(bufp, ELFDATA2LSB);        /* data encoding :: MSB? */
    YASM_WRITE_8(bufp, EV_CURRENT);         /* elf version */
    while (bufp-buf < EI_NIDENT)            /* e_ident padding */
        YASM_WRITE_8(bufp, 0);

    YASM_WRITE_16_L(bufp, ET_REL);          /* e_type - object file */
    YASM_WRITE_16_L(bufp, EM_386);          /* e_machine - or others */
    YASM_WRITE_32_L(bufp, EV_CURRENT);      /* elf version */
    YASM_WRITE_32_L(bufp, 0);           /* e_entry exection startaddr */
    YASM_WRITE_32_L(bufp, 0);           /* e_phoff program header off */
    YASM_WRITE_32_L(bufp, secthead_addr);   /* e_shoff section header off */
    YASM_WRITE_32_L(bufp, 0);               /* e_flags also by arch */
    YASM_WRITE_16_L(bufp, EHDR32_SIZE);     /* e_ehsize */
    YASM_WRITE_16_L(bufp, 0);               /* e_phentsize */
    YASM_WRITE_16_L(bufp, 0);               /* e_phnum */
    YASM_WRITE_16_L(bufp, SHDR32_SIZE);     /* e_shentsize */
    YASM_WRITE_16_L(bufp, secthead_count);  /* e_shnum */
    YASM_WRITE_16_L(bufp, shstrtab_index);  /* e_shstrndx */
    *bufpp = bufp;
}
Exemple #2
0
static void
elf_x86_amd64_write_proghead(unsigned char **bufpp,
                             elf_offset secthead_addr,
                             unsigned long secthead_count,
                             elf_section_index shstrtab_index)
{
    unsigned char *bufp = *bufpp;
    unsigned char *buf = bufp-4;
    YASM_WRITE_8(bufp, ELFCLASS64);         /* elf class */
    YASM_WRITE_8(bufp, ELFDATA2LSB);        /* data encoding :: MSB? */
    YASM_WRITE_8(bufp, EV_CURRENT);         /* elf version */
    YASM_WRITE_8(bufp, ELFOSABI_SYSV);      /* os/abi */
    YASM_WRITE_8(bufp, 0);                  /* SYSV v3 ABI=0 */
    while (bufp-buf < EI_NIDENT)            /* e_ident padding */
        YASM_WRITE_8(bufp, 0);

    YASM_WRITE_16_L(bufp, ET_REL);          /* e_type - object file */
    YASM_WRITE_16_L(bufp, EM_X86_64);       /* e_machine - or others */
    YASM_WRITE_32_L(bufp, EV_CURRENT);      /* elf version */
    YASM_WRITE_64Z_L(bufp, 0);              /* e_entry */
    YASM_WRITE_64Z_L(bufp, 0);              /* e_phoff */
    YASM_WRITE_64Z_L(bufp, secthead_addr);  /* e_shoff secthead off */

    YASM_WRITE_32_L(bufp, 0);               /* e_flags */
    YASM_WRITE_16_L(bufp, EHDR64_SIZE);     /* e_ehsize */
    YASM_WRITE_16_L(bufp, 0);               /* e_phentsize */
    YASM_WRITE_16_L(bufp, 0);               /* e_phnum */
    YASM_WRITE_16_L(bufp, SHDR64_SIZE);     /* e_shentsize */
    YASM_WRITE_16_L(bufp, secthead_count);  /* e_shnum */
    YASM_WRITE_16_L(bufp, shstrtab_index);  /* e_shstrndx */
    *bufpp = bufp;
}
Exemple #3
0
static int
xdf_objfmt_output_secthead(yasm_section *sect, /*@null@*/ void *d)
{
    /*@null@*/ xdf_objfmt_output_info *info = (xdf_objfmt_output_info *)d;
    yasm_objfmt_xdf *objfmt_xdf;
    /*@dependent@*/ /*@null@*/ xdf_section_data *xsd;
    /*@null@*/ xdf_symrec_data *xsymd;
    unsigned char *localbuf;

    assert(info != NULL);
    objfmt_xdf = info->objfmt_xdf;
    xsd = yasm_section_get_data(sect, &xdf_section_data_cb);
    assert(xsd != NULL);

    localbuf = info->buf;
    xsymd = yasm_symrec_get_data(xsd->sym, &xdf_symrec_data_cb);
    assert(xsymd != NULL);

    YASM_WRITE_32_L(localbuf, xsymd->index);    /* section name symbol */
    if (xsd->addr) {
        yasm_intnum_get_sized(xsd->addr, localbuf, 8, 64, 0, 0, 0);
        localbuf += 8;                          /* physical address */
    } else {
        YASM_WRITE_32_L(localbuf, 0);
        YASM_WRITE_32_L(localbuf, 0);
    }
    if (xsd->vaddr) {
        yasm_intnum_get_sized(xsd->vaddr, localbuf, 8, 64, 0, 0, 0);
        localbuf += 8;                          /* virtual address */
    } else if (xsd->addr) {
        yasm_intnum_get_sized(xsd->addr, localbuf, 8, 64, 0, 0, 0);
        localbuf += 8;                          /* VA=PA */
    } else {
        YASM_WRITE_32_L(localbuf, 0);
        YASM_WRITE_32_L(localbuf, 0);
    }
    YASM_WRITE_16_L(localbuf, yasm_section_get_align(sect)); /* alignment */
    YASM_WRITE_16_L(localbuf, xsd->flags);      /* flags */
    YASM_WRITE_32_L(localbuf, xsd->scnptr);     /* file ptr to data */
    YASM_WRITE_32_L(localbuf, xsd->size);       /* section size */
    YASM_WRITE_32_L(localbuf, xsd->relptr);     /* file ptr to relocs */
    YASM_WRITE_32_L(localbuf, xsd->nreloc); /* num of relocation entries */
    fwrite(info->buf, 40, 1, info->f);

    return 0;
}
Exemple #4
0
static void
elf_x86_amd64_write_symtab_entry(unsigned char *bufp,
                                 elf_symtab_entry *entry,
                                 yasm_intnum *value_intn,
                                 yasm_intnum *size_intn)
{
    YASM_WRITE_32_L(bufp, entry->name ? entry->name->index : 0);
    YASM_WRITE_8(bufp, ELF64_ST_INFO(entry->bind, entry->type));
    YASM_WRITE_8(bufp, ELF64_ST_OTHER(entry->vis));
    if (entry->sect) {
        elf_secthead *shead =
            yasm_section_get_data(entry->sect, &elf_section_data);
        if (!shead)
            yasm_internal_error(N_("symbol references section without data"));
        YASM_WRITE_16_L(bufp, shead->index);
    } else {
        YASM_WRITE_16_L(bufp, entry->index);
    }
    YASM_WRITE_64I_L(bufp, value_intn);
    YASM_WRITE_64I_L(bufp, size_intn);
}