本文整理匯總了Golang中cmd/link/internal/ld.Addrel函數的典型用法代碼示例。如果您正苦於以下問題:Golang Addrel函數的具體用法?Golang Addrel怎麽用?Golang Addrel使用的例子?那麽, 這裏精選的函數代碼示例或許可以為您提供幫助。
在下文中一共展示了Addrel函數的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的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: gentext
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
o := func(op uint32) {
ld.Adduint32(ld.Ctxt, initfunc, op)
}
// 0000000000000000 <local.dso_init>:
// 0: 90000000 adrp x0, 0 <runtime.firstmoduledata>
// 0: R_AARCH64_ADR_PREL_PG_HI21 local.moduledata
// 4: 91000000 add x0, x0, #0x0
// 4: R_AARCH64_ADD_ABS_LO12_NC local.moduledata
o(0x90000000)
o(0x91000000)
rel := ld.Addrel(initfunc)
rel.Off = 0
rel.Siz = 8
rel.Sym = ld.Ctxt.Moduledata
rel.Type = obj.R_ADDRARM64
// 8: 14000000 bl 0 <runtime.addmoduledata>
// 8: R_AARCH64_CALL26 runtime.addmoduledata
o(0x14000000)
rel = ld.Addrel(initfunc)
rel.Off = 8
rel.Siz = 4
rel.Sym = ld.Linklookup(ld.Ctxt, "runtime.addmoduledata", 0)
rel.Type = obj.R_CALLARM64 // Really should be R_AARCH64_JUMP26 but doesn't seem to make any difference
if ld.Ctxt.Etextp != nil {
ld.Ctxt.Etextp.Next = initfunc
} else {
ld.Ctxt.Textp = initfunc
}
ld.Ctxt.Etextp = 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)
}
示例3: 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(ctxt *ld.Link) {
if !ld.DynlinkingGo() {
return
}
addmoduledata := ld.Linklookup(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(ctxt, "go.link.addmoduledata", 0)
initfunc.Type = obj.STEXT
initfunc.Attr |= ld.AttrLocal
initfunc.Attr |= ld.AttrReachable
// larl %r2, <local.moduledata>
ld.Adduint8(ctxt, initfunc, 0xc0)
ld.Adduint8(ctxt, initfunc, 0x20)
lmd := ld.Addrel(initfunc)
lmd.Off = int32(initfunc.Size)
lmd.Siz = 4
lmd.Sym = ctxt.Moduledata
lmd.Type = obj.R_PCREL
lmd.Variant = ld.RV_390_DBL
lmd.Add = 2 + int64(lmd.Siz)
ld.Adduint32(ctxt, initfunc, 0)
// jg <runtime.addmoduledata[@plt]>
ld.Adduint8(ctxt, initfunc, 0xc0)
ld.Adduint8(ctxt, initfunc, 0xf4)
rel := ld.Addrel(initfunc)
rel.Off = int32(initfunc.Size)
rel.Siz = 4
rel.Sym = ld.Linklookup(ctxt, "runtime.addmoduledata", 0)
rel.Type = obj.R_CALL
rel.Variant = ld.RV_390_DBL
rel.Add = 2 + int64(rel.Siz)
ld.Adduint32(ctxt, initfunc, 0)
// undef (for debugging)
ld.Adduint32(ctxt, initfunc, 0)
ctxt.Textp = append(ctxt.Textp, initfunc)
initarray_entry := ld.Linklookup(ctxt, "go.link.addmoduledatainit", 0)
initarray_entry.Attr |= ld.AttrLocal
initarray_entry.Attr |= ld.AttrReachable
initarray_entry.Type = obj.SINITARR
ld.Addaddr(ctxt, initarray_entry, initfunc)
}
示例4: gentext
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.Reachable = true
initfunc := ld.Linklookup(ld.Ctxt, "go.link.addmoduledata", 0)
initfunc.Type = obj.STEXT
initfunc.Local = true
initfunc.Reachable = true
o := func(op uint32) {
ld.Adduint32(ld.Ctxt, initfunc, op)
}
o(0xe59f0004)
o(0xe08f0000)
o(0xeafffffe)
rel := ld.Addrel(initfunc)
rel.Off = 8
rel.Siz = 4
rel.Sym = ld.Linklookup(ld.Ctxt, "runtime.addmoduledata", 0)
rel.Type = obj.R_CALLARM
rel.Add = 0xeafffffe // vomit
o(0x00000000)
rel = ld.Addrel(initfunc)
rel.Off = 12
rel.Siz = 4
rel.Sym = ld.Ctxt.Moduledata
rel.Type = obj.R_PCREL
rel.Add = 4
if ld.Ctxt.Etextp != nil {
ld.Ctxt.Etextp.Next = initfunc
} else {
ld.Ctxt.Textp = initfunc
}
ld.Ctxt.Etextp = initfunc
initarray_entry := ld.Linklookup(ld.Ctxt, "go.link.addmoduledatainit", 0)
initarray_entry.Reachable = true
initarray_entry.Local = true
initarray_entry.Type = obj.SINITARR
ld.Addaddr(ld.Ctxt, initarray_entry, initfunc)
}
示例5: 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
// addis r11,0,[email protected]; addi r11,r11,[email protected]
r.Add = 0x3d600000<<32 | 0x396b0000
glink.Size += 8
// 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
}
示例6: gentext
func gentext(ctxt *ld.Link) {
if !ctxt.DynlinkingGo() {
return
}
addmoduledata := ctxt.Syms.Lookup("runtime.addmoduledata", 0)
if addmoduledata.Type == obj.STEXT && ld.Buildmode != ld.BuildmodePlugin {
// we're linking a module containing the runtime -> no need for
// an init function
return
}
addmoduledata.Attr |= ld.AttrReachable
initfunc := ctxt.Syms.Lookup("go.link.addmoduledata", 0)
initfunc.Type = obj.STEXT
initfunc.Attr |= ld.AttrLocal
initfunc.Attr |= ld.AttrReachable
o := func(op uint32) {
ld.Adduint32(ctxt, initfunc, op)
}
o(0xe59f0004)
o(0xe08f0000)
o(0xeafffffe)
rel := ld.Addrel(initfunc)
rel.Off = 8
rel.Siz = 4
rel.Sym = ctxt.Syms.Lookup("runtime.addmoduledata", 0)
rel.Type = obj.R_CALLARM
rel.Add = 0xeafffffe // vomit
o(0x00000000)
rel = ld.Addrel(initfunc)
rel.Off = 12
rel.Siz = 4
rel.Sym = ctxt.Moduledata
rel.Type = obj.R_PCREL
rel.Add = 4
if ld.Buildmode == ld.BuildmodePlugin {
ctxt.Textp = append(ctxt.Textp, addmoduledata)
}
ctxt.Textp = append(ctxt.Textp, initfunc)
initarray_entry := ctxt.Syms.Lookup("go.link.addmoduledatainit", 0)
initarray_entry.Attr |= ld.AttrReachable
initarray_entry.Attr |= ld.AttrLocal
initarray_entry.Type = obj.SINITARR
ld.Addaddr(ctxt, initarray_entry, initfunc)
}
示例7: gencallstub
// Construct a call stub in stub that calls symbol targ via its PLT
// entry.
func gencallstub(abicase int, stub *ld.Symbol, targ *ld.Symbol) {
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
}
示例8: addcall
// Append 4 bytes to s and create a R_CALL relocation targeting t to fill them in.
func addcall(ctxt *ld.Link, s *ld.Symbol, t *ld.Symbol) {
s.Attr |= ld.AttrReachable
i := s.Size
s.Size += 4
ld.Symgrow(s, s.Size)
r := ld.Addrel(s)
r.Sym = t
r.Off = int32(i)
r.Type = obj.R_CALL
r.Siz = 4
}
示例9: addcall
// Append 4 bytes to s and create a R_CALL relocation targeting t to fill them in.
func addcall(ctxt *ld.Link, s *ld.LSym, t *ld.LSym) {
s.Reachable = true
i := s.Size
s.Size += 4
ld.Symgrow(ctxt, s, s.Size)
r := ld.Addrel(s)
r.Sym = t
r.Off = int32(i)
r.Type = obj.R_CALL
r.Siz = 4
}
示例10: Addcall
func Addcall(ctxt *ld.Link, s *ld.LSym, t *ld.LSym) int64 {
s.Attr |= ld.AttrReachable
i := s.Size
s.Size += 4
ld.Symgrow(ctxt, s, s.Size)
r := ld.Addrel(s)
r.Sym = t
r.Off = int32(i)
r.Type = obj.R_CALL
r.Siz = 4
return i + int64(r.Siz)
}
示例11: addpltreloc
func addpltreloc(ctxt *ld.Link, plt *ld.Symbol, got *ld.Symbol, sym *ld.Symbol, typ int) *ld.Reloc {
r := ld.Addrel(plt)
r.Sym = got
r.Off = int32(plt.Size)
r.Siz = 4
r.Type = int32(typ)
r.Add = int64(sym.Got) - 8
plt.Attr |= ld.AttrReachable
plt.Size += 4
ld.Symgrow(ctxt, plt, plt.Size)
return r
}
示例12: addpltsym
func addpltsym(ctxt *ld.Link, s *ld.Symbol) {
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")
}
}
示例13: gentramppic
// generate a trampoline to target+offset in position independent code
func gentramppic(tramp, target *ld.Symbol, offset int64) {
tramp.Size = 16 // 4 instructions
tramp.P = make([]byte, tramp.Size)
o1 := uint32(0xe5900000 | 11<<12 | 15<<16 | 4) // MOVW 4(R15), R11 // R15 is actual pc + 8
o2 := uint32(0xe0800000 | 11<<12 | 15<<16 | 11) // ADD R15, R11, R11
o3 := uint32(0xe12fff10 | 11) // JMP (R11)
o4 := uint32(0) // WORD $(target-pc) // filled in with relocation
ld.SysArch.ByteOrder.PutUint32(tramp.P, o1)
ld.SysArch.ByteOrder.PutUint32(tramp.P[4:], o2)
ld.SysArch.ByteOrder.PutUint32(tramp.P[8:], o3)
ld.SysArch.ByteOrder.PutUint32(tramp.P[12:], o4)
r := ld.Addrel(tramp)
r.Off = 12
r.Type = obj.R_PCREL
r.Siz = 4
r.Sym = target
r.Add = offset + 4
}
示例14: gentramp
// generate a trampoline to target+offset
func gentramp(tramp, target *ld.Symbol, offset int64) {
tramp.Size = 12 // 3 instructions
tramp.P = make([]byte, tramp.Size)
t := ld.Symaddr(target) + int64(offset)
o1 := uint32(0xe5900000 | 11<<12 | 15<<16) // MOVW (R15), R11 // R15 is actual pc + 8
o2 := uint32(0xe12fff10 | 11) // JMP (R11)
o3 := uint32(t) // WORD $target
ld.SysArch.ByteOrder.PutUint32(tramp.P, o1)
ld.SysArch.ByteOrder.PutUint32(tramp.P[4:], o2)
ld.SysArch.ByteOrder.PutUint32(tramp.P[8:], o3)
if ld.Linkmode == ld.LinkExternal {
r := ld.Addrel(tramp)
r.Off = 8
r.Type = obj.R_ADDR
r.Siz = 4
r.Sym = target
r.Add = offset
}
}
示例15: gentrampdyn
// generate a trampoline to target+offset in dynlink mode (using GOT)
func gentrampdyn(tramp, target *ld.Symbol, offset int64) {
tramp.Size = 20 // 5 instructions
o1 := uint32(0xe5900000 | 11<<12 | 15<<16 | 8) // MOVW 8(R15), R11 // R15 is actual pc + 8
o2 := uint32(0xe0800000 | 11<<12 | 15<<16 | 11) // ADD R15, R11, R11
o3 := uint32(0xe5900000 | 11<<12 | 11<<16) // MOVW (R11), R11
o4 := uint32(0xe12fff10 | 11) // JMP (R11)
o5 := uint32(0) // WORD [email protected] // filled in with relocation
o6 := uint32(0)
if offset != 0 {
// insert an instruction to add offset
tramp.Size = 24 // 6 instructions
o6 = o5
o5 = o4
o4 = uint32(0xe2800000 | 11<<12 | 11<<16 | immrot(uint32(offset))) // ADD $offset, R11, R11
o1 = uint32(0xe5900000 | 11<<12 | 15<<16 | 12) // MOVW 12(R15), R11
}
tramp.P = make([]byte, tramp.Size)
ld.SysArch.ByteOrder.PutUint32(tramp.P, o1)
ld.SysArch.ByteOrder.PutUint32(tramp.P[4:], o2)
ld.SysArch.ByteOrder.PutUint32(tramp.P[8:], o3)
ld.SysArch.ByteOrder.PutUint32(tramp.P[12:], o4)
ld.SysArch.ByteOrder.PutUint32(tramp.P[16:], o5)
if offset != 0 {
ld.SysArch.ByteOrder.PutUint32(tramp.P[20:], o6)
}
r := ld.Addrel(tramp)
r.Off = 16
r.Type = obj.R_GOTPCREL
r.Siz = 4
r.Sym = target
r.Add = 8
if offset != 0 {
// increase reloc offset by 4 as we inserted an ADD instruction
r.Off = 20
r.Add = 12
}
}