github.com/eh-steve/goloader@v0.0.0-20240111193454-90ff3cfdae39/obj/readobj.go (about)

     1  package obj
     2  
     3  import (
     4  	"os"
     5  )
     6  
     7  type CompilationUnitFiles struct {
     8  	ArchiveName string
     9  	Files       []string
    10  }
    11  
    12  type ExportSymType struct {
    13  	SymName  string
    14  	TypeName string
    15  }
    16  
    17  type Pkg struct {
    18  	Syms           map[string]*ObjSymbol
    19  	CUFiles        []CompilationUnitFiles
    20  	Arch           string
    21  	PkgPath        string
    22  	F              *os.File
    23  	SymNameOrder   []string
    24  	Objidx         uint32 // index of this archive in the slice of files
    25  	ReferencedPkgs []string
    26  	SymNamesByIdx  map[uint32]string
    27  	AutoLib        []string
    28  	Exports        map[string]ExportSymType
    29  }
    30  
    31  type FuncInfo struct {
    32  	Args      uint32
    33  	Locals    uint32
    34  	FuncID    uint8
    35  	FuncFlag  uint8
    36  	StartLine int32
    37  	PCSP      []byte
    38  	PCFile    []byte
    39  	PCLine    []byte
    40  	PCInline  []byte
    41  	PCData    [][]byte
    42  	File      []string
    43  	FuncData  []string
    44  	InlTree   []InlTreeNode
    45  	ABI       uint16
    46  	CUOffset  int
    47  }
    48  
    49  type ObjSymbol struct {
    50  	Name   string
    51  	Kind   int    // kind of symbol
    52  	DupOK  bool   // are duplicate definitions okay?
    53  	Size   int64  // size of corresponding data
    54  	Data   []byte // memory image of symbol
    55  	Type   string
    56  	Reloc  []Reloc
    57  	Func   *FuncInfo // additional data for functions
    58  	Objidx uint32    // the index of the archive which the symbol came from when loading multiple files
    59  	Pkg    string
    60  }
    61  
    62  type InlTreeNode struct {
    63  	Parent   int64
    64  	File     string
    65  	Line     int64
    66  	Func     string
    67  	ParentPC int64
    68  }
    69  
    70  type Func struct {
    71  	PCData   []uint32
    72  	FuncData []uintptr
    73  }
    74  
    75  // copy from $GOROOT/src/cmd/internal/goobj/read.go type Sym struct
    76  type Sym struct {
    77  	Name   string
    78  	Kind   int
    79  	Offset int
    80  	Func   *Func
    81  	Reloc  []Reloc
    82  	Pkg    string
    83  	Size   int
    84  }
    85  
    86  // copy from $GOROOT/src/cmd/internal/goobj/read.go type Reloc struct
    87  type Reloc struct {
    88  	Offset         int
    89  	Sym            *Sym
    90  	Size           int
    91  	Type           int
    92  	Add            int
    93  	EpilogueOffset int // This is added to store the offset of the extra instructions added by goloader in the case of certain overflowing relocations, e.g. ADRP, PCREL, CALLARM64
    94  	EpilogueSize   int
    95  }