Commit 2f783c34 authored by Michael Matloob's avatar Michael Matloob

cmd/link/internal: thread *ld.Link through calls

Ctxt is a global defined in cmd/link/internal/ld of type *ld.Link.
Start threading a *ld.Link through function calls instead of
relying on the global variable.

Ctxt is still used as a global by the architecture-specific packages,
but I plan to fix that in a subsequent CL.

Change-Id: I77a3a58bd396fafd959fa1d8b1c83008a9f5a7fb
Reviewed-on: https://go-review.googlesource.com/27408
Run-TryBot: Michael Matloob <matloob@golang.org>
TryBot-Result: Gobot Gobot <gobot@golang.org>
Reviewed-by: 's avatarBrad Fitzpatrick <bradfitz@golang.org>
Reviewed-by: 's avatarMichael Hudson-Doyle <michael.hudson@canonical.com>
parent 4b17b152
......@@ -101,17 +101,17 @@ func adddynrel(s *ld.Symbol, r *ld.Reloc) {
switch r.Type {
default:
if r.Type >= 256 {
ld.Diag("unexpected relocation type %d", r.Type)
ld.Ctxt.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)
ld.Ctxt.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)
ld.Ctxt.Diag("unknown symbol %s in pcrel", targ.Name)
}
r.Type = obj.R_PCREL
r.Add += 4
......@@ -153,7 +153,7 @@ func adddynrel(s *ld.Symbol, r *ld.Reloc) {
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)
ld.Ctxt.Diag("unexpected R_X86_64_64 relocation for dynamic symbol %s", targ.Name)
}
r.Type = obj.R_ADDR
return
......@@ -166,7 +166,7 @@ func adddynrel(s *ld.Symbol, r *ld.Reloc) {
r.Type = obj.R_ADDR
if targ.Type == obj.SDYNIMPORT {
ld.Diag("unexpected reloc for dynamic symbol %s", targ.Name)
ld.Ctxt.Diag("unexpected reloc for dynamic symbol %s", targ.Name)
}
return
......@@ -189,7 +189,7 @@ func adddynrel(s *ld.Symbol, r *ld.Reloc) {
r.Type = obj.R_PCREL
if targ.Type == obj.SDYNIMPORT {
ld.Diag("unexpected pc-relative reloc for dynamic symbol %s", targ.Name)
ld.Ctxt.Diag("unexpected pc-relative reloc for dynamic symbol %s", targ.Name)
}
return
......@@ -198,7 +198,7 @@ func adddynrel(s *ld.Symbol, r *ld.Reloc) {
// have symbol
// turn MOVQ of GOT entry into LEAQ of symbol itself
if r.Off < 2 || s.P[r.Off-2] != 0x8b {
ld.Diag("unexpected GOT_LOAD reloc for non-dynamic symbol %s", targ.Name)
ld.Ctxt.Diag("unexpected GOT_LOAD reloc for non-dynamic symbol %s", targ.Name)
return
}
......@@ -211,7 +211,7 @@ func adddynrel(s *ld.Symbol, r *ld.Reloc) {
// fall through
case 512 + ld.MACHO_X86_64_RELOC_GOT*2 + 1:
if targ.Type != obj.SDYNIMPORT {
ld.Diag("unexpected GOT reloc for non-dynamic symbol %s", targ.Name)
ld.Ctxt.Diag("unexpected GOT reloc for non-dynamic symbol %s", targ.Name)
}
addgotsym(targ)
r.Type = obj.R_PCREL
......@@ -306,7 +306,7 @@ func adddynrel(s *ld.Symbol, r *ld.Reloc) {
}
ld.Ctxt.Cursym = s
ld.Diag("unsupported relocation for dynamic symbol %s (type=%d stype=%d)", targ.Name, r.Type, targ.Type)
ld.Ctxt.Diag("unsupported relocation for dynamic symbol %s (type=%d stype=%d)", targ.Name, r.Type, targ.Type)
}
func elfreloc1(r *ld.Reloc, sectoff int64) int {
......@@ -385,7 +385,7 @@ func machoreloc1(r *ld.Reloc, sectoff int64) int {
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)
ld.Ctxt.Diag("reloc %d to non-macho symbol %s type=%d", r.Type, rs.Name, rs.Type)
return -1
}
......@@ -394,7 +394,7 @@ func machoreloc1(r *ld.Reloc, sectoff int64) int {
} 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)
ld.Ctxt.Diag("reloc %d to symbol %s in non-macho section %s type=%d", r.Type, rs.Name, rs.Sect.Name, rs.Type)
return -1
}
}
......@@ -444,7 +444,7 @@ func pereloc1(r *ld.Reloc, sectoff int64) bool {
rs := r.Xsym
if rs.Dynid < 0 {
ld.Diag("reloc %d to non-coff symbol %s type=%d", r.Type, rs.Name, rs.Type)
ld.Ctxt.Diag("reloc %d to non-coff symbol %s type=%d", r.Type, rs.Name, rs.Type)
return false
}
......@@ -572,7 +572,7 @@ func addpltsym(s *ld.Symbol) {
ld.Adduint8(ld.Ctxt, plt, 0x25)
ld.Addpcrelplus(ld.Ctxt, plt, ld.Linklookup(ld.Ctxt, ".got", 0), int64(s.Got))
} else {
ld.Diag("addpltsym: unsupported binary format")
ld.Ctxt.Diag("addpltsym: unsupported binary format")
}
}
......@@ -594,11 +594,11 @@ func addgotsym(s *ld.Symbol) {
} 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")
ld.Ctxt.Diag("addgotsym: unsupported binary format")
}
}
func asmb() {
func asmb(ctxt *ld.Link) {
if ld.Debug['v'] != 0 {
fmt.Fprintf(ld.Bso, "%5.2f asmb\n", obj.Cputime())
}
......@@ -610,16 +610,16 @@ func asmb() {
ld.Bso.Flush()
if ld.Iself {
ld.Asmbelfsetup()
ld.Asmbelfsetup(ctxt)
}
sect := ld.Segtext.Sect
ld.Cseek(int64(sect.Vaddr - ld.Segtext.Vaddr + ld.Segtext.Fileoff))
// 0xCC is INT $3 - breakpoint instruction
ld.CodeblkPad(int64(sect.Vaddr), int64(sect.Length), []byte{0xCC})
ld.CodeblkPad(ctxt, int64(sect.Vaddr), int64(sect.Length), []byte{0xCC})
for sect = sect.Next; sect != nil; sect = sect.Next {
ld.Cseek(int64(sect.Vaddr - ld.Segtext.Vaddr + ld.Segtext.Fileoff))
ld.Datblk(int64(sect.Vaddr), int64(sect.Length))
ld.Datblk(ctxt, int64(sect.Vaddr), int64(sect.Length))
}
if ld.Segrodata.Filelen > 0 {
......@@ -629,7 +629,7 @@ func asmb() {
ld.Bso.Flush()
ld.Cseek(int64(ld.Segrodata.Fileoff))
ld.Datblk(int64(ld.Segrodata.Vaddr), int64(ld.Segrodata.Filelen))
ld.Datblk(ctxt, int64(ld.Segrodata.Vaddr), int64(ld.Segrodata.Filelen))
}
if ld.Debug['v'] != 0 {
......@@ -638,19 +638,19 @@ func asmb() {
ld.Bso.Flush()
ld.Cseek(int64(ld.Segdata.Fileoff))
ld.Datblk(int64(ld.Segdata.Vaddr), int64(ld.Segdata.Filelen))
ld.Datblk(ctxt, int64(ld.Segdata.Vaddr), int64(ld.Segdata.Filelen))
ld.Cseek(int64(ld.Segdwarf.Fileoff))
ld.Dwarfblk(int64(ld.Segdwarf.Vaddr), int64(ld.Segdwarf.Filelen))
ld.Dwarfblk(ctxt, int64(ld.Segdwarf.Vaddr), int64(ld.Segdwarf.Filelen))
machlink := int64(0)
if ld.HEADTYPE == obj.Hdarwin {
machlink = ld.Domacholink()
machlink = ld.Domacholink(ctxt)
}
switch ld.HEADTYPE {
default:
ld.Diag("unknown header type %d", ld.HEADTYPE)
ld.Ctxt.Diag("unknown header type %d", ld.HEADTYPE)
fallthrough
case obj.Hplan9:
......@@ -710,7 +710,7 @@ func asmb() {
default:
if ld.Iself {
ld.Cseek(symo)
ld.Asmelfsym()
ld.Asmelfsym(ctxt)
ld.Cflush()
ld.Cwrite(ld.Elfstrdat)
......@@ -719,12 +719,12 @@ func asmb() {
}
if ld.Linkmode == ld.LinkExternal {
ld.Elfemitreloc()
ld.Elfemitreloc(ctxt)
}
}
case obj.Hplan9:
ld.Asmplan9sym()
ld.Asmplan9sym(ctxt)
ld.Cflush()
sym := ld.Linklookup(ld.Ctxt, "pclntab", 0)
......@@ -744,7 +744,7 @@ func asmb() {
case obj.Hdarwin:
if ld.Linkmode == ld.LinkExternal {
ld.Machoemitreloc()
ld.Machoemitreloc(ctxt)
}
}
}
......@@ -765,14 +765,14 @@ func asmb() {
ld.Lputb(uint32(ld.Segdata.Filelen))
ld.Lputb(uint32(ld.Segdata.Length - ld.Segdata.Filelen))
ld.Lputb(uint32(ld.Symsize)) /* nsyms */
vl := ld.Entryvalue()
vl := ld.Entryvalue(ctxt)
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()
ld.Asmbmacho(ctxt)
case obj.Hlinux,
obj.Hfreebsd,
......@@ -781,10 +781,10 @@ func asmb() {
obj.Hdragonfly,
obj.Hsolaris,
obj.Hnacl:
ld.Asmbelf(symo)
ld.Asmbelf(ctxt, symo)
case obj.Hwindows:
ld.Asmbpe()
ld.Asmbpe(ctxt)
}
ld.Cflush()
......
......@@ -83,6 +83,8 @@ func linkarchinit() {
}
func archinit() {
ctxt := ld.Ctxt
// getgoextlinkenabled is based on GO_EXTLINK_ENABLED when
// Go was built; see ../../make.bash.
if ld.Linkmode == ld.LinkAuto && obj.Getgoextlinkenabled() == "0" {
......@@ -151,7 +153,7 @@ func archinit() {
obj.Hopenbsd, /* openbsd */
obj.Hdragonfly, /* dragonfly */
obj.Hsolaris: /* solaris */
ld.Elfinit()
ld.Elfinit(ld.Ctxt)
ld.HEADR = ld.ELFRESERVE
if ld.INITTEXT == -1 {
......@@ -165,7 +167,7 @@ func archinit() {
}
case obj.Hnacl:
ld.Elfinit()
ld.Elfinit(ld.Ctxt)
ld.Debug['w']++ // disable dwarf, which gets confused and is useless anyway
ld.HEADR = 0x10000
ld.Funcalign = 32
......@@ -180,7 +182,7 @@ func archinit() {
}
case obj.Hwindows: /* PE executable */
ld.Peinit()
ld.Peinit(ctxt)
ld.HEADR = ld.PEFILEHEADR
if ld.INITTEXT == -1 {
......
......@@ -116,7 +116,7 @@ func adddynrel(s *ld.Symbol, r *ld.Reloc) {
switch r.Type {
default:
if r.Type >= 256 {
ld.Diag("unexpected relocation type %d", r.Type)
ld.Ctxt.Diag("unexpected relocation type %d", r.Type)
return
}
......@@ -190,7 +190,7 @@ func adddynrel(s *ld.Symbol, r *ld.Reloc) {
case 256 + ld.R_ARM_ABS32:
if targ.Type == obj.SDYNIMPORT {
ld.Diag("unexpected R_ARM_ABS32 relocation for dynamic symbol %s", targ.Name)
ld.Ctxt.Diag("unexpected R_ARM_ABS32 relocation for dynamic symbol %s", targ.Name)
}
r.Type = obj.R_ADDR
return
......@@ -245,7 +245,7 @@ func adddynrel(s *ld.Symbol, r *ld.Reloc) {
}
ld.Ctxt.Cursym = s
ld.Diag("unsupported relocation for dynamic symbol %s (type=%d stype=%d)", targ.Name, r.Type, targ.Type)
ld.Ctxt.Diag("unsupported relocation for dynamic symbol %s (type=%d stype=%d)", targ.Name, r.Type, targ.Type)
}
func elfreloc1(r *ld.Reloc, sectoff int64) int {
......@@ -332,7 +332,7 @@ func machoreloc1(r *ld.Reloc, sectoff int64) int {
if r.Type == obj.R_PCREL {
if rs.Type == obj.SHOSTOBJ {
ld.Diag("pc-relative relocation of external symbol is not supported")
ld.Ctxt.Diag("pc-relative relocation of external symbol is not supported")
return -1
}
if r.Siz != 4 {
......@@ -354,7 +354,7 @@ func machoreloc1(r *ld.Reloc, sectoff int64) int {
o2 |= 2 << 28 // size = 4
ld.Thearch.Lput(o1)
ld.Thearch.Lput(uint32(ld.Symaddr(rs)))
ld.Thearch.Lput(uint32(ld.Symaddr(ld.Ctxt, rs)))
ld.Thearch.Lput(o2)
ld.Thearch.Lput(uint32(ld.Ctxt.Cursym.Value + int64(r.Off)))
return 0
......@@ -362,7 +362,7 @@ func machoreloc1(r *ld.Reloc, sectoff int64) int {
if rs.Type == obj.SHOSTOBJ || r.Type == obj.R_CALLARM {
if rs.Dynid < 0 {
ld.Diag("reloc %d to non-macho symbol %s type=%d", r.Type, rs.Name, rs.Type)
ld.Ctxt.Diag("reloc %d to non-macho symbol %s type=%d", r.Type, rs.Name, rs.Type)
return -1
}
......@@ -371,7 +371,7 @@ func machoreloc1(r *ld.Reloc, sectoff int64) int {
} 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)
ld.Ctxt.Diag("reloc %d to symbol %s in non-macho section %s type=%d", r.Type, rs.Name, rs.Sect.Name, rs.Type)
return -1
}
}
......@@ -411,6 +411,7 @@ func machoreloc1(r *ld.Reloc, sectoff int64) int {
}
func archreloc(r *ld.Reloc, s *ld.Symbol, val *int64) int {
ctxt := ld.Ctxt
if ld.Linkmode == ld.LinkExternal {
switch r.Type {
case obj.R_CALLARM:
......@@ -425,12 +426,12 @@ func archreloc(r *ld.Reloc, s *ld.Symbol, val *int64) int {
}
r.Xadd *= 4
for rs.Outer != nil {
r.Xadd += ld.Symaddr(rs) - ld.Symaddr(rs.Outer)
r.Xadd += ld.Symaddr(ctxt, rs) - ld.Symaddr(ctxt, rs.Outer)
rs = rs.Outer
}
if rs.Type != obj.SHOSTOBJ && rs.Type != obj.SDYNIMPORT && rs.Sect == nil {
ld.Diag("missing section for %s", rs.Name)
ld.Ctxt.Diag("missing section for %s", rs.Name)
}
r.Xsym = rs
......@@ -440,7 +441,7 @@ func archreloc(r *ld.Reloc, s *ld.Symbol, val *int64) int {
// we need to compensate that by removing the instruction's address
// from addend.
if ld.HEADTYPE == obj.Hdarwin {
r.Xadd -= ld.Symaddr(s) + int64(r.Off)
r.Xadd -= ld.Symaddr(ctxt, s) + int64(r.Off)
}
*val = int64(braddoff(int32(0xff000000&uint32(r.Add)), int32(0xffffff&uint32(r.Xadd/4))))
......@@ -456,30 +457,30 @@ func archreloc(r *ld.Reloc, s *ld.Symbol, val *int64) int {
return 0
case obj.R_GOTOFF:
*val = ld.Symaddr(r.Sym) + r.Add - ld.Symaddr(ld.Linklookup(ld.Ctxt, ".got", 0))
*val = ld.Symaddr(ctxt, r.Sym) + r.Add - ld.Symaddr(ctxt, ld.Linklookup(ld.Ctxt, ".got", 0))
return 0
// The following three arch specific relocations are only for generation of
// Linux/ARM ELF's PLT entry (3 assembler instruction)
case obj.R_PLT0: // add ip, pc, #0xXX00000
if ld.Symaddr(ld.Linklookup(ld.Ctxt, ".got.plt", 0)) < ld.Symaddr(ld.Linklookup(ld.Ctxt, ".plt", 0)) {
ld.Diag(".got.plt should be placed after .plt section.")
if ld.Symaddr(ctxt, ld.Linklookup(ld.Ctxt, ".got.plt", 0)) < ld.Symaddr(ctxt, ld.Linklookup(ld.Ctxt, ".plt", 0)) {
ld.Ctxt.Diag(".got.plt should be placed after .plt section.")
}
*val = 0xe28fc600 + (0xff & (int64(uint32(ld.Symaddr(r.Sym)-(ld.Symaddr(ld.Linklookup(ld.Ctxt, ".plt", 0))+int64(r.Off))+r.Add)) >> 20))
*val = 0xe28fc600 + (0xff & (int64(uint32(ld.Symaddr(ctxt, r.Sym)-(ld.Symaddr(ctxt, ld.Linklookup(ld.Ctxt, ".plt", 0))+int64(r.Off))+r.Add)) >> 20))
return 0
case obj.R_PLT1: // add ip, ip, #0xYY000
*val = 0xe28cca00 + (0xff & (int64(uint32(ld.Symaddr(r.Sym)-(ld.Symaddr(ld.Linklookup(ld.Ctxt, ".plt", 0))+int64(r.Off))+r.Add+4)) >> 12))
*val = 0xe28cca00 + (0xff & (int64(uint32(ld.Symaddr(ctxt, r.Sym)-(ld.Symaddr(ctxt, ld.Linklookup(ld.Ctxt, ".plt", 0))+int64(r.Off))+r.Add+4)) >> 12))
return 0
case obj.R_PLT2: // ldr pc, [ip, #0xZZZ]!
*val = 0xe5bcf000 + (0xfff & int64(uint32(ld.Symaddr(r.Sym)-(ld.Symaddr(ld.Linklookup(ld.Ctxt, ".plt", 0))+int64(r.Off))+r.Add+8)))
*val = 0xe5bcf000 + (0xfff & int64(uint32(ld.Symaddr(ctxt, r.Sym)-(ld.Symaddr(ctxt, ld.Linklookup(ld.Ctxt, ".plt", 0))+int64(r.Off))+r.Add+8)))
return 0
case obj.R_CALLARM: // bl XXXXXX or b YYYYYY
*val = int64(braddoff(int32(0xff000000&uint32(r.Add)), int32(0xffffff&uint32((ld.Symaddr(r.Sym)+int64((uint32(r.Add))*4)-(s.Value+int64(r.Off)))/4))))
*val = int64(braddoff(int32(0xff000000&uint32(r.Add)), int32(0xffffff&uint32((ld.Symaddr(ctxt, r.Sym)+int64((uint32(r.Add))*4)-(s.Value+int64(r.Off)))/4))))
return 0
}
......@@ -542,7 +543,7 @@ func addpltsym(ctxt *ld.Link, s *ld.Symbol) {
ld.Adduint32(ctxt, rel, ld.ELF32_R_INFO(uint32(s.Dynid), ld.R_ARM_JUMP_SLOT))
} else {
ld.Diag("addpltsym: unsupported binary format")
ld.Ctxt.Diag("addpltsym: unsupported binary format")
}
}
......@@ -558,7 +559,7 @@ func addgotsyminternal(ctxt *ld.Link, s *ld.Symbol) {
if ld.Iself {
} else {
ld.Diag("addgotsyminternal: unsupported binary format")
ld.Ctxt.Diag("addgotsyminternal: unsupported binary format")
}
}
......@@ -577,26 +578,26 @@ func addgotsym(ctxt *ld.Link, s *ld.Symbol) {
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")
ld.Ctxt.Diag("addgotsym: unsupported binary format")
}
}
func asmb() {
func asmb(ctxt *ld.Link) {
if ld.Debug['v'] != 0 {
fmt.Fprintf(ld.Bso, "%5.2f asmb\n", obj.Cputime())
}
ld.Bso.Flush()
if ld.Iself {
ld.Asmbelfsetup()
ld.Asmbelfsetup(ctxt)
}
sect := ld.Segtext.Sect
ld.Cseek(int64(sect.Vaddr - ld.Segtext.Vaddr + ld.Segtext.Fileoff))
ld.Codeblk(int64(sect.Vaddr), int64(sect.Length))
ld.Codeblk(ctxt, int64(sect.Vaddr), int64(sect.Length))
for sect = sect.Next; sect != nil; sect = sect.Next {
ld.Cseek(int64(sect.Vaddr - ld.Segtext.Vaddr + ld.Segtext.Fileoff))
ld.Datblk(int64(sect.Vaddr), int64(sect.Length))
ld.Datblk(ctxt, int64(sect.Vaddr), int64(sect.Length))
}
if ld.Segrodata.Filelen > 0 {
......@@ -606,7 +607,7 @@ func asmb() {
ld.Bso.Flush()
ld.Cseek(int64(ld.Segrodata.Fileoff))
ld.Datblk(int64(ld.Segrodata.Vaddr), int64(ld.Segrodata.Filelen))
ld.Datblk(ctxt, int64(ld.Segrodata.Vaddr), int64(ld.Segrodata.Filelen))
}
if ld.Debug['v'] != 0 {
......@@ -615,14 +616,14 @@ func asmb() {
ld.Bso.Flush()
ld.Cseek(int64(ld.Segdata.Fileoff))
ld.Datblk(int64(ld.Segdata.Vaddr), int64(ld.Segdata.Filelen))
ld.Datblk(ctxt, int64(ld.Segdata.Vaddr), int64(ld.Segdata.Filelen))
ld.Cseek(int64(ld.Segdwarf.Fileoff))
ld.Dwarfblk(int64(ld.Segdwarf.Vaddr), int64(ld.Segdwarf.Filelen))
ld.Dwarfblk(ctxt, int64(ld.Segdwarf.Vaddr), int64(ld.Segdwarf.Filelen))
machlink := uint32(0)
if ld.HEADTYPE == obj.Hdarwin {
machlink = uint32(ld.Domacholink())
machlink = uint32(ld.Domacholink(ctxt))
}
/* output symbol table */
......@@ -657,17 +658,17 @@ func asmb() {
if ld.Debug['v'] != 0 {
fmt.Fprintf(ld.Bso, "%5.2f elfsym\n", obj.Cputime())
}
ld.Asmelfsym()
ld.Asmelfsym(ctxt)
ld.Cflush()
ld.Cwrite(ld.Elfstrdat)
if ld.Linkmode == ld.LinkExternal {
ld.Elfemitreloc()
ld.Elfemitreloc(ctxt)
}
}
case obj.Hplan9:
ld.Asmplan9sym()
ld.Asmplan9sym(ctxt)
ld.Cflush()
sym := ld.Linklookup(ld.Ctxt, "pclntab", 0)
......@@ -682,7 +683,7 @@ func asmb() {
case obj.Hdarwin:
if ld.Linkmode == ld.LinkExternal {
ld.Machoemitreloc()
ld.Machoemitreloc(ctxt)
}
}
}
......@@ -701,7 +702,7 @@ func asmb() {
ld.Lputb(uint32(ld.Segdata.Filelen))
ld.Lputb(uint32(ld.Segdata.Length - ld.Segdata.Filelen))
ld.Lputb(uint32(ld.Symsize)) /* nsyms */
ld.Lputb(uint32(ld.Entryvalue())) /* va of entry */
ld.Lputb(uint32(ld.Entryvalue(ctxt))) /* va of entry */
ld.Lputb(0)
ld.Lputb(uint32(ld.Lcsize))
......@@ -710,10 +711,10 @@ func asmb() {
obj.Hnetbsd,
obj.Hopenbsd,
obj.Hnacl:
ld.Asmbelf(int64(symo))
ld.Asmbelf(ctxt, int64(symo))
case obj.Hdarwin:
ld.Asmbmacho()
ld.Asmbmacho(ctxt)
}
ld.Cflush()
......
......@@ -128,7 +128,7 @@ func archinit() {
obj.Hopenbsd:
ld.Debug['d'] = 0
// with dynamic linking
ld.Elfinit()
ld.Elfinit(ld.Ctxt)
ld.HEADR = ld.ELFRESERVE
if ld.INITTEXT == -1 {
ld.INITTEXT = 0x10000 + int64(ld.HEADR)
......@@ -141,7 +141,7 @@ func archinit() {
}
case obj.Hnacl:
ld.Elfinit()
ld.Elfinit(ld.Ctxt)
ld.HEADR = 0x10000
ld.Funcalign = 16
if ld.INITTEXT == -1 {
......
......@@ -157,7 +157,7 @@ func machoreloc1(r *ld.Reloc, sectoff int64) int {
// UNSIGNED relocation at all.
if rs.Type == obj.SHOSTOBJ || r.Type == obj.R_CALLARM64 || r.Type == obj.R_ADDRARM64 || r.Type == obj.R_ADDR {
if rs.Dynid < 0 {
ld.Diag("reloc %d to non-macho symbol %s type=%d", r.Type, rs.Name, rs.Type)
ld.Ctxt.Diag("reloc %d to non-macho symbol %s type=%d", r.Type, rs.Name, rs.Type)
return -1
}
......@@ -166,7 +166,7 @@ func machoreloc1(r *ld.Reloc, sectoff int64) int {
} 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)
ld.Ctxt.Diag("reloc %d to symbol %s in non-macho section %s type=%d", r.Type, rs.Name, rs.Sect.Name, rs.Type)
return -1
}
}
......@@ -180,7 +180,7 @@ func machoreloc1(r *ld.Reloc, sectoff int64) int {
case obj.R_CALLARM64:
if r.Xadd != 0 {
ld.Diag("ld64 doesn't allow BR26 reloc with non-zero addend: %s+%d", rs.Name, r.Xadd)
ld.Ctxt.Diag("ld64 doesn't allow BR26 reloc with non-zero addend: %s+%d", rs.Name, r.Xadd)
}
v |= 1 << 24 // pc-relative bit
......@@ -227,6 +227,7 @@ func machoreloc1(r *ld.Reloc, sectoff int64) int {
}
func archreloc(r *ld.Reloc, s *ld.Symbol, val *int64) int {
ctxt := ld.Ctxt
if ld.Linkmode == ld.LinkExternal {
switch r.Type {
default:
......@@ -270,12 +271,12 @@ func archreloc(r *ld.Reloc, s *ld.Symbol, val *int64) int {
rs := r.Sym
r.Xadd = r.Add
for rs.Outer != nil {
r.Xadd += ld.Symaddr(rs) - ld.Symaddr(rs.Outer)
r.Xadd += ld.Symaddr(ctxt, rs) - ld.Symaddr(ctxt, rs.Outer)
rs = rs.Outer
}
if rs.Type != obj.SHOSTOBJ && rs.Type != obj.SDYNIMPORT && rs.Sect == nil {
ld.Diag("missing section for %s", rs.Name)
ld.Ctxt.Diag("missing section for %s", rs.Name)
}
r.Xsym = rs
......@@ -329,13 +330,13 @@ func archreloc(r *ld.Reloc, s *ld.Symbol, val *int64) int {
return 0
case obj.R_GOTOFF:
*val = ld.Symaddr(r.Sym) + r.Add - ld.Symaddr(ld.Linklookup(ld.Ctxt, ".got", 0))
*val = ld.Symaddr(ctxt, r.Sym) + r.Add - ld.Symaddr(ctxt, ld.Linklookup(ld.Ctxt, ".got", 0))
return 0
case obj.R_ADDRARM64:
t := ld.Symaddr(r.Sym) + r.Add - ((s.Value + int64(r.Off)) &^ 0xfff)
t := ld.Symaddr(ctxt, r.Sym) + r.Add - ((s.Value + int64(r.Off)) &^ 0xfff)
if t >= 1<<32 || t < -1<<32 {
ld.Diag("program too large, address relocation distance = %d", t)
ld.Ctxt.Diag("program too large, address relocation distance = %d", t)
}
var o0, o1 uint32
......@@ -362,21 +363,21 @@ func archreloc(r *ld.Reloc, s *ld.Symbol, val *int64) int {
case obj.R_ARM64_TLS_LE:
r.Done = 0
if ld.HEADTYPE != obj.Hlinux {
ld.Diag("TLS reloc on unsupported OS %s", ld.Headstr(int(ld.HEADTYPE)))
ld.Ctxt.Diag("TLS reloc on unsupported OS %s", ld.Headstr(int(ld.HEADTYPE)))
}
// The TCB is two pointers. This is not documented anywhere, but is
// de facto part of the ABI.
v := r.Sym.Value + int64(2*ld.SysArch.PtrSize)
if v < 0 || v >= 32678 {
ld.Diag("TLS offset out of range %d", v)
ld.Ctxt.Diag("TLS offset out of range %d", v)
}
*val |= v << 5
return 0
case obj.R_CALLARM64:
t := (ld.Symaddr(r.Sym) + r.Add) - (s.Value + int64(r.Off))
t := (ld.Symaddr(ctxt, r.Sym) + r.Add) - (s.Value + int64(r.Off))
if t >= 1<<27 || t < -1<<27 {
ld.Diag("program too large, call relocation distance = %d", t)
ld.Ctxt.Diag("program too large, call relocation distance = %d", t)
}
*val |= (t >> 2) & 0x03ffffff
return 0
......@@ -390,22 +391,22 @@ func archrelocvariant(r *ld.Reloc, s *ld.Symbol, t int64) int64 {
return -1
}
func asmb() {
func asmb(ctxt *ld.Link) {
if ld.Debug['v'] != 0 {
fmt.Fprintf(ld.Bso, "%5.2f asmb\n", obj.Cputime())
}
ld.Bso.Flush()
if ld.Iself {
ld.Asmbelfsetup()
ld.Asmbelfsetup(ctxt)
}
sect := ld.Segtext.Sect
ld.Cseek(int64(sect.Vaddr - ld.Segtext.Vaddr + ld.Segtext.Fileoff))
ld.Codeblk(int64(sect.Vaddr), int64(sect.Length))
ld.Codeblk(ctxt, int64(sect.Vaddr), int64(sect.Length))
for sect = sect.Next; sect != nil; sect = sect.Next {
ld.Cseek(int64(sect.Vaddr - ld.Segtext.Vaddr + ld.Segtext.Fileoff))
ld.Datblk(int64(sect.Vaddr), int64(sect.Length))
ld.Datblk(ctxt, int64(sect.Vaddr), int64(sect.Length))
}
if ld.Segrodata.Filelen > 0 {
......@@ -415,7 +416,7 @@ func asmb() {
ld.Bso.Flush()
ld.Cseek(int64(ld.Segrodata.Fileoff))
ld.Datblk(int64(ld.Segrodata.Vaddr), int64(ld.Segrodata.Filelen))
ld.Datblk(ctxt, int64(ld.Segrodata.Vaddr), int64(ld.Segrodata.Filelen))
}
if ld.Debug['v'] != 0 {
......@@ -424,14 +425,14 @@ func asmb() {
ld.Bso.Flush()
ld.Cseek(int64(ld.Segdata.Fileoff))
ld.Datblk(int64(ld.Segdata.Vaddr), int64(ld.Segdata.Filelen))
ld.Datblk(ctxt, int64(ld.Segdata.Vaddr), int64(ld.Segdata.Filelen))
ld.Cseek(int64(ld.Segdwarf.Fileoff))
ld.Dwarfblk(int64(ld.Segdwarf.Vaddr), int64(ld.Segdwarf.Filelen))
ld.Dwarfblk(ctxt, int64(ld.Segdwarf.Vaddr), int64(ld.Segdwarf.Filelen))
machlink := uint32(0)
if ld.HEADTYPE == obj.Hdarwin {
machlink = uint32(ld.Domacholink())
machlink = uint32(ld.Domacholink(ctxt))
}
/* output symbol table */
......@@ -466,17 +467,17 @@ func asmb() {
if ld.Debug['v'] != 0 {
fmt.Fprintf(ld.Bso, "%5.2f elfsym\n", obj.Cputime())
}
ld.Asmelfsym()
ld.Asmelfsym(ctxt)
ld.Cflush()
ld.Cwrite(ld.Elfstrdat)
if ld.Linkmode == ld.LinkExternal {
ld.Elfemitreloc()
ld.Elfemitreloc(ctxt)
}
}
case obj.Hplan9:
ld.Asmplan9sym()
ld.Asmplan9sym(ctxt)
ld.Cflush()
sym := ld.Linklookup(ld.Ctxt, "pclntab", 0)
......@@ -491,7 +492,7 @@ func asmb() {
case obj.Hdarwin:
if ld.Linkmode == ld.LinkExternal {
ld.Machoemitreloc()
ld.Machoemitreloc(ctxt)
}
}
}
......@@ -510,7 +511,7 @@ func asmb() {
ld.Thearch.Lput(uint32(ld.Segdata.Filelen))
ld.Thearch.Lput(uint32(ld.Segdata.Length - ld.Segdata.Filelen))
ld.Thearch.Lput(uint32(ld.Symsize)) /* nsyms */
ld.Thearch.Lput(uint32(ld.Entryvalue())) /* va of entry */
ld.Thearch.Lput(uint32(ld.Entryvalue(ctxt))) /* va of entry */
ld.Thearch.Lput(0)
ld.Thearch.Lput(uint32(ld.Lcsize))
......@@ -519,10 +520,10 @@ func asmb() {
obj.Hnetbsd,
obj.Hopenbsd,
obj.Hnacl:
ld.Asmbelf(int64(symo))
ld.Asmbelf(ctxt, int64(symo))
case obj.Hdarwin:
ld.Asmbmacho()
ld.Asmbmacho(ctxt)
}
ld.Cflush()
......
......@@ -125,7 +125,7 @@ func archinit() {
}
case obj.Hlinux: /* arm64 elf */
ld.Elfinit()
ld.Elfinit(ld.Ctxt)
ld.HEADR = ld.ELFRESERVE
if ld.INITTEXT == -1 {
ld.INITTEXT = 0x10000 + int64(ld.HEADR)
......@@ -152,7 +152,7 @@ func archinit() {
}
case obj.Hnacl:
ld.Elfinit()
ld.Elfinit(ld.Ctxt)
ld.HEADR = 0x10000
ld.Funcalign = 16
if ld.INITTEXT == -1 {
......
......@@ -63,7 +63,7 @@ type ArHdr struct {
// file, but it has an armap listing symbols and the objects that
// define them. This is used for the compiler support library
// libgcc.a.
func hostArchive(name string) {
func hostArchive(ctxt *Link, name string) {
f, err := bio.Open(name)
if err != nil {
if os.IsNotExist(err) {
......@@ -99,7 +99,7 @@ func hostArchive(name string) {
any := true
for any {
var load []uint64
for _, s := range Ctxt.Allsym {
for _, s := range ctxt.Allsym {
for _, r := range s.R {
if r.Sym != nil && r.Sym.Type&obj.SMASK == obj.SXREF {
if off := armap[r.Sym.Name]; off != 0 && !loaded[off] {
......@@ -118,9 +118,9 @@ func hostArchive(name string) {
pname := fmt.Sprintf("%s(%s)", name, arhdr.name)
l = atolwhex(arhdr.size)
h := ldobj(f, "libgcc", l, pname, name, ArchiveObj)
h := ldobj(ctxt, f, "libgcc", l, pname, name, ArchiveObj)
f.Seek(h.off, 0)
h.ld(f, h.pkg, h.length, h.pn)
h.ld(ctxt, f, h.pkg, h.length, h.pn)
}
any = len(load) > 0
......
This diff is collapsed.
......@@ -277,7 +277,7 @@ func (d *deadcodepass) flood() {
if strings.HasPrefix(s.Name, "type.") && s.Name[5] != '.' {
if decodetype_kind(s)&kindMask == kindInterface {
for _, sig := range decodetype_ifacemethods(s) {
for _, sig := range decodetype_ifacemethods(d.ctxt.Arch, s) {
if Debug['v'] > 1 {
fmt.Fprintf(d.ctxt.Bso, "reached iface method: %s\n", sig)
}
......@@ -315,7 +315,7 @@ func (d *deadcodepass) flood() {
// Decode runtime type information for type methods
// to help work out which methods can be called
// dynamically via interfaces.
methodsigs := decodetype_methods(s)
methodsigs := decodetype_methods(d.ctxt.Arch, s)
if len(methods) != len(methodsigs) {
panic(fmt.Sprintf("%q has %d method relocations for %d methods", s.Name, len(methods), len(methodsigs)))
}
......
......@@ -45,14 +45,14 @@ func decode_reloc_sym(s *Symbol, off int32) *Symbol {
return r.Sym
}
func decode_inuxi(p []byte, sz int) uint64 {
func decode_inuxi(arch *sys.Arch, p []byte, sz int) uint64 {
switch sz {
case 2:
return uint64(Ctxt.Arch.ByteOrder.Uint16(p))
return uint64(arch.ByteOrder.Uint16(p))
case 4:
return uint64(Ctxt.Arch.ByteOrder.Uint32(p))
return uint64(arch.ByteOrder.Uint32(p))
case 8:
return Ctxt.Arch.ByteOrder.Uint64(p)
return arch.ByteOrder.Uint64(p)
default:
Exitf("dwarf: decode inuxi %d", sz)
panic("unreachable")
......@@ -74,13 +74,13 @@ func decodetype_usegcprog(s *Symbol) uint8 {
}
// Type.commonType.size
func decodetype_size(s *Symbol) int64 {
return int64(decode_inuxi(s.P, SysArch.PtrSize)) // 0x8 / 0x10
func decodetype_size(arch *sys.Arch, s *Symbol) int64 {
return int64(decode_inuxi(arch, s.P, SysArch.PtrSize)) // 0x8 / 0x10
}
// Type.commonType.ptrdata
func decodetype_ptrdata(s *Symbol) int64 {
return int64(decode_inuxi(s.P[SysArch.PtrSize:], SysArch.PtrSize)) // 0x8 / 0x10
func decodetype_ptrdata(arch *sys.Arch, s *Symbol) int64 {
return int64(decode_inuxi(arch, s.P[SysArch.PtrSize:], SysArch.PtrSize)) // 0x8 / 0x10
}
// Type.commonType.tflag
......@@ -89,8 +89,8 @@ func decodetype_hasUncommon(s *Symbol) bool {
}
// Find the elf.Section of a given shared library that contains a given address.
func findShlibSection(path string, addr uint64) *elf.Section {
for _, shlib := range Ctxt.Shlibs {
func findShlibSection(ctxt *Link, path string, addr uint64) *elf.Section {
for _, shlib := range ctxt.Shlibs {
if shlib.Path == path {
for _, sect := range shlib.File.Sections {
if sect.Addr <= addr && addr <= sect.Addr+sect.Size {
......@@ -103,16 +103,16 @@ func findShlibSection(path string, addr uint64) *elf.Section {
}
// Type.commonType.gc
func decodetype_gcprog(s *Symbol) []byte {
func decodetype_gcprog(ctxt *Link, s *Symbol) []byte {
if s.Type == obj.SDYNIMPORT {
addr := decodetype_gcprog_shlib(s)
sect := findShlibSection(s.File, addr)
addr := decodetype_gcprog_shlib(ctxt, s)
sect := findShlibSection(ctxt, s.File, addr)
if sect != nil {
// A gcprog is a 4-byte uint32 indicating length, followed by
// the actual program.
progsize := make([]byte, 4)
sect.ReadAt(progsize, int64(addr-sect.Addr))
progbytes := make([]byte, Ctxt.Arch.ByteOrder.Uint32(progsize))
progbytes := make([]byte, ctxt.Arch.ByteOrder.Uint32(progsize))
sect.ReadAt(progbytes, int64(addr-sect.Addr+4))
return append(progsize, progbytes...)
}
......@@ -122,23 +122,23 @@ func decodetype_gcprog(s *Symbol) []byte {
return decode_reloc_sym(s, 2*int32(SysArch.PtrSize)+8+1*int32(SysArch.PtrSize)).P
}
func decodetype_gcprog_shlib(s *Symbol) uint64 {
func decodetype_gcprog_shlib(ctxt *Link, s *Symbol) uint64 {
if SysArch.Family == sys.ARM64 {
for _, shlib := range Ctxt.Shlibs {
for _, shlib := range ctxt.Shlibs {
if shlib.Path == s.File {
return shlib.gcdata_addresses[s]
}
}
return 0
}
return decode_inuxi(s.P[2*int32(SysArch.PtrSize)+8+1*int32(SysArch.PtrSize):], SysArch.PtrSize)
return decode_inuxi(ctxt.Arch, s.P[2*int32(SysArch.PtrSize)+8+1*int32(SysArch.PtrSize):], SysArch.PtrSize)
}
func decodetype_gcmask(s *Symbol) []byte {
func decodetype_gcmask(ctxt *Link, s *Symbol) []byte {
if s.Type == obj.SDYNIMPORT {
addr := decodetype_gcprog_shlib(s)
ptrdata := decodetype_ptrdata(s)
sect := findShlibSection(s.File, addr)
addr := decodetype_gcprog_shlib(ctxt, s)
ptrdata := decodetype_ptrdata(ctxt.Arch, s)
sect := findShlibSection(ctxt, s.File, addr)
if sect != nil {
r := make([]byte, ptrdata/int64(SysArch.PtrSize))
sect.ReadAt(r, int64(addr-sect.Addr))
......@@ -156,8 +156,8 @@ func decodetype_arrayelem(s *Symbol) *Symbol {
return decode_reloc_sym(s, int32(commonsize())) // 0x1c / 0x30
}
func decodetype_arraylen(s *Symbol) int64 {
return int64(decode_inuxi(s.P[commonsize()+2*SysArch.PtrSize:], SysArch.PtrSize))
func decodetype_arraylen(arch *sys.Arch, s *Symbol) int64 {
return int64(decode_inuxi(arch, s.P[commonsize()+2*SysArch.PtrSize:], SysArch.PtrSize))
}
// Type.PtrType.elem
......@@ -180,17 +180,17 @@ func decodetype_chanelem(s *Symbol) *Symbol {
}
// Type.FuncType.dotdotdot
func decodetype_funcdotdotdot(s *Symbol) bool {
return uint16(decode_inuxi(s.P[commonsize()+2:], 2))&(1<<15) != 0
func decodetype_funcdotdotdot(arch *sys.Arch, s *Symbol) bool {
return uint16(decode_inuxi(arch, s.P[commonsize()+2:], 2))&(1<<15) != 0
}
// Type.FuncType.inCount
func decodetype_funcincount(s *Symbol) int {
return int(decode_inuxi(s.P[commonsize():], 2))
func decodetype_funcincount(arch *sys.Arch, s *Symbol) int {
return int(decode_inuxi(arch, s.P[commonsize():], 2))
}
func decodetype_funcoutcount(s *Symbol) int {
return int(uint16(decode_inuxi(s.P[commonsize()+2:], 2)) & (1<<15 - 1))
func decodetype_funcoutcount(arch *sys.Arch, s *Symbol) int {
return int(uint16(decode_inuxi(arch, s.P[commonsize()+2:], 2)) & (1<<15 - 1))
}
func decodetype_funcintype(s *Symbol, i int) *Symbol {
......@@ -204,13 +204,13 @@ func decodetype_funcintype(s *Symbol, i int) *Symbol {
return decode_reloc_sym(s, int32(uadd+i*SysArch.PtrSize))
}
func decodetype_funcouttype(s *Symbol, i int) *Symbol {
return decodetype_funcintype(s, i+decodetype_funcincount(s))
func decodetype_funcouttype(arch *sys.Arch, s *Symbol, i int) *Symbol {
return decodetype_funcintype(s, i+decodetype_funcincount(arch, s))
}
// Type.StructType.fields.Slice::length
func decodetype_structfieldcount(s *Symbol) int {
return int(decode_inuxi(s.P[commonsize()+2*SysArch.PtrSize:], SysArch.IntSize))
func decodetype_structfieldcount(arch *sys.Arch, s *Symbol) int {
return int(decode_inuxi(arch, s.P[commonsize()+2*SysArch.PtrSize:], SysArch.IntSize))
}
func decodetype_structfieldarrayoff(s *Symbol, i int) int {
......@@ -253,14 +253,14 @@ func decodetype_structfieldtype(s *Symbol, i int) *Symbol {
return decode_reloc_sym(s, int32(off+SysArch.PtrSize))
}
func decodetype_structfieldoffs(s *Symbol, i int) int64 {
func decodetype_structfieldoffs(arch *sys.Arch, s *Symbol, i int) int64 {
off := decodetype_structfieldarrayoff(s, i)
return int64(decode_inuxi(s.P[off+2*SysArch.PtrSize:], SysArch.IntSize))
return int64(decode_inuxi(arch, s.P[off+2*SysArch.PtrSize:], SysArch.IntSize))
}
// InterfaceType.methods.length
func decodetype_ifacemethodcount(s *Symbol) int64 {
return int64(decode_inuxi(s.P[commonsize()+2*SysArch.PtrSize:], SysArch.IntSize))
func decodetype_ifacemethodcount(arch *sys.Arch, s *Symbol) int64 {
return int64(decode_inuxi(arch, s.P[commonsize()+2*SysArch.PtrSize:], SysArch.IntSize))
}
// methodsig is a fully qualified typed method signature, like
......@@ -286,7 +286,7 @@ const (
// the function type.
//
// Conveniently this is the layout of both runtime.method and runtime.imethod.
func decode_methodsig(s *Symbol, off, size, count int) []methodsig {
func decode_methodsig(arch *sys.Arch, s *Symbol, off, size, count int) []methodsig {
var buf bytes.Buffer
var methods []methodsig
for i := 0; i < count; i++ {
......@@ -294,7 +294,7 @@ func decode_methodsig(s *Symbol, off, size, count int) []methodsig {
mtypSym := decode_reloc_sym(s, int32(off+4))
buf.WriteRune('(')
inCount := decodetype_funcincount(mtypSym)
inCount := decodetype_funcincount(arch, mtypSym)
for i := 0; i < inCount; i++ {
if i > 0 {
buf.WriteString(", ")
......@@ -302,12 +302,12 @@ func decode_methodsig(s *Symbol, off, size, count int) []methodsig {
buf.WriteString(decodetype_funcintype(mtypSym, i).Name)
}
buf.WriteString(") (")
outCount := decodetype_funcoutcount(mtypSym)
outCount := decodetype_funcoutcount(arch, mtypSym)
for i := 0; i < outCount; i++ {
if i > 0 {
buf.WriteString(", ")
}
buf.WriteString(decodetype_funcouttype(mtypSym, i).Name)
buf.WriteString(decodetype_funcouttype(arch, mtypSym, i).Name)
}
buf.WriteRune(')')
......@@ -318,7 +318,7 @@ func decode_methodsig(s *Symbol, off, size, count int) []methodsig {
return methods
}
func decodetype_ifacemethods(s *Symbol) []methodsig {
func decodetype_ifacemethods(arch *sys.Arch, s *Symbol) []methodsig {
if decodetype_kind(s)&kindMask != kindInterface {
panic(fmt.Sprintf("symbol %q is not an interface", s.Name))
}
......@@ -330,12 +330,12 @@ func decodetype_ifacemethods(s *Symbol) []methodsig {
panic(fmt.Sprintf("imethod slice pointer in %q leads to a different symbol", s.Name))
}
off := int(r.Add) // array of reflect.imethod values
numMethods := int(decodetype_ifacemethodcount(s))
numMethods := int(decodetype_ifacemethodcount(arch, s))
sizeofIMethod := 4 + 4
return decode_methodsig(s, off, sizeofIMethod, numMethods)
return decode_methodsig(arch, s, off, sizeofIMethod, numMethods)
}
func decodetype_methods(s *Symbol) []methodsig {
func decodetype_methods(arch *sys.Arch, s *Symbol) []methodsig {
if !decodetype_hasUncommon(s) {
panic(fmt.Sprintf("no methods on %q", s.Name))
}
......@@ -361,9 +361,9 @@ func decodetype_methods(s *Symbol) []methodsig {
// just Sizeof(rtype)
}
mcount := int(decode_inuxi(s.P[off+4:], 2))
moff := int(decode_inuxi(s.P[off+4+2+2:], 4))
mcount := int(decode_inuxi(arch, s.P[off+4:], 2))
moff := int(decode_inuxi(arch, s.P[off+4+2+2:], 4))
off += moff // offset to array of reflect.method values
const sizeofMethod = 4 * 4 // sizeof reflect.method in program
return decode_methodsig(s, off, sizeofMethod, mcount)
return decode_methodsig(arch, s, off, sizeofMethod, mcount)
}
This diff is collapsed.
This diff is collapsed.
......@@ -28,7 +28,7 @@ func expandpkg(t0 string, pkg string) string {
// once the dust settles, try to move some code to
// libmach, so that other linkers and ar can share.
func ldpkg(f *bio.Reader, pkg string, length int64, filename string, whence int) {
func ldpkg(ctxt *Link, f *bio.Reader, pkg string, length int64, filename string, whence int) {
var p0, p1 int
if Debug['g'] != 0 {
......@@ -121,11 +121,11 @@ func ldpkg(f *bio.Reader, pkg string, length int64, filename string, whence int)
}
p1 += p0
loadcgo(filename, pkg, data[p0:p1])
loadcgo(ctxt, filename, pkg, data[p0:p1])
}
}
func loadcgo(file string, pkg string, p string) {
func loadcgo(ctxt *Link, file string, pkg string, p string) {
var next string
var q string
var f []string
......@@ -187,7 +187,7 @@ func loadcgo(file string, pkg string, p string) {
if i := strings.Index(remote, "#"); i >= 0 {
remote, q = remote[:i], remote[i+1:]
}
s = Linklookup(Ctxt, local, 0)
s = Linklookup(ctxt, local, 0)
if local != f[1] {
}
if s.Type == 0 || s.Type == obj.SXREF || s.Type == obj.SHOSTOBJ {
......@@ -208,7 +208,7 @@ func loadcgo(file string, pkg string, p string) {
goto err
}
local = f[1]
s = Linklookup(Ctxt, local, 0)
s = Linklookup(ctxt, local, 0)
s.Type = obj.SHOSTOBJ
s.Size = 0
continue
......@@ -225,11 +225,11 @@ func loadcgo(file string, pkg string, p string) {
remote = local
}
local = expandpkg(local, pkg)
s = Linklookup(Ctxt, local, 0)
s = Linklookup(ctxt, local, 0)
switch Buildmode {
case BuildmodeCShared, BuildmodeCArchive:
if s == Linklookup(Ctxt, "main", 0) {
if s == Linklookup(ctxt, "main", 0) {
continue
}
}
......@@ -298,20 +298,20 @@ err:
var seenlib = make(map[string]bool)
func adddynlib(lib string) {
func adddynlib(ctxt *Link, lib string) {
if seenlib[lib] || Linkmode == LinkExternal {
return
}
seenlib[lib] = true
if Iself {
s := Linklookup(Ctxt, ".dynstr", 0)
s := Linklookup(ctxt, ".dynstr", 0)
if s.Size == 0 {
Addstring(s, "")
Addstring(ctxt, s, "")
}
Elfwritedynent(Linklookup(Ctxt, ".dynamic", 0), DT_NEEDED, uint64(Addstring(s, lib)))
Elfwritedynent(ctxt, Linklookup(ctxt, ".dynamic", 0), DT_NEEDED, uint64(Addstring(ctxt, s, lib)))
} else {
Diag("adddynlib: unsupported binary format")
ctxt.Diag("adddynlib: unsupported binary format")
}
}
......@@ -323,11 +323,11 @@ func Adddynsym(ctxt *Link, s *Symbol) {
if Iself {
Elfadddynsym(ctxt, s)
} else if HEADTYPE == obj.Hdarwin {
Diag("adddynsym: missed symbol %s (%s)", s.Name, s.Extname)
ctxt.Diag("adddynsym: missed symbol %s (%s)", s.Name, s.Extname)
} else if HEADTYPE == obj.Hwindows {
// already taken care of
} else {
Diag("adddynsym: unsupported binary format")
ctxt.Diag("adddynsym: unsupported binary format")
}
}
......@@ -359,19 +359,19 @@ func fieldtrack(ctxt *Link) {
if !s.Attr.Reachable() {
return
}
addstrdata(tracksym, buf.String())
addstrdata(ctxt, tracksym, buf.String())
}
func addexport() {
func (ctxt *Link) addexport() {
if HEADTYPE == obj.Hdarwin {
return
}
for _, exp := range dynexp {
Adddynsym(Ctxt, exp)
Adddynsym(ctxt, exp)
}
for _, lib := range dynlib {
adddynlib(lib)
adddynlib(ctxt, lib)
}
}
......
......@@ -118,7 +118,7 @@ func addlibpath(ctxt *Link, srcref string, objref string, file string, pkg strin
if shlibnamefile != "" {
shlibbytes, err := ioutil.ReadFile(shlibnamefile)
if err != nil {
Diag("cannot read %s: %v", shlibnamefile, err)
ctxt.Diag("cannot read %s: %v", shlibnamefile, err)
}
l.Shlib = strings.TrimSpace(string(shlibbytes))
}
......
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
......@@ -177,7 +177,7 @@ type Link struct {
Library []*Library
Shlibs []Shlib
Tlsoffset int
Diag func(string, ...interface{})
Cursym *Symbol
Version int
Textp []*Symbol
......
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
......@@ -130,7 +130,7 @@ func archinit() {
}
case obj.Hlinux: /* mips64 elf */
ld.Elfinit()
ld.Elfinit(ld.Ctxt)
ld.HEADR = ld.ELFRESERVE
if ld.INITTEXT == -1 {
ld.INITTEXT = 0x10000 + int64(ld.HEADR)
......@@ -143,7 +143,7 @@ func archinit() {
}
case obj.Hnacl:
ld.Elfinit()
ld.Elfinit(ld.Ctxt)
ld.HEADR = 0x10000
ld.Funcalign = 16
if ld.INITTEXT == -1 {
......
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
......@@ -95,7 +95,7 @@ func archinit() {
ld.Exitf("unknown -H option: %v", ld.HEADTYPE)
case obj.Hlinux: // s390x ELF
ld.Elfinit()
ld.Elfinit(ld.Ctxt)
ld.HEADR = ld.ELFRESERVE
if ld.INITTEXT == -1 {
ld.INITTEXT = 0x10000 + int64(ld.HEADR)
......
This diff is collapsed.
This diff is collapsed.
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment