From 3979061f0de5f29f5474cafb2de910a162962552 Mon Sep 17 00:00:00 2001 From: Mikael Pettersson Date: Wed, 10 Jul 2013 19:59:31 +0000 Subject: [PATCH] pdp10-elf36: change Ehdr e_ident{1,2,3,4} to e_wident[4] to make it eaiser to process, define EI_NIDENT, define ELF36_EHDR_SIZEOF or avoid host-level sizeof mishaps --- include/pdp10-elf36.h | 9 +++++---- lib/pdp10-elf36.c | 16 ++++++++-------- 2 files changed, 13 insertions(+), 12 deletions(-) diff --git a/include/pdp10-elf36.h b/include/pdp10-elf36.h index 6565ff8..a2dcd22 100644 --- a/include/pdp10-elf36.h +++ b/include/pdp10-elf36.h @@ -19,6 +19,8 @@ typedef pdp10_uint36_t Elf36_Word; /* ELF Header */ +#define EI_NIDENT 16 + typedef struct { /* In the standard 32 and 64 bit ELF specifications the ELF header starts * with a 16-octet e_ident[] array, of which the first 9 octets are defined, @@ -26,10 +28,7 @@ typedef struct { * e_ident with Elf36, we pack the first 9 octets in two 36-bit words, and * add two words of padding, making e_ident 16 bits larger in Elf36. */ - Elf36_Word e_ident1; /* e_ident[] indices 0 to 4.5 */ - Elf36_Word e_ident2; /* e_ident[] indices 4.5 to 8 */ - Elf36_Word e_ident3; /* padding zeros */ - Elf36_Word e_ident4; /* padding zeros */ + Elf36_Word e_wident[4]; /* e_ident[] indices 0 to 4.5 */ Elf36_Half e_type; /* Identifies object file type */ Elf36_Half e_machine; /* Specifies required architecture */ Elf36_Word e_version; /* Identifies object file version */ @@ -45,6 +44,8 @@ typedef struct { Elf36_Half e_shstrndx; /* Section header string table index */ } Elf36_Ehdr; +#define ELF36_EHDR_SIZEOF (8 * 2 + (5 + 4) * 4) + /* e_ident[] identification indexes */ #define EI_MAG0 0 /* File identification byte 0 index */ diff --git a/lib/pdp10-elf36.c b/lib/pdp10-elf36.c index 841667b..545bff8 100644 --- a/lib/pdp10-elf36.c +++ b/lib/pdp10-elf36.c @@ -95,10 +95,10 @@ int pdp10_elf36_read_sint36(PDP10_FILE *pdp10fp, pdp10_int36_t *dst) int pdp10_elf36_write_ehdr(PDP10_FILE *pdp10fp, const Elf36_Ehdr *ehdr) { - if (pdp10_elf36_write_uint36(pdp10fp, ehdr->e_ident1) < 0 - || pdp10_elf36_write_uint36(pdp10fp, ehdr->e_ident2) < 0 - || pdp10_elf36_write_uint36(pdp10fp, ehdr->e_ident3) < 0 - || pdp10_elf36_write_uint36(pdp10fp, ehdr->e_ident4) < 0 + if (pdp10_elf36_write_uint36(pdp10fp, ehdr->e_wident[0]) < 0 + || pdp10_elf36_write_uint36(pdp10fp, ehdr->e_wident[1]) < 0 + || pdp10_elf36_write_uint36(pdp10fp, ehdr->e_wident[2]) < 0 + || pdp10_elf36_write_uint36(pdp10fp, ehdr->e_wident[3]) < 0 || pdp10_elf36_write_uint18(pdp10fp, ehdr->e_type) < 0 || pdp10_elf36_write_uint18(pdp10fp, ehdr->e_machine) < 0 || pdp10_elf36_write_uint36(pdp10fp, ehdr->e_version) < 0 @@ -118,10 +118,10 @@ int pdp10_elf36_write_ehdr(PDP10_FILE *pdp10fp, const Elf36_Ehdr *ehdr) int pdp10_elf36_read_ehdr(PDP10_FILE *pdp10fp, Elf36_Ehdr *ehdr) { - if (pdp10_elf36_read_uint36(pdp10fp, &ehdr->e_ident1) < 0 - || pdp10_elf36_read_uint36(pdp10fp, &ehdr->e_ident2) < 0 - || pdp10_elf36_read_uint36(pdp10fp, &ehdr->e_ident3) < 0 - || pdp10_elf36_read_uint36(pdp10fp, &ehdr->e_ident4) < 0 + if (pdp10_elf36_read_uint36(pdp10fp, &ehdr->e_wident[0]) < 0 + || pdp10_elf36_read_uint36(pdp10fp, &ehdr->e_wident[1]) < 0 + || pdp10_elf36_read_uint36(pdp10fp, &ehdr->e_wident[2]) < 0 + || pdp10_elf36_read_uint36(pdp10fp, &ehdr->e_wident[3]) < 0 || pdp10_elf36_read_uint18(pdp10fp, &ehdr->e_type) < 0 || pdp10_elf36_read_uint18(pdp10fp, &ehdr->e_machine) < 0 || pdp10_elf36_read_uint36(pdp10fp, &ehdr->e_version) < 0