linker

package
v0.0.0-...-b078ee1 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Apr 24, 2024 License: AGPL-3.0 Imports: 12 Imported by: 0

Documentation

Index

Constants

View Source
const ArHdrSize = int(unsafe.Sizeof(ArHdr{}))
View Source
const EF_RISCV_RVC uint32 = 1
View Source
const EhdrSize = int(unsafe.Sizeof(Ehdr{}))
View Source
const IMAGE_BASE uint64 = 0x200000
View Source
const (
	NeedsGotTp uint32 = 1 << 0
)
View Source
const PageSize = 4096
View Source
const PhdrSize = int(unsafe.Sizeof(Phdr{}))
View Source
const RelaSize = int(unsafe.Sizeof(Rela{}))
View Source
const ShdrSize = int(unsafe.Sizeof(Shdr{}))
View Source
const SymSize = int(unsafe.Sizeof(Sym{}))

Variables

This section is empty.

Functions

func BinSections

func BinSections(ctx *Context)

func CheckFileCompatibility

func CheckFileCompatibility(ctx *Context, file *File)

func CheckMagic

func CheckMagic(contents []byte) bool

func ComputeMergedSectionSizes

func ComputeMergedSectionSizes(ctx *Context)

func ComputeSectionSizes

func ComputeSectionSizes(ctx *Context)

func CreateSyntheticSections

func CreateSyntheticSections(ctx *Context)

func ElfGetName

func ElfGetName(strTab []byte, offset uint32) string

func GetOutputName

func GetOutputName(name string, flags uint64) string

func MarkLiveObjects

func MarkLiveObjects(ctx *Context)

func ReadFile

func ReadFile(ctx *Context, file *File)

func ReadInputFiles

func ReadInputFiles(ctx *Context, remaining []string)

func RegisterSectionPieces

func RegisterSectionPieces(ctx *Context)

func ResolveSymbols

func ResolveSymbols(ctx *Context)

func ScanRelocations

func ScanRelocations(ctx *Context)

func SetOutputSectionOffsets

func SetOutputSectionOffsets(ctx *Context) uint64

func SortOutputSections

func SortOutputSections(ctx *Context)

func WriteMagic

func WriteMagic(contents []byte)

Types

type ArHdr

type ArHdr struct {
	Name [16]byte
	Date [12]byte
	Uid  [6]byte
	Gid  [6]byte
	Mode [8]byte
	Size [10]byte
	Fmag [2]byte
}

func (*ArHdr) GetSize

func (a *ArHdr) GetSize() int

func (*ArHdr) HasPrefix

func (a *ArHdr) HasPrefix(s string) bool

func (*ArHdr) IsStrtab

func (a *ArHdr) IsStrtab() bool

func (*ArHdr) IsSymtab

func (a *ArHdr) IsSymtab() bool

func (*ArHdr) ReadName

func (a *ArHdr) ReadName(strTab []byte) string

type Chunk

type Chunk struct {
	Name  string
	Shdr  Shdr
	Shndx int64
}

func NewChunk

func NewChunk() Chunk

func (*Chunk) CopyBuf

func (c *Chunk) CopyBuf(ctx *Context)

func (*Chunk) GetName

func (c *Chunk) GetName() string

func (*Chunk) GetShdr

func (c *Chunk) GetShdr() *Shdr

func (*Chunk) UpdateShdr

func (c *Chunk) UpdateShdr(ctx *Context)

type Chunker

type Chunker interface {
	GetName() string
	GetShdr() *Shdr
	UpdateShdr(ctx *Context)
	CopyBuf(ctx *Context)
}

func CollectOutputSections

func CollectOutputSections(ctx *Context) []Chunker

type Context

type Context struct {
	Args ContextArgs
	Buf  []byte

	Ehdr *OutputEhdr
	Shdr *OutputShdr
	Phdr *OutputPhdr
	Got  *GotSection

	TpAddr uint64

	OutputSections []*OutputSection

	Chunks []Chunker

	Objs           []*ObjectFile
	SymbolMap      map[string]*Symbol
	MergedSections []*MergedSection
}

func NewContext

func NewContext() *Context

type ContextArgs

type ContextArgs struct {
	Output       string
	Emulation    MachineType
	LibraryPaths []string
}

type Ehdr

type Ehdr struct {
	Ident     [16]uint8
	Type      uint16
	Machine   uint16
	Version   uint32
	Entry     uint64
	PhOff     uint64
	ShOff     uint64
	Flags     uint32
	EhSize    uint16
	PhEntSize uint16
	PhNum     uint16
	ShEntSize uint16
	ShNum     uint16
	ShStrndx  uint16
}

type File

type File struct {
	Name     string
	Contents []byte
	Parent   *File
}

func FindLibrary

func FindLibrary(ctx *Context, name string) *File

func MustNewFile

func MustNewFile(filename string) *File

func OpenLibrary

func OpenLibrary(filepath string) *File

func ReadArchiveMembers

func ReadArchiveMembers(file *File) []*File

type FileType

type FileType = uint8
const (
	FileTypeUnknown FileType = iota
	FileTypeEmpty   FileType = iota
	FileTypeObject  FileType = iota
	FileTypeArchive FileType = iota
)

func GetFileType

func GetFileType(contents []byte) FileType

type GotEntry

type GotEntry struct {
	Idx int64
	Val uint64
}

type GotSection

type GotSection struct {
	Chunk
	GotTpSyms []*Symbol
}

func NewGotSection

func NewGotSection() *GotSection

func (*GotSection) AddGotTpSymbol

func (g *GotSection) AddGotTpSymbol(sym *Symbol)

func (*GotSection) CopyBuf

func (g *GotSection) CopyBuf(ctx *Context)

func (*GotSection) GetEntries

func (g *GotSection) GetEntries(ctx *Context) []GotEntry

type InputFile

type InputFile struct {
	File         *File
	ElfSections  []Shdr
	ElfSyms      []Sym
	FirstGlobal  int
	ShStrtab     []byte
	SymbolStrtab []byte
	IsAlive      bool
	Symbols      []*Symbol
	LocalSymbols []Symbol
}

func NewInputFile

func NewInputFile(file *File) InputFile

func (*InputFile) FillUpElfSyms

func (f *InputFile) FillUpElfSyms(s *Shdr)

func (*InputFile) FindSection

func (f *InputFile) FindSection(ty uint32) *Shdr

func (*InputFile) GetBytesFromIdx

func (f *InputFile) GetBytesFromIdx(idx int64) []byte

func (*InputFile) GetBytesFromShdr

func (f *InputFile) GetBytesFromShdr(s *Shdr) []byte

func (*InputFile) GetEhdr

func (f *InputFile) GetEhdr() Ehdr

type InputSection

type InputSection struct {
	File     *ObjectFile
	Contents []byte
	Shndx    uint32
	ShSize   uint32
	IsAlive  bool
	P2Align  uint8

	Offset        uint32
	OutputSection *OutputSection

	RelsecIdx uint32
	Rels      []Rela
}

func NewInputSection

func NewInputSection(ctx *Context, name string, file *ObjectFile, shndx uint32) *InputSection

func (*InputSection) ApplyRelocAlloc

func (i *InputSection) ApplyRelocAlloc(ctx *Context, base []byte)

func (*InputSection) CopyContents

func (i *InputSection) CopyContents(buf []byte)

func (*InputSection) GetAddr

func (i *InputSection) GetAddr() uint64

func (*InputSection) GetRels

func (i *InputSection) GetRels() []Rela

func (*InputSection) Name

func (i *InputSection) Name() string

func (*InputSection) ScanRelocations

func (i *InputSection) ScanRelocations()

func (*InputSection) Shdr

func (i *InputSection) Shdr() *Shdr

func (*InputSection) WriteTo

func (i *InputSection) WriteTo(ctx *Context, buf []byte)

type MachineType

type MachineType = uint8
const (
	MachineTypeNone    MachineType = iota
	MachineTypeRISCV64 MachineType = iota
)

func GetMachineTypeFromContents

func GetMachineTypeFromContents(contents []byte) MachineType

type MachineTypeStringer

type MachineTypeStringer struct {
	MachineType
}

func (MachineTypeStringer) String

func (m MachineTypeStringer) String() string

type MergeableSection

type MergeableSection struct {
	Parent      *MergedSection
	P2Align     uint8
	Strs        []string
	FragOffsets []uint32
	Fragments   []*SectionFragment
}

func (*MergeableSection) GetFragment

func (m *MergeableSection) GetFragment(offset uint32) (*SectionFragment, uint32)

type MergedSection

type MergedSection struct {
	Chunk
	Map map[string]*SectionFragment
}

func GetMergedSectionInstance

func GetMergedSectionInstance(
	ctx *Context, name string, typ uint32, flags uint64) *MergedSection

func NewMergedSection

func NewMergedSection(
	name string, flags uint64, typ uint32) *MergedSection

func (*MergedSection) AssignOffsets

func (m *MergedSection) AssignOffsets()

func (*MergedSection) CopyBuf

func (m *MergedSection) CopyBuf(ctx *Context)

func (*MergedSection) Insert

func (m *MergedSection) Insert(
	key string, p2align uint32) *SectionFragment

type ObjectFile

type ObjectFile struct {
	InputFile
	SymtabSec         *Shdr
	SymtabShndxSec    []uint32
	Sections          []*InputSection
	MergeableSections []*MergeableSection
}

func CreateObjectFile

func CreateObjectFile(ctx *Context, file *File, inLib bool) *ObjectFile

func NewObjectFile

func NewObjectFile(file *File, isAlive bool) *ObjectFile

func (*ObjectFile) ClearSymbols

func (o *ObjectFile) ClearSymbols()

func (*ObjectFile) FillUpSymtabShndxSec

func (o *ObjectFile) FillUpSymtabShndxSec(s *Shdr)

func (*ObjectFile) GetSection

func (o *ObjectFile) GetSection(esym *Sym, idx int) *InputSection

func (*ObjectFile) GetShndx

func (o *ObjectFile) GetShndx(esym *Sym, idx int) int64

func (*ObjectFile) InitializeMergeableSections

func (o *ObjectFile) InitializeMergeableSections(ctx *Context)

func (*ObjectFile) InitializeSections

func (o *ObjectFile) InitializeSections(ctx *Context)

func (*ObjectFile) InitializeSymbols

func (o *ObjectFile) InitializeSymbols(ctx *Context)

func (*ObjectFile) MarkLiveObjects

func (o *ObjectFile) MarkLiveObjects(feeder func(*ObjectFile))

func (*ObjectFile) Parse

func (o *ObjectFile) Parse(ctx *Context)

func (*ObjectFile) RegisterSectionPieces

func (o *ObjectFile) RegisterSectionPieces()

func (*ObjectFile) ResolveSymbols

func (o *ObjectFile) ResolveSymbols()

func (*ObjectFile) ScanRelocations

func (o *ObjectFile) ScanRelocations()

func (*ObjectFile) SkipEhframeSections

func (o *ObjectFile) SkipEhframeSections()

type OutputEhdr

type OutputEhdr struct {
	Chunk
}

func NewOutputEhdr

func NewOutputEhdr() *OutputEhdr

func (*OutputEhdr) CopyBuf

func (o *OutputEhdr) CopyBuf(ctx *Context)

type OutputPhdr

type OutputPhdr struct {
	Chunk

	Phdrs []Phdr
}

func NewOutputPhdr

func NewOutputPhdr() *OutputPhdr

func (*OutputPhdr) CopyBuf

func (o *OutputPhdr) CopyBuf(ctx *Context)

func (*OutputPhdr) UpdateShdr

func (o *OutputPhdr) UpdateShdr(ctx *Context)

type OutputSection

type OutputSection struct {
	Chunk
	Members []*InputSection
	Idx     uint32
}

func GetOutputSection

func GetOutputSection(
	ctx *Context, name string, typ, flags uint64) *OutputSection

func NewOutputSection

func NewOutputSection(
	name string, typ uint32, flags uint64, idx uint32) *OutputSection

func (*OutputSection) CopyBuf

func (o *OutputSection) CopyBuf(ctx *Context)

type OutputShdr

type OutputShdr struct {
	Chunk
}

func NewOutputShdr

func NewOutputShdr() *OutputShdr

func (*OutputShdr) CopyBuf

func (o *OutputShdr) CopyBuf(ctx *Context)

func (*OutputShdr) UpdateShdr

func (o *OutputShdr) UpdateShdr(ctx *Context)

type Phdr

type Phdr struct {
	Type     uint32
	Flags    uint32
	Offset   uint64
	VAddr    uint64
	PAddr    uint64
	FileSize uint64
	MemSize  uint64
	Align    uint64
}

type Rela

type Rela struct {
	Offset uint64
	Type   uint32
	Sym    uint32
	Addend int64
}

type SectionFragment

type SectionFragment struct {
	OutputSection *MergedSection
	Offset        uint32
	P2Align       uint32
	IsAlive       bool
}

func NewSectionFragment

func NewSectionFragment(m *MergedSection) *SectionFragment

func (*SectionFragment) GetAddr

func (s *SectionFragment) GetAddr() uint64

type Shdr

type Shdr struct {
	Name      uint32
	Type      uint32
	Flags     uint64
	Addr      uint64
	Offset    uint64
	Size      uint64
	Link      uint32
	Info      uint32
	AddrAlign uint64
	EntSize   uint64
}

type Sym

type Sym struct {
	Name  uint32
	Info  uint8
	Other uint8
	Shndx uint16
	Val   uint64
	Size  uint64
}

func (*Sym) IsAbs

func (s *Sym) IsAbs() bool

func (*Sym) IsCommon

func (s *Sym) IsCommon() bool

func (*Sym) IsUndef

func (s *Sym) IsUndef() bool

type Symbol

type Symbol struct {
	File     *ObjectFile
	Name     string
	Value    uint64
	SymIdx   int
	GotTpIdx int32

	InputSection    *InputSection
	SectionFragment *SectionFragment

	Flags uint32
}

func GetSymbolByName

func GetSymbolByName(ctx *Context, name string) *Symbol

func NewSymbol

func NewSymbol(name string) *Symbol

func (*Symbol) Clear

func (s *Symbol) Clear()

func (*Symbol) ElfSym

func (s *Symbol) ElfSym() *Sym

func (*Symbol) GetAddr

func (s *Symbol) GetAddr() uint64

func (*Symbol) GetGotTpAddr

func (s *Symbol) GetGotTpAddr(ctx *Context) uint64

func (*Symbol) SetInputSection

func (s *Symbol) SetInputSection(isec *InputSection)

func (*Symbol) SetSectionFragment

func (s *Symbol) SetSectionFragment(frag *SectionFragment)

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL