diff --git a/output/elf.h b/output/elf.h index b20d63f8..4ae818a9 100644 --- a/output/elf.h +++ b/output/elf.h @@ -202,7 +202,8 @@ #define EI_DATA 5 #define EI_VERSION 6 #define EI_OSABI 7 -#define EI_PAD 8 +#define EI_ABIVERSION 8 +#define EI_NINDENT 16 #define ELFMAG0 0x7f /* EI_MAG */ #define ELFMAG1 'E' @@ -257,7 +258,7 @@ #define ELF32_ST_BIND(i) ((i) >> 4) #define ELF32_ST_MKBIND(i) ((i) << 4) /* just a helper */ #define ELF32_ST_TYPE(i) ((i) & 0xf) -#define ELF32_ST_INFO(b, i) (ELF_ST_MKBIND(b) + ELF_ST_TYPE(i)) +#define ELF32_ST_INFO(b, i) (ELF32_ST_MKBIND(b) + ELF32_ST_TYPE(i)) #define ELF64_ST_BIND(i) ELF32_ST_BIND(i) #define ELF64_ST_MKBIND(i) ELF32_ST_MKBIND(i) @@ -295,18 +296,18 @@ typedef uint16_t Elf64_Section; */ typedef struct elf32_dyn { - Elf32_Sword d_tag; + Elf32_Sword d_tag; union { Elf32_Sword d_val; - Elf32_Addr d_ptr; + Elf32_Addr d_ptr; } d_un; } Elf32_Dyn; typedef struct elf64_dyn { - Elf64_Sxword d_tag; + Elf64_Sxword d_tag; union { Elf64_Xword d_val; - Elf64_Addr d_ptr; + Elf64_Addr d_ptr; } d_un; } Elf64_Dyn; @@ -318,14 +319,14 @@ typedef struct elf64_dyn { #define ELF32_R_TYPE(x) ((x) & 0xff) typedef struct elf32_rel { - Elf32_Addr r_offset; - Elf32_Word r_info; + Elf32_Addr r_offset; + Elf32_Word r_info; } Elf32_Rel; typedef struct elf32_rela { - Elf32_Addr r_offset; - Elf32_Word r_info; - Elf32_Sword r_addend; + Elf32_Addr r_offset; + Elf32_Word r_info; + Elf32_Sword r_addend; } Elf32_Rela; enum reloc32_type { @@ -352,14 +353,14 @@ enum reloc32_type { #define ELF64_R_TYPE(x) ((x) & 0xffffffff) typedef struct elf64_rel { - Elf64_Addr r_offset; - Elf64_Xword r_info; + Elf64_Addr r_offset; + Elf64_Xword r_info; } Elf64_Rel; typedef struct elf64_rela { - Elf64_Addr r_offset; - Elf64_Xword r_info; - Elf64_Sxword r_addend; + Elf64_Addr r_offset; + Elf64_Xword r_info; + Elf64_Sxword r_addend; } Elf64_Rela; enum reloc64_type { @@ -407,21 +408,21 @@ enum reloc64_type { */ typedef struct elf32_sym { - Elf32_Word st_name; - Elf32_Addr st_value; - Elf32_Word st_size; - unsigned char st_info; - unsigned char st_other; - Elf32_Half st_shndx; + Elf32_Word st_name; + Elf32_Addr st_value; + Elf32_Word st_size; + unsigned char st_info; + unsigned char st_other; + Elf32_Half st_shndx; } Elf32_Sym; typedef struct elf64_sym { - Elf64_Word st_name; - unsigned char st_info; - unsigned char st_other; - Elf64_Half st_shndx; - Elf64_Addr st_value; - Elf64_Xword st_size; + Elf64_Word st_name; + unsigned char st_info; + unsigned char st_other; + Elf64_Half st_shndx; + Elf64_Addr st_value; + Elf64_Xword st_size; } Elf64_Sym; /* @@ -429,37 +430,37 @@ typedef struct elf64_sym { */ typedef struct elf32_hdr { - unsigned char e_ident[EI_NIDENT]; - Elf32_Half e_type; - Elf32_Half e_machine; - Elf32_Word e_version; - Elf32_Addr e_entry; - Elf32_Off e_phoff; - Elf32_Off e_shoff; - Elf32_Word e_flags; - Elf32_Half e_ehsize; - Elf32_Half e_phentsize; - Elf32_Half e_phnum; - Elf32_Half e_shentsize; - Elf32_Half e_shnum; - Elf32_Half e_shstrndx; + unsigned char e_ident[EI_NIDENT]; + Elf32_Half e_type; + Elf32_Half e_machine; + Elf32_Word e_version; + Elf32_Addr e_entry; + Elf32_Off e_phoff; + Elf32_Off e_shoff; + Elf32_Word e_flags; + Elf32_Half e_ehsize; + Elf32_Half e_phentsize; + Elf32_Half e_phnum; + Elf32_Half e_shentsize; + Elf32_Half e_shnum; + Elf32_Half e_shstrndx; } Elf32_Ehdr; typedef struct elf64_hdr { - unsigned char e_ident[EI_NIDENT]; - Elf64_Half e_type; - Elf64_Half e_machine; - Elf64_Word e_version; - Elf64_Addr e_entry; - Elf64_Off e_phoff; - Elf64_Off e_shoff; - Elf64_Word e_flags; - Elf64_Half e_ehsize; - Elf64_Half e_phentsize; - Elf64_Half e_phnum; - Elf64_Half e_shentsize; - Elf64_Half e_shnum; - Elf64_Half e_shstrndx; + unsigned char e_ident[EI_NIDENT]; + Elf64_Half e_type; + Elf64_Half e_machine; + Elf64_Word e_version; + Elf64_Addr e_entry; + Elf64_Off e_phoff; + Elf64_Off e_shoff; + Elf64_Word e_flags; + Elf64_Half e_ehsize; + Elf64_Half e_phentsize; + Elf64_Half e_phnum; + Elf64_Half e_shentsize; + Elf64_Half e_shnum; + Elf64_Half e_shstrndx; } Elf64_Ehdr; /* @@ -467,25 +468,25 @@ typedef struct elf64_hdr { */ typedef struct elf32_phdr { - Elf32_Word p_type; - Elf32_Off p_offset; - Elf32_Addr p_vaddr; - Elf32_Addr p_paddr; - Elf32_Word p_filesz; - Elf32_Word p_memsz; - Elf32_Word p_flags; - Elf32_Word p_align; + Elf32_Word p_type; + Elf32_Off p_offset; + Elf32_Addr p_vaddr; + Elf32_Addr p_paddr; + Elf32_Word p_filesz; + Elf32_Word p_memsz; + Elf32_Word p_flags; + Elf32_Word p_align; } Elf32_Phdr; typedef struct elf64_phdr { - Elf64_Word p_type; - Elf64_Word p_flags; - Elf64_Off p_offset; - Elf64_Addr p_vaddr; - Elf64_Addr p_paddr; - Elf64_Xword p_filesz; - Elf64_Xword p_memsz; - Elf64_Xword p_align; + Elf64_Word p_type; + Elf64_Word p_flags; + Elf64_Off p_offset; + Elf64_Addr p_vaddr; + Elf64_Addr p_paddr; + Elf64_Xword p_filesz; + Elf64_Xword p_memsz; + Elf64_Xword p_align; } Elf64_Phdr; /* @@ -493,44 +494,44 @@ typedef struct elf64_phdr { */ typedef struct elf32_shdr { - Elf32_Word sh_name; - Elf32_Word sh_type; - Elf32_Word sh_flags; - Elf32_Addr sh_addr; - Elf32_Off sh_offset; - Elf32_Word sh_size; - Elf32_Word sh_link; - Elf32_Word sh_info; - Elf32_Word sh_addralign; - Elf32_Word sh_entsize; + Elf32_Word sh_name; + Elf32_Word sh_type; + Elf32_Word sh_flags; + Elf32_Addr sh_addr; + Elf32_Off sh_offset; + Elf32_Word sh_size; + Elf32_Word sh_link; + Elf32_Word sh_info; + Elf32_Word sh_addralign; + Elf32_Word sh_entsize; } Elf32_Shdr; typedef struct elf64_shdr { - Elf64_Word sh_name; - Elf64_Word sh_type; - Elf64_Xword sh_flags; - Elf64_Addr sh_addr; - Elf64_Off sh_offset; - Elf64_Xword sh_size; - Elf64_Word sh_link; - Elf64_Word sh_info; - Elf64_Xword sh_addralign; - Elf64_Xword sh_entsize; + Elf64_Word sh_name; + Elf64_Word sh_type; + Elf64_Xword sh_flags; + Elf64_Addr sh_addr; + Elf64_Off sh_offset; + Elf64_Xword sh_size; + Elf64_Word sh_link; + Elf64_Word sh_info; + Elf64_Xword sh_addralign; + Elf64_Xword sh_entsize; } Elf64_Shdr; /* * Note header */ typedef struct elf32_note { - Elf32_Word n_namesz; /* Name size */ - Elf32_Word n_descsz; /* Content size */ - Elf32_Word n_type; /* Content type */ + Elf32_Word n_namesz; /* Name size */ + Elf32_Word n_descsz; /* Content size */ + Elf32_Word n_type; /* Content type */ } Elf32_Nhdr; typedef struct elf64_note { - Elf64_Word n_namesz; /* Name size */ - Elf64_Word n_descsz; /* Content size */ - Elf64_Word n_type; /* Content type */ + Elf64_Word n_namesz; /* Name size */ + Elf64_Word n_descsz; /* Content size */ + Elf64_Word n_type; /* Content type */ } Elf64_Nhdr; #endif /* OUTPUT_ELF_H */ diff --git a/output/outelf.c b/output/outelf.c index b347fdfd..8be97b39 100644 --- a/output/outelf.c +++ b/output/outelf.c @@ -2118,20 +2118,7 @@ static void elf_section_header(int name, int type, uint64_t flags, elf_sects[elf_nsect].is_saa = is_saa; elf_nsect++; - if (is_elf32()) { - fwriteint32_t((int32_t)name, ofile); - fwriteint32_t((int32_t)type, ofile); - fwriteint32_t((int32_t)flags, ofile); - fwriteint32_t(0L, ofile); /* no address, ever, in object files */ - fwriteint32_t(type == 0 ? 0L : elf_foffs, ofile); - fwriteint32_t(datalen, ofile); - if (data) - elf_foffs += ALIGN(datalen, SEC_FILEALIGN); - fwriteint32_t((int32_t)link, ofile); - fwriteint32_t((int32_t)info, ofile); - fwriteint32_t((int32_t)align, ofile); - fwriteint32_t((int32_t)eltsize, ofile); - } else if (is_elfx32()) { + if (is_elf32() || is_elfx32()) { fwriteint32_t((int32_t)name, ofile); fwriteint32_t((int32_t)type, ofile); fwriteint32_t((int32_t)flags, ofile);