From 4dc745576fc50502703ecf84b7558559482a9b16 Mon Sep 17 00:00:00 2001 From: Jonathan Gray Date: Sun, 1 Dec 2019 13:10:52 +0000 Subject: Change Elf64 types and structs to match the System V ABI specification. Change Elf64_Half from a uint32_t type to a uint16_t type. The size of structs do not change as the previous uses of Elf64_Half become Elf64_Word (uint32_t). Remove Elf64_Quarter as 16 bit values now use Elf64_Half. Replace Elf_Byte use with unsigned char. Change some uses of Elf64_Xword to Elf64_Addr (both uint64_t). Corrects behaviour with libelf where the file size of a symtab section came back as 26 not 24 as libelf determines this by the size of a the involved types not the size of the struct in exec_elf.h. As a result libelf's elf_getdata() returned ELF_E_SECTION due to the size of the section not being a multiple of the file size of the section type. This occurred with the new runtime linker for radeon shaders in Mesa 19.2. Sync description of Elf32 and Elf64 types in elf(5) with FreeBSD and adjust types in structs mentioned. ok guenther@ deraadt@ --- sys/sys/exec_elf.h | 65 ++++++++++++++++++++++++++---------------------------- 1 file changed, 31 insertions(+), 34 deletions(-) (limited to 'sys') diff --git a/sys/sys/exec_elf.h b/sys/sys/exec_elf.h index 8a88773093c..a40e0510273 100644 --- a/sys/sys/exec_elf.h +++ b/sys/sys/exec_elf.h @@ -1,4 +1,4 @@ -/* $OpenBSD: exec_elf.h,v 1.86 2019/12/01 10:25:50 jsg Exp $ */ +/* $OpenBSD: exec_elf.h,v 1.87 2019/12/01 13:10:51 jsg Exp $ */ /* * Copyright (c) 1995, 1996 Erik Theisen. All rights reserved. * @@ -36,8 +36,6 @@ #include #include -typedef __uint8_t Elf_Byte; - typedef __uint32_t Elf32_Addr; /* Unsigned program address */ typedef __uint32_t Elf32_Off; /* Unsigned file offset */ typedef __int32_t Elf32_Sword; /* Signed large integer */ @@ -56,8 +54,7 @@ typedef __int64_t Elf64_Sxword; typedef __uint64_t Elf64_Xword; typedef __uint64_t Elf64_Lword; -typedef __uint32_t Elf64_Half; -typedef __uint16_t Elf64_Quarter; +typedef __uint16_t Elf64_Half; /* * e_ident[] identification indexes @@ -139,19 +136,19 @@ typedef struct elfhdr { typedef struct { unsigned char e_ident[EI_NIDENT]; /* Id bytes */ - Elf64_Quarter e_type; /* file type */ - Elf64_Quarter e_machine; /* machine type */ - Elf64_Half e_version; /* version number */ + Elf64_Half e_type; /* file type */ + Elf64_Half e_machine; /* machine type */ + Elf64_Word e_version; /* version number */ Elf64_Addr e_entry; /* entry point */ Elf64_Off e_phoff; /* Program hdr offset */ Elf64_Off e_shoff; /* Section hdr offset */ - Elf64_Half e_flags; /* Processor flags */ - Elf64_Quarter e_ehsize; /* sizeof ehdr */ - Elf64_Quarter e_phentsize; /* Program header entry size */ - Elf64_Quarter e_phnum; /* Number of program headers */ - Elf64_Quarter e_shentsize; /* Section header entry size */ - Elf64_Quarter e_shnum; /* Number of section headers */ - Elf64_Quarter e_shstrndx; /* String table index */ + Elf64_Word e_flags; /* Processor flags */ + Elf64_Half e_ehsize; /* sizeof ehdr */ + Elf64_Half e_phentsize; /* Program header entry size */ + Elf64_Half e_phnum; /* Number of program headers */ + Elf64_Half e_shentsize; /* Section header entry size */ + Elf64_Half e_shnum; /* Number of section headers */ + Elf64_Half e_shstrndx; /* String table index */ } Elf64_Ehdr; /* e_type */ @@ -225,14 +222,14 @@ typedef struct { } Elf32_Shdr; typedef struct { - Elf64_Half sh_name; /* section name */ - Elf64_Half sh_type; /* section type */ + Elf64_Word sh_name; /* section name */ + Elf64_Word sh_type; /* section type */ Elf64_Xword sh_flags; /* section flags */ Elf64_Addr sh_addr; /* virtual address */ Elf64_Off sh_offset; /* file offset */ Elf64_Xword sh_size; /* section size */ - Elf64_Half sh_link; /* link to another */ - Elf64_Half sh_info; /* misc info */ + Elf64_Word sh_link; /* link to another */ + Elf64_Word sh_info; /* misc info */ Elf64_Xword sh_addralign; /* memory alignment */ Elf64_Xword sh_entsize; /* table entry size */ } Elf64_Shdr; @@ -335,11 +332,11 @@ typedef struct elf32_sym { } Elf32_Sym; typedef struct { - Elf64_Half st_name; /* Symbol name index in str table */ - Elf_Byte st_info; /* type / binding attrs */ - Elf_Byte st_other; /* unused */ - Elf64_Quarter st_shndx; /* section index of symbol */ - Elf64_Xword st_value; /* value of symbol */ + Elf64_Word st_name; /* Symbol name index in str table */ + unsigned char st_info; /* type / binding attrs */ + unsigned char st_other; /* unused */ + Elf64_Half st_shndx; /* section index of symbol */ + Elf64_Addr st_value; /* value of symbol */ Elf64_Xword st_size; /* size of symbol */ } Elf64_Sym; @@ -402,12 +399,12 @@ typedef struct { #define ELF32_R_INFO(s,t) (((s) << 8) + (unsigned char)(t)) typedef struct { - Elf64_Xword r_offset; /* where to do it */ + Elf64_Addr r_offset; /* where to do it */ Elf64_Xword r_info; /* index & type of relocation */ } Elf64_Rel; typedef struct { - Elf64_Xword r_offset; /* where to do it */ + Elf64_Addr r_offset; /* where to do it */ Elf64_Xword r_info; /* index & type of relocation */ Elf64_Sxword r_addend; /* adjustment value */ } Elf64_Rela; @@ -443,8 +440,8 @@ typedef struct { } Elf32_Phdr; typedef struct { - Elf64_Half p_type; /* entry type */ - Elf64_Half p_flags; /* flags */ + Elf64_Word p_type; /* entry type */ + Elf64_Word p_flags; /* flags */ Elf64_Off p_offset; /* offset */ Elf64_Addr p_vaddr; /* virtual address */ Elf64_Addr p_paddr; /* physical address */ @@ -578,9 +575,9 @@ typedef struct { } Elf32_Nhdr; typedef struct { - Elf64_Half n_namesz; - Elf64_Half n_descsz; - Elf64_Half n_type; + Elf64_Word n_namesz; + Elf64_Word n_descsz; + Elf64_Word n_type; } Elf64_Nhdr; /* @@ -593,9 +590,9 @@ typedef struct { } Elf32_Note; typedef struct { - Elf64_Half namesz; - Elf64_Half descsz; - Elf64_Half type; + Elf64_Word namesz; + Elf64_Word descsz; + Elf64_Word type; } Elf64_Note; /* Values for n_type. */ -- cgit v1.2.3