github.com/shogo82148/std@v1.22.1-0.20240327122250-4e474527810c/cmd/link/internal/loadmacho/ldmacho.go (about) 1 // Copyright 2017 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 loadmacho implements a Mach-O file reader. 6 package loadmacho 7 8 import ( 9 "github.com/shogo82148/std/cmd/internal/bio" 10 "github.com/shogo82148/std/cmd/internal/sys" 11 "github.com/shogo82148/std/cmd/link/internal/loader" 12 ) 13 14 // TODO(crawshaw): de-duplicate these symbols with cmd/link/internal/ld 15 const ( 16 MACHO_X86_64_RELOC_UNSIGNED = 0 17 MACHO_X86_64_RELOC_SIGNED = 1 18 MACHO_ARM64_RELOC_ADDEND = 10 19 ) 20 21 // ldMachoSym.type_ 22 const ( 23 N_EXT = 0x01 24 N_TYPE = 0x1e 25 N_STAB = 0xe0 26 ) 27 28 // ldMachoSym.desc 29 const ( 30 N_WEAK_REF = 0x40 31 N_WEAK_DEF = 0x80 32 ) 33 34 const ( 35 LdMachoCpuVax = 1 36 LdMachoCpu68000 = 6 37 LdMachoCpu386 = 7 38 LdMachoCpuAmd64 = 1<<24 | 7 39 LdMachoCpuMips = 8 40 LdMachoCpu98000 = 10 41 LdMachoCpuHppa = 11 42 LdMachoCpuArm = 12 43 LdMachoCpuArm64 = 1<<24 | 12 44 LdMachoCpu88000 = 13 45 LdMachoCpuSparc = 14 46 LdMachoCpu860 = 15 47 LdMachoCpuAlpha = 16 48 LdMachoCpuPower = 18 49 LdMachoCmdSegment = 1 50 LdMachoCmdSymtab = 2 51 LdMachoCmdSymseg = 3 52 LdMachoCmdThread = 4 53 LdMachoCmdDysymtab = 11 54 LdMachoCmdSegment64 = 25 55 LdMachoFileObject = 1 56 LdMachoFileExecutable = 2 57 LdMachoFileFvmlib = 3 58 LdMachoFileCore = 4 59 LdMachoFilePreload = 5 60 ) 61 62 // Load the Mach-O file pn from f. 63 // Symbols are written into syms, and a slice of the text symbols is returned. 64 func Load(l *loader.Loader, arch *sys.Arch, localSymVersion int, f *bio.Reader, pkg string, length int64, pn string) (textp []loader.Sym, err error)