github.com/shogo82148/std@v1.22.1-0.20240327122250-4e474527810c/internal/xcoff/file.go (about) 1 // Copyright 2018 The Go Authors. All rights reserved. 2 // Use of this source code is governed by a BSD-style 3 // license that can be found in the LICENSE file. 4 5 // Package xcoff implements access to XCOFF (Extended Common Object File Format) files. 6 package xcoff 7 8 import ( 9 "github.com/shogo82148/std/debug/dwarf" 10 "github.com/shogo82148/std/io" 11 ) 12 13 // SectionHeader holds information about an XCOFF section header. 14 type SectionHeader struct { 15 Name string 16 VirtualAddress uint64 17 Size uint64 18 Type uint32 19 Relptr uint64 20 Nreloc uint32 21 } 22 23 type Section struct { 24 SectionHeader 25 Relocs []Reloc 26 io.ReaderAt 27 sr *io.SectionReader 28 } 29 30 // AuxiliaryCSect holds information about an XCOFF symbol in an AUX_CSECT entry. 31 type AuxiliaryCSect struct { 32 Length int64 33 StorageMappingClass int 34 SymbolType int 35 } 36 37 // AuxiliaryFcn holds information about an XCOFF symbol in an AUX_FCN entry. 38 type AuxiliaryFcn struct { 39 Size int64 40 } 41 42 type Symbol struct { 43 Name string 44 Value uint64 45 SectionNumber int 46 StorageClass int 47 AuxFcn AuxiliaryFcn 48 AuxCSect AuxiliaryCSect 49 } 50 51 type Reloc struct { 52 VirtualAddress uint64 53 Symbol *Symbol 54 Signed bool 55 InstructionFixed bool 56 Length uint8 57 Type uint8 58 } 59 60 // ImportedSymbol holds information about an imported XCOFF symbol. 61 type ImportedSymbol struct { 62 Name string 63 Library string 64 } 65 66 // FileHeader holds information about an XCOFF file header. 67 type FileHeader struct { 68 TargetMachine uint16 69 } 70 71 // A File represents an open XCOFF file. 72 type File struct { 73 FileHeader 74 Sections []*Section 75 Symbols []*Symbol 76 StringTable []byte 77 LibraryPaths []string 78 79 closer io.Closer 80 } 81 82 // Open opens the named file using os.Open and prepares it for use as an XCOFF binary. 83 func Open(name string) (*File, error) 84 85 // Close closes the File. 86 // If the File was created using NewFile directly instead of Open, 87 // Close has no effect. 88 func (f *File) Close() error 89 90 // Section returns the first section with the given name, or nil if no such 91 // section exists. 92 // Xcoff have section's name limited to 8 bytes. Some sections like .gosymtab 93 // can be trunked but this method will still find them. 94 func (f *File) Section(name string) *Section 95 96 // SectionByType returns the first section in f with the 97 // given type, or nil if there is no such section. 98 func (f *File) SectionByType(typ uint32) *Section 99 100 // NewFile creates a new File for accessing an XCOFF binary in an underlying reader. 101 func NewFile(r io.ReaderAt) (*File, error) 102 103 // Data reads and returns the contents of the XCOFF section s. 104 func (s *Section) Data() ([]byte, error) 105 106 // CSect reads and returns the contents of a csect. 107 func (f *File) CSect(name string) []byte 108 109 func (f *File) DWARF() (*dwarf.Data, error) 110 111 // ImportedSymbols returns the names of all symbols 112 // referred to by the binary f that are expected to be 113 // satisfied by other libraries at dynamic load time. 114 // It does not return weak symbols. 115 func (f *File) ImportedSymbols() ([]ImportedSymbol, error) 116 117 // ImportedLibraries returns the names of all libraries 118 // referred to by the binary f that are expected to be 119 // linked with the binary at dynamic link time. 120 func (f *File) ImportedLibraries() ([]string, error)