-
-
Notifications
You must be signed in to change notification settings - Fork 0
/
elfdef.go
134 lines (113 loc) · 4.5 KB
/
elfdef.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
// Copyright 2020 The kube-timeleap Authors.
// SPDX-License-Identifier: BSD-3-Clause
// +build linux
// Package elfdef prodives the ELF64 structure definitions for use by the vDSO loader.
package elfdef
import (
"debug/elf"
)
// DynTag type alias of elf.DynTag.
type DynTag = elf.DynTag
const (
AT_SYSINFO_EHDR = 33
// Indexes into the Header.Ident array.
EI_NIDENT = 16 // Size of Header.Ident array.
// Version is found in Header.Ident[EI_VERSION] and Header.Version.
VER_FLG_BASE = 0x1 // Version definition of file itself
// Special section indices.
SHN_UNDEF = elf.SectionIndex(0) // Undefined section
// Section type.
SHT_DYNSYM = elf.SectionType(11) // Dynamic linker symbol table
// Prog.Type
PT_LOAD = elf.ProgType(1) // Loadable program segment
PT_DYNAMIC = elf.ProgType(2) // Dynamic linking information
// Dyn.Tag
DT_NULL = DynTag(0) // Marks end of dynamic section
DT_HASH = DynTag(4) // Dynamic symbol hash table
DT_STRTAB = DynTag(5) // Address of string table
DT_SYMTAB = DynTag(6) // Address of symbol table
DT_GNU_HASH = DynTag(0x6ffffef5) // GNU-style dynamic symbol hash table
DT_VERSYM = DynTag(0x6ffffff0) // Address of version symbols table
DT_VERDEF = DynTag(0x6ffffffc) // Address of version dependencies table
// Symbol Binding
STB_GLOBAL = elf.SymBind(1) // Global symbol
STB_WEAK = elf.SymBind(2) // Weak symbol
// Symbol type
STT_FUNC = elf.SymType(2) // Symbol is a code object
STT_NOTYPE = elf.SymType(0) // Symbol type is not specified
)
// Header represents a ELF64 file header.
type Header struct {
Ident [EI_NIDENT]byte // Magic number and other info
Type uint16 // Object file type
Machine uint16 // Architecture
Version uint32 // Object file version
Entry uint64 // Entry point virtual address
Phoff uint64 // Program header table file offset
Shoff uint64 // Section header table file offset
Flags uint32 // Processor-specific flags
Ehsize uint16 // ELF header size in bytes
Phentsize uint16 // Program header table entry size
Phnum uint16 // Program header table entry count
Shentsize uint16 // Section header table entry size
Shnum uint16 // Section header table entry count
Shstrndx uint16 // Section header string table index
}
// Section represents a ELF64 Section header.
type Section struct {
Name uint32 // Section name (string tbl index)
Type uint32 // Section type
Flags uint64 // Section flags
Addr uint64 // Section virtual addr at execution
Offset uint64 // Section file offset
Size uint64 // Section size in bytes
Link uint32 // Link to another section
Info uint32 // Additional section information
Addralign uint64 // Section alignment
Entsize uint64 // Entry size if section holds table
}
// Prog represents a ELF64 Program header.
type Prog struct {
Type uint32 // Segment type
Flags uint32 // Segment flags
Offset uint64 // Segment file offset
Vaddr uint64 // Segment virtual address
Paddr uint64 // Segment physical address
Filesz uint64 // Segment size in file
Memsz uint64 // Segment size in memory
Align uint64 // Segment alignment
}
// Dyn represents a ELF64 Dynamic structure.
//
// The ".dynamic" section contains an array of them.
type Dyn struct {
Tag int64 // Dynamic entry type
Val uint64 // Integer value
}
// Sym represents a ELF64 symbol table entries.
type Sym struct {
Name uint32 // String table index of name
Info byte // Type and binding information
Other byte // Reserved (not used)
Shndx uint16 // Section index of symbol
Value uint64 // Symbol value
Size uint64 // Size of associated object
}
// Verdef represents a ELF64 Version table entries.
type Verdef struct {
Version uint16 // Version revision
Flags uint16 // Version information
Ndx uint16 // Version Index
Cnt uint16 // Number of associated aux entries
Hash uint32 // Version name hash value
Aux uint32 // Offset in bytes to verdaux array
Next uint32 // Offset in bytes to next verdef entry
}
// Verdaux represents a ELF64 Version dependency table entries.
type Verdaux struct {
Name uint32 // Version or dependency names
Next uint32 // Offset in bytes to next verdaux entry
}
// How to extract and insert information held in the st_info field.
func ST_BIND(info uint8) elf.SymBind { return elf.SymBind(info >> 4) }
func ST_TYPE(info uint8) elf.SymType { return elf.SymType(info & 0xF) }