tcc-stupidos/libtcc/object/coff.c

135 lines
2.5 KiB
C
Raw Normal View History

2025-02-11 19:16:44 +00:00
#include <string.h>
#ifdef HAVE_CONFIG_H
# include "config.h"
#endif /* !HAVE_CONFIG_H */
#include <tcc/state.h>
#include <tcc/memory.h>
2025-02-11 12:07:04 +00:00
#include <tcc/object/coff.h>
2025-02-11 19:16:44 +00:00
#include <tcc/state.h>
2025-02-11 12:07:04 +00:00
#define COFF_DEFAULT_ENTRYNAME "_start"
2025-02-11 19:16:44 +00:00
void dynarray_add(void *ptab, int *nb_ptr, void *data);
void dynarray_reset(void *pp, int *n);
static TCCSection *
coff_new_section(TCCState2 *s1, const char *name, int flags)
{
TCCSection *sec;
sec = tcc_mallocz(sizeof(TCCSection));
sec->state = s1;
strncpy(sec->name, name, 8); /* truncate section name */
sec->flags = flags;
sec->secnum = s1->nb_sections;
dynarray_add(&s1->sections, &s1->nb_sections, sec);
return (sec);
}
static void
coff_free_section(TCCSection *s)
{
if (!s) return;
tcc_free(s->data);
s->data = NULL;
s->data_allocated = s->data_offset = 0;
}
static void
coff_new_symtab(TCCState2 *s1)
{
TCCSymtab *symtab;
symtab = tcc_mallocz(sizeof(TCCSymtab));
}
void
coff_new(TCCState2 *s1)
{
dynarray_add(&s1->sections, &s1->nb_sections, NULL);
s1->text_section = coff_new_section(s1, ".text", COFF_STYP_TEXT);
s1->data_section = coff_new_section(s1, ".data", COFF_STYP_DATA);
s1->bss_section = coff_new_section(s1, ".bss", COFF_STYP_BSS);
s1->rodata_section = coff_new_section(s1, ".rodata", COFF_STYP_DATA);
coff_new_symtab(s1);
}
void
coff_delete(TCCState2 *s1)
{
int i;
for (i = 1; i < s1->nb_sections; i++)
{
coff_free_section(s1->sections[i]);
}
dynarray_reset(&s1->sections, &s1->nb_sections);
}
2025-02-11 12:07:04 +00:00
int
2025-02-11 19:16:44 +00:00
tcc_output_coff(TCCState2 *s1, FILE *f)
2025-02-11 12:07:04 +00:00
{
COFFFileHeader coffhdr;
AOutHeader aouthdr;
COFFSectionHeader coffsec;
const char *entry_name = COFF_DEFAULT_ENTRYNAME;
memset(&coffhdr, 0, sizeof(COFFFileHeader));
coffhdr.flags = COFF_F_LITTLE | COFF_F_LNNO;
coffhdr.magic = COFF_MAGIC;
coffhdr.nscns = s1->nb_sections;
2025-02-11 19:16:44 +00:00
if (s1->output_type == /*TCC_OUTPUT_EXE*/666)
2025-02-11 12:07:04 +00:00
{
coffhdr.flags |= COFF_F_RELFLG | COFF_F_EXEC | COFF_F_LSYMS;
coffhdr.nsyms = 0;
memset(&aouthdr, 0, sizeof(AOutHeader));
aouthdr.magic = AOUT_ZMAGIC;
coffhdr.opthdr = sizeof(AOutHeader);
if (s1->entryname != NULL)
{
entry_name = s1->entryname;
}
2025-02-11 19:16:44 +00:00
//aouthdr.entry = get_sym_addr(s1, entry_name, 1, 0);
2025-02-11 12:07:04 +00:00
if (s1->nb_errors)
{
return (-1);
}
}
return (0);
}
int
2025-02-11 19:16:44 +00:00
coff_output_object(TCCState2 *s, const char *filename)
2025-02-11 12:07:04 +00:00
{
2025-02-11 19:16:44 +00:00
return (0);
2025-02-11 12:07:04 +00:00
}
int
2025-02-11 19:16:44 +00:00
coff_output_exe(TCCState2 *s, const char *filename)
2025-02-11 12:07:04 +00:00
{
2025-02-11 19:16:44 +00:00
return (0);
}
2025-02-11 12:07:04 +00:00
2025-02-11 19:16:44 +00:00
int
coff_load_object(TCCState2 *s, int fd, size_t file_offset)
{
COFFFileHeader chdr;
return (0);
2025-02-11 12:07:04 +00:00
}