ld

package
v0.9.2202 Latest Latest
Warning

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

Go to latest
Published: Apr 21, 2024 License: BSD-3-Clause Imports: 53 Imported by: 0

Documentation

Index

Constants

View Source
const (
	SARMAG  = 8
	SAR_HDR = 16 + 44
)
View Source
const (
	GdbScriptPythonFileId = 1
	GdbScriptSchemeFileId = 3
	GdbScriptPythonTextId = 4
	GdbScriptSchemeTextId = 6
)

https://sourceware.org/gdb/onlinedocs/gdb/dotdebug_005fgdb_005fscripts-section.html Each entry inside .debug_gdb_scripts section begins with a non-null prefix byte that specifies the kind of entry. The following entries are supported:

View Source
const (
	MaxKeySize = abi.MapMaxKeyBytes
	MaxValSize = abi.MapMaxElemBytes
	BucketSize = abi.MapBucketCount
)

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 = 11
)

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

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 (
	// No floating point is present in the module (default)
	MIPS_FPABI_NONE = 0
	// FP code in the module uses the FP32 ABI for a 32-bit ABI
	MIPS_FPABI_ANY = 1
	// FP code in the module only uses single precision ABI
	MIPS_FPABI_SINGLE = 2
	// FP code in the module uses soft-float ABI
	MIPS_FPABI_SOFT = 3
	// FP code in the module assumes an FPU with FR=1 and has 12
	// callee-saved doubles. Historic, no longer supported.
	MIPS_FPABI_HIST = 4
	// FP code in the module uses the FPXX  ABI
	MIPS_FPABI_FPXX = 5
	// FP code in the module uses the FP64  ABI
	MIPS_FPABI_FP64 = 6
	// FP code in the module uses the FP64A ABI
	MIPS_FPABI_FP64A = 7
)

member of .gnu.attributes of MIPS for fpAbi

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

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_FREEBSD_NAMESZ            = 8
	ELF_NOTE_FREEBSD_DESCSZ            = 4
	ELF_NOTE_FREEBSD_ABI_TAG           = 1
	ELF_NOTE_FREEBSD_NOINIT_TAG        = 2
	ELF_NOTE_FREEBSD_FEATURE_CTL_TAG   = 4
	ELF_NOTE_FREEBSD_VERSION           = 1203000 // 12.3-RELEASE
	ELF_NOTE_FREEBSD_FCTL_ASLR_DISABLE = 0x1
)

FreeBSD Signature (as per sys/elf_common.h)

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 (
	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
	MACHO_SUBCPU_ARM64_V8                = 1
	MACHO_SUBCPU_ARM64E                  = 2
	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_GOT_LOAD_PAGE21    = 5
	MACHO_ARM64_RELOC_GOT_LOAD_PAGEOFF12 = 6
	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
	MH_DYLDLINK = 0x4
	MH_PIE      = 0x200000
)
View Source
const (
	LC_SEGMENT                  = 0x1
	LC_SYMTAB                   = 0x2
	LC_SYMSEG                   = 0x3
	LC_THREAD                   = 0x4
	LC_UNIXTHREAD               = 0x5
	LC_LOADFVMLIB               = 0x6
	LC_IDFVMLIB                 = 0x7
	LC_IDENT                    = 0x8
	LC_FVMFILE                  = 0x9
	LC_PREPAGE                  = 0xa
	LC_DYSYMTAB                 = 0xb
	LC_LOAD_DYLIB               = 0xc
	LC_ID_DYLIB                 = 0xd
	LC_LOAD_DYLINKER            = 0xe
	LC_ID_DYLINKER              = 0xf
	LC_PREBOUND_DYLIB           = 0x10
	LC_ROUTINES                 = 0x11
	LC_SUB_FRAMEWORK            = 0x12
	LC_SUB_UMBRELLA             = 0x13
	LC_SUB_CLIENT               = 0x14
	LC_SUB_LIBRARY              = 0x15
	LC_TWOLEVEL_HINTS           = 0x16
	LC_PREBIND_CKSUM            = 0x17
	LC_LOAD_WEAK_DYLIB          = 0x80000018
	LC_SEGMENT_64               = 0x19
	LC_ROUTINES_64              = 0x1a
	LC_UUID                     = 0x1b
	LC_RPATH                    = 0x8000001c
	LC_CODE_SIGNATURE           = 0x1d
	LC_SEGMENT_SPLIT_INFO       = 0x1e
	LC_REEXPORT_DYLIB           = 0x8000001f
	LC_LAZY_LOAD_DYLIB          = 0x20
	LC_ENCRYPTION_INFO          = 0x21
	LC_DYLD_INFO                = 0x22
	LC_DYLD_INFO_ONLY           = 0x80000022
	LC_LOAD_UPWARD_DYLIB        = 0x80000023
	LC_VERSION_MIN_MACOSX       = 0x24
	LC_VERSION_MIN_IPHONEOS     = 0x25
	LC_FUNCTION_STARTS          = 0x26
	LC_DYLD_ENVIRONMENT         = 0x27
	LC_MAIN                     = 0x80000028
	LC_DATA_IN_CODE             = 0x29
	LC_SOURCE_VERSION           = 0x2A
	LC_DYLIB_CODE_SIGN_DRS      = 0x2B
	LC_ENCRYPTION_INFO_64       = 0x2C
	LC_LINKER_OPTION            = 0x2D
	LC_LINKER_OPTIMIZATION_HINT = 0x2E
	LC_VERSION_MIN_TVOS         = 0x2F
	LC_VERSION_MIN_WATCHOS      = 0x30
	LC_VERSION_NOTE             = 0x31
	LC_BUILD_VERSION            = 0x32
	LC_DYLD_EXPORTS_TRIE        = 0x80000033
	LC_DYLD_CHAINED_FIXUPS      = 0x80000034
)
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 (
	REBASE_TYPE_POINTER         = 1
	REBASE_TYPE_TEXT_ABSOLUTE32 = 2
	REBASE_TYPE_TEXT_PCREL32    = 3

	REBASE_OPCODE_MASK                               = 0xF0
	REBASE_IMMEDIATE_MASK                            = 0x0F
	REBASE_OPCODE_DONE                               = 0x00
	REBASE_OPCODE_SET_TYPE_IMM                       = 0x10
	REBASE_OPCODE_SET_SEGMENT_AND_OFFSET_ULEB        = 0x20
	REBASE_OPCODE_ADD_ADDR_ULEB                      = 0x30
	REBASE_OPCODE_ADD_ADDR_IMM_SCALED                = 0x40
	REBASE_OPCODE_DO_REBASE_IMM_TIMES                = 0x50
	REBASE_OPCODE_DO_REBASE_ULEB_TIMES               = 0x60
	REBASE_OPCODE_DO_REBASE_ADD_ADDR_ULEB            = 0x70
	REBASE_OPCODE_DO_REBASE_ULEB_TIMES_SKIPPING_ULEB = 0x80
)

rebase table opcode

View Source
const (
	BIND_TYPE_POINTER         = 1
	BIND_TYPE_TEXT_ABSOLUTE32 = 2
	BIND_TYPE_TEXT_PCREL32    = 3

	BIND_SPECIAL_DYLIB_SELF            = 0
	BIND_SPECIAL_DYLIB_MAIN_EXECUTABLE = -1
	BIND_SPECIAL_DYLIB_FLAT_LOOKUP     = -2
	BIND_SPECIAL_DYLIB_WEAK_LOOKUP     = -3

	BIND_OPCODE_MASK                                         = 0xF0
	BIND_IMMEDIATE_MASK                                      = 0x0F
	BIND_OPCODE_DONE                                         = 0x00
	BIND_OPCODE_SET_DYLIB_ORDINAL_IMM                        = 0x10
	BIND_OPCODE_SET_DYLIB_ORDINAL_ULEB                       = 0x20
	BIND_OPCODE_SET_DYLIB_SPECIAL_IMM                        = 0x30
	BIND_OPCODE_SET_SYMBOL_TRAILING_FLAGS_IMM                = 0x40
	BIND_OPCODE_SET_TYPE_IMM                                 = 0x50
	BIND_OPCODE_SET_ADDEND_SLEB                              = 0x60
	BIND_OPCODE_SET_SEGMENT_AND_OFFSET_ULEB                  = 0x70
	BIND_OPCODE_ADD_ADDR_ULEB                                = 0x80
	BIND_OPCODE_DO_BIND                                      = 0x90
	BIND_OPCODE_DO_BIND_ADD_ADDR_ULEB                        = 0xA0
	BIND_OPCODE_DO_BIND_ADD_ADDR_IMM_SCALED                  = 0xB0
	BIND_OPCODE_DO_BIND_ULEB_TIMES_SKIPPING_ULEB             = 0xC0
	BIND_OPCODE_THREADED                                     = 0xD0
	BIND_SUBOPCODE_THREADED_SET_BIND_ORDINAL_TABLE_SIZE_ULEB = 0x00
	BIND_SUBOPCODE_THREADED_APPLY                            = 0x01
)

bind table opcode

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_SCN_CNT_CODE               = 0x00000020
	IMAGE_SCN_CNT_INITIALIZED_DATA   = 0x00000040
	IMAGE_SCN_CNT_UNINITIALIZED_DATA = 0x00000080
	IMAGE_SCN_LNK_OTHER              = 0x00000100
	IMAGE_SCN_LNK_INFO               = 0x00000200
	IMAGE_SCN_LNK_REMOVE             = 0x00000800
	IMAGE_SCN_LNK_COMDAT             = 0x00001000
	IMAGE_SCN_GPREL                  = 0x00008000
	IMAGE_SCN_MEM_PURGEABLE          = 0x00020000
	IMAGE_SCN_MEM_16BIT              = 0x00020000
	IMAGE_SCN_MEM_LOCKED             = 0x00040000
	IMAGE_SCN_MEM_PRELOAD            = 0x00080000
	IMAGE_SCN_ALIGN_1BYTES           = 0x00100000
	IMAGE_SCN_ALIGN_2BYTES           = 0x00200000
	IMAGE_SCN_ALIGN_4BYTES           = 0x00300000
	IMAGE_SCN_ALIGN_8BYTES           = 0x00400000
	IMAGE_SCN_ALIGN_16BYTES          = 0x00500000
	IMAGE_SCN_ALIGN_32BYTES          = 0x00600000
	IMAGE_SCN_ALIGN_64BYTES          = 0x00700000
	IMAGE_SCN_ALIGN_128BYTES         = 0x00800000
	IMAGE_SCN_ALIGN_256BYTES         = 0x00900000
	IMAGE_SCN_ALIGN_512BYTES         = 0x00A00000
	IMAGE_SCN_ALIGN_1024BYTES        = 0x00B00000
	IMAGE_SCN_ALIGN_2048BYTES        = 0x00C00000
	IMAGE_SCN_ALIGN_4096BYTES        = 0x00D00000
	IMAGE_SCN_ALIGN_8192BYTES        = 0x00E00000
	IMAGE_SCN_LNK_NRELOC_OVFL        = 0x01000000
	IMAGE_SCN_MEM_DISCARDABLE        = 0x02000000
	IMAGE_SCN_MEM_NOT_CACHED         = 0x04000000
	IMAGE_SCN_MEM_NOT_PAGED          = 0x08000000
	IMAGE_SCN_MEM_SHARED             = 0x10000000
	IMAGE_SCN_MEM_EXECUTE            = 0x20000000
	IMAGE_SCN_MEM_READ               = 0x40000000
	IMAGE_SCN_MEM_WRITE              = 0x80000000
)
View Source
const (
	IMAGE_SYM_TYPE_NULL      = 0
	IMAGE_SYM_TYPE_STRUCT    = 8
	IMAGE_SYM_DTYPE_FUNCTION = 2
	IMAGE_SYM_DTYPE_ARRAY    = 3
	IMAGE_SYM_CLASS_EXTERNAL = 2
	IMAGE_SYM_CLASS_STATIC   = 3

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

	IMAGE_REL_AMD64_ADDR64   = 0x0001
	IMAGE_REL_AMD64_ADDR32   = 0x0002
	IMAGE_REL_AMD64_ADDR32NB = 0x0003
	IMAGE_REL_AMD64_REL32    = 0x0004
	IMAGE_REL_AMD64_SECREL   = 0x000B

	IMAGE_REL_ARM_ABSOLUTE = 0x0000
	IMAGE_REL_ARM_ADDR32   = 0x0001
	IMAGE_REL_ARM_ADDR32NB = 0x0002
	IMAGE_REL_ARM_BRANCH24 = 0x0003
	IMAGE_REL_ARM_BRANCH11 = 0x0004
	IMAGE_REL_ARM_SECREL   = 0x000F

	IMAGE_REL_ARM64_ABSOLUTE       = 0x0000
	IMAGE_REL_ARM64_ADDR32         = 0x0001
	IMAGE_REL_ARM64_ADDR32NB       = 0x0002
	IMAGE_REL_ARM64_BRANCH26       = 0x0003
	IMAGE_REL_ARM64_PAGEBASE_REL21 = 0x0004
	IMAGE_REL_ARM64_REL21          = 0x0005
	IMAGE_REL_ARM64_PAGEOFFSET_12A = 0x0006
	IMAGE_REL_ARM64_PAGEOFFSET_12L = 0x0007
	IMAGE_REL_ARM64_SECREL         = 0x0008
	IMAGE_REL_ARM64_SECREL_LOW12A  = 0x0009
	IMAGE_REL_ARM64_SECREL_HIGH12A = 0x000A
	IMAGE_REL_ARM64_SECREL_LOW12L  = 0x000B
	IMAGE_REL_ARM64_TOKEN          = 0x000C
	IMAGE_REL_ARM64_SECTION        = 0x000D
	IMAGE_REL_ARM64_ADDR64         = 0x000E
	IMAGE_REL_ARM64_BRANCH19       = 0x000F
	IMAGE_REL_ARM64_BRANCH14       = 0x0010
	IMAGE_REL_ARM64_REL32          = 0x0011

	IMAGE_REL_BASED_HIGHLOW = 3
	IMAGE_REL_BASED_DIR64   = 10
)

See https://docs.microsoft.com/en-us/windows/win32/debug/pe-format. TODO(crawshaw): add these constants to debug/pe.

View Source
const (
	PeMinimumTargetMajorVersion = 6
	PeMinimumTargetMinorVersion = 1
)
View Source
const (
	// Total amount of space to reserve at the start of the file
	// for File Header, Auxiliary Header, and Section Headers.
	// May waste some.
	XCOFFHDRRESERVE = FILHSZ_64 + AOUTHSZ_EXEC64 + SCNHSZ_64*23

	// base on dump -o, then rounded from 32B to 64B to
	// match worst case elf text section alignment on ppc64.
	XCOFFSECTALIGN int64 = 64

	// XCOFF binaries should normally have all its sections position-independent.
	// However, this is not yet possible for .text because of some R_ADDR relocations
	// inside RODATA symbols.
	// .data and .bss are position-independent so their address start inside an unreachable
	// segment during execution to force segfault if something is wrong.
	XCOFFTEXTBASE = 0x100000000 // Start of text address
	XCOFFDATABASE = 0x200000000 // Start of data address
)
View Source
const (
	F_RELFLG    = 0x0001
	F_EXEC      = 0x0002
	F_LNNO      = 0x0004
	F_FDPR_PROF = 0x0010
	F_FDPR_OPTI = 0x0020
	F_DSA       = 0x0040
	F_VARPG     = 0x0100
	F_DYNLOAD   = 0x1000
	F_SHROBJ    = 0x2000
	F_LOADONLY  = 0x4000
)

Flags that describe the type of the object file.

View Source
const (
	STYP_DWARF  = 0x0010
	STYP_TEXT   = 0x0020
	STYP_DATA   = 0x0040
	STYP_BSS    = 0x0080
	STYP_EXCEPT = 0x0100
	STYP_INFO   = 0x0200
	STYP_TDATA  = 0x0400
	STYP_TBSS   = 0x0800
	STYP_LOADER = 0x1000
	STYP_DEBUG  = 0x2000
	STYP_TYPCHK = 0x4000
	STYP_OVRFLO = 0x8000
)

Flags defining the section type.

View Source
const (
	SSUBTYP_DWINFO  = 0x10000 // DWARF info section
	SSUBTYP_DWLINE  = 0x20000 // DWARF line-number section
	SSUBTYP_DWPBNMS = 0x30000 // DWARF public names section
	SSUBTYP_DWPBTYP = 0x40000 // DWARF public types section
	SSUBTYP_DWARNGE = 0x50000 // DWARF aranges section
	SSUBTYP_DWABREV = 0x60000 // DWARF abbreviation section
	SSUBTYP_DWSTR   = 0x70000 // DWARF strings section
	SSUBTYP_DWRNGES = 0x80000 // DWARF ranges section
	SSUBTYP_DWLOC   = 0x90000 // DWARF location lists section
	SSUBTYP_DWFRAME = 0xA0000 // DWARF frames section
	SSUBTYP_DWMAC   = 0xB0000 // DWARF macros section
)
View Source
const (
	FILHSZ_32      = 20
	FILHSZ_64      = 24
	AOUTHSZ_EXEC32 = 72
	AOUTHSZ_EXEC64 = 120
	SCNHSZ_32      = 40
	SCNHSZ_64      = 72
	LDHDRSZ_32     = 32
	LDHDRSZ_64     = 56
	LDSYMSZ_64     = 24
	RELSZ_64       = 14
)

Headers size

View Source
const (
	// Nscnum
	N_DEBUG = -2
	N_ABS   = -1
	N_UNDEF = 0

	//Ntype
	SYM_V_INTERNAL  = 0x1000
	SYM_V_HIDDEN    = 0x2000
	SYM_V_PROTECTED = 0x3000
	SYM_V_EXPORTED  = 0x4000
	SYM_TYPE_FUNC   = 0x0020 // is function
)
View Source
const (
	C_NULL    = 0   // Symbol table entry marked for deletion
	C_EXT     = 2   // External symbol
	C_STAT    = 3   // Static symbol
	C_BLOCK   = 100 // Beginning or end of inner block
	C_FCN     = 101 // Beginning or end of function
	C_FILE    = 103 // Source file name and compiler information
	C_HIDEXT  = 107 // Unnamed external symbol
	C_BINCL   = 108 // Beginning of include file
	C_EINCL   = 109 // End of include file
	C_WEAKEXT = 111 // Weak external symbol
	C_DWARF   = 112 // DWARF symbol
	C_GSYM    = 128 // Global variable
	C_LSYM    = 129 // Automatic variable allocated on stack
	C_PSYM    = 130 // Argument to subroutine allocated on stack
	C_RSYM    = 131 // Register variable
	C_RPSYM   = 132 // Argument to function or procedure stored in register
	C_STSYM   = 133 // Statically allocated symbol
	C_BCOMM   = 135 // Beginning of common block
	C_ECOML   = 136 // Local member of common block
	C_ECOMM   = 137 // End of common block
	C_DECL    = 140 // Declaration of object
	C_ENTRY   = 141 // Alternate entry
	C_FUN     = 142 // Function or procedure
	C_BSTAT   = 143 // Beginning of static block
	C_ESTAT   = 144 // End of static block
	C_GTLS    = 145 // Global thread-local variable
	C_STTLS   = 146 // Static thread-local variable
)

Storage Class.

View Source
const (
	XFT_FN = 0   // Source File Name
	XFT_CT = 1   // Compile Time Stamp
	XFT_CV = 2   // Compiler Version Number
	XFT_CD = 128 // Compiler Defined Information/

)

Xftype field

View Source
const (
	XTY_ER  = 0    // External reference
	XTY_SD  = 1    // Section definition
	XTY_LD  = 2    // Label definition
	XTY_CM  = 3    // Common csect definition
	XTY_WK  = 0x8  // Weak symbol
	XTY_EXP = 0x10 // Exported symbol
	XTY_ENT = 0x20 // Entry point symbol
	XTY_IMP = 0x40 // Imported symbol
)

Symbol type field.

View Source
const (
	XMC_PR     = 0  // Program code
	XMC_RO     = 1  // Read-only constant
	XMC_DB     = 2  // Debug dictionary table
	XMC_TC     = 3  // TOC entry
	XMC_UA     = 4  // Unclassified
	XMC_RW     = 5  // Read/Write data
	XMC_GL     = 6  // Global linkage
	XMC_XO     = 7  // Extended operation
	XMC_SV     = 8  // 32-bit supervisor call descriptor
	XMC_BS     = 9  // BSS class
	XMC_DS     = 10 // Function descriptor
	XMC_UC     = 11 // Unnamed FORTRAN common
	XMC_TC0    = 15 // TOC anchor
	XMC_TD     = 16 // Scalar data entry in the TOC
	XMC_SV64   = 17 // 64-bit supervisor call descriptor
	XMC_SV3264 = 18 // Supervisor call descriptor for both 32-bit and 64-bit
	XMC_TL     = 20 // Read/Write thread-local data
	XMC_UL     = 21 // Read/Write thread-local data (.tbss)
	XMC_TE     = 22 // TOC entry
)

Storage-mapping class.

View Source
const (
	XCOFF_R_POS = 0x00 // A(sym) Positive Relocation
	XCOFF_R_NEG = 0x01 // -A(sym) Negative Relocation
	XCOFF_R_REL = 0x02 // A(sym-*) Relative to self
	XCOFF_R_TOC = 0x03 // A(sym-TOC) Relative to TOC
	XCOFF_R_TRL = 0x12 // A(sym-TOC) TOC Relative indirect load.

	XCOFF_R_TRLA = 0x13 // A(sym-TOC) TOC Rel load address. modifiable inst
	XCOFF_R_GL   = 0x05 // A(external TOC of sym) Global Linkage
	XCOFF_R_TCL  = 0x06 // A(local TOC of sym) Local object TOC address
	XCOFF_R_RL   = 0x0C // A(sym) Pos indirect load. modifiable instruction
	XCOFF_R_RLA  = 0x0D // A(sym) Pos Load Address. modifiable instruction
	XCOFF_R_REF  = 0x0F // AL0(sym) Non relocating ref. No garbage collect
	XCOFF_R_BA   = 0x08 // A(sym) Branch absolute. Cannot modify instruction
	XCOFF_R_RBA  = 0x18 // A(sym) Branch absolute. modifiable instruction
	XCOFF_R_BR   = 0x0A // A(sym-*) Branch rel to self. non modifiable
	XCOFF_R_RBR  = 0x1A // A(sym-*) Branch rel to self. modifiable instr

	XCOFF_R_TLS    = 0x20 // General-dynamic reference to TLS symbol
	XCOFF_R_TLS_IE = 0x21 // Initial-exec reference to TLS symbol
	XCOFF_R_TLS_LD = 0x22 // Local-dynamic reference to TLS symbol
	XCOFF_R_TLS_LE = 0x23 // Local-exec reference to TLS symbol
	XCOFF_R_TLSM   = 0x24 // Module reference to TLS symbol
	XCOFF_R_TLSML  = 0x25 // Module reference to local (own) module

	XCOFF_R_TOCU = 0x30 // Relative to TOC - high order bits
	XCOFF_R_TOCL = 0x31 // Relative to TOC - low order bits
)
View Source
const (
	ARMAG = "!<arch>\n"
)
View Source
const (
	ARM_MAGIC_TRAMP_NUMBER = 0x5c000003
)

* Relocation types.

View Source
const (
	COMPUNITHEADERSIZE = 4 + 2 + 4 + 1
)
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 ELF_NOTE_FREEBSD_NAME = "FreeBSD\x00"
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 SYMESZ = 18
View Source
const (
	U64_TOCMAGIC = 0767 // AIX 64-bit XCOFF
)

Variables

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
	Segpdata     sym.Segment // windows-only
	Segxdata     sym.Segment // windows-only

	Segments = []*sym.Segment{&Segtext, &Segrodata, &Segrelrodata, &Segdata, &Segdwarf, &Segpdata, &Segxdata}
)
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")

	FlagDebugTramp    = flag.Int("debugtramp", 0, "debug trampolines")
	FlagDebugTextSize = flag.Int("debugtextsize", 0, "debug text section max size")

	FlagStrictDups = flag.Int("strictdups", 0, "sanity check duplicate symbol contents during object file reading (1=warn 2=err).")
	FlagRound      = flag.Int64("R", -1, "set address rounding `quantum`")
	FlagTextAddr   = flag.Int64("T", -1, "set the start address of text symbols")

	FlagW = new(bool) // the -w flag, computed in main from flagW
)

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

View Source
var (
	// PEBASE is the base address for the executable.
	// It is small for 32-bit and large for 64-bit.
	PEBASE int64

	// 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 CarrierSymByType [sym.SXREF]struct {
	Sym  loader.Sym
	Size int64
}

CarrierSymByType tracks carrier symbols and their sizes.

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 (
	Nelfsym = 1
)

Functions

func AddGotSym

func AddGotSym(target *Target, ldr *loader.Loader, syms *ArchSyms, s loader.Sym, elfRelocTyp uint32)

func AddMachoSym

func AddMachoSym(ldr *loader.Loader, s loader.Sym)

AddMachoSym adds s to Mach-O symbol table, used in GenSymLate. Currently only used on ARM64 when external linking.

func AddPELabelSym

func AddPELabelSym(ldr *loader.Loader, s loader.Sym)

func Adddynsym

func Adddynsym(ldr *loader.Loader, target *Target, syms *ArchSyms, s loader.Sym)

func Asmbelfsetup

func Asmbelfsetup()

func AtExit

func AtExit(f func())

func CodeblkPad

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

func DatblkBytes

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

Used only on Wasm for now.

func ElfSymForReloc

func ElfSymForReloc(ctxt *Link, s loader.Sym) int32

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(arch *sys.Arch, s *loader.SymbolBuilder, tag elf.DynTag, val uint64)

func Elfwritedynentsymplus

func Elfwritedynentsymplus(ctxt *Link, s *loader.SymbolBuilder, tag elf.DynTag, t loader.Sym, add int64)

func Entryvalue

func Entryvalue(ctxt *Link) int64

func Errorf

func Errorf(dummy *int, 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.

TODO: remove. Use ctxt.Errorf instead. All remaining calls use nil as first arg.

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 ExtrelocSimple

func ExtrelocSimple(ldr *loader.Loader, r loader.Reloc) loader.ExtReloc

ExtrelocSimple creates a simple external relocation from r, with the same symbol and addend.

func ExtrelocViaOuterSym

func ExtrelocViaOuterSym(ldr *loader.Loader, r loader.Reloc, s loader.Sym) loader.ExtReloc

ExtrelocViaOuterSym creates an external relocation from r targeting the outer symbol and folding the subsymbol's offset into the addend.

func FoldSubSymbolOffset

func FoldSubSymbolOffset(ldr *loader.Loader, s loader.Sym) (loader.Sym, int64)

FoldSubSymbolOffset computes the offset of symbol s to its top-level outer symbol. Returns the top-level symbol and the offset. This is used in generating external relocations.

func Lflag

func Lflag(ctxt *Link, arg string)

func Loaderblk

func Loaderblk(ctxt *Link, off uint64)

Create loader section and returns its size.

func MachoAddBind

func MachoAddBind(off int64, targ loader.Sym)

func MachoAddRebase

func MachoAddRebase(s loader.Sym, off int64)

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 PrepareAddmoduledata

func PrepareAddmoduledata(ctxt *Link) (*loader.SymbolBuilder, loader.Sym)

PrepareAddmoduledata returns a symbol builder that target-specific code can use to build up the linker-generated go.link.addmoduledata function, along with the sym for runtime.addmoduledata itself. If this function is not needed (for example in cases where we're linking a module that contains the runtime) the returned builder will be nil.

func Rnd

func Rnd(v int64, r int64) int64

func Xcoffadddynrel

func Xcoffadddynrel(target *Target, ldr *loader.Loader, syms *ArchSyms, s loader.Sym, r loader.Reloc, rIdx int) bool

Xcoffadddynrel adds a dynamic relocation in a XCOFF file. This relocation will be made by the loader.

func Xcoffinit

func Xcoffinit(ctxt *Link)

Xcoffinit initialised some internal value and setups already known header information.

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

	// Threshold of total text size, used for trampoline insertion. If the total
	// text size is smaller than TrampLimit, we won't need to insert trampolines.
	// It is pretty close to the offset range of a direct CALL machine instruction.
	// We leave some room for extra stuff like PLT stubs.
	TrampLimit uint64

	// Empty spaces between codeblocks will be padded with this value.
	// For example an architecture might want to pad with a trap instruction to
	// catch wayward programs. Architectures that do not define a padding value
	// are padded with zeros.
	CodePad []byte

	// Plan 9 variables.
	Plan9Magic  uint32
	Plan9_64Bit bool

	Adddynrel func(*Target, *loader.Loader, *ArchSyms, loader.Sym, loader.Reloc, int) bool
	Archinit  func(*Link)
	// Archreloc is an arch-specific hook that assists in relocation processing
	// (invoked by 'relocsym'); it handles target-specific relocation tasks.
	// Here "rel" is the current relocation being examined, "sym" is the symbol
	// containing the chunk of data to which the relocation applies, and "off"
	// is the contents of the to-be-relocated data item (from sym.P). Return
	// value is the appropriately relocated value (to be written back to the
	// same spot in sym.P), number of external _host_ relocations needed (i.e.
	// ELF/Mach-O/etc. relocations, not Go relocations, this must match ELF.Reloc1,
	// etc.), and a boolean indicating success/failure (a failing value indicates
	// a fatal error).
	Archreloc func(*Target, *loader.Loader, *ArchSyms, loader.Reloc, loader.Sym,
		int64) (relocatedOffset int64, nExtReloc int, ok bool)
	// Archrelocvariant is a second arch-specific hook used for
	// relocation processing; it handles relocations where r.Type is
	// insufficient to describe the relocation (r.Variant !=
	// sym.RV_NONE). Here "rel" is the relocation being applied, "sym"
	// is the symbol containing the chunk of data to which the
	// relocation applies, and "off" is the contents of the
	// to-be-relocated data item (from sym.P). Return is an updated
	// offset value.
	Archrelocvariant func(target *Target, ldr *loader.Loader, rel loader.Reloc,
		rv sym.RelocVariant, sym loader.Sym, offset int64, data []byte) (relocatedOffset int64)

	// Generate a trampoline for a call from s to rs if necessary. ri is
	// index of the relocation.
	Trampoline func(ctxt *Link, ldr *loader.Loader, ri int, rs, s loader.Sym)

	// Assembling the binary breaks into two phases, writing the code/data/
	// dwarf information (which is rather generic), and some more architecture
	// specific work like setting up the elf headers/dynamic relocations, etc.
	// The phases are called "Asmb" and "Asmb2". Asmb2 needs to be defined for
	// every architecture, but only if architecture has an Asmb function will
	// it be used for assembly.  Otherwise a generic assembly Asmb function is
	// used.
	Asmb  func(*Link, *loader.Loader)
	Asmb2 func(*Link, *loader.Loader)

	// Extreloc is an arch-specific hook that converts a Go relocation to an
	// external relocation. Return the external relocation and whether it is
	// needed.
	Extreloc func(*Target, *loader.Loader, loader.Reloc, loader.Sym) (loader.ExtReloc, bool)

	Gentext        func(*Link, *loader.Loader) // Generate text before addressing has been performed.
	Machoreloc1    func(*sys.Arch, *OutBuf, *loader.Loader, loader.Sym, loader.ExtReloc, int64) bool
	MachorelocSize uint32 // size of an Mach-O relocation record, must match Machoreloc1.
	PEreloc1       func(*sys.Arch, *OutBuf, *loader.Loader, loader.Sym, loader.ExtReloc, int64) bool
	Xcoffreloc1    func(*sys.Arch, *OutBuf, *loader.Loader, loader.Sym, loader.ExtReloc, int64) bool

	// Generate additional symbols for the native symbol table just prior to
	// code generation.
	GenSymsLate func(*Link, *loader.Loader)

	// 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(P []byte, off, size int)

	// optional override for assignAddress
	AssignAddress func(ldr *loader.Loader, sect *sym.Section, n int, s loader.Sym, va uint64, isTramp bool) (*sym.Section, int, uint64)

	// ELF specific information.
	ELF ELFArch
}

type ArchSyms

type ArchSyms struct {
	Rel     loader.Sym
	Rela    loader.Sym
	RelPLT  loader.Sym
	RelaPLT loader.Sym

	LinkEditGOT loader.Sym
	LinkEditPLT loader.Sym

	TOC    loader.Sym
	DotTOC []loader.Sym // for each version

	GOT    loader.Sym
	PLT    loader.Sym
	GOTPLT loader.Sym

	Tlsg      loader.Sym
	Tlsoffset int

	Dynamic loader.Sym
	DynSym  loader.Sym
	DynStr  loader.Sym
	// contains filtered or unexported fields
}

ArchSyms holds a number of architecture specific symbols used during relocation. Rather than allowing them universal access to all symbols, we keep a subset for relocation application.

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

Set implements flag.Value to set the build mode based on the argument to the -buildmode flag.

func (BuildMode) String

func (mode BuildMode) String() string

type Dll

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

type ELFArch added in v0.7.2202

type ELFArch struct {
	Androiddynld   string
	Linuxdynld     string
	LinuxdynldMusl string
	Freebsddynld   string
	Netbsddynld    string
	Openbsddynld   string
	Dragonflydynld string
	Solarisdynld   string

	Reloc1    func(*Link, *OutBuf, *loader.Loader, loader.Sym, loader.ExtReloc, int, int64) bool
	RelocSize uint32 // size of an ELF relocation record, must match Reloc1.
	SetupPLT  func(ctxt *Link, ldr *loader.Loader, plt, gotplt *loader.SymbolBuilder, dynamic loader.Sym)

	// DynamicReadOnly can be set to true to make the .dynamic
	// section read-only. By default it is writable.
	// This is used by MIPS targets.
	DynamicReadOnly bool
}

ELFArch includes target-specific hooks for ELF targets. This is initialized by the target-specific Init function called by the linker's main function in cmd/link/main.go.

type ElfEhdr

type ElfEhdr elf.Header64

* ELF header.

type ElfPhdr

type ElfPhdr elf.ProgHeader

* Program header.

type ElfShdr

type ElfShdr struct {
	elf.Section64
	// 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 ErrorReporter

type ErrorReporter struct {
	loader.ErrorReporter

	SymName symNameFn
	// contains filtered or unexported fields
}

ErrorReporter is used to make error reporting thread safe.

type GCProg

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

func (*GCProg) AddSym

func (p *GCProg) AddSym(s loader.Sym)

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 {
	Target
	ErrorReporter
	ArchSyms

	Out *OutBuf

	Debugvlog int
	Bso       *bufio.Writer

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

	Libdir       []string
	Library      []*sym.Library
	LibraryByPkg map[string]*sym.Library
	Shlibs       []Shlib
	Textp        []loader.Sym
	Moduledata   loader.Sym

	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 *loader.SymbolBuilder)

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

func (*Link) CanUsePlugins

func (ctxt *Link) CanUsePlugins() bool

CanUsePlugins reports whether a plugins can be used

func (*Link) DynlinkingGo

func (ctxt *Link) DynlinkingGo() bool

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

func (*Link) Errorf

func (ctxt *Link) Errorf(s loader.Sym, format string, args ...interface{})

Errorf method 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 (*Link) IncVersion

func (ctxt *Link) IncVersion() int

Allocate a new version (i.e. symbol namespace).

func (*Link) Logf

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

func (*Link) MaxVersion

func (ctxt *Link) MaxVersion() int

returns the maximum version number

func (*Link) NeedCodeSign

func (ctxt *Link) NeedCodeSign() bool

NeedCodeSign reports whether we need to code-sign the output binary.

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 MachoPlatform

type MachoPlatform int
const (
	PLATFORM_MACOS    MachoPlatform = 1
	PLATFORM_IOS      MachoPlatform = 2
	PLATFORM_TVOS     MachoPlatform = 3
	PLATFORM_WATCHOS  MachoPlatform = 4
	PLATFORM_BRIDGEOS MachoPlatform = 5
)

type MachoPlatformLoad

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

MachoPlatformLoad represents a LC_VERSION_MIN_* or LC_BUILD_VERSION load command.

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 similar 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.

Third, it also mmaps the output file (if available). The intended usage is:

  • Mmap the output file
  • Write the content
  • possibly apply any edits in the output buffer
  • possibly write more content to the file. These writes take place in a heap backed buffer that will get synced to disk.
  • Munmap the output file

And finally, it provides a mechanism by which you can multithread the writing of output files. This mechanism is accomplished by copying a OutBuf, and using it in the thread/goroutine.

Parallel OutBuf is intended to be used like:

func write(out *OutBuf) {
  var wg sync.WaitGroup
  for i := 0; i < 10; i++ {
    wg.Add(1)
    view, err := out.View(start[i])
    if err != nil {
       // handle output
       continue
    }
    go func(out *OutBuf, i int) {
      // do output
      wg.Done()
    }(view, i)
  }
  wg.Wait()
}

func NewOutBuf

func NewOutBuf(arch *sys.Arch) *OutBuf

func (*OutBuf) Close

func (out *OutBuf) Close() error

func (*OutBuf) Data

func (out *OutBuf) Data() []byte

Data returns the whole written OutBuf as a byte slice.

func (*OutBuf) ErrorClose

func (out *OutBuf) ErrorClose()

ErrorClose closes the output file (if any). It is supposed to be called only at exit on error, so it doesn't do any clean up or buffer flushing, just closes the file.

func (*OutBuf) Mmap

func (out *OutBuf) Mmap(filesize uint64) (err error)

Mmap maps the output file with the given size. It unmaps the old mapping if it is already mapped. It also flushes any in-heap data to the new mapping.

func (*OutBuf) Offset

func (out *OutBuf) Offset() int64

func (*OutBuf) Open

func (out *OutBuf) Open(name string) error

func (*OutBuf) SeekSet

func (out *OutBuf) SeekSet(p int64)

func (*OutBuf) View

func (out *OutBuf) View(start uint64) (*OutBuf, error)

func (*OutBuf) Write

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

Write writes the contents of v to the buffer.

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) WriteByte

func (out *OutBuf) WriteByte(v byte) error

WriteByte is an alias for Write8 to fulfill the io.ByteWriter interface.

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).

func (*OutBuf) WriteSym

func (out *OutBuf) WriteSym(ldr *loader.Loader, s loader.Sym) []byte

WriteSym writes the content of a Symbol, and returns the output buffer that we just wrote, so we can apply further edit to the symbol content. For generator symbols, it also sets the symbol's Data to the output buffer.

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
}

type SymbolType

type SymbolType int8 // TODO: after genasmsym is gone, maybe rename to plan9typeChar or something
const (
	// see also https://9p.io/magic/man2html/1/nm
	TextSym      SymbolType = 'T'
	DataSym      SymbolType = 'D'
	BSSSym       SymbolType = 'B'
	UndefinedSym SymbolType = 'U'
	TLSSym       SymbolType = 't'
	FrameSym     SymbolType = 'm'
	ParamSym     SymbolType = 'p'
	AutoSym      SymbolType = 'a'

	// Deleted auto (not a real sym, just placeholder for type)
	DeletedAutoSym = 'x'
)

type Target

type Target struct {
	Arch *sys.Arch

	HeadType objabi.HeadType

	LinkMode  LinkMode
	BuildMode BuildMode

	IsELF bool
	// contains filtered or unexported fields
}

Target holds the configuration we're building for.

func (*Target) CanUsePlugins

func (t *Target) CanUsePlugins() bool

func (*Target) Is386

func (t *Target) Is386() bool

func (*Target) IsAIX

func (t *Target) IsAIX() bool

func (*Target) IsAMD64

func (t *Target) IsAMD64() bool

func (*Target) IsARM

func (t *Target) IsARM() bool

func (*Target) IsARM64

func (t *Target) IsARM64() bool

func (*Target) IsBigEndian

func (t *Target) IsBigEndian() bool

func (*Target) IsDarwin

func (t *Target) IsDarwin() bool

func (*Target) IsDynlinkingGo

func (t *Target) IsDynlinkingGo() bool

func (*Target) IsElf

func (t *Target) IsElf() bool

func (*Target) IsExe

func (t *Target) IsExe() bool

func (*Target) IsExternal

func (t *Target) IsExternal() bool

func (*Target) IsFreebsd added in v0.3.205

func (t *Target) IsFreebsd() bool

func (*Target) IsInternal

func (t *Target) IsInternal() bool

func (*Target) IsLOONG64

func (t *Target) IsLOONG64() bool

func (*Target) IsLinux

func (t *Target) IsLinux() bool

func (*Target) IsMIPS

func (t *Target) IsMIPS() bool

func (*Target) IsMIPS64

func (t *Target) IsMIPS64() bool

func (*Target) IsNetbsd

func (t *Target) IsNetbsd() bool

func (*Target) IsOpenbsd

func (t *Target) IsOpenbsd() bool

func (*Target) IsPIE

func (t *Target) IsPIE() bool

func (*Target) IsPPC64

func (t *Target) IsPPC64() bool

func (*Target) IsPlan9

func (t *Target) IsPlan9() bool

func (*Target) IsPlugin

func (t *Target) IsPlugin() bool

func (*Target) IsRISCV64

func (t *Target) IsRISCV64() bool

func (*Target) IsS390X

func (t *Target) IsS390X() bool

func (*Target) IsShared

func (t *Target) IsShared() bool
func (t *Target) IsSharedGoLink() bool

func (*Target) IsSolaris

func (t *Target) IsSolaris() bool

func (*Target) IsWasm

func (t *Target) IsWasm() bool

func (*Target) IsWindows

func (t *Target) IsWindows() bool

func (*Target) UseRelro

func (t *Target) UseRelro() bool

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

func (*Target) UsesLibc

func (t *Target) UsesLibc() bool

type XcoffAoutHdr64

type XcoffAoutHdr64 struct {
	Omagic      int16    // Flags - Ignored If Vstamp Is 1
	Ovstamp     int16    // Version
	Odebugger   uint32   // Reserved For Debugger
	Otextstart  uint64   // Virtual Address Of Text
	Odatastart  uint64   // Virtual Address Of Data
	Otoc        uint64   // Toc Address
	Osnentry    int16    // Section Number For Entry Point
	Osntext     int16    // Section Number For Text
	Osndata     int16    // Section Number For Data
	Osntoc      int16    // Section Number For Toc
	Osnloader   int16    // Section Number For Loader
	Osnbss      int16    // Section Number For Bss
	Oalgntext   int16    // Max Text Alignment
	Oalgndata   int16    // Max Data Alignment
	Omodtype    [2]byte  // Module Type Field
	Ocpuflag    uint8    // Bit Flags - Cputypes Of Objects
	Ocputype    uint8    // Reserved for CPU type
	Otextpsize  uint8    // Requested text page size
	Odatapsize  uint8    // Requested data page size
	Ostackpsize uint8    // Requested stack page size
	Oflags      uint8    // Flags And TLS Alignment
	Otsize      uint64   // Text Size In Bytes
	Odsize      uint64   // Data Size In Bytes
	Obsize      uint64   // Bss Size In Bytes
	Oentry      uint64   // Entry Point Address
	Omaxstack   uint64   // Max Stack Size Allowed
	Omaxdata    uint64   // Max Data Size Allowed
	Osntdata    int16    // Section Number For Tdata Section
	Osntbss     int16    // Section Number For Tbss Section
	Ox64flags   uint16   // Additional Flags For 64-Bit Objects
	Oresv3a     int16    // Reserved
	Oresv3      [2]int32 // Reserved
}

Auxiliary Header

type XcoffAuxCSect64

type XcoffAuxCSect64 struct {
	Xscnlenlo uint32 // Lower 4 bytes of length or symbol table index
	Xparmhash uint32 // Offset of parameter type-check string
	Xsnhash   uint16 // .typchk section number
	Xsmtyp    uint8  // Symbol alignment and type
	Xsmclas   uint8  // Storage-mapping class
	Xscnlenhi uint32 // Upper 4 bytes of length or symbol table index
	Xpad      uint8  // Unused
	Xauxtype  uint8  // Type of auxiliary entry
}

csect Auxiliary Entry.

type XcoffAuxDWARF64

type XcoffAuxDWARF64 struct {
	Xscnlen  uint64 // Length of this symbol section
	X_pad    [9]byte
	Xauxtype uint8 // Type of auxiliary entry
}

DWARF Auxiliary Entry

type XcoffAuxFcn64

type XcoffAuxFcn64 struct {
	Xlnnoptr uint64 // File pointer to line number
	Xfsize   uint32 // Size of function in bytes
	Xendndx  uint32 // Symbol table index of next entry
	Xpad     uint8  // Unused
	Xauxtype uint8  // Type of auxiliary entry
}

Function Auxiliary Entry

type XcoffAuxFile64

type XcoffAuxFile64 struct {
	Xzeroes  uint32 // The name is always in the string table
	Xoffset  uint32 // Offset in the string table
	X_pad1   [6]byte
	Xftype   uint8 // Source file string type
	X_pad2   [2]byte
	Xauxtype uint8 // Type of auxiliary entry
}

File Auxiliary Entry

type XcoffFileHdr64

type XcoffFileHdr64 struct {
	Fmagic   uint16 // Target machine
	Fnscns   uint16 // Number of sections
	Ftimedat int32  // Time and date of file creation
	Fsymptr  uint64 // Byte offset to symbol table start
	Fopthdr  uint16 // Number of bytes in optional header
	Fflags   uint16 // Flags
	Fnsyms   int32  // Number of entries in symbol table
}

File Header

type XcoffLdHdr64

type XcoffLdHdr64 struct {
	Lversion int32  // Loader section version number
	Lnsyms   int32  // Number of symbol table entries
	Lnreloc  int32  // Number of relocation table entries
	Listlen  uint32 // Length of import file ID string table
	Lnimpid  int32  // Number of import file IDs
	Lstlen   uint32 // Length of string table
	Limpoff  uint64 // Offset to start of import file IDs
	Lstoff   uint64 // Offset to start of string table
	Lsymoff  uint64 // Offset to start of symbol table
	Lrldoff  uint64 // Offset to start of relocation entries
}

Loader Header

type XcoffLdImportFile64

type XcoffLdImportFile64 struct {
	Limpidpath string
	Limpidbase string
	Limpidmem  string
}

type XcoffLdRel64

type XcoffLdRel64 struct {
	Lvaddr  uint64 // Address Field
	Lrtype  uint16 // Relocation Size and Type
	Lrsecnm int16  // Section Number being relocated
	Lsymndx int32  // Loader-Section symbol table index
}

type XcoffLdStr64

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

type XcoffLdSym64

type XcoffLdSym64 struct {
	Lvalue  uint64 // Address field
	Loffset uint32 // Byte offset into string table of symbol name
	Lscnum  int16  // Section number containing symbol
	Lsmtype int8   // Symbol type, export, import flags
	Lsmclas int8   // Symbol storage class
	Lifile  int32  // Import file ID; ordinal of import file IDs
	Lparm   uint32 // Parameter type-check field
}

Loader Symbol

type XcoffScnHdr64

type XcoffScnHdr64 struct {
	Sname    [8]byte // Section Name
	Spaddr   uint64  // Physical Address
	Svaddr   uint64  // Virtual Address
	Ssize    uint64  // Section Size
	Sscnptr  uint64  // File Offset To Raw Data
	Srelptr  uint64  // File Offset To Relocation
	Slnnoptr uint64  // File Offset To Line Numbers
	Snreloc  uint32  // Number Of Relocation Entries
	Snlnno   uint32  // Number Of Line Number Entries
	Sflags   uint32  // flags
}

Section Header

type XcoffSymEnt64

type XcoffSymEnt64 struct {
	Nvalue  uint64 // Symbol value
	Noffset uint32 // Offset of the name in string table or .debug section
	Nscnum  int16  // Section number of symbol
	Ntype   uint16 // Basic and derived type specification
	Nsclass uint8  // Storage class of symbol
	Nnumaux int8   // Number of auxiliary entries
}

Symbol Table Entry

Jump to

Keyboard shortcuts

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