Skip to content

Commit 24babd8

Browse files
committed
Add ELF header structures for ELF generation
These changes introduce elf32_hdr_t, elf32_phdr_t and elf32_shdr_t structures to represent the ELF header, program header and section header, respectively. By using these structures, the ELF generation process becomes more readable when filling in header data.
1 parent e3a7201 commit 24babd8

File tree

2 files changed

+278
-117
lines changed

2 files changed

+278
-117
lines changed

src/defs.h

Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -547,3 +547,48 @@ typedef struct {
547547
var_t *var;
548548
int polluted;
549549
} regfile_t;
550+
551+
/* FIXME: replace char[2] with a short data type in ELF header structures */
552+
/* ELF header */
553+
typedef struct {
554+
char e_ident[16];
555+
char e_type[2];
556+
char e_machine[2];
557+
int e_version;
558+
int e_entry;
559+
int e_phoff;
560+
int e_shoff;
561+
int e_flags;
562+
char e_ehsize[2];
563+
char e_phentsize[2];
564+
char e_phnum[2];
565+
char e_shentsize[2];
566+
char e_shnum[2];
567+
char e_shstrndx[2];
568+
} elf32_hdr_t;
569+
570+
/* ELF program header */
571+
typedef struct {
572+
int p_type;
573+
int p_offset;
574+
int p_vaddr;
575+
int p_paddr;
576+
int p_filesz;
577+
int p_memsz;
578+
int p_flags;
579+
int p_align;
580+
} elf32_phdr_t;
581+
582+
/* ELF section header */
583+
typedef struct {
584+
int sh_name;
585+
int sh_type;
586+
int sh_flags;
587+
int sh_addr;
588+
int sh_offset;
589+
int sh_size;
590+
int sh_link;
591+
int sh_info;
592+
int sh_addralign;
593+
int sh_entsize;
594+
} elf32_shdr_t;

0 commit comments

Comments
 (0)