ld

package
v0.0.0-...-07a73a0 Latest Latest
Warning

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

Go to latest
Published: Mar 20, 2018 License: BSD-3-Clause Imports: 39 Imported by: 0

Documentation

Index

Constants

View Source
const (
	SARMAG  = 8
	SAR_HDR = 16 + 44
)
View Source
const (
	MaxKeySize = 128
	MaxValSize = 128
	BucketSize = 8
)

synthesizemaptypes is way too closely married to runtime/hashmap.c

View Source
const (
	LINE_BASE   = -4
	LINE_RANGE  = 10
	PC_RANGE    = (255 - OPCODE_BASE) / LINE_RANGE
	OPCODE_BASE = 10
)

* Generate a sequence of opcodes that is as short as possible. * See section 6.2.5

View Source
const (
	EI_MAG0              = 0
	EI_MAG1              = 1
	EI_MAG2              = 2
	EI_MAG3              = 3
	EI_CLASS             = 4
	EI_DATA              = 5
	EI_VERSION           = 6
	EI_OSABI             = 7
	EI_ABIVERSION        = 8
	OLD_EI_BRAND         = 8
	EI_PAD               = 9
	EI_NIDENT            = 16
	ELFMAG0              = 0x7f
	ELFMAG1              = 'E'
	ELFMAG2              = 'L'
	ELFMAG3              = 'F'
	SELFMAG              = 4
	EV_NONE              = 0
	EV_CURRENT           = 1
	ELFCLASSNONE         = 0
	ELFCLASS32           = 1
	ELFCLASS64           = 2
	ELFDATANONE          = 0
	ELFDATA2LSB          = 1
	ELFDATA2MSB          = 2
	ELFOSABI_NONE        = 0
	ELFOSABI_HPUX        = 1
	ELFOSABI_NETBSD      = 2
	ELFOSABI_LINUX       = 3
	ELFOSABI_HURD        = 4
	ELFOSABI_86OPEN      = 5
	ELFOSABI_SOLARIS     = 6
	ELFOSABI_AIX         = 7
	ELFOSABI_IRIX        = 8
	ELFOSABI_FREEBSD     = 9
	ELFOSABI_TRU64       = 10
	ELFOSABI_MODESTO     = 11
	ELFOSABI_OPENBSD     = 12
	ELFOSABI_OPENVMS     = 13
	ELFOSABI_NSK         = 14
	ELFOSABI_ARM         = 97
	ELFOSABI_STANDALONE  = 255
	ELFOSABI_SYSV        = ELFOSABI_NONE
	ELFOSABI_MONTEREY    = ELFOSABI_AIX
	ET_NONE              = 0
	ET_REL               = 1
	ET_EXEC              = 2
	ET_DYN               = 3
	ET_CORE              = 4
	ET_LOOS              = 0xfe00
	ET_HIOS              = 0xfeff
	ET_LOPROC            = 0xff00
	ET_HIPROC            = 0xffff
	EM_NONE              = 0
	EM_M32               = 1
	EM_SPARC             = 2
	EM_386               = 3
	EM_68K               = 4
	EM_88K               = 5
	EM_860               = 7
	EM_MIPS              = 8
	EM_S370              = 9
	EM_MIPS_RS3_LE       = 10
	EM_PARISC            = 15
	EM_VPP500            = 17
	EM_SPARC32PLUS       = 18
	EM_960               = 19
	EM_PPC               = 20
	EM_PPC64             = 21
	EM_S390              = 22
	EM_V800              = 36
	EM_FR20              = 37
	EM_RH32              = 38
	EM_RCE               = 39
	EM_ARM               = 40
	EM_SH                = 42
	EM_SPARCV9           = 43
	EM_TRICORE           = 44
	EM_ARC               = 45
	EM_H8_300            = 46
	EM_H8_300H           = 47
	EM_H8S               = 48
	EM_H8_500            = 49
	EM_IA_64             = 50
	EM_MIPS_X            = 51
	EM_COLDFIRE          = 52
	EM_68HC12            = 53
	EM_MMA               = 54
	EM_PCP               = 55
	EM_NCPU              = 56
	EM_NDR1              = 57
	EM_STARCORE          = 58
	EM_ME16              = 59
	EM_ST100             = 60
	EM_TINYJ             = 61
	EM_X86_64            = 62
	EM_AARCH64           = 183
	EM_486               = 6
	EM_MIPS_RS4_BE       = 10
	EM_ALPHA_STD         = 41
	EM_ALPHA             = 0x9026
	SHN_UNDEF            = 0
	SHN_LORESERVE        = 0xff00
	SHN_LOPROC           = 0xff00
	SHN_HIPROC           = 0xff1f
	SHN_LOOS             = 0xff20
	SHN_HIOS             = 0xff3f
	SHN_ABS              = 0xfff1
	SHN_COMMON           = 0xfff2
	SHN_XINDEX           = 0xffff
	SHN_HIRESERVE        = 0xffff
	SHT_NULL             = 0
	SHT_PROGBITS         = 1
	SHT_SYMTAB           = 2
	SHT_STRTAB           = 3
	SHT_RELA             = 4
	SHT_HASH             = 5
	SHT_DYNAMIC          = 6
	SHT_NOTE             = 7
	SHT_NOBITS           = 8
	SHT_REL              = 9
	SHT_SHLIB            = 10
	SHT_DYNSYM           = 11
	SHT_INIT_ARRAY       = 14
	SHT_FINI_ARRAY       = 15
	SHT_PREINIT_ARRAY    = 16
	SHT_GROUP            = 17
	SHT_SYMTAB_SHNDX     = 18
	SHT_LOOS             = 0x60000000
	SHT_HIOS             = 0x6fffffff
	SHT_GNU_VERDEF       = 0x6ffffffd
	SHT_GNU_VERNEED      = 0x6ffffffe
	SHT_GNU_VERSYM       = 0x6fffffff
	SHT_LOPROC           = 0x70000000
	SHT_ARM_ATTRIBUTES   = 0x70000003
	SHT_HIPROC           = 0x7fffffff
	SHT_LOUSER           = 0x80000000
	SHT_HIUSER           = 0xffffffff
	SHF_WRITE            = 0x1
	SHF_ALLOC            = 0x2
	SHF_EXECINSTR        = 0x4
	SHF_MERGE            = 0x10
	SHF_STRINGS          = 0x20
	SHF_INFO_LINK        = 0x40
	SHF_LINK_ORDER       = 0x80
	SHF_OS_NONCONFORMING = 0x100
	SHF_GROUP            = 0x200
	SHF_TLS              = 0x400
	SHF_MASKOS           = 0x0ff00000
	SHF_MASKPROC         = 0xf0000000
	PT_NULL              = 0
	PT_LOAD              = 1
	PT_DYNAMIC           = 2
	PT_INTERP            = 3
	PT_NOTE              = 4
	PT_SHLIB             = 5
	PT_PHDR              = 6
	PT_TLS               = 7
	PT_LOOS              = 0x60000000
	PT_HIOS              = 0x6fffffff
	PT_LOPROC            = 0x70000000
	PT_HIPROC            = 0x7fffffff
	PT_GNU_STACK         = 0x6474e551
	PT_GNU_RELRO         = 0x6474e552
	PT_PAX_FLAGS         = 0x65041580
	PT_SUNWSTACK         = 0x6ffffffb
	PF_X                 = 0x1
	PF_W                 = 0x2
	PF_R                 = 0x4
	PF_MASKOS            = 0x0ff00000
	PF_MASKPROC          = 0xf0000000
	DT_NULL              = 0
	DT_NEEDED            = 1
	DT_PLTRELSZ          = 2
	DT_PLTGOT            = 3
	DT_HASH              = 4
	DT_STRTAB            = 5
	DT_SYMTAB            = 6
	DT_RELA              = 7
	DT_RELASZ            = 8
	DT_RELAENT           = 9
	DT_STRSZ             = 10
	DT_SYMENT            = 11
	DT_INIT              = 12
	DT_FINI              = 13
	DT_SONAME            = 14
	DT_RPATH             = 15
	DT_SYMBOLIC          = 16
	DT_REL               = 17
	DT_RELSZ             = 18
	DT_RELENT            = 19
	DT_PLTREL            = 20
	DT_DEBUG             = 21
	DT_TEXTREL           = 22
	DT_JMPREL            = 23
	DT_BIND_NOW          = 24
	DT_INIT_ARRAY        = 25
	DT_FINI_ARRAY        = 26
	DT_INIT_ARRAYSZ      = 27
	DT_FINI_ARRAYSZ      = 28
	DT_RUNPATH           = 29
	DT_FLAGS             = 30
	DT_ENCODING          = 32
	DT_PREINIT_ARRAY     = 32
	DT_PREINIT_ARRAYSZ   = 33
	DT_LOOS              = 0x6000000d
	DT_HIOS              = 0x6ffff000
	DT_LOPROC            = 0x70000000
	DT_HIPROC            = 0x7fffffff
	DT_VERNEED           = 0x6ffffffe
	DT_VERNEEDNUM        = 0x6fffffff
	DT_VERSYM            = 0x6ffffff0
	DT_PPC64_GLINK       = DT_LOPROC + 0
	DT_PPC64_OPT         = DT_LOPROC + 3
	DF_ORIGIN            = 0x0001
	DF_SYMBOLIC          = 0x0002
	DF_TEXTREL           = 0x0004
	DF_BIND_NOW          = 0x0008
	DF_STATIC_TLS        = 0x0010
	NT_PRSTATUS          = 1
	NT_FPREGSET          = 2
	NT_PRPSINFO          = 3
	STB_LOCAL            = 0
	STB_GLOBAL           = 1
	STB_WEAK             = 2
	STB_LOOS             = 10
	STB_HIOS             = 12
	STB_LOPROC           = 13
	STB_HIPROC           = 15
	STT_NOTYPE           = 0
	STT_OBJECT           = 1
	STT_FUNC             = 2
	STT_SECTION          = 3
	STT_FILE             = 4
	STT_COMMON           = 5
	STT_TLS              = 6
	STT_LOOS             = 10
	STT_HIOS             = 12
	STT_LOPROC           = 13
	STT_HIPROC           = 15
	STV_DEFAULT          = 0x0
	STV_INTERNAL         = 0x1
	STV_HIDDEN           = 0x2
	STV_PROTECTED        = 0x3
	STN_UNDEF            = 0
)
View Source
const (
	ELF64HDRSIZE  = 64
	ELF64PHDRSIZE = 56
	ELF64SHDRSIZE = 64
	ELF64RELSIZE  = 16
	ELF64RELASIZE = 24
	ELF64SYMSIZE  = 24
	ELF32HDRSIZE  = 52
	ELF32PHDRSIZE = 32
	ELF32SHDRSIZE = 40
	ELF32SYMSIZE  = 16
	ELF32RELSIZE  = 8
)

* Go linker interface

View Source
const (
	ELF_NOTE_NETBSD_NAMESZ  = 7
	ELF_NOTE_NETBSD_DESCSZ  = 4
	ELF_NOTE_NETBSD_TAG     = 1
	ELF_NOTE_NETBSD_VERSION = 599000000 /* NetBSD 5.99 */
)

NetBSD Signature (as per sys/exec_elf.h)

View Source
const (
	ELF_NOTE_OPENBSD_NAMESZ  = 8
	ELF_NOTE_OPENBSD_DESCSZ  = 4
	ELF_NOTE_OPENBSD_TAG     = 1
	ELF_NOTE_OPENBSD_VERSION = 0
)

OpenBSD Signature

View Source
const (
	ELF_NOTE_BUILDINFO_NAMESZ = 4
	ELF_NOTE_BUILDINFO_TAG    = 3
)

Build info note

View Source
const (
	ELF_NOTE_GOPKGLIST_TAG = 1
	ELF_NOTE_GOABIHASH_TAG = 2
	ELF_NOTE_GODEPS_TAG    = 3
	ELF_NOTE_GOBUILDID_TAG = 4
)

Go specific notes

View Source
const (
	FileObj = 0 + iota
	ArchiveObj
	Pkgdef
)

whence for ldpkg

View Source
const (
	// see also http://9p.io/magic/man2html/1/nm
	TextSym      SymbolType = 'T'
	DataSym                 = 'D'
	BSSSym                  = 'B'
	UndefinedSym            = 'U'
	TLSSym                  = 't'
	FrameSym                = 'm'
	ParamSym                = 'p'
	AutoSym                 = 'a'

	// Deleted auto (not a real sym, just placeholder for type)
	DeletedAutoSym = 'x'
)
View Source
const (
	MACHO_CPU_AMD64               = 1<<24 | 7
	MACHO_CPU_386                 = 7
	MACHO_SUBCPU_X86              = 3
	MACHO_CPU_ARM                 = 12
	MACHO_SUBCPU_ARM              = 0
	MACHO_SUBCPU_ARMV7            = 9
	MACHO_CPU_ARM64               = 1<<24 | 12
	MACHO_SUBCPU_ARM64_ALL        = 0
	MACHO32SYMSIZE                = 12
	MACHO64SYMSIZE                = 16
	MACHO_X86_64_RELOC_UNSIGNED   = 0
	MACHO_X86_64_RELOC_SIGNED     = 1
	MACHO_X86_64_RELOC_BRANCH     = 2
	MACHO_X86_64_RELOC_GOT_LOAD   = 3
	MACHO_X86_64_RELOC_GOT        = 4
	MACHO_X86_64_RELOC_SUBTRACTOR = 5
	MACHO_X86_64_RELOC_SIGNED_1   = 6
	MACHO_X86_64_RELOC_SIGNED_2   = 7
	MACHO_X86_64_RELOC_SIGNED_4   = 8
	MACHO_ARM_RELOC_VANILLA       = 0
	MACHO_ARM_RELOC_PAIR          = 1
	MACHO_ARM_RELOC_SECTDIFF      = 2
	MACHO_ARM_RELOC_BR24          = 5
	MACHO_ARM64_RELOC_UNSIGNED    = 0
	MACHO_ARM64_RELOC_BRANCH26    = 2
	MACHO_ARM64_RELOC_PAGE21      = 3
	MACHO_ARM64_RELOC_PAGEOFF12   = 4
	MACHO_ARM64_RELOC_ADDEND      = 10
	MACHO_GENERIC_RELOC_VANILLA   = 0
	MACHO_FAKE_GOTPCREL           = 100
)
View Source
const (
	MH_MAGIC    = 0xfeedface
	MH_MAGIC_64 = 0xfeedfacf

	MH_OBJECT  = 0x1
	MH_EXECUTE = 0x2

	MH_NOUNDEFS = 0x1
)
View Source
const (
	LC_SEGMENT              = 0x1
	LC_SYMTAB               = 0x2
	LC_UNIXTHREAD           = 0x5
	LC_DYSYMTAB             = 0xb
	LC_LOAD_DYLIB           = 0xc
	LC_ID_DYLIB             = 0xd
	LC_LOAD_DYLINKER        = 0xe
	LC_PREBOUND_DYLIB       = 0x10
	LC_LOAD_WEAK_DYLIB      = 0x18
	LC_SEGMENT_64           = 0x19
	LC_UUID                 = 0x1b
	LC_RPATH                = 0x8000001c
	LC_CODE_SIGNATURE       = 0x1d
	LC_SEGMENT_SPLIT_INFO   = 0x1e
	LC_REEXPORT_DYLIB       = 0x8000001f
	LC_ENCRYPTION_INFO      = 0x21
	LC_DYLD_INFO            = 0x22
	LC_DYLD_INFO_ONLY       = 0x80000022
	LC_VERSION_MIN_MACOSX   = 0x24
	LC_VERSION_MIN_IPHONEOS = 0x25
	LC_FUNCTION_STARTS      = 0x26
	LC_MAIN                 = 0x80000028
	LC_DATA_IN_CODE         = 0x29
	LC_SOURCE_VERSION       = 0x2A
	LC_DYLIB_CODE_SIGN_DRS  = 0x2B
	LC_ENCRYPTION_INFO_64   = 0x2C
)
View Source
const (
	S_REGULAR                  = 0x0
	S_ZEROFILL                 = 0x1
	S_NON_LAZY_SYMBOL_POINTERS = 0x6
	S_SYMBOL_STUBS             = 0x8
	S_MOD_INIT_FUNC_POINTERS   = 0x9
	S_ATTR_PURE_INSTRUCTIONS   = 0x80000000
	S_ATTR_DEBUG               = 0x02000000
	S_ATTR_SOME_INSTRUCTIONS   = 0x00000400
)
View Source
const (
	SymKindLocal = 0 + iota
	SymKindExtdef
	SymKindUndef
	NumSymKind
)
View Source
const (
	BUCKETSIZE    = 256 * MINFUNC
	SUBBUCKETS    = 16
	SUBBUCKETSIZE = BUCKETSIZE / SUBBUCKETS
	NOIDX         = 0x7fffffff
)
View Source
const (
	IMAGE_FILE_MACHINE_I386              = 0x14c
	IMAGE_FILE_MACHINE_AMD64             = 0x8664
	IMAGE_FILE_RELOCS_STRIPPED           = 0x0001
	IMAGE_FILE_EXECUTABLE_IMAGE          = 0x0002
	IMAGE_FILE_LINE_NUMS_STRIPPED        = 0x0004
	IMAGE_FILE_LARGE_ADDRESS_AWARE       = 0x0020
	IMAGE_FILE_32BIT_MACHINE             = 0x0100
	IMAGE_FILE_DEBUG_STRIPPED            = 0x0200
	IMAGE_SCN_CNT_CODE                   = 0x00000020
	IMAGE_SCN_CNT_INITIALIZED_DATA       = 0x00000040
	IMAGE_SCN_CNT_UNINITIALIZED_DATA     = 0x00000080
	IMAGE_SCN_MEM_EXECUTE                = 0x20000000
	IMAGE_SCN_MEM_READ                   = 0x40000000
	IMAGE_SCN_MEM_WRITE                  = 0x80000000
	IMAGE_SCN_MEM_DISCARDABLE            = 0x2000000
	IMAGE_SCN_LNK_NRELOC_OVFL            = 0x1000000
	IMAGE_SCN_ALIGN_32BYTES              = 0x600000
	IMAGE_DIRECTORY_ENTRY_EXPORT         = 0
	IMAGE_DIRECTORY_ENTRY_IMPORT         = 1
	IMAGE_DIRECTORY_ENTRY_RESOURCE       = 2
	IMAGE_DIRECTORY_ENTRY_EXCEPTION      = 3
	IMAGE_DIRECTORY_ENTRY_SECURITY       = 4
	IMAGE_DIRECTORY_ENTRY_BASERELOC      = 5
	IMAGE_DIRECTORY_ENTRY_DEBUG          = 6
	IMAGE_DIRECTORY_ENTRY_COPYRIGHT      = 7
	IMAGE_DIRECTORY_ENTRY_ARCHITECTURE   = 7
	IMAGE_DIRECTORY_ENTRY_GLOBALPTR      = 8
	IMAGE_DIRECTORY_ENTRY_TLS            = 9
	IMAGE_DIRECTORY_ENTRY_LOAD_CONFIG    = 10
	IMAGE_DIRECTORY_ENTRY_BOUND_IMPORT   = 11
	IMAGE_DIRECTORY_ENTRY_IAT            = 12
	IMAGE_DIRECTORY_ENTRY_DELAY_IMPORT   = 13
	IMAGE_DIRECTORY_ENTRY_COM_DESCRIPTOR = 14
	IMAGE_SUBSYSTEM_WINDOWS_GUI          = 2
	IMAGE_SUBSYSTEM_WINDOWS_CUI          = 3
)
View Source
const (
	// TODO: the Microsoft doco says IMAGE_SYM_DTYPE_ARRAY is 3 and IMAGE_SYM_DTYPE_FUNCTION is 2
	IMAGE_SYM_TYPE_NULL      = 0
	IMAGE_SYM_TYPE_STRUCT    = 8
	IMAGE_SYM_DTYPE_FUNCTION = 0x20
	IMAGE_SYM_DTYPE_ARRAY    = 0x30
	IMAGE_SYM_CLASS_EXTERNAL = 2
	IMAGE_SYM_CLASS_STATIC   = 3

	IMAGE_REL_I386_DIR32  = 0x0006
	IMAGE_REL_I386_SECREL = 0x000B
	IMAGE_REL_I386_REL32  = 0x0014

	IMAGE_REL_AMD64_ADDR64 = 0x0001
	IMAGE_REL_AMD64_ADDR32 = 0x0002
	IMAGE_REL_AMD64_REL32  = 0x0004
	IMAGE_REL_AMD64_SECREL = 0x000B
)

TODO(crawshaw): add these constants to debug/pe.

View Source
const (
	ARMAG = "!<arch>\n"
)
View Source
const (
	ARM_MAGIC_TRAMP_NUMBER = 0x5c000003
)

* Relocation types.

View Source
const (
	COMPUNITHEADERSIZE = 4 + 2 + 4 + 1
)

* Walk DWarfDebugInfoEntries, and emit .debug_info

View Source
const (
	ELFRESERVE = 4096
)

* Total amount of space to reserve at the start of the file * for Header, PHeaders, SHeaders, and interp. * May waste some. * On FreeBSD, cannot be larger than a page.

View Source
const (
	INITIAL_MACHO_HEADR = 4 * 1024
)

* Total amount of space to reserve at the start of the file * for Header, PHeaders, and SHeaders. * May waste some.

View Source
const (
	MINFUNC = 16 // minimum size for a function
)
View Source
const (
	NSECT = 400
)

* We use the 64-bit data structures on both 32- and 64-bit machines * in order to write the code just once. The 64-bit data structure is * written in the 32-bit format on the 32-bit machines.

View Source
const (
	PEBASE = 0x00400000
)

Variables

View Source
var (
	Thearch Arch
	Lcsize  int32

	Spsize  int32
	Symsize int32
)
View Source
var (
	Funcalign int

	HEADR int32
)
View Source
var (
	Segtext      sym.Segment
	Segrodata    sym.Segment
	Segrelrodata sym.Segment
	Segdata      sym.Segment
	Segdwarf     sym.Segment
)
View Source
var (
	FlagC = flag.Bool("c", false, "dump call graph")
	FlagD = flag.Bool("d", false, "disable dynamic executable")

	FlagS = flag.Bool("s", false, "disable symbol table")

	FlagW = flag.Bool("w", false, "disable DWARF generation")
	Flag8 bool // use 64-bit addresses in symbol table

	FlagDebugTramp = flag.Int("debugtramp", 0, "debug trampolines")

	FlagRound    = flag.Int("R", -1, "set address rounding `quantum`")
	FlagTextAddr = flag.Int64("T", -1, "set text segment `address`")
	FlagDataAddr = flag.Int64("D", -1, "set data segment `address`")
)

Flags used by the linker. The exported flags are used by the architecture-specific packages.

View Source
var (
	// SectionAlignment must be greater than or equal to FileAlignment.
	// The default is the page size for the architecture.
	PESECTALIGN int64 = 0x1000

	// FileAlignment should be a power of 2 between 512 and 64 K, inclusive.
	// The default is 512. If the SectionAlignment is less than
	// the architecture's page size, then FileAlignment must match SectionAlignment.
	PEFILEALIGN int64 = 2 << 8
)
View Source
var (
	PESECTHEADR int32
	PEFILEHEADR int32
)
View Source
var ELF_NOTE_BUILDINFO_NAME = []byte("GNU\x00")
View Source
var ELF_NOTE_GO_NAME = []byte("Go\x00\x00")
View Source
var ELF_NOTE_NETBSD_NAME = []byte("NetBSD\x00")
View Source
var ELF_NOTE_OPENBSD_NAME = []byte("OpenBSD\x00")
View Source
var Elfstrdat []byte
View Source
var (
	Nelfsym = 1
)

Functions

func Adddynsym

func Adddynsym(ctxt *Link, s *sym.Symbol)

func Addstring

func Addstring(s *sym.Symbol, str string) int64

func Asmbelf

func Asmbelf(ctxt *Link, symo int64)

func Asmbelfsetup

func Asmbelfsetup()

func Asmbmacho

func Asmbmacho(ctxt *Link)

func Asmbpe

func Asmbpe(ctxt *Link)

func Asmelfsym

func Asmelfsym(ctxt *Link)

func Asmplan9sym

func Asmplan9sym(ctxt *Link)

func AtExit

func AtExit(f func())

func Be16

func Be16(b []byte) uint16

func Be32

func Be32(b []byte) uint32

func Codeblk

func Codeblk(ctxt *Link, addr int64, size int64)

func CodeblkPad

func CodeblkPad(ctxt *Link, addr int64, size int64, pad []byte)

func Cputime

func Cputime() float64

TODO(josharian): delete. See issue 19865.

func Datblk

func Datblk(ctxt *Link, addr int64, size int64)
func Domacholink(ctxt *Link) int64

func Dwarfblk

func Dwarfblk(ctxt *Link, addr int64, size int64)

func ELF32_R_INFO

func ELF32_R_INFO(sym uint32, type_ uint32) uint32

func ELF32_R_SYM

func ELF32_R_SYM(info uint32) uint32

func ELF32_R_TYPE

func ELF32_R_TYPE(info uint32) uint32

func ELF32_ST_BIND

func ELF32_ST_BIND(info uint8) uint8

func ELF32_ST_INFO

func ELF32_ST_INFO(bind uint8, type_ uint8) uint8

func ELF32_ST_TYPE

func ELF32_ST_TYPE(info uint8) uint8

func ELF32_ST_VISIBILITY

func ELF32_ST_VISIBILITY(oth uint8) uint8

func ELF64_R_INFO

func ELF64_R_INFO(sym uint32, type_ uint32) uint64

func ELF64_R_SYM

func ELF64_R_SYM(info uint64) uint32

func ELF64_R_TYPE

func ELF64_R_TYPE(info uint64) uint32

func ELF64_ST_BIND

func ELF64_ST_BIND(info uint8) uint8

func ELF64_ST_INFO

func ELF64_ST_INFO(bind uint8, type_ uint8) uint8

func ELF64_ST_TYPE

func ELF64_ST_TYPE(info uint8) uint8

func ELF64_ST_VISIBILITY

func ELF64_ST_VISIBILITY(oth uint8) uint8

func Elfemitreloc

func Elfemitreloc(ctxt *Link)

func Elfinit

func Elfinit(ctxt *Link)

Initialize the global variable that describes the ELF header. It will be updated as we write section and prog headers.

func Elfwritedynent

func Elfwritedynent(ctxt *Link, s *sym.Symbol, tag int, val uint64)

func Elfwritedynentsymplus

func Elfwritedynentsymplus(ctxt *Link, s *sym.Symbol, tag int, t *sym.Symbol, add int64)

func Entryvalue

func Entryvalue(ctxt *Link) int64

func Errorf

func Errorf(s *sym.Symbol, format string, args ...interface{})

Errorf logs an error message.

If more than 20 errors have been printed, exit with an error.

Logging an error means that on exit cmd/link will delete any output file and return a non-zero error code.

func Exit

func Exit(code int)

Exit exits with code after executing all atExitFuncs.

func Exitf

func Exitf(format string, a ...interface{})

Exitf logs an error message then calls Exit(2).

func Le16

func Le16(b []byte) uint16

func Le32

func Le32(b []byte) uint32

func Le64

func Le64(b []byte) uint64

func Lflag

func Lflag(ctxt *Link, arg string)

func Machoemitreloc

func Machoemitreloc(ctxt *Link)

func Main

func Main(arch *sys.Arch, theArch Arch)

Main is the main entry point for the linker code.

func Peinit

func Peinit(ctxt *Link)

func Rnd

func Rnd(v int64, r int64) int64

func Symaddr

func Symaddr(s *sym.Symbol) int64

Types

type ArHdr

type ArHdr struct {
	// contains filtered or unexported fields
}

type Arch

type Arch struct {
	Funcalign        int
	Maxalign         int
	Minalign         int
	Dwarfregsp       int
	Dwarfreglr       int
	Linuxdynld       string
	Freebsddynld     string
	Netbsddynld      string
	Openbsddynld     string
	Dragonflydynld   string
	Solarisdynld     string
	Adddynrel        func(*Link, *sym.Symbol, *sym.Reloc) bool
	Archinit         func(*Link)
	Archreloc        func(*Link, *sym.Reloc, *sym.Symbol, *int64) bool
	Archrelocvariant func(*Link, *sym.Reloc, *sym.Symbol, int64) int64
	Trampoline       func(*Link, *sym.Reloc, *sym.Symbol)
	Asmb             func(*Link)
	Elfreloc1        func(*Link, *sym.Reloc, int64) bool
	Elfsetupplt      func(*Link)
	Gentext          func(*Link)
	Machoreloc1      func(*sys.Arch, *OutBuf, *sym.Symbol, *sym.Reloc, int64) bool
	PEreloc1         func(*sys.Arch, *OutBuf, *sym.Symbol, *sym.Reloc, int64) bool

	// TLSIEtoLE converts a TLS Initial Executable relocation to
	// a TLS Local Executable relocation.
	//
	// This is possible when a TLS IE relocation refers to a local
	// symbol in an executable, which is typical when internally
	// linking PIE binaries.
	TLSIEtoLE func(s *sym.Symbol, off, size int)
}

type BuildMode

type BuildMode uint8

A BuildMode indicates the sort of object we are building.

Possible build modes are the same as those for the -buildmode flag in cmd/go, and are documented in 'go help buildmode'.

const (
	BuildModeUnset BuildMode = iota
	BuildModeExe
	BuildModePIE
	BuildModeCArchive
	BuildModeCShared
	BuildModeShared
	BuildModePlugin
)

func (*BuildMode) Set

func (mode *BuildMode) Set(s string) error

func (*BuildMode) String

func (mode *BuildMode) String() string

type Dll

type Dll struct {
	// contains filtered or unexported fields
}

type ElfEhdr

type ElfEhdr struct {
	// contains filtered or unexported fields
}

* ELF header.

type ElfPhdr

type ElfPhdr struct {
	// contains filtered or unexported fields
}

* Program header.

type ElfShdr

type ElfShdr struct {
	// contains filtered or unexported fields
}

* Section header.

type Elfaux

type Elfaux struct {
	// contains filtered or unexported fields
}

type Elflib

type Elflib struct {
	// contains filtered or unexported fields
}

type Elfstring

type Elfstring struct {
	// contains filtered or unexported fields
}

type GCProg

type GCProg struct {
	// contains filtered or unexported fields
}

func (*GCProg) AddSym

func (p *GCProg) AddSym(s *sym.Symbol)

func (*GCProg) End

func (p *GCProg) End(size int64)

func (*GCProg) Init

func (p *GCProg) Init(ctxt *Link, name string)

type Hostobj

type Hostobj struct {
	// contains filtered or unexported fields
}

type IMAGE_EXPORT_DIRECTORY

type IMAGE_EXPORT_DIRECTORY struct {
	Characteristics       uint32
	TimeDateStamp         uint32
	MajorVersion          uint16
	MinorVersion          uint16
	Name                  uint32
	Base                  uint32
	NumberOfFunctions     uint32
	NumberOfNames         uint32
	AddressOfFunctions    uint32
	AddressOfNames        uint32
	AddressOfNameOrdinals uint32
}

type IMAGE_IMPORT_DESCRIPTOR

type IMAGE_IMPORT_DESCRIPTOR struct {
	OriginalFirstThunk uint32
	TimeDateStamp      uint32
	ForwarderChain     uint32
	Name               uint32
	FirstThunk         uint32
}

type Imp

type Imp struct {
	// contains filtered or unexported fields
}
type Link struct {
	Out *OutBuf

	Syms *sym.Symbols

	Arch      *sys.Arch
	Debugvlog int
	Bso       *bufio.Writer

	Loaded bool // set after all inputs have been loaded as symbols

	IsELF    bool
	HeadType objabi.HeadType

	LinkMode  LinkMode
	BuildMode BuildMode

	Tlsg         *sym.Symbol
	Libdir       []string
	Library      []*sym.Library
	LibraryByPkg map[string]*sym.Library
	Shlibs       []Shlib
	Tlsoffset    int
	Textp        []*sym.Symbol
	Filesyms     []*sym.Symbol
	Moduledata   *sym.Symbol

	PackageFile  map[string]string
	PackageShlib map[string]string
	// contains filtered or unexported fields
}

Link holds the context for writing object code from a compiler or for reading that input into the linker.

func (*Link) AddTramp

func (ctxt *Link) AddTramp(s *sym.Symbol)

add a trampoline with symbol s (to be laid down after the current function)

func (*Link) CanUsePlugins

func (ctxt *Link) CanUsePlugins() bool

CanUsePlugins returns whether a plugins can be used

func (*Link) DynlinkingGo

func (ctxt *Link) DynlinkingGo() bool

DynlinkingGo returns whether we are producing Go code that can live in separate shared libraries linked together at runtime.

func (*Link) FixedFrameSize

func (ctxt *Link) FixedFrameSize() int64

The smallest possible offset from the hardware stack pointer to a local variable on the stack. Architectures that use a link register save its value on the stack in the function prologue and so always have a pointer between the hardware stack pointer and the local variable area.

func (*Link) Logf

func (ctxt *Link) Logf(format string, args ...interface{})

func (*Link) UseRelro

func (ctxt *Link) UseRelro() bool

UseRelro returns whether to make use of "read only relocations" aka relro.

type LinkMode

type LinkMode uint8

LinkMode indicates whether an external linker is used for the final link.

const (
	LinkAuto LinkMode = iota
	LinkInternal
	LinkExternal
)

func (*LinkMode) Set

func (mode *LinkMode) Set(s string) error

func (*LinkMode) String

func (mode *LinkMode) String() string

type MachoHdr

type MachoHdr struct {
	// contains filtered or unexported fields
}

type MachoLoad

type MachoLoad struct {
	// contains filtered or unexported fields
}

type MachoSect

type MachoSect struct {
	// contains filtered or unexported fields
}

type MachoSeg

type MachoSeg struct {
	// contains filtered or unexported fields
}

type OutBuf

type OutBuf struct {
	// contains filtered or unexported fields
}

OutBuf is a buffered file writer.

It is simlar to the Writer in cmd/internal/bio with a few small differences.

First, it tracks the output architecture and uses it to provide endian helpers.

Second, it provides a very cheap offset counter that doesn't require any system calls to read the value.

func (*OutBuf) Flush

func (out *OutBuf) Flush()

func (*OutBuf) Offset

func (out *OutBuf) Offset() int64

func (*OutBuf) SeekSet

func (out *OutBuf) SeekSet(p int64)

func (*OutBuf) Write

func (out *OutBuf) Write(v []byte) (int, error)

Write writes the contents of v to the buffer.

As Write is backed by a bufio.Writer, callers do not have to explicitly handle the returned error as long as Flush is eventually called.

func (*OutBuf) Write16

func (out *OutBuf) Write16(v uint16)

func (*OutBuf) Write32

func (out *OutBuf) Write32(v uint32)

func (*OutBuf) Write32b

func (out *OutBuf) Write32b(v uint32)

func (*OutBuf) Write64

func (out *OutBuf) Write64(v uint64)

func (*OutBuf) Write64b

func (out *OutBuf) Write64b(v uint64)

func (*OutBuf) Write8

func (out *OutBuf) Write8(v uint8)

func (*OutBuf) WriteString

func (out *OutBuf) WriteString(s string)

func (*OutBuf) WriteStringN

func (out *OutBuf) WriteStringN(s string, n int)

WriteStringN writes the first n bytes of s. If n is larger than len(s) then it is padded with zero bytes.

func (*OutBuf) WriteStringPad

func (out *OutBuf) WriteStringPad(s string, n int, pad []byte)

WriteStringPad writes the first n bytes of s. If n is larger than len(s) then it is padded with the bytes in pad (repeated as needed).

type Pciter

type Pciter struct {
	// contains filtered or unexported fields
}

type Pkg

type Pkg struct {
	// contains filtered or unexported fields
}

type Rpath

type Rpath struct {
	// contains filtered or unexported fields
}

func (*Rpath) Set

func (r *Rpath) Set(val string) error

func (*Rpath) String

func (r *Rpath) String() string

type Shlib

type Shlib struct {
	Path string
	Hash []byte
	Deps []string
	File *elf.File
	// contains filtered or unexported fields
}

type SymbolType

type SymbolType int8

Jump to

Keyboard shortcuts

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