github.com/primecitizens/pcz/std@v0.2.1/encoding/binfmt/elf/elf32.go (about) 1 // SPDX-License-Identifier: Apache-2.0 2 // Copyright 2023 The Prime Citizens 3 // 4 // Copyright 2009 The Go Authors. All rights reserved. 5 // Use of this source code is governed by a BSD-style 6 // license that can be found in the LICENSE file. 7 8 package elf 9 10 // ELF32 File header. 11 type Header32 struct { 12 Ident [EI_NIDENT]byte /* File identification. */ 13 Type uint16 /* File type. */ 14 Machine uint16 /* Machine architecture. */ 15 Version uint32 /* ELF format version. */ 16 Entry uint32 /* Entry point. */ 17 Phoff uint32 /* Program header file offset. */ 18 Shoff uint32 /* Section header file offset. */ 19 Flags uint32 /* Architecture-specific flags. */ 20 Ehsize uint16 /* Size of ELF header in bytes. */ 21 Phentsize uint16 /* Size of program header entry. */ 22 Phnum uint16 /* Number of program header entries. */ 23 Shentsize uint16 /* Size of section header entry. */ 24 Shnum uint16 /* Number of section header entries. */ 25 Shstrndx uint16 /* Section name strings section. */ 26 } 27 28 // ELF32 Section header. 29 type Section32 struct { 30 Name uint32 /* Section name (index into the section header string table). */ 31 Type uint32 /* Section type. */ 32 Flags uint32 /* Section flags. */ 33 Addr uint32 /* Address in memory image. */ 34 Off uint32 /* Offset in file. */ 35 Size uint32 /* Size in bytes. */ 36 Link uint32 /* Index of a related section. */ 37 Info uint32 /* Depends on section type. */ 38 Addralign uint32 /* Alignment in bytes. */ 39 Entsize uint32 /* Size of each entry in section. */ 40 } 41 42 // ELF32 Program header. 43 type Prog32 struct { 44 Type uint32 /* Entry type. */ 45 Off uint32 /* File offset of contents. */ 46 Vaddr uint32 /* Virtual address in memory image. */ 47 Paddr uint32 /* Physical address (not used). */ 48 Filesz uint32 /* Size of contents in file. */ 49 Memsz uint32 /* Size of contents in memory. */ 50 Flags uint32 /* Access permission flags. */ 51 Align uint32 /* Alignment in memory and file. */ 52 } 53 54 // ELF32 Dynamic structure. The ".dynamic" section contains an array of them. 55 type Dyn32 struct { 56 Tag int32 /* Entry type. */ 57 Val uint32 /* Integer/Address value. */ 58 } 59 60 // ELF32 Compression header. 61 type Chdr32 struct { 62 Type uint32 63 Size uint32 64 Addralign uint32 65 } 66 67 /* 68 * Relocation entries. 69 */ 70 71 // ELF32 Relocations that don't need an addend field. 72 type Rel32 struct { 73 Off uint32 /* Location to be relocated. */ 74 Info uint32 /* Relocation type and symbol index. */ 75 } 76 77 // ELF32 Relocations that need an addend field. 78 type Rela32 struct { 79 Off uint32 /* Location to be relocated. */ 80 Info uint32 /* Relocation type and symbol index. */ 81 Addend int32 /* Addend. */ 82 } 83 84 func R_SYM32(info uint32) uint32 { return info >> 8 } 85 func R_TYPE32(info uint32) uint32 { return info & 0xff } 86 func R_INFO32(sym, typ uint32) uint32 { return sym<<8 | typ } 87 88 // ELF32 Symbol. 89 type Sym32 struct { 90 Name uint32 91 Value uint32 92 Size uint32 93 Info uint8 94 Other uint8 95 Shndx uint16 96 } 97 98 const Sym32Size = 16 99 100 func ST_BIND(info uint8) SymBind { return SymBind(info >> 4) } 101 func ST_TYPE(info uint8) SymType { return SymType(info & 0xF) } 102 func ST_INFO(bind SymBind, typ SymType) uint8 { 103 return uint8(bind)<<4 | uint8(typ)&0xf 104 } 105 func ST_VISIBILITY(other uint8) SymVis { return SymVis(other & 3) }