func adddynsym(ctxt *ld.Link, s *ld.LSym) { if s.Dynid >= 0 { return } if ld.Iself { s.Dynid = int32(ld.Nelfsym) ld.Nelfsym++ d := ld.Linklookup(ctxt, ".dynsym", 0) name := s.Extname ld.Adduint32(ctxt, d, uint32(ld.Addstring(ld.Linklookup(ctxt, ".dynstr", 0), name))) /* type */ t := ld.STB_GLOBAL << 4 if s.Cgoexport != 0 && s.Type&ld.SMASK == ld.STEXT { t |= ld.STT_FUNC } else { t |= ld.STT_OBJECT } ld.Adduint8(ctxt, d, uint8(t)) /* reserved */ ld.Adduint8(ctxt, d, 0) /* section where symbol is defined */ if s.Type == ld.SDYNIMPORT { ld.Adduint16(ctxt, d, ld.SHN_UNDEF) } else { ld.Adduint16(ctxt, d, 1) } /* value */ if s.Type == ld.SDYNIMPORT { ld.Adduint64(ctxt, d, 0) } else { ld.Addaddr(ctxt, d, s) } /* size of object */ ld.Adduint64(ctxt, d, uint64(s.Size)) if s.Cgoexport&ld.CgoExportDynamic == 0 && s.Dynimplib != "" && needlib(s.Dynimplib) != 0 { ld.Elfwritedynent(ld.Linklookup(ctxt, ".dynamic", 0), ld.DT_NEEDED, uint64(ld.Addstring(ld.Linklookup(ctxt, ".dynstr", 0), s.Dynimplib))) } } else if ld.HEADTYPE == ld.Hdarwin { ld.Diag("adddynsym: missed symbol %s (%s)", s.Name, s.Extname) } else if ld.HEADTYPE == ld.Hwindows { } else // already taken care of { ld.Diag("adddynsym: unsupported binary format") } }
func adddynsym(ctxt *ld.Link, s *ld.LSym) { if s.Dynid >= 0 { return } if ld.Iself { s.Dynid = int32(ld.Nelfsym) ld.Nelfsym++ d := ld.Linklookup(ctxt, ".dynsym", 0) /* name */ name := s.Extname ld.Adduint32(ctxt, d, uint32(ld.Addstring(ld.Linklookup(ctxt, ".dynstr", 0), name))) /* value */ if s.Type == ld.SDYNIMPORT { ld.Adduint32(ctxt, d, 0) } else { ld.Addaddr(ctxt, d, s) } /* size */ ld.Adduint32(ctxt, d, 0) /* type */ t := ld.STB_GLOBAL << 4 if s.Cgoexport != 0 && s.Type&ld.SMASK == ld.STEXT { t |= ld.STT_FUNC } else { t |= ld.STT_OBJECT } ld.Adduint8(ctxt, d, uint8(t)) ld.Adduint8(ctxt, d, 0) /* shndx */ if s.Type == ld.SDYNIMPORT { ld.Adduint16(ctxt, d, ld.SHN_UNDEF) } else { ld.Adduint16(ctxt, d, 1) } } else if ld.HEADTYPE == ld.Hdarwin { ld.Diag("adddynsym: missed symbol %s (%s)", s.Name, s.Extname) } else if ld.HEADTYPE == ld.Hwindows { } else // already taken care of { ld.Diag("adddynsym: unsupported binary format") } }
func adddynsym(ctxt *ld.Link, s *ld.LSym) { if s.Dynid >= 0 { return } if ld.Iself { s.Dynid = int32(ld.Nelfsym) ld.Nelfsym++ d := ld.Linklookup(ctxt, ".dynsym", 0) /* name */ name := s.Extname ld.Adduint32(ctxt, d, uint32(ld.Addstring(ld.Linklookup(ctxt, ".dynstr", 0), name))) /* value */ if s.Type == ld.SDYNIMPORT { ld.Adduint32(ctxt, d, 0) } else { ld.Addaddr(ctxt, d, s) } /* size */ ld.Adduint32(ctxt, d, 0) /* type */ t := ld.STB_GLOBAL << 4 if (s.Cgoexport&ld.CgoExportDynamic != 0) && s.Type&ld.SMASK == ld.STEXT { t |= ld.STT_FUNC } else { t |= ld.STT_OBJECT } ld.Adduint8(ctxt, d, uint8(t)) ld.Adduint8(ctxt, d, 0) /* shndx */ if s.Type == ld.SDYNIMPORT { ld.Adduint16(ctxt, d, ld.SHN_UNDEF) } else { ld.Adduint16(ctxt, d, 1) } } else { ld.Diag("adddynsym: unsupported binary format") } }
func adddynsym(ctxt *ld.Link, s *ld.LSym) { if s.Dynid >= 0 { return } if ld.Iself { s.Dynid = int32(ld.Nelfsym) ld.Nelfsym++ d := ld.Linklookup(ctxt, ".dynsym", 0) name := s.Extname ld.Adduint32(ctxt, d, uint32(ld.Addstring(ld.Linklookup(ctxt, ".dynstr", 0), name))) /* type */ t := ld.STB_GLOBAL << 4 if s.Cgoexport != 0 && s.Type&ld.SMASK == ld.STEXT { t |= ld.STT_FUNC } else { t |= ld.STT_OBJECT } ld.Adduint8(ctxt, d, uint8(t)) /* reserved */ ld.Adduint8(ctxt, d, 0) /* section where symbol is defined */ if s.Type == ld.SDYNIMPORT { ld.Adduint16(ctxt, d, ld.SHN_UNDEF) } else { ld.Adduint16(ctxt, d, 1) } /* value */ if s.Type == ld.SDYNIMPORT { ld.Adduint64(ctxt, d, 0) } else { ld.Addaddr(ctxt, d, s) } /* size of object */ ld.Adduint64(ctxt, d, uint64(s.Size)) } else { ld.Diag("adddynsym: unsupported binary format") } }
func gentext() { if !ld.DynlinkingGo() { return } addmoduledata := ld.Linklookup(ld.Ctxt, "runtime.addmoduledata", 0) if addmoduledata.Type == ld.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 = ld.STEXT initfunc.Local = true initfunc.Reachable = true o := func(op ...uint8) { for _, op1 := range op { ld.Adduint8(ld.Ctxt, initfunc, op1) } } // 0000000000000000 <local.dso_init>: // 0: 48 8d 3d 00 00 00 00 lea 0x0(%rip),%rdi # 7 <local.dso_init+0x7> // 3: R_X86_64_PC32 runtime.firstmoduledata-0x4 o(0x48, 0x8d, 0x3d) ld.Addpcrelplus(ld.Ctxt, initfunc, ld.Linklookup(ld.Ctxt, "runtime.firstmoduledata", 0), 0) // 7: e8 00 00 00 00 callq c <local.dso_init+0xc> // 8: R_X86_64_PLT32 runtime.addmoduledata-0x4 o(0xe8) Addcall(ld.Ctxt, initfunc, addmoduledata) // c: c3 retq o(0xc3) 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 = ld.SINITARR ld.Addaddr(ld.Ctxt, initarray_entry, initfunc) }