本文整理匯總了Golang中cmd/link/internal/ld.Diag函數的典型用法代碼示例。如果您正苦於以下問題:Golang Diag函數的具體用法?Golang Diag怎麽用?Golang Diag使用的例子?那麽, 這裏精選的函數代碼示例或許可以為您提供幫助。
在下文中一共展示了Diag函數的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Golang代碼示例。
示例1: machoreloc1
func machoreloc1(r *ld.Reloc, sectoff int64) int {
var v uint32
rs := r.Xsym
if rs.Type == obj.SHOSTOBJ || r.Type == obj.R_PCREL {
if rs.Dynid < 0 {
ld.Diag("reloc %d to non-macho symbol %s type=%d", r.Type, rs.Name, rs.Type)
return -1
}
v = uint32(rs.Dynid)
v |= 1 << 27 // external relocation
} else {
v = uint32(rs.Sect.Extnum)
if v == 0 {
ld.Diag("reloc %d to symbol %s in non-macho section %s type=%d", r.Type, rs.Name, rs.Sect.Name, rs.Type)
return -1
}
}
switch r.Type {
default:
return -1
case obj.R_ADDR:
v |= ld.MACHO_X86_64_RELOC_UNSIGNED << 28
case obj.R_CALL:
v |= 1 << 24 // pc-relative bit
v |= ld.MACHO_X86_64_RELOC_BRANCH << 28
// NOTE: Only works with 'external' relocation. Forced above.
case obj.R_PCREL:
v |= 1 << 24 // pc-relative bit
v |= ld.MACHO_X86_64_RELOC_SIGNED << 28
}
switch r.Siz {
default:
return -1
case 1:
v |= 0 << 25
case 2:
v |= 1 << 25
case 4:
v |= 2 << 25
case 8:
v |= 3 << 25
}
ld.Thearch.Lput(uint32(sectoff))
ld.Thearch.Lput(v)
return 0
}
示例2: machoreloc1
func machoreloc1(r *ld.Reloc, sectoff int64) int {
var v uint32
rs := r.Xsym
if rs.Type == obj.SHOSTOBJ {
if rs.Dynid < 0 {
ld.Diag("reloc %d to non-macho symbol %s type=%d", r.Type, rs.Name, rs.Type)
return -1
}
v = uint32(rs.Dynid)
v |= 1 << 27 // external relocation
} else {
v = uint32(rs.Sect.Extnum)
if v == 0 {
ld.Diag("reloc %d to symbol %s in non-macho section %s type=%d", r.Type, rs.Name, rs.Sect.Name, rs.Type)
return -1
}
}
switch r.Type {
default:
return -1
case obj.R_ADDR:
v |= ld.MACHO_GENERIC_RELOC_VANILLA << 28
case obj.R_CALL,
obj.R_PCREL:
v |= 1 << 24 // pc-relative bit
v |= ld.MACHO_GENERIC_RELOC_VANILLA << 28
}
switch r.Siz {
default:
return -1
case 1:
v |= 0 << 25
case 2:
v |= 1 << 25
case 4:
v |= 2 << 25
case 8:
v |= 3 << 25
}
ld.Thearch.Lput(uint32(sectoff))
ld.Thearch.Lput(v)
return 0
}
示例3: archrelocaddr
func archrelocaddr(r *ld.Reloc, s *ld.LSym, val *int64) int {
var o1, o2 uint32
if ld.Ctxt.Arch.ByteOrder == binary.BigEndian {
o1 = uint32(*val >> 32)
o2 = uint32(*val)
} else {
o1 = uint32(*val)
o2 = uint32(*val >> 32)
}
// We are inserting an address into two instructions: adrp and
// then either addi or a load.
address := ld.Symaddr(r.Sym) + r.Add
pgaddress := (address &^ 0xfff) - ((s.Value + int64(r.Off)) &^ 0xfff)
if pgaddress < -1<<31 || pgaddress >= 1<<31 {
ld.Ctxt.Diag("relocation for %s is too big (>=2G): %d", s.Name, pgaddress)
}
pgoff := uint32(address & 0xfff)
o1 |= uint32((((pgaddress >> 12) & 3) << 29) | (((pgaddress >> 12 >> 2) & 0x7ffff) << 5))
switch r.Type {
case obj.R_ADDRARM64, obj.R_ARM64_LOAD8:
o2 |= pgoff << 10
case obj.R_ARM64_LOAD16:
if pgoff&0x1 != 0 {
ld.Diag("offset for 16-byte load/store has unaligned value %d", pgoff)
}
o2 |= pgoff << 9
case obj.R_ARM64_LOAD32:
if pgoff&0x3 != 0 {
ld.Diag("offset for 32-byte load/store has unaligned value %d", pgoff)
}
o2 |= pgoff << 8
case obj.R_ARM64_LOAD64:
if pgoff&0x7 != 0 {
ld.Diag("offset for 64-byte load/store has unaligned value %d", pgoff)
}
o2 |= pgoff << 7
default:
return -1
}
if ld.Ctxt.Arch.ByteOrder == binary.BigEndian {
*val = int64(o1)<<32 | int64(o2)
} else {
*val = int64(o2)<<32 | int64(o1)
}
return 0
}
示例4: pereloc1
func pereloc1(r *ld.Reloc, sectoff int64) bool {
var v uint32
rs := r.Xsym
if rs.Dynid < 0 {
ld.Diag("reloc %d to non-coff symbol %s type=%d", r.Type, rs.Name, rs.Type)
return false
}
ld.Thearch.Lput(uint32(sectoff))
ld.Thearch.Lput(uint32(rs.Dynid))
switch r.Type {
default:
return false
case obj.R_ADDR:
v = ld.IMAGE_REL_I386_DIR32
case obj.R_CALL,
obj.R_PCREL:
v = ld.IMAGE_REL_I386_REL32
}
ld.Thearch.Wput(uint16(v))
return true
}
示例5: archrelocvariant
func archrelocvariant(r *ld.Reloc, s *ld.Symbol, t int64) int64 {
switch r.Variant & ld.RV_TYPE_MASK {
default:
ld.Diag("unexpected relocation variant %d", r.Variant)
return t
case ld.RV_NONE:
return t
case ld.RV_390_DBL:
if (t & 1) != 0 {
ld.Diag("%s+%v is not 2-byte aligned", r.Sym.Name, r.Sym.Value)
}
return t >> 1
}
}
示例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)
got := ld.Linklookup(ctxt, ".got.plt", 0)
rel := ld.Linklookup(ctxt, ".rel.plt", 0)
if plt.Size == 0 {
elfsetupplt()
}
// jmpq *got+size
ld.Adduint8(ctxt, plt, 0xff)
ld.Adduint8(ctxt, plt, 0x25)
ld.Addaddrplus(ctxt, plt, got, got.Size)
// add to got: pointer to current pos in plt
ld.Addaddrplus(ctxt, got, plt, plt.Size)
// pushl $x
ld.Adduint8(ctxt, plt, 0x68)
ld.Adduint32(ctxt, plt, uint32(rel.Size))
// jmp .plt
ld.Adduint8(ctxt, plt, 0xe9)
ld.Adduint32(ctxt, plt, uint32(-(plt.Size + 4)))
// rel
ld.Addaddrplus(ctxt, rel, got, got.Size-4)
ld.Adduint32(ctxt, rel, ld.ELF32_R_INFO(uint32(s.Dynid), ld.R_386_JMP_SLOT))
s.Plt = int32(plt.Size - 16)
} else if ld.HEADTYPE == obj.Hdarwin {
// Same laziness as in 6l.
plt := ld.Linklookup(ctxt, ".plt", 0)
addgotsym(ctxt, s)
ld.Adduint32(ctxt, ld.Linklookup(ctxt, ".linkedit.plt", 0), uint32(s.Dynid))
// jmpq *got+size(IP)
s.Plt = int32(plt.Size)
ld.Adduint8(ctxt, plt, 0xff)
ld.Adduint8(ctxt, plt, 0x25)
ld.Addaddrplus(ctxt, plt, ld.Linklookup(ctxt, ".got", 0), int64(s.Got))
} else {
ld.Diag("addpltsym: unsupported binary format")
}
}
示例7: archreloc
func archreloc(r *ld.Reloc, s *ld.LSym, val *int64) int {
if ld.Linkmode == ld.LinkExternal {
// TODO(minux): translate R_ADDRPOWER and R_CALLPOWER into standard ELF relocations.
// R_ADDRPOWER corresponds to R_PPC_ADDR16_HA and R_PPC_ADDR16_LO.
// R_CALLPOWER corresponds to R_PPC_REL24.
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
case obj.R_ADDRPOWER, obj.R_ADDRPOWER_DS:
return archrelocaddr(r, s, val)
case obj.R_CALLPOWER:
// Bits 6 through 29 = (S + A - P) >> 2
t := ld.Symaddr(r.Sym) + r.Add - (s.Value + int64(r.Off))
if t&3 != 0 {
ld.Ctxt.Diag("relocation for %s+%d is not aligned: %d", r.Sym.Name, r.Off, t)
}
if int64(int32(t<<6)>>6) != t {
// TODO(austin) This can happen if text > 32M.
// Add a call trampoline to .text in that case.
ld.Ctxt.Diag("relocation for %s+%d is too big: %d", r.Sym.Name, r.Off, t)
}
*val |= int64(uint32(t) &^ 0xfc000003)
return 0
case obj.R_POWER_TOC: // S + A - .TOC.
*val = ld.Symaddr(r.Sym) + r.Add - symtoc(s)
return 0
case obj.R_POWER_TLS_LE:
// The thread pointer points 0x7000 bytes after the start of the the
// thread local storage area as documented in section "3.7.2 TLS
// Runtime Handling" of "Power Architecture 64-Bit ELF V2 ABI
// Specification".
v := r.Sym.Value - 0x7000
if int64(int16(v)) != v {
ld.Diag("TLS offset out of range %d", v)
}
*val = (*val &^ 0xffff) | (v & 0xffff)
return 0
}
return -1
}
示例8: 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")
}
}
示例9: symtoc
// Return the value of .TOC. for symbol s
func symtoc(s *ld.Symbol) int64 {
var toc *ld.Symbol
if s.Outer != nil {
toc = ld.Linkrlookup(ld.Ctxt, ".TOC.", int(s.Outer.Version))
} else {
toc = ld.Linkrlookup(ld.Ctxt, ".TOC.", int(s.Version))
}
if toc == nil {
ld.Diag("TOC-relative relocation in object without .TOC.")
return 0
}
return toc.Value
}
示例10: 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
case obj.R_ADDRMIPS:
t := ld.Symaddr(r.Sym) + r.Add
if t >= 1<<32 || t < -1<<32 {
ld.Diag("program too large, address relocation = %v", t)
}
// the first instruction is always at the lower address, this is endian neutral;
// but note that o1 and o2 should still use the target endian.
o1 := ld.Thelinkarch.ByteOrder.Uint32(s.P[r.Off:])
o2 := ld.Thelinkarch.ByteOrder.Uint32(s.P[r.Off+4:])
o1 = o1&0xffff0000 | uint32(t>>16)&0xffff
o2 = o2&0xffff0000 | uint32(t)&0xffff
// when laid out, the instruction order must always be o1, o2.
if ld.Ctxt.Arch.ByteOrder == binary.BigEndian {
*val = int64(o1)<<32 | int64(o2)
} else {
*val = int64(o2)<<32 | int64(o1)
}
return 0
case obj.R_CALLMIPS,
obj.R_JMPMIPS:
// Low 26 bits = (S + A) >> 2
t := ld.Symaddr(r.Sym) + r.Add
o1 := ld.Thelinkarch.ByteOrder.Uint32(s.P[r.Off:])
*val = int64(o1&0xfc000000 | uint32(t>>2)&^0xfc000000)
return 0
}
return -1
}
示例11: 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")
}
}
示例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: addgotsym
func addgotsym(s *ld.Symbol) {
if s.Got >= 0 {
return
}
ld.Adddynsym(ld.Ctxt, s)
got := ld.Linklookup(ld.Ctxt, ".got", 0)
s.Got = int32(got.Size)
ld.Adduint64(ld.Ctxt, got, 0)
if ld.Iself {
rela := ld.Linklookup(ld.Ctxt, ".rela", 0)
ld.Addaddrplus(ld.Ctxt, rela, got, int64(s.Got))
ld.Adduint64(ld.Ctxt, rela, ld.ELF64_R_INFO(uint32(s.Dynid), ld.R_390_GLOB_DAT))
ld.Adduint64(ld.Ctxt, rela, 0)
} else {
ld.Diag("addgotsym: unsupported binary format")
}
}
示例14: addgotsym
func addgotsym(s *ld.LSym) {
if s.Got >= 0 {
return
}
ld.Adddynsym(ld.Ctxt, s)
got := ld.Linklookup(ld.Ctxt, ".got", 0)
s.Got = int32(got.Size)
ld.Adduint64(ld.Ctxt, got, 0)
if ld.Iself {
rela := ld.Linklookup(ld.Ctxt, ".rela", 0)
ld.Addaddrplus(ld.Ctxt, rela, got, int64(s.Got))
ld.Adduint64(ld.Ctxt, rela, ld.ELF64_R_INFO(uint32(s.Dynid), ld.R_X86_64_GLOB_DAT))
ld.Adduint64(ld.Ctxt, rela, 0)
} else if ld.HEADTYPE == obj.Hdarwin {
ld.Adduint32(ld.Ctxt, ld.Linklookup(ld.Ctxt, ".linkedit.got", 0), uint32(s.Dynid))
} else {
ld.Diag("addgotsym: unsupported binary format")
}
}
示例15: 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)
got := ld.Linklookup(ctxt, ".got.plt", 0)
rel := ld.Linklookup(ctxt, ".rel.plt", 0)
if plt.Size == 0 {
elfsetupplt()
}
// .got entry
s.Got = int32(got.Size)
// In theory, all GOT should point to the first PLT entry,
// Linux/ARM's dynamic linker will do that for us, but FreeBSD/ARM's
// dynamic linker won't, so we'd better do it ourselves.
ld.Addaddrplus(ctxt, got, plt, 0)
// .plt entry, this depends on the .got entry
s.Plt = int32(plt.Size)
addpltreloc(ctxt, plt, got, s, obj.R_PLT0) // add lr, pc, #0xXX00000
addpltreloc(ctxt, plt, got, s, obj.R_PLT1) // add lr, lr, #0xYY000
addpltreloc(ctxt, plt, got, s, obj.R_PLT2) // ldr pc, [lr, #0xZZZ]!
// rel
ld.Addaddrplus(ctxt, rel, got, int64(s.Got))
ld.Adduint32(ctxt, rel, ld.ELF32_R_INFO(uint32(s.Dynid), ld.R_ARM_JUMP_SLOT))
} else {
ld.Diag("addpltsym: unsupported binary format")
}
}