本文整理匯總了Golang中cmd/link/avail/ld.Linklookup函數的典型用法代碼示例。如果您正苦於以下問題:Golang Linklookup函數的具體用法?Golang Linklookup怎麽用?Golang Linklookup使用的例子?那麽, 這裏精選的函數代碼示例或許可以為您提供幫助。
在下文中一共展示了Linklookup函數的13個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Golang代碼示例。
示例1: genaddmoduledata
func genaddmoduledata() {
addmoduledata := ld.Linkrlookup(ld.Ctxt, "runtime.addmoduledata", 0)
if addmoduledata.Type == obj.STEXT {
return
}
addmoduledata.Attr |= ld.AttrReachable
initfunc := ld.Linklookup(ld.Ctxt, "go.link.addmoduledata", 0)
initfunc.Type = obj.STEXT
initfunc.Attr |= ld.AttrLocal
initfunc.Attr |= ld.AttrReachable
o := func(op uint32) {
ld.Adduint32(ld.Ctxt, initfunc, op)
}
// addis r2, r12, [email protected]
rel := ld.Addrel(initfunc)
rel.Off = int32(initfunc.Size)
rel.Siz = 8
rel.Sym = ld.Linklookup(ld.Ctxt, ".TOC.", 0)
rel.Type = obj.R_ADDRPOWER_PCREL
o(0x3c4c0000)
// addi r2, r2, [email protected]
o(0x38420000)
// mflr r31
o(0x7c0802a6)
// stdu r31, -32(r1)
o(0xf801ffe1)
// addis r3, r2, [email protected]@ha
rel = ld.Addrel(initfunc)
rel.Off = int32(initfunc.Size)
rel.Siz = 8
rel.Sym = ld.Linklookup(ld.Ctxt, "local.moduledata", 0)
rel.Type = obj.R_ADDRPOWER_GOT
o(0x3c620000)
// ld r3, [email protected]@l(r3)
o(0xe8630000)
// bl runtime.addmoduledata
rel = ld.Addrel(initfunc)
rel.Off = int32(initfunc.Size)
rel.Siz = 4
rel.Sym = addmoduledata
rel.Type = obj.R_CALLPOWER
o(0x48000001)
// nop
o(0x60000000)
// ld r31, 0(r1)
o(0xe8010000)
// mtlr r31
o(0x7c0803a6)
// addi r1,r1,32
o(0x38210020)
// blr
o(0x4e800020)
ld.Ctxt.Textp = append(ld.Ctxt.Textp, initfunc)
initarray_entry := ld.Linklookup(ld.Ctxt, "go.link.addmoduledatainit", 0)
initarray_entry.Attr |= ld.AttrReachable
initarray_entry.Attr |= ld.AttrLocal
initarray_entry.Type = obj.SINITARR
ld.Addaddr(ld.Ctxt, initarray_entry, initfunc)
}
示例2: elfsetupplt
func elfsetupplt() {
plt := ld.Linklookup(ld.Ctxt, ".plt", 0)
got := ld.Linklookup(ld.Ctxt, ".got.plt", 0)
if plt.Size == 0 {
// pushl got+4
ld.Adduint8(ld.Ctxt, plt, 0xff)
ld.Adduint8(ld.Ctxt, plt, 0x35)
ld.Addaddrplus(ld.Ctxt, plt, got, 4)
// jmp *got+8
ld.Adduint8(ld.Ctxt, plt, 0xff)
ld.Adduint8(ld.Ctxt, plt, 0x25)
ld.Addaddrplus(ld.Ctxt, plt, got, 8)
// zero pad
ld.Adduint32(ld.Ctxt, plt, 0)
// assume got->size == 0 too
ld.Addaddrplus(ld.Ctxt, got, ld.Linklookup(ld.Ctxt, ".dynamic", 0), 0)
ld.Adduint32(ld.Ctxt, got, 0)
ld.Adduint32(ld.Ctxt, got, 0)
}
}
示例3: ensureglinkresolver
// Generate the glink resolver stub if necessary and return the .glink section
func ensureglinkresolver() *ld.LSym {
glink := ld.Linklookup(ld.Ctxt, ".glink", 0)
if glink.Size != 0 {
return glink
}
// This is essentially the resolver from the ppc64 ELF ABI.
// At entry, r12 holds the address of the symbol resolver stub
// for the target routine and the argument registers hold the
// arguments for the target routine.
//
// This stub is PIC, so first get the PC of label 1 into r11.
// Other things will be relative to this.
ld.Adduint32(ld.Ctxt, glink, 0x7c0802a6) // mflr r0
ld.Adduint32(ld.Ctxt, glink, 0x429f0005) // bcl 20,31,1f
ld.Adduint32(ld.Ctxt, glink, 0x7d6802a6) // 1: mflr r11
ld.Adduint32(ld.Ctxt, glink, 0x7c0803a6) // mtlf r0
// Compute the .plt array index from the entry point address.
// Because this is PIC, everything is relative to label 1b (in
// r11):
// r0 = ((r12 - r11) - (res_0 - r11)) / 4 = (r12 - res_0) / 4
ld.Adduint32(ld.Ctxt, glink, 0x3800ffd0) // li r0,-(res_0-1b)=-48
ld.Adduint32(ld.Ctxt, glink, 0x7c006214) // add r0,r0,r12
ld.Adduint32(ld.Ctxt, glink, 0x7c0b0050) // sub r0,r0,r11
ld.Adduint32(ld.Ctxt, glink, 0x7800f082) // srdi r0,r0,2
// r11 = address of the first byte of the PLT
r := ld.Addrel(glink)
r.Off = int32(glink.Size)
r.Sym = ld.Linklookup(ld.Ctxt, ".plt", 0)
r.Siz = 8
r.Type = obj.R_ADDRPOWER
ld.Adduint32(ld.Ctxt, glink, 0x3d600000) // addis r11,0,[email protected]
ld.Adduint32(ld.Ctxt, glink, 0x396b0000) // addi r11,r11,[email protected]
// Load r12 = dynamic resolver address and r11 = DSO
// identifier from the first two doublewords of the PLT.
ld.Adduint32(ld.Ctxt, glink, 0xe98b0000) // ld r12,0(r11)
ld.Adduint32(ld.Ctxt, glink, 0xe96b0008) // ld r11,8(r11)
// Jump to the dynamic resolver
ld.Adduint32(ld.Ctxt, glink, 0x7d8903a6) // mtctr r12
ld.Adduint32(ld.Ctxt, glink, 0x4e800420) // bctr
// The symbol resolvers must immediately follow.
// res_0:
// Add DT_PPC64_GLINK .dynamic entry, which points to 32 bytes
// before the first symbol resolver stub.
s := ld.Linklookup(ld.Ctxt, ".dynamic", 0)
ld.Elfwritedynentsymplus(s, ld.DT_PPC64_GLINK, glink, glink.Size-32)
return glink
}
示例4: gentext
// gentext generates assembly to append the local moduledata to the global
// moduledata linked list at initialization time. This is only done if the runtime
// is in a different module.
//
// <go.link.addmoduledata>:
// larl %r2, <local.moduledata>
// jg <[email protected]>
// undef
//
// The job of appending the moduledata is delegated to runtime.addmoduledata.
func gentext() {
if !ld.DynlinkingGo() {
return
}
addmoduledata := ld.Linklookup(ld.Ctxt, "runtime.addmoduledata", 0)
if addmoduledata.Type == obj.STEXT {
// we're linking a module containing the runtime -> no need for
// an init function
return
}
addmoduledata.Attr |= ld.AttrReachable
initfunc := ld.Linklookup(ld.Ctxt, "go.link.addmoduledata", 0)
initfunc.Type = obj.STEXT
initfunc.Attr |= ld.AttrLocal
initfunc.Attr |= ld.AttrReachable
// larl %r2, <local.moduledata>
ld.Adduint8(ld.Ctxt, initfunc, 0xc0)
ld.Adduint8(ld.Ctxt, initfunc, 0x20)
lmd := ld.Addrel(initfunc)
lmd.Off = int32(initfunc.Size)
lmd.Siz = 4
lmd.Sym = ld.Ctxt.Moduledata
lmd.Type = obj.R_PCREL
lmd.Variant = ld.RV_390_DBL
lmd.Add = 2 + int64(lmd.Siz)
ld.Adduint32(ld.Ctxt, initfunc, 0)
// jg <runtime.addmoduledata[@plt]>
ld.Adduint8(ld.Ctxt, initfunc, 0xc0)
ld.Adduint8(ld.Ctxt, initfunc, 0xf4)
rel := ld.Addrel(initfunc)
rel.Off = int32(initfunc.Size)
rel.Siz = 4
rel.Sym = ld.Linklookup(ld.Ctxt, "runtime.addmoduledata", 0)
rel.Type = obj.R_CALL
rel.Variant = ld.RV_390_DBL
rel.Add = 2 + int64(rel.Siz)
ld.Adduint32(ld.Ctxt, initfunc, 0)
// undef (for debugging)
ld.Adduint32(ld.Ctxt, initfunc, 0)
ld.Ctxt.Textp = append(ld.Ctxt.Textp, initfunc)
initarray_entry := ld.Linklookup(ld.Ctxt, "go.link.addmoduledatainit", 0)
initarray_entry.Attr |= ld.AttrLocal
initarray_entry.Attr |= ld.AttrReachable
initarray_entry.Type = obj.SINITARR
ld.Addaddr(ld.Ctxt, initarray_entry, initfunc)
}
示例5: addgotsym
func addgotsym(ctxt *ld.Link, s *ld.LSym) {
if s.Got >= 0 {
return
}
ld.Adddynsym(ctxt, s)
got := ld.Linklookup(ctxt, ".got", 0)
s.Got = int32(got.Size)
ld.Adduint32(ctxt, got, 0)
if ld.Iself {
rel := ld.Linklookup(ctxt, ".rel", 0)
ld.Addaddrplus(ctxt, rel, got, int64(s.Got))
ld.Adduint32(ctxt, rel, ld.ELF32_R_INFO(uint32(s.Dynid), ld.R_ARM_GLOB_DAT))
} else {
ld.Diag("addgotsym: unsupported binary format")
}
}
示例6: addpltsym
func addpltsym(ctxt *ld.Link, s *ld.LSym) {
if s.Plt >= 0 {
return
}
ld.Adddynsym(ctxt, s)
if ld.Iself {
plt := ld.Linklookup(ctxt, ".plt", 0)
rela := ld.Linklookup(ctxt, ".rela.plt", 0)
if plt.Size == 0 {
elfsetupplt()
}
// Create the glink resolver if necessary
glink := ensureglinkresolver()
// Write symbol resolver stub (just a branch to the
// glink resolver stub)
r := ld.Addrel(glink)
r.Sym = glink
r.Off = int32(glink.Size)
r.Siz = 4
r.Type = obj.R_CALLPOWER
ld.Adduint32(ctxt, glink, 0x48000000) // b .glink
// In the ppc64 ABI, the dynamic linker is responsible
// for writing the entire PLT. We just need to
// reserve 8 bytes for each PLT entry and generate a
// JMP_SLOT dynamic relocation for it.
//
// TODO(austin): ABI v1 is different
s.Plt = int32(plt.Size)
plt.Size += 8
ld.Addaddrplus(ctxt, rela, plt, int64(s.Plt))
ld.Adduint64(ctxt, rela, ld.ELF64_R_INFO(uint32(s.Dynid), ld.R_PPC64_JMP_SLOT))
ld.Adduint64(ctxt, rela, 0)
} else {
ld.Diag("addpltsym: unsupported binary format")
}
}
示例7: addgotsyminternal
func addgotsyminternal(ctxt *ld.Link, s *ld.LSym) {
if s.Got >= 0 {
return
}
got := ld.Linklookup(ctxt, ".got", 0)
s.Got = int32(got.Size)
ld.Addaddrplus(ctxt, got, s, 0)
if ld.Iself {
} else {
ld.Diag("addgotsyminternal: unsupported binary format")
}
}
示例8: archreloc
func archreloc(r *ld.Reloc, s *ld.LSym, val *int64) int {
if ld.Linkmode == ld.LinkExternal {
return -1
}
switch r.Type {
case obj.R_CONST:
*val = r.Add
return 0
case obj.R_GOTOFF:
*val = ld.Symaddr(r.Sym) + r.Add - ld.Symaddr(ld.Linklookup(ld.Ctxt, ".got", 0))
return 0
}
return -1
}
示例9: gencallstub
// Construct a call stub in stub that calls symbol targ via its PLT
// entry.
func gencallstub(abicase int, stub *ld.LSym, targ *ld.LSym) {
if abicase != 1 {
// If we see R_PPC64_TOCSAVE or R_PPC64_REL24_NOTOC
// relocations, we'll need to implement cases 2 and 3.
log.Fatalf("gencallstub only implements case 1 calls")
}
plt := ld.Linklookup(ld.Ctxt, ".plt", 0)
stub.Type = obj.STEXT
// Save TOC pointer in TOC save slot
ld.Adduint32(ld.Ctxt, stub, 0xf8410018) // std r2,24(r1)
// Load the function pointer from the PLT.
r := ld.Addrel(stub)
r.Off = int32(stub.Size)
r.Sym = plt
r.Add = int64(targ.Plt)
r.Siz = 2
if ld.Ctxt.Arch.ByteOrder == binary.BigEndian {
r.Off += int32(r.Siz)
}
r.Type = obj.R_POWER_TOC
r.Variant = ld.RV_POWER_HA
ld.Adduint32(ld.Ctxt, stub, 0x3d820000) // addis r12,r2,[email protected]@[email protected]
r = ld.Addrel(stub)
r.Off = int32(stub.Size)
r.Sym = plt
r.Add = int64(targ.Plt)
r.Siz = 2
if ld.Ctxt.Arch.ByteOrder == binary.BigEndian {
r.Off += int32(r.Siz)
}
r.Type = obj.R_POWER_TOC
r.Variant = ld.RV_POWER_LO
ld.Adduint32(ld.Ctxt, stub, 0xe98c0000) // ld r12,[email protected]@[email protected](r12)
// Jump to the loaded pointer
ld.Adduint32(ld.Ctxt, stub, 0x7d8903a6) // mtctr r12
ld.Adduint32(ld.Ctxt, stub, 0x4e800420) // bctr
}
示例10: asmb
//.........這裏部分代碼省略.........
case obj.Hlinux,
obj.Hfreebsd,
obj.Hnetbsd,
obj.Hopenbsd,
obj.Hdragonfly,
obj.Hsolaris,
obj.Hnacl:
symo = int64(ld.Segdwarf.Fileoff + ld.Segdwarf.Filelen)
symo = ld.Rnd(symo, int64(ld.INITRND))
case obj.Hwindows:
symo = int64(ld.Segdwarf.Fileoff + ld.Segdwarf.Filelen)
symo = ld.Rnd(symo, ld.PEFILEALIGN)
}
ld.Cseek(symo)
switch ld.HEADTYPE {
default:
if ld.Iself {
ld.Cseek(symo)
ld.Asmelfsym()
ld.Cflush()
ld.Cwrite(ld.Elfstrdat)
if ld.Debug['v'] != 0 {
fmt.Fprintf(ld.Bso, "%5.2f dwarf\n", obj.Cputime())
}
if ld.Linkmode == ld.LinkExternal {
ld.Elfemitreloc()
}
}
case obj.Hplan9:
ld.Asmplan9sym()
ld.Cflush()
sym := ld.Linklookup(ld.Ctxt, "pclntab", 0)
if sym != nil {
ld.Lcsize = int32(len(sym.P))
for i := 0; int32(i) < ld.Lcsize; i++ {
ld.Cput(sym.P[i])
}
ld.Cflush()
}
case obj.Hwindows:
if ld.Debug['v'] != 0 {
fmt.Fprintf(ld.Bso, "%5.2f dwarf\n", obj.Cputime())
}
case obj.Hdarwin:
if ld.Linkmode == ld.LinkExternal {
ld.Machoemitreloc()
}
}
}
if ld.Debug['v'] != 0 {
fmt.Fprintf(ld.Bso, "%5.2f headr\n", obj.Cputime())
}
ld.Bso.Flush()
ld.Cseek(0)
switch ld.HEADTYPE {
default:
case obj.Hplan9: /* plan9 */
magic := int32(4*26*26 + 7)
magic |= 0x00008000 /* fat header */
ld.Lputb(uint32(magic)) /* magic */
ld.Lputb(uint32(ld.Segtext.Filelen)) /* sizes */
ld.Lputb(uint32(ld.Segdata.Filelen))
ld.Lputb(uint32(ld.Segdata.Length - ld.Segdata.Filelen))
ld.Lputb(uint32(ld.Symsize)) /* nsyms */
vl := ld.Entryvalue()
ld.Lputb(PADDR(uint32(vl))) /* va of entry */
ld.Lputb(uint32(ld.Spsize)) /* sp offsets */
ld.Lputb(uint32(ld.Lcsize)) /* line offsets */
ld.Vputb(uint64(vl)) /* va of entry */
case obj.Hdarwin:
ld.Asmbmacho()
case obj.Hlinux,
obj.Hfreebsd,
obj.Hnetbsd,
obj.Hopenbsd,
obj.Hdragonfly,
obj.Hsolaris,
obj.Hnacl:
ld.Asmbelf(symo)
case obj.Hwindows:
ld.Asmbpe()
}
ld.Cflush()
}
示例11: genplt
func genplt() {
// The ppc64 ABI PLT has similar concepts to other
// architectures, but is laid out quite differently. When we
// see an R_PPC64_REL24 relocation to a dynamic symbol
// (indicating that the call needs to go through the PLT), we
// generate up to three stubs and reserve a PLT slot.
//
// 1) The call site will be bl x; nop (where the relocation
// applies to the bl). We rewrite this to bl x_stub; ld
// r2,24(r1). The ld is necessary because x_stub will save
// r2 (the TOC pointer) at 24(r1) (the "TOC save slot").
//
// 2) We reserve space for a pointer in the .plt section (once
// per referenced dynamic function). .plt is a data
// section filled solely by the dynamic linker (more like
// .plt.got on other architectures). Initially, the
// dynamic linker will fill each slot with a pointer to the
// corresponding [email protected] entry point.
//
// 3) We generate the "call stub" x_stub (once per dynamic
// function/object file pair). This saves the TOC in the
// TOC save slot, reads the function pointer from x's .plt
// slot and calls it like any other global entry point
// (including setting r12 to the function address).
//
// 4) We generate the "symbol resolver stub" [email protected] (once per
// dynamic function). This is solely a branch to the glink
// resolver stub.
//
// 5) We generate the glink resolver stub (only once). This
// computes which symbol resolver stub we came through and
// invokes the dynamic resolver via a pointer provided by
// the dynamic linker. This will patch up the .plt slot to
// point directly at the function so future calls go
// straight from the call stub to the real function, and
// then call the function.
// NOTE: It's possible we could make ppc64 closer to other
// architectures: ppc64's .plt is like .plt.got on other
// platforms and ppc64's .glink is like .plt on other
// platforms.
// Find all R_PPC64_REL24 relocations that reference dynamic
// imports. Reserve PLT entries for these symbols and
// generate call stubs. The call stubs need to live in .text,
// which is why we need to do this pass this early.
//
// This assumes "case 1" from the ABI, where the caller needs
// us to save and restore the TOC pointer.
for _, s := range ld.Ctxt.Textp {
for i := range s.R {
r := &s.R[i]
if r.Type != 256+ld.R_PPC64_REL24 || r.Sym.Type != obj.SDYNIMPORT {
continue
}
// Reserve PLT entry and generate symbol
// resolver
addpltsym(ld.Ctxt, r.Sym)
// Generate call stub
n := fmt.Sprintf("%s.%s", s.Name, r.Sym.Name)
stub := ld.Linklookup(ld.Ctxt, n, 0)
if s.Attr.Reachable() {
stub.Attr |= ld.AttrReachable
}
if stub.Size == 0 {
// Need outer to resolve .TOC.
stub.Outer = s
ld.Ctxt.Textp = append(ld.Ctxt.Textp, stub)
gencallstub(1, stub, r.Sym)
}
// Update the relocation to use the call stub
r.Sym = stub
// Restore TOC after bl. The compiler put a
// nop here for us to overwrite.
const o1 = 0xe8410018 // ld r2,24(r1)
ld.Ctxt.Arch.ByteOrder.PutUint32(s.P[r.Off+4:], o1)
}
}
}
示例12: adddynrel
func adddynrel(s *ld.LSym, r *ld.Reloc) {
targ := r.Sym
ld.Ctxt.Cursym = s
switch r.Type {
default:
if r.Type >= 256 {
ld.Diag("unexpected relocation type %d", r.Type)
return
}
// Handle relocations found in ELF object files.
case 256 + ld.R_X86_64_PC32:
if targ.Type == obj.SDYNIMPORT {
ld.Diag("unexpected R_X86_64_PC32 relocation for dynamic symbol %s", targ.Name)
}
if targ.Type == 0 || targ.Type == obj.SXREF {
ld.Diag("unknown symbol %s in pcrel", targ.Name)
}
r.Type = obj.R_PCREL
r.Add += 4
return
case 256 + ld.R_X86_64_PLT32:
r.Type = obj.R_PCREL
r.Add += 4
if targ.Type == obj.SDYNIMPORT {
addpltsym(targ)
r.Sym = ld.Linklookup(ld.Ctxt, ".plt", 0)
r.Add += int64(targ.Plt)
}
return
case 256 + ld.R_X86_64_GOTPCREL, 256 + ld.R_X86_64_GOTPCRELX, 256 + ld.R_X86_64_REX_GOTPCRELX:
if targ.Type != obj.SDYNIMPORT {
// have symbol
if r.Off >= 2 && s.P[r.Off-2] == 0x8b {
// turn MOVQ of GOT entry into LEAQ of symbol itself
s.P[r.Off-2] = 0x8d
r.Type = obj.R_PCREL
r.Add += 4
return
}
}
// fall back to using GOT and hope for the best (CMOV*)
// TODO: just needs relocation, no need to put in .dynsym
addgotsym(targ)
r.Type = obj.R_PCREL
r.Sym = ld.Linklookup(ld.Ctxt, ".got", 0)
r.Add += 4
r.Add += int64(targ.Got)
return
case 256 + ld.R_X86_64_64:
if targ.Type == obj.SDYNIMPORT {
ld.Diag("unexpected R_X86_64_64 relocation for dynamic symbol %s", targ.Name)
}
r.Type = obj.R_ADDR
return
// Handle relocations found in Mach-O object files.
case 512 + ld.MACHO_X86_64_RELOC_UNSIGNED*2 + 0,
512 + ld.MACHO_X86_64_RELOC_SIGNED*2 + 0,
512 + ld.MACHO_X86_64_RELOC_BRANCH*2 + 0:
// TODO: What is the difference between all these?
r.Type = obj.R_ADDR
if targ.Type == obj.SDYNIMPORT {
ld.Diag("unexpected reloc for dynamic symbol %s", targ.Name)
}
return
case 512 + ld.MACHO_X86_64_RELOC_BRANCH*2 + 1:
if targ.Type == obj.SDYNIMPORT {
addpltsym(targ)
r.Sym = ld.Linklookup(ld.Ctxt, ".plt", 0)
r.Add = int64(targ.Plt)
r.Type = obj.R_PCREL
return
}
fallthrough
// fall through
case 512 + ld.MACHO_X86_64_RELOC_UNSIGNED*2 + 1,
512 + ld.MACHO_X86_64_RELOC_SIGNED*2 + 1,
512 + ld.MACHO_X86_64_RELOC_SIGNED_1*2 + 1,
512 + ld.MACHO_X86_64_RELOC_SIGNED_2*2 + 1,
512 + ld.MACHO_X86_64_RELOC_SIGNED_4*2 + 1:
r.Type = obj.R_PCREL
if targ.Type == obj.SDYNIMPORT {
ld.Diag("unexpected pc-relative reloc for dynamic symbol %s", targ.Name)
}
return
case 512 + ld.MACHO_X86_64_RELOC_GOT_LOAD*2 + 1:
//.........這裏部分代碼省略.........
示例13: archinit
func archinit() {
// getgoextlinkenabled is based on GO_EXTLINK_ENABLED when
// Go was built; see ../../make.bash.
if ld.Linkmode == ld.LinkAuto && obj.Getgoextlinkenabled() == "0" {
ld.Linkmode = ld.LinkInternal
}
if ld.Buildmode == ld.BuildmodeCShared || ld.Buildmode == ld.BuildmodePIE || ld.DynlinkingGo() {
ld.Linkmode = ld.LinkExternal
got := ld.Linklookup(ld.Ctxt, "_GLOBAL_OFFSET_TABLE_", 0)
got.Type = obj.SDYNIMPORT
got.Attr |= ld.AttrReachable
}
switch ld.HEADTYPE {
default:
if ld.Linkmode == ld.LinkAuto {
ld.Linkmode = ld.LinkInternal
}
if ld.Linkmode == ld.LinkExternal && obj.Getgoextlinkenabled() != "1" {
log.Fatalf("cannot use -linkmode=external with -H %s", ld.Headstr(int(ld.HEADTYPE)))
}
case obj.Hdarwin,
obj.Hfreebsd,
obj.Hlinux,
obj.Hnetbsd,
obj.Hopenbsd,
obj.Hwindows:
break
}
switch ld.HEADTYPE {
default:
ld.Exitf("unknown -H option: %v", ld.HEADTYPE)
case obj.Hplan9: /* plan 9 */
ld.HEADR = 32
if ld.INITTEXT == -1 {
ld.INITTEXT = 4096 + 32
}
if ld.INITDAT == -1 {
ld.INITDAT = 0
}
if ld.INITRND == -1 {
ld.INITRND = 4096
}
case obj.Hdarwin: /* apple MACH */
ld.Machoinit()
ld.HEADR = ld.INITIAL_MACHO_HEADR
if ld.INITTEXT == -1 {
ld.INITTEXT = 4096 + int64(ld.HEADR)
}
if ld.INITDAT == -1 {
ld.INITDAT = 0
}
if ld.INITRND == -1 {
ld.INITRND = 4096
}
case obj.Hlinux, /* elf32 executable */
obj.Hfreebsd,
obj.Hnetbsd,
obj.Hopenbsd:
ld.Elfinit()
ld.HEADR = ld.ELFRESERVE
if ld.INITTEXT == -1 {
ld.INITTEXT = 0x08048000 + int64(ld.HEADR)
}
if ld.INITDAT == -1 {
ld.INITDAT = 0
}
if ld.INITRND == -1 {
ld.INITRND = 4096
}
case obj.Hnacl:
ld.Elfinit()
ld.HEADR = 0x10000
ld.Funcalign = 32
if ld.INITTEXT == -1 {
ld.INITTEXT = 0x20000
}
if ld.INITDAT == -1 {
ld.INITDAT = 0
}
if ld.INITRND == -1 {
ld.INITRND = 0x10000
}
case obj.Hwindows: /* PE executable */
ld.Peinit()
ld.HEADR = ld.PEFILEHEADR
if ld.INITTEXT == -1 {
ld.INITTEXT = ld.PEBASE + int64(ld.PESECTHEADR)
//.........這裏部分代碼省略.........