-
Notifications
You must be signed in to change notification settings - Fork 0
/
relocations.go
62 lines (56 loc) · 1.75 KB
/
relocations.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
package file
import (
"fmt"
"github.com/vsoch/gosmeagle/pkg/debug/elf"
)
// https://cs.opensource.google/go/go/+/master:src/debug/elf/elf.go;l=3108
type Relocation struct {
Address uint64 // Address of first byte that reloc applies to.
Size uint64 // Number of bytes
Stringer RelocStringer
// Added to suppored retriving raw
SymbolName string
Offset uint64
SymbolValue uint64
RelocType string // can be parse from into
Info uint64
SectionIndex int
}
func getRelocationType(rType uint32, mType elf.Machine) string {
switch mType {
case elf.EM_X86_64:
return fmt.Sprintf("%s", elf.R_X86_64(rType))
case elf.EM_386:
return fmt.Sprintf("%s", elf.R_386(rType))
case elf.EM_ARM:
return fmt.Sprintf("%s", elf.R_ARM(rType))
case elf.EM_AARCH64:
return fmt.Sprintf("%s", elf.R_AARCH64(rType))
case elf.EM_PPC:
return fmt.Sprintf("%s", elf.R_PPC(rType))
case elf.EM_PPC64:
return fmt.Sprintf("%s", elf.R_PPC64(rType))
case elf.EM_MIPS:
return fmt.Sprintf("%s", elf.R_MIPS(rType))
case elf.EM_RISCV:
return fmt.Sprintf("%s", elf.R_RISCV(rType))
case elf.EM_S390:
return fmt.Sprintf("%s", elf.R_390(rType))
case elf.EM_SPARCV9:
return fmt.Sprintf("%s", elf.R_SPARC(rType))
default:
return "R_UNKNOWN"
}
}
type RelocStringer interface {
// insnOffset is the offset of the instruction containing the relocation
// from the start of the symbol containing the relocation.
String(insnOffset uint64) string
}
// Print the relocation table - currently not used
func PrintRelocationTable(relocs []Relocation) {
fmt.Println("Offset\t\t\tInfo\t\t\t\tType\t\t\tSym.Value\t\t\tSym.Name")
for _, r := range relocs {
fmt.Printf("%016x\t%016x\t%s\t%016x\t\t%s\n", r.Offset, r.Info, r.RelocType, r.SymbolValue, r.SymbolName)
}
}