Commit 4338e5a8 authored by Michael Matloob's avatar Michael Matloob

cmd/link/internal: remove global Ctxt variable

This change threads the *ld.Link Ctxt variable through
code in arch-specific packages. This removes all remaining
uses of Ctxt, so remove the global variable too.

This CL continues the work in golang.org/cl/27408

Updates #16818

Change-Id: I5f4536847a1825fd0b944824e8ae4e122ec0fb78
Reviewed-on: https://go-review.googlesource.com/27459
Run-TryBot: Michael Matloob <matloob@golang.org>
Reviewed-by: 's avatarBrad Fitzpatrick <bradfitz@golang.org>
TryBot-Result: Gobot Gobot <gobot@golang.org>
parent e2b30e90
This diff is collapsed.
...@@ -82,9 +82,7 @@ func linkarchinit() { ...@@ -82,9 +82,7 @@ func linkarchinit() {
ld.Thearch.Solarisdynld = "/lib/amd64/ld.so.1" ld.Thearch.Solarisdynld = "/lib/amd64/ld.so.1"
} }
func archinit() { func archinit(ctxt *ld.Link) {
ctxt := ld.Ctxt
// getgoextlinkenabled is based on GO_EXTLINK_ENABLED when // getgoextlinkenabled is based on GO_EXTLINK_ENABLED when
// Go was built; see ../../make.bash. // Go was built; see ../../make.bash.
if ld.Linkmode == ld.LinkAuto && obj.Getgoextlinkenabled() == "0" { if ld.Linkmode == ld.LinkAuto && obj.Getgoextlinkenabled() == "0" {
...@@ -153,7 +151,7 @@ func archinit() { ...@@ -153,7 +151,7 @@ func archinit() {
obj.Hopenbsd, /* openbsd */ obj.Hopenbsd, /* openbsd */
obj.Hdragonfly, /* dragonfly */ obj.Hdragonfly, /* dragonfly */
obj.Hsolaris: /* solaris */ obj.Hsolaris: /* solaris */
ld.Elfinit(ld.Ctxt) ld.Elfinit(ctxt)
ld.HEADR = ld.ELFRESERVE ld.HEADR = ld.ELFRESERVE
if ld.INITTEXT == -1 { if ld.INITTEXT == -1 {
...@@ -167,7 +165,7 @@ func archinit() { ...@@ -167,7 +165,7 @@ func archinit() {
} }
case obj.Hnacl: case obj.Hnacl:
ld.Elfinit(ld.Ctxt) ld.Elfinit(ctxt)
ld.Debug['w']++ // disable dwarf, which gets confused and is useless anyway ld.Debug['w']++ // disable dwarf, which gets confused and is useless anyway
ld.HEADR = 0x10000 ld.HEADR = 0x10000
ld.Funcalign = 32 ld.Funcalign = 32
......
This diff is collapsed.
...@@ -78,7 +78,7 @@ func linkarchinit() { ...@@ -78,7 +78,7 @@ func linkarchinit() {
ld.Thearch.Solarisdynld = "XXX" ld.Thearch.Solarisdynld = "XXX"
} }
func archinit() { func archinit(ctxt *ld.Link) {
// getgoextlinkenabled is based on GO_EXTLINK_ENABLED when // getgoextlinkenabled is based on GO_EXTLINK_ENABLED when
// Go was built; see ../../make.bash. // Go was built; see ../../make.bash.
if ld.Linkmode == ld.LinkAuto && obj.Getgoextlinkenabled() == "0" { if ld.Linkmode == ld.LinkAuto && obj.Getgoextlinkenabled() == "0" {
...@@ -128,7 +128,7 @@ func archinit() { ...@@ -128,7 +128,7 @@ func archinit() {
obj.Hopenbsd: obj.Hopenbsd:
ld.Debug['d'] = 0 ld.Debug['d'] = 0
// with dynamic linking // with dynamic linking
ld.Elfinit(ld.Ctxt) ld.Elfinit(ctxt)
ld.HEADR = ld.ELFRESERVE ld.HEADR = ld.ELFRESERVE
if ld.INITTEXT == -1 { if ld.INITTEXT == -1 {
ld.INITTEXT = 0x10000 + int64(ld.HEADR) ld.INITTEXT = 0x10000 + int64(ld.HEADR)
...@@ -141,7 +141,7 @@ func archinit() { ...@@ -141,7 +141,7 @@ func archinit() {
} }
case obj.Hnacl: case obj.Hnacl:
ld.Elfinit(ld.Ctxt) ld.Elfinit(ctxt)
ld.HEADR = 0x10000 ld.HEADR = 0x10000
ld.Funcalign = 16 ld.Funcalign = 16
if ld.INITTEXT == -1 { if ld.INITTEXT == -1 {
......
...@@ -38,23 +38,23 @@ import ( ...@@ -38,23 +38,23 @@ import (
"log" "log"
) )
func gentext() { func gentext(ctxt *ld.Link) {
if !ld.DynlinkingGo() { if !ld.DynlinkingGo() {
return return
} }
addmoduledata := ld.Linklookup(ld.Ctxt, "runtime.addmoduledata", 0) addmoduledata := ld.Linklookup(ctxt, "runtime.addmoduledata", 0)
if addmoduledata.Type == obj.STEXT { if addmoduledata.Type == obj.STEXT {
// we're linking a module containing the runtime -> no need for // we're linking a module containing the runtime -> no need for
// an init function // an init function
return return
} }
addmoduledata.Attr |= ld.AttrReachable addmoduledata.Attr |= ld.AttrReachable
initfunc := ld.Linklookup(ld.Ctxt, "go.link.addmoduledata", 0) initfunc := ld.Linklookup(ctxt, "go.link.addmoduledata", 0)
initfunc.Type = obj.STEXT initfunc.Type = obj.STEXT
initfunc.Attr |= ld.AttrLocal initfunc.Attr |= ld.AttrLocal
initfunc.Attr |= ld.AttrReachable initfunc.Attr |= ld.AttrReachable
o := func(op uint32) { o := func(op uint32) {
ld.Adduint32(ld.Ctxt, initfunc, op) ld.Adduint32(ctxt, initfunc, op)
} }
// 0000000000000000 <local.dso_init>: // 0000000000000000 <local.dso_init>:
// 0: 90000000 adrp x0, 0 <runtime.firstmoduledata> // 0: 90000000 adrp x0, 0 <runtime.firstmoduledata>
...@@ -66,7 +66,7 @@ func gentext() { ...@@ -66,7 +66,7 @@ func gentext() {
rel := ld.Addrel(initfunc) rel := ld.Addrel(initfunc)
rel.Off = 0 rel.Off = 0
rel.Siz = 8 rel.Siz = 8
rel.Sym = ld.Ctxt.Moduledata rel.Sym = ctxt.Moduledata
rel.Type = obj.R_ADDRARM64 rel.Type = obj.R_ADDRARM64
// 8: 14000000 bl 0 <runtime.addmoduledata> // 8: 14000000 bl 0 <runtime.addmoduledata>
...@@ -75,22 +75,22 @@ func gentext() { ...@@ -75,22 +75,22 @@ func gentext() {
rel = ld.Addrel(initfunc) rel = ld.Addrel(initfunc)
rel.Off = 8 rel.Off = 8
rel.Siz = 4 rel.Siz = 4
rel.Sym = ld.Linklookup(ld.Ctxt, "runtime.addmoduledata", 0) rel.Sym = ld.Linklookup(ctxt, "runtime.addmoduledata", 0)
rel.Type = obj.R_CALLARM64 // Really should be R_AARCH64_JUMP26 but doesn't seem to make any difference rel.Type = obj.R_CALLARM64 // Really should be R_AARCH64_JUMP26 but doesn't seem to make any difference
ld.Ctxt.Textp = append(ld.Ctxt.Textp, initfunc) ctxt.Textp = append(ctxt.Textp, initfunc)
initarray_entry := ld.Linklookup(ld.Ctxt, "go.link.addmoduledatainit", 0) initarray_entry := ld.Linklookup(ctxt, "go.link.addmoduledatainit", 0)
initarray_entry.Attr |= ld.AttrReachable initarray_entry.Attr |= ld.AttrReachable
initarray_entry.Attr |= ld.AttrLocal initarray_entry.Attr |= ld.AttrLocal
initarray_entry.Type = obj.SINITARR initarray_entry.Type = obj.SINITARR
ld.Addaddr(ld.Ctxt, initarray_entry, initfunc) ld.Addaddr(ctxt, initarray_entry, initfunc)
} }
func adddynrel(s *ld.Symbol, r *ld.Reloc) { func adddynrel(ctxt *ld.Link, s *ld.Symbol, r *ld.Reloc) {
log.Fatalf("adddynrel not implemented") log.Fatalf("adddynrel not implemented")
} }
func elfreloc1(r *ld.Reloc, sectoff int64) int { func elfreloc1(ctxt *ld.Link, r *ld.Reloc, sectoff int64) int {
ld.Thearch.Vput(uint64(sectoff)) ld.Thearch.Vput(uint64(sectoff))
elfsym := r.Xsym.ElfsymForReloc() elfsym := r.Xsym.ElfsymForReloc()
...@@ -142,12 +142,12 @@ func elfreloc1(r *ld.Reloc, sectoff int64) int { ...@@ -142,12 +142,12 @@ func elfreloc1(r *ld.Reloc, sectoff int64) int {
return 0 return 0
} }
func elfsetupplt() { func elfsetupplt(ctxt *ld.Link) {
// TODO(aram) // TODO(aram)
return return
} }
func machoreloc1(r *ld.Reloc, sectoff int64) int { func machoreloc1(ctxt *ld.Link, r *ld.Reloc, sectoff int64) int {
var v uint32 var v uint32
rs := r.Xsym rs := r.Xsym
...@@ -157,7 +157,7 @@ func machoreloc1(r *ld.Reloc, sectoff int64) int { ...@@ -157,7 +157,7 @@ func machoreloc1(r *ld.Reloc, sectoff int64) int {
// UNSIGNED relocation at all. // 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.Type == obj.SHOSTOBJ || r.Type == obj.R_CALLARM64 || r.Type == obj.R_ADDRARM64 || r.Type == obj.R_ADDR {
if rs.Dynid < 0 { if rs.Dynid < 0 {
ld.Ctxt.Diag("reloc %d to non-macho symbol %s type=%d", r.Type, rs.Name, rs.Type) ctxt.Diag("reloc %d to non-macho symbol %s type=%d", r.Type, rs.Name, rs.Type)
return -1 return -1
} }
...@@ -166,7 +166,7 @@ func machoreloc1(r *ld.Reloc, sectoff int64) int { ...@@ -166,7 +166,7 @@ func machoreloc1(r *ld.Reloc, sectoff int64) int {
} else { } else {
v = uint32(rs.Sect.Extnum) v = uint32(rs.Sect.Extnum)
if v == 0 { if v == 0 {
ld.Ctxt.Diag("reloc %d to symbol %s in non-macho section %s type=%d", r.Type, rs.Name, rs.Sect.Name, rs.Type) 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 return -1
} }
} }
...@@ -180,7 +180,7 @@ func machoreloc1(r *ld.Reloc, sectoff int64) int { ...@@ -180,7 +180,7 @@ func machoreloc1(r *ld.Reloc, sectoff int64) int {
case obj.R_CALLARM64: case obj.R_CALLARM64:
if r.Xadd != 0 { if r.Xadd != 0 {
ld.Ctxt.Diag("ld64 doesn't allow BR26 reloc with non-zero addend: %s+%d", rs.Name, r.Xadd) ctxt.Diag("ld64 doesn't allow BR26 reloc with non-zero addend: %s+%d", rs.Name, r.Xadd)
} }
v |= 1 << 24 // pc-relative bit v |= 1 << 24 // pc-relative bit
...@@ -226,8 +226,7 @@ func machoreloc1(r *ld.Reloc, sectoff int64) int { ...@@ -226,8 +226,7 @@ func machoreloc1(r *ld.Reloc, sectoff int64) int {
return 0 return 0
} }
func archreloc(r *ld.Reloc, s *ld.Symbol, val *int64) int { func archreloc(ctxt *ld.Link, r *ld.Reloc, s *ld.Symbol, val *int64) int {
ctxt := ld.Ctxt
if ld.Linkmode == ld.LinkExternal { if ld.Linkmode == ld.LinkExternal {
switch r.Type { switch r.Type {
default: default:
...@@ -235,7 +234,7 @@ func archreloc(r *ld.Reloc, s *ld.Symbol, val *int64) int { ...@@ -235,7 +234,7 @@ func archreloc(r *ld.Reloc, s *ld.Symbol, val *int64) int {
case obj.R_ARM64_GOTPCREL: case obj.R_ARM64_GOTPCREL:
var o1, o2 uint32 var o1, o2 uint32
if ld.Ctxt.Arch.ByteOrder == binary.BigEndian { if ctxt.Arch.ByteOrder == binary.BigEndian {
o1 = uint32(*val >> 32) o1 = uint32(*val >> 32)
o2 = uint32(*val) o2 = uint32(*val)
} else { } else {
...@@ -252,12 +251,12 @@ func archreloc(r *ld.Reloc, s *ld.Symbol, val *int64) int { ...@@ -252,12 +251,12 @@ func archreloc(r *ld.Reloc, s *ld.Symbol, val *int64) int {
// add + R_ADDRARM64. // add + R_ADDRARM64.
if !(r.Sym.Version != 0 || (r.Sym.Type&obj.SHIDDEN != 0) || r.Sym.Attr.Local()) && r.Sym.Type == obj.STEXT && ld.DynlinkingGo() { if !(r.Sym.Version != 0 || (r.Sym.Type&obj.SHIDDEN != 0) || r.Sym.Attr.Local()) && r.Sym.Type == obj.STEXT && ld.DynlinkingGo() {
if o2&0xffc00000 != 0xf9400000 { if o2&0xffc00000 != 0xf9400000 {
ld.Ctxt.Diag("R_ARM64_GOTPCREL against unexpected instruction %x", o2) ctxt.Diag("R_ARM64_GOTPCREL against unexpected instruction %x", o2)
} }
o2 = 0x91000000 | (o2 & 0x000003ff) o2 = 0x91000000 | (o2 & 0x000003ff)
r.Type = obj.R_ADDRARM64 r.Type = obj.R_ADDRARM64
} }
if ld.Ctxt.Arch.ByteOrder == binary.BigEndian { if ctxt.Arch.ByteOrder == binary.BigEndian {
*val = int64(o1)<<32 | int64(o2) *val = int64(o1)<<32 | int64(o2)
} else { } else {
*val = int64(o2)<<32 | int64(o1) *val = int64(o2)<<32 | int64(o1)
...@@ -276,7 +275,7 @@ func archreloc(r *ld.Reloc, s *ld.Symbol, val *int64) int { ...@@ -276,7 +275,7 @@ func archreloc(r *ld.Reloc, s *ld.Symbol, val *int64) int {
} }
if rs.Type != obj.SHOSTOBJ && rs.Type != obj.SDYNIMPORT && rs.Sect == nil { if rs.Type != obj.SHOSTOBJ && rs.Type != obj.SDYNIMPORT && rs.Sect == nil {
ld.Ctxt.Diag("missing section for %s", rs.Name) ctxt.Diag("missing section for %s", rs.Name)
} }
r.Xsym = rs r.Xsym = rs
...@@ -288,7 +287,7 @@ func archreloc(r *ld.Reloc, s *ld.Symbol, val *int64) int { ...@@ -288,7 +287,7 @@ func archreloc(r *ld.Reloc, s *ld.Symbol, val *int64) int {
if false && ld.HEADTYPE == obj.Hdarwin { if false && ld.HEADTYPE == obj.Hdarwin {
var o0, o1 uint32 var o0, o1 uint32
if ld.Ctxt.Arch.ByteOrder == binary.BigEndian { if ctxt.Arch.ByteOrder == binary.BigEndian {
o0 = uint32(*val >> 32) o0 = uint32(*val >> 32)
o1 = uint32(*val) o1 = uint32(*val)
} else { } else {
...@@ -305,7 +304,7 @@ func archreloc(r *ld.Reloc, s *ld.Symbol, val *int64) int { ...@@ -305,7 +304,7 @@ func archreloc(r *ld.Reloc, s *ld.Symbol, val *int64) int {
r.Xadd = 0 r.Xadd = 0
// when laid out, the instruction order must always be o1, o2. // when laid out, the instruction order must always be o1, o2.
if ld.Ctxt.Arch.ByteOrder == binary.BigEndian { if ctxt.Arch.ByteOrder == binary.BigEndian {
*val = int64(o0)<<32 | int64(o1) *val = int64(o0)<<32 | int64(o1)
} else { } else {
*val = int64(o1)<<32 | int64(o0) *val = int64(o1)<<32 | int64(o0)
...@@ -330,18 +329,18 @@ func archreloc(r *ld.Reloc, s *ld.Symbol, val *int64) int { ...@@ -330,18 +329,18 @@ func archreloc(r *ld.Reloc, s *ld.Symbol, val *int64) int {
return 0 return 0
case obj.R_GOTOFF: case obj.R_GOTOFF:
*val = ld.Symaddr(ctxt, r.Sym) + r.Add - ld.Symaddr(ctxt, ld.Linklookup(ld.Ctxt, ".got", 0)) *val = ld.Symaddr(ctxt, r.Sym) + r.Add - ld.Symaddr(ctxt, ld.Linklookup(ctxt, ".got", 0))
return 0 return 0
case obj.R_ADDRARM64: case obj.R_ADDRARM64:
t := ld.Symaddr(ctxt, 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 { if t >= 1<<32 || t < -1<<32 {
ld.Ctxt.Diag("program too large, address relocation distance = %d", t) ctxt.Diag("program too large, address relocation distance = %d", t)
} }
var o0, o1 uint32 var o0, o1 uint32
if ld.Ctxt.Arch.ByteOrder == binary.BigEndian { if ctxt.Arch.ByteOrder == binary.BigEndian {
o0 = uint32(*val >> 32) o0 = uint32(*val >> 32)
o1 = uint32(*val) o1 = uint32(*val)
} else { } else {
...@@ -353,7 +352,7 @@ func archreloc(r *ld.Reloc, s *ld.Symbol, val *int64) int { ...@@ -353,7 +352,7 @@ func archreloc(r *ld.Reloc, s *ld.Symbol, val *int64) int {
o1 |= uint32(t&0xfff) << 10 o1 |= uint32(t&0xfff) << 10
// when laid out, the instruction order must always be o1, o2. // when laid out, the instruction order must always be o1, o2.
if ld.Ctxt.Arch.ByteOrder == binary.BigEndian { if ctxt.Arch.ByteOrder == binary.BigEndian {
*val = int64(o0)<<32 | int64(o1) *val = int64(o0)<<32 | int64(o1)
} else { } else {
*val = int64(o1)<<32 | int64(o0) *val = int64(o1)<<32 | int64(o0)
...@@ -363,13 +362,13 @@ func archreloc(r *ld.Reloc, s *ld.Symbol, val *int64) int { ...@@ -363,13 +362,13 @@ func archreloc(r *ld.Reloc, s *ld.Symbol, val *int64) int {
case obj.R_ARM64_TLS_LE: case obj.R_ARM64_TLS_LE:
r.Done = 0 r.Done = 0
if ld.HEADTYPE != obj.Hlinux { if ld.HEADTYPE != obj.Hlinux {
ld.Ctxt.Diag("TLS reloc on unsupported OS %s", ld.Headstr(int(ld.HEADTYPE))) 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 // The TCB is two pointers. This is not documented anywhere, but is
// de facto part of the ABI. // de facto part of the ABI.
v := r.Sym.Value + int64(2*ld.SysArch.PtrSize) v := r.Sym.Value + int64(2*ld.SysArch.PtrSize)
if v < 0 || v >= 32678 { if v < 0 || v >= 32678 {
ld.Ctxt.Diag("TLS offset out of range %d", v) ctxt.Diag("TLS offset out of range %d", v)
} }
*val |= v << 5 *val |= v << 5
return 0 return 0
...@@ -377,7 +376,7 @@ func archreloc(r *ld.Reloc, s *ld.Symbol, val *int64) int { ...@@ -377,7 +376,7 @@ func archreloc(r *ld.Reloc, s *ld.Symbol, val *int64) int {
case obj.R_CALLARM64: case obj.R_CALLARM64:
t := (ld.Symaddr(ctxt, 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 { if t >= 1<<27 || t < -1<<27 {
ld.Ctxt.Diag("program too large, call relocation distance = %d", t) ctxt.Diag("program too large, call relocation distance = %d", t)
} }
*val |= (t >> 2) & 0x03ffffff *val |= (t >> 2) & 0x03ffffff
return 0 return 0
...@@ -386,7 +385,7 @@ func archreloc(r *ld.Reloc, s *ld.Symbol, val *int64) int { ...@@ -386,7 +385,7 @@ func archreloc(r *ld.Reloc, s *ld.Symbol, val *int64) int {
return -1 return -1
} }
func archrelocvariant(r *ld.Reloc, s *ld.Symbol, t int64) int64 { func archrelocvariant(ctxt *ld.Link, r *ld.Reloc, s *ld.Symbol, t int64) int64 {
log.Fatalf("unexpected relocation variant") log.Fatalf("unexpected relocation variant")
return -1 return -1
} }
...@@ -480,7 +479,7 @@ func asmb(ctxt *ld.Link) { ...@@ -480,7 +479,7 @@ func asmb(ctxt *ld.Link) {
ld.Asmplan9sym(ctxt) ld.Asmplan9sym(ctxt)
ld.Cflush() ld.Cflush()
sym := ld.Linklookup(ld.Ctxt, "pclntab", 0) sym := ld.Linklookup(ctxt, "pclntab", 0)
if sym != nil { if sym != nil {
ld.Lcsize = int32(len(sym.P)) ld.Lcsize = int32(len(sym.P))
for i := 0; int32(i) < ld.Lcsize; i++ { for i := 0; int32(i) < ld.Lcsize; i++ {
...@@ -497,7 +496,7 @@ func asmb(ctxt *ld.Link) { ...@@ -497,7 +496,7 @@ func asmb(ctxt *ld.Link) {
} }
} }
ld.Ctxt.Cursym = nil ctxt.Cursym = nil
if ld.Debug['v'] != 0 { if ld.Debug['v'] != 0 {
fmt.Fprintf(ld.Bso, "%5.2f header\n", obj.Cputime()) fmt.Fprintf(ld.Bso, "%5.2f header\n", obj.Cputime())
} }
......
...@@ -79,7 +79,7 @@ func linkarchinit() { ...@@ -79,7 +79,7 @@ func linkarchinit() {
ld.Thearch.Solarisdynld = "XXX" ld.Thearch.Solarisdynld = "XXX"
} }
func archinit() { func archinit(ctxt *ld.Link) {
// getgoextlinkenabled is based on GO_EXTLINK_ENABLED when // getgoextlinkenabled is based on GO_EXTLINK_ENABLED when
// Go was built; see ../../make.bash. // Go was built; see ../../make.bash.
if ld.Linkmode == ld.LinkAuto && obj.Getgoextlinkenabled() == "0" { if ld.Linkmode == ld.LinkAuto && obj.Getgoextlinkenabled() == "0" {
...@@ -125,7 +125,7 @@ func archinit() { ...@@ -125,7 +125,7 @@ func archinit() {
} }
case obj.Hlinux: /* arm64 elf */ case obj.Hlinux: /* arm64 elf */
ld.Elfinit(ld.Ctxt) ld.Elfinit(ctxt)
ld.HEADR = ld.ELFRESERVE ld.HEADR = ld.ELFRESERVE
if ld.INITTEXT == -1 { if ld.INITTEXT == -1 {
ld.INITTEXT = 0x10000 + int64(ld.HEADR) ld.INITTEXT = 0x10000 + int64(ld.HEADR)
...@@ -152,7 +152,7 @@ func archinit() { ...@@ -152,7 +152,7 @@ func archinit() {
} }
case obj.Hnacl: case obj.Hnacl:
ld.Elfinit(ld.Ctxt) ld.Elfinit(ctxt)
ld.HEADR = 0x10000 ld.HEADR = 0x10000
ld.Funcalign = 16 ld.Funcalign = 16
if ld.INITTEXT == -1 { if ld.INITTEXT == -1 {
......
...@@ -399,7 +399,7 @@ func relocsym(ctxt *Link, s *Symbol) { ...@@ -399,7 +399,7 @@ func relocsym(ctxt *Link, s *Symbol) {
case 8: case 8:
o = int64(ctxt.Arch.ByteOrder.Uint64(s.P[off:])) o = int64(ctxt.Arch.ByteOrder.Uint64(s.P[off:]))
} }
if Thearch.Archreloc(r, s, &o) < 0 { if Thearch.Archreloc(ctxt, r, s, &o) < 0 {
ctxt.Diag("unknown reloc %d", r.Type) ctxt.Diag("unknown reloc %d", r.Type)
} }
...@@ -604,7 +604,7 @@ func relocsym(ctxt *Link, s *Symbol) { ...@@ -604,7 +604,7 @@ func relocsym(ctxt *Link, s *Symbol) {
} }
if r.Variant != RV_NONE { if r.Variant != RV_NONE {
o = Thearch.Archrelocvariant(r, s, o) o = Thearch.Archrelocvariant(ctxt, r, s, o)
} }
if false { if false {
...@@ -717,7 +717,7 @@ func dynrelocsym(ctxt *Link, s *Symbol) { ...@@ -717,7 +717,7 @@ func dynrelocsym(ctxt *Link, s *Symbol) {
if r.Sym != nil && !r.Sym.Attr.Reachable() { if r.Sym != nil && !r.Sym.Attr.Reachable() {
ctxt.Diag("internal inconsistency: dynamic symbol %s is not reachable.", r.Sym.Name) ctxt.Diag("internal inconsistency: dynamic symbol %s is not reachable.", r.Sym.Name)
} }
Thearch.Adddynrel(s, r) Thearch.Adddynrel(ctxt, s, r)
} }
} }
} }
......
...@@ -1762,7 +1762,7 @@ func elfrelocsect(ctxt *Link, sect *Section, syms []*Symbol) { ...@@ -1762,7 +1762,7 @@ func elfrelocsect(ctxt *Link, sect *Section, syms []*Symbol) {
if r.Xsym.ElfsymForReloc() == 0 { if r.Xsym.ElfsymForReloc() == 0 {
ctxt.Diag("reloc %d to non-elf symbol %s (outer=%s) %d", r.Type, r.Sym.Name, r.Xsym.Name, r.Sym.Type) ctxt.Diag("reloc %d to non-elf symbol %s (outer=%s) %d", r.Type, r.Sym.Name, r.Xsym.Name, r.Sym.Type)
} }
if Thearch.Elfreloc1(r, int64(uint64(sym.Value+int64(r.Off))-sect.Vaddr)) < 0 { if Thearch.Elfreloc1(ctxt, r, int64(uint64(sym.Value+int64(r.Off))-sect.Vaddr)) < 0 {
ctxt.Diag("unsupported obj reloc %d/%d to %s", r.Type, r.Siz, r.Sym.Name) ctxt.Diag("unsupported obj reloc %d/%d to %s", r.Type, r.Siz, r.Sym.Name)
} }
} }
...@@ -1990,7 +1990,7 @@ func (ctxt *Link) doelf() { ...@@ -1990,7 +1990,7 @@ func (ctxt *Link) doelf() {
s.Type = obj.SELFRXSECT s.Type = obj.SELFRXSECT
} }
Thearch.Elfsetupplt() Thearch.Elfsetupplt(ctxt)
s = Linklookup(ctxt, elfRelType+".plt", 0) s = Linklookup(ctxt, elfRelType+".plt", 0)
s.Attr |= AttrReachable s.Attr |= AttrReachable
......
...@@ -95,16 +95,16 @@ type Arch struct { ...@@ -95,16 +95,16 @@ type Arch struct {
Openbsddynld string Openbsddynld string
Dragonflydynld string Dragonflydynld string
Solarisdynld string Solarisdynld string
Adddynrel func(*Symbol, *Reloc) Adddynrel func(*Link, *Symbol, *Reloc)
Archinit func() Archinit func(*Link)
Archreloc func(*Reloc, *Symbol, *int64) int Archreloc func(*Link, *Reloc, *Symbol, *int64) int
Archrelocvariant func(*Reloc, *Symbol, int64) int64 Archrelocvariant func(*Link, *Reloc, *Symbol, int64) int64
Asmb func(*Link) Asmb func(*Link)
Elfreloc1 func(*Reloc, int64) int Elfreloc1 func(*Link, *Reloc, int64) int
Elfsetupplt func() Elfsetupplt func(*Link)
Gentext func() Gentext func(*Link)
Machoreloc1 func(*Reloc, int64) int Machoreloc1 func(*Link, *Reloc, int64) int
PEreloc1 func(*Reloc, int64) bool PEreloc1 func(*Link, *Reloc, int64) bool
Wput func(uint16) Wput func(uint16)
Lput func(uint32) Lput func(uint32)
Vput func(uint64) Vput func(uint64)
...@@ -209,8 +209,7 @@ var ( ...@@ -209,8 +209,7 @@ var (
extldflags string extldflags string
extar string extar string
libgccfile string libgccfile string
debug_s int // backup old value of debug['s'] debug_s int // backup old value of debug['s']
Ctxt *Link // Global pointer to ctxt used by arch-specific packages
HEADR int32 HEADR int32
HEADTYPE int32 HEADTYPE int32
INITRND int32 INITRND int32
......
...@@ -841,7 +841,7 @@ func machorelocsect(ctxt *Link, sect *Section, syms []*Symbol) { ...@@ -841,7 +841,7 @@ func machorelocsect(ctxt *Link, sect *Section, syms []*Symbol) {
if r.Done != 0 { if r.Done != 0 {
continue continue
} }
if Thearch.Machoreloc1(r, int64(uint64(sym.Value+int64(r.Off))-sect.Vaddr)) < 0 { if Thearch.Machoreloc1(ctxt, r, int64(uint64(sym.Value+int64(r.Off))-sect.Vaddr)) < 0 {
ctxt.Diag("unsupported obj reloc %d/%d to %s", r.Type, r.Siz, r.Sym.Name) ctxt.Diag("unsupported obj reloc %d/%d to %s", r.Type, r.Siz, r.Sym.Name)
} }
} }
......
...@@ -806,7 +806,7 @@ func perelocsect(ctxt *Link, sect *Section, syms []*Symbol) int { ...@@ -806,7 +806,7 @@ func perelocsect(ctxt *Link, sect *Section, syms []*Symbol) int {
if r.Xsym.Dynid < 0 { if r.Xsym.Dynid < 0 {
ctxt.Diag("reloc %d to non-coff symbol %s (outer=%s) %d", r.Type, r.Sym.Name, r.Xsym.Name, r.Sym.Type) ctxt.Diag("reloc %d to non-coff symbol %s (outer=%s) %d", r.Type, r.Sym.Name, r.Xsym.Name, r.Sym.Type)
} }
if !Thearch.PEreloc1(r, int64(uint64(sym.Value+int64(r.Off))-PEBASE)) { if !Thearch.PEreloc1(ctxt, r, int64(uint64(sym.Value+int64(r.Off))-PEBASE)) {
ctxt.Diag("unsupported obj reloc %d/%d to %s", r.Type, r.Siz, r.Sym.Name) ctxt.Diag("unsupported obj reloc %d/%d to %s", r.Type, r.Siz, r.Sym.Name)
} }
......
...@@ -49,7 +49,6 @@ func Ldmain() { ...@@ -49,7 +49,6 @@ func Ldmain() {
Bso = bufio.NewWriter(os.Stdout) Bso = bufio.NewWriter(os.Stdout)
ctxt := linknew(SysArch) ctxt := linknew(SysArch)
Ctxt = ctxt // Export Ctxt because it's currently used by the arch-specific packages
ctxt.Bso = Bso ctxt.Bso = Bso
Debug = [128]int{} Debug = [128]int{}
...@@ -158,7 +157,7 @@ func Ldmain() { ...@@ -158,7 +157,7 @@ func Ldmain() {
headstring = Headstr(int(HEADTYPE)) headstring = Headstr(int(HEADTYPE))
} }
Thearch.Archinit() Thearch.Archinit(ctxt)
if Linkshared && !Iself { if Linkshared && !Iself {
Exitf("-linkshared can only be used on elf systems") Exitf("-linkshared can only be used on elf systems")
...@@ -202,7 +201,7 @@ func Ldmain() { ...@@ -202,7 +201,7 @@ func Ldmain() {
ctxt.dope() ctxt.dope()
} }
ctxt.addexport() ctxt.addexport()
Thearch.Gentext() // trampolines, call stubs, etc. Thearch.Gentext(ctxt) // trampolines, call stubs, etc.
ctxt.textbuildid() ctxt.textbuildid()
ctxt.textaddress() ctxt.textaddress()
ctxt.pclntab() ctxt.pclntab()
......
...@@ -38,13 +38,13 @@ import ( ...@@ -38,13 +38,13 @@ import (
"log" "log"
) )
func gentext() {} func gentext(ctxt *ld.Link) {}
func adddynrel(s *ld.Symbol, r *ld.Reloc) { func adddynrel(ctxt *ld.Link, s *ld.Symbol, r *ld.Reloc) {
log.Fatalf("adddynrel not implemented") log.Fatalf("adddynrel not implemented")
} }
func elfreloc1(r *ld.Reloc, sectoff int64) int { func elfreloc1(ctxt *ld.Link, r *ld.Reloc, sectoff int64) int {
// mips64 ELF relocation (endian neutral) // mips64 ELF relocation (endian neutral)
// offset uint64 // offset uint64
// sym uint32 // sym uint32
...@@ -93,16 +93,15 @@ func elfreloc1(r *ld.Reloc, sectoff int64) int { ...@@ -93,16 +93,15 @@ func elfreloc1(r *ld.Reloc, sectoff int64) int {
return 0 return 0
} }
func elfsetupplt() { func elfsetupplt(ctxt *ld.Link) {
return return
} }
func machoreloc1(r *ld.Reloc, sectoff int64) int { func machoreloc1(ctxt *ld.Link, r *ld.Reloc, sectoff int64) int {
return -1 return -1
} }
func archreloc(r *ld.Reloc, s *ld.Symbol, val *int64) int { func archreloc(ctxt *ld.Link, r *ld.Reloc, s *ld.Symbol, val *int64) int {
ctxt := ld.Ctxt
if ld.Linkmode == ld.LinkExternal { if ld.Linkmode == ld.LinkExternal {
switch r.Type { switch r.Type {
default: default:
...@@ -121,7 +120,7 @@ func archreloc(r *ld.Reloc, s *ld.Symbol, val *int64) int { ...@@ -121,7 +120,7 @@ func archreloc(r *ld.Reloc, s *ld.Symbol, val *int64) int {
} }
if rs.Type != obj.SHOSTOBJ && rs.Type != obj.SDYNIMPORT && rs.Sect == nil { if rs.Type != obj.SHOSTOBJ && rs.Type != obj.SDYNIMPORT && rs.Sect == nil {
ld.Ctxt.Diag("missing section for %s", rs.Name) ctxt.Diag("missing section for %s", rs.Name)
} }
r.Xsym = rs r.Xsym = rs
...@@ -143,7 +142,7 @@ func archreloc(r *ld.Reloc, s *ld.Symbol, val *int64) int { ...@@ -143,7 +142,7 @@ func archreloc(r *ld.Reloc, s *ld.Symbol, val *int64) int {
return 0 return 0
case obj.R_GOTOFF: case obj.R_GOTOFF:
*val = ld.Symaddr(ctxt, r.Sym) + r.Add - ld.Symaddr(ctxt, ld.Linklookup(ld.Ctxt, ".got", 0)) *val = ld.Symaddr(ctxt, r.Sym) + r.Add - ld.Symaddr(ctxt, ld.Linklookup(ctxt, ".got", 0))
return 0 return 0
case obj.R_ADDRMIPS, case obj.R_ADDRMIPS,
...@@ -161,7 +160,7 @@ func archreloc(r *ld.Reloc, s *ld.Symbol, val *int64) int { ...@@ -161,7 +160,7 @@ func archreloc(r *ld.Reloc, s *ld.Symbol, val *int64) int {
// thread pointer is at 0x7000 offset from the start of TLS data area // thread pointer is at 0x7000 offset from the start of TLS data area
t := ld.Symaddr(ctxt, r.Sym) + r.Add - 0x7000 t := ld.Symaddr(ctxt, r.Sym) + r.Add - 0x7000
if t < -32768 || t >= 32678 { if t < -32768 || t >= 32678 {
ld.Ctxt.Diag("TLS offset out of range %d", t) ctxt.Diag("TLS offset out of range %d", t)
} }
o1 := ld.SysArch.ByteOrder.Uint32(s.P[r.Off:]) o1 := ld.SysArch.ByteOrder.Uint32(s.P[r.Off:])
*val = int64(o1&0xffff0000 | uint32(t)&0xffff) *val = int64(o1&0xffff0000 | uint32(t)&0xffff)
...@@ -179,7 +178,7 @@ func archreloc(r *ld.Reloc, s *ld.Symbol, val *int64) int { ...@@ -179,7 +178,7 @@ func archreloc(r *ld.Reloc, s *ld.Symbol, val *int64) int {
return -1 return -1
} }
func archrelocvariant(r *ld.Reloc, s *ld.Symbol, t int64) int64 { func archrelocvariant(ctxt *ld.Link, r *ld.Reloc, s *ld.Symbol, t int64) int64 {
return -1 return -1
} }
...@@ -264,7 +263,7 @@ func asmb(ctxt *ld.Link) { ...@@ -264,7 +263,7 @@ func asmb(ctxt *ld.Link) {
ld.Asmplan9sym(ctxt) ld.Asmplan9sym(ctxt)
ld.Cflush() ld.Cflush()
sym := ld.Linklookup(ld.Ctxt, "pclntab", 0) sym := ld.Linklookup(ctxt, "pclntab", 0)
if sym != nil { if sym != nil {
ld.Lcsize = int32(len(sym.P)) ld.Lcsize = int32(len(sym.P))
for i := 0; int32(i) < ld.Lcsize; i++ { for i := 0; int32(i) < ld.Lcsize; i++ {
...@@ -276,7 +275,7 @@ func asmb(ctxt *ld.Link) { ...@@ -276,7 +275,7 @@ func asmb(ctxt *ld.Link) {
} }
} }
ld.Ctxt.Cursym = nil ctxt.Cursym = nil
if ld.Debug['v'] != 0 { if ld.Debug['v'] != 0 {
fmt.Fprintf(ld.Bso, "%5.2f header\n", obj.Cputime()) fmt.Fprintf(ld.Bso, "%5.2f header\n", obj.Cputime())
} }
......
...@@ -92,7 +92,7 @@ func linkarchinit() { ...@@ -92,7 +92,7 @@ func linkarchinit() {
ld.Thearch.Solarisdynld = "XXX" ld.Thearch.Solarisdynld = "XXX"
} }
func archinit() { func archinit(ctxt *ld.Link) {
// getgoextlinkenabled is based on GO_EXTLINK_ENABLED when // getgoextlinkenabled is based on GO_EXTLINK_ENABLED when
// Go was built; see ../../make.bash. // Go was built; see ../../make.bash.
if ld.Linkmode == ld.LinkAuto && obj.Getgoextlinkenabled() == "0" { if ld.Linkmode == ld.LinkAuto && obj.Getgoextlinkenabled() == "0" {
...@@ -130,7 +130,7 @@ func archinit() { ...@@ -130,7 +130,7 @@ func archinit() {
} }
case obj.Hlinux: /* mips64 elf */ case obj.Hlinux: /* mips64 elf */
ld.Elfinit(ld.Ctxt) ld.Elfinit(ctxt)
ld.HEADR = ld.ELFRESERVE ld.HEADR = ld.ELFRESERVE
if ld.INITTEXT == -1 { if ld.INITTEXT == -1 {
ld.INITTEXT = 0x10000 + int64(ld.HEADR) ld.INITTEXT = 0x10000 + int64(ld.HEADR)
...@@ -143,7 +143,7 @@ func archinit() { ...@@ -143,7 +143,7 @@ func archinit() {
} }
case obj.Hnacl: case obj.Hnacl:
ld.Elfinit(ld.Ctxt) ld.Elfinit(ctxt)
ld.HEADR = 0x10000 ld.HEADR = 0x10000
ld.Funcalign = 16 ld.Funcalign = 16
if ld.INITTEXT == -1 { if ld.INITTEXT == -1 {
......
This diff is collapsed.
...@@ -93,7 +93,7 @@ func linkarchinit() { ...@@ -93,7 +93,7 @@ func linkarchinit() {
ld.Thearch.Solarisdynld = "XXX" ld.Thearch.Solarisdynld = "XXX"
} }
func archinit() { func archinit(ctxt *ld.Link) {
// getgoextlinkenabled is based on GO_EXTLINK_ENABLED when // getgoextlinkenabled is based on GO_EXTLINK_ENABLED when
// Go was built; see ../../make.bash. // Go was built; see ../../make.bash.
if ld.Linkmode == ld.LinkAuto && obj.Getgoextlinkenabled() == "0" { if ld.Linkmode == ld.LinkAuto && obj.Getgoextlinkenabled() == "0" {
...@@ -110,7 +110,7 @@ func archinit() { ...@@ -110,7 +110,7 @@ func archinit() {
} }
if ld.Linkmode == ld.LinkExternal { if ld.Linkmode == ld.LinkExternal {
toc := ld.Linklookup(ld.Ctxt, ".TOC.", 0) toc := ld.Linklookup(ctxt, ".TOC.", 0)
toc.Type = obj.SDYNIMPORT toc.Type = obj.SDYNIMPORT
} }
...@@ -148,7 +148,7 @@ func archinit() { ...@@ -148,7 +148,7 @@ func archinit() {
if ld.SysArch == sys.ArchPPC64 { if ld.SysArch == sys.ArchPPC64 {
ld.Debug['d'] = 1 // TODO(austin): ELF ABI v1 not supported yet ld.Debug['d'] = 1 // TODO(austin): ELF ABI v1 not supported yet
} }
ld.Elfinit(ld.Ctxt) ld.Elfinit(ctxt)
ld.HEADR = ld.ELFRESERVE ld.HEADR = ld.ELFRESERVE
if ld.INITTEXT == -1 { if ld.INITTEXT == -1 {
ld.INITTEXT = 0x10000 + int64(ld.HEADR) ld.INITTEXT = 0x10000 + int64(ld.HEADR)
...@@ -161,7 +161,7 @@ func archinit() { ...@@ -161,7 +161,7 @@ func archinit() {
} }
case obj.Hnacl: case obj.Hnacl:
ld.Elfinit(ld.Ctxt) ld.Elfinit(ctxt)
ld.HEADR = 0x10000 ld.HEADR = 0x10000
ld.Funcalign = 16 ld.Funcalign = 16
if ld.INITTEXT == -1 { if ld.INITTEXT == -1 {
......
This diff is collapsed.
...@@ -79,7 +79,7 @@ func linkarchinit() { ...@@ -79,7 +79,7 @@ func linkarchinit() {
ld.Thearch.Solarisdynld = "XXX" ld.Thearch.Solarisdynld = "XXX"
} }
func archinit() { func archinit(ctxt *ld.Link) {
// getgoextlinkenabled is based on GO_EXTLINK_ENABLED when // getgoextlinkenabled is based on GO_EXTLINK_ENABLED when
// Go was built; see ../../make.bash. // Go was built; see ../../make.bash.
if ld.Linkmode == ld.LinkAuto && obj.Getgoextlinkenabled() == "0" { if ld.Linkmode == ld.LinkAuto && obj.Getgoextlinkenabled() == "0" {
...@@ -95,7 +95,7 @@ func archinit() { ...@@ -95,7 +95,7 @@ func archinit() {
ld.Exitf("unknown -H option: %v", ld.HEADTYPE) ld.Exitf("unknown -H option: %v", ld.HEADTYPE)
case obj.Hlinux: // s390x ELF case obj.Hlinux: // s390x ELF
ld.Elfinit(ld.Ctxt) ld.Elfinit(ctxt)
ld.HEADR = ld.ELFRESERVE ld.HEADR = ld.ELFRESERVE
if ld.INITTEXT == -1 { if ld.INITTEXT == -1 {
ld.INITTEXT = 0x10000 + int64(ld.HEADR) ld.INITTEXT = 0x10000 + int64(ld.HEADR)
......
This diff is collapsed.
...@@ -78,7 +78,7 @@ func linkarchinit() { ...@@ -78,7 +78,7 @@ func linkarchinit() {
ld.Thearch.Solarisdynld = "/lib/ld.so.1" ld.Thearch.Solarisdynld = "/lib/ld.so.1"
} }
func archinit() { func archinit(ctxt *ld.Link) {
// getgoextlinkenabled is based on GO_EXTLINK_ENABLED when // getgoextlinkenabled is based on GO_EXTLINK_ENABLED when
// Go was built; see ../../make.bash. // Go was built; see ../../make.bash.
if ld.Linkmode == ld.LinkAuto && obj.Getgoextlinkenabled() == "0" { if ld.Linkmode == ld.LinkAuto && obj.Getgoextlinkenabled() == "0" {
...@@ -87,7 +87,7 @@ func archinit() { ...@@ -87,7 +87,7 @@ func archinit() {
if ld.Buildmode == ld.BuildmodeCShared || ld.Buildmode == ld.BuildmodePIE || ld.DynlinkingGo() { if ld.Buildmode == ld.BuildmodeCShared || ld.Buildmode == ld.BuildmodePIE || ld.DynlinkingGo() {
ld.Linkmode = ld.LinkExternal ld.Linkmode = ld.LinkExternal
got := ld.Linklookup(ld.Ctxt, "_GLOBAL_OFFSET_TABLE_", 0) got := ld.Linklookup(ctxt, "_GLOBAL_OFFSET_TABLE_", 0)
got.Type = obj.SDYNIMPORT got.Type = obj.SDYNIMPORT
got.Attr |= ld.AttrReachable got.Attr |= ld.AttrReachable
} }
...@@ -145,7 +145,7 @@ func archinit() { ...@@ -145,7 +145,7 @@ func archinit() {
obj.Hfreebsd, obj.Hfreebsd,
obj.Hnetbsd, obj.Hnetbsd,
obj.Hopenbsd: obj.Hopenbsd:
ld.Elfinit(ld.Ctxt) ld.Elfinit(ctxt)
ld.HEADR = ld.ELFRESERVE ld.HEADR = ld.ELFRESERVE
if ld.INITTEXT == -1 { if ld.INITTEXT == -1 {
...@@ -159,7 +159,7 @@ func archinit() { ...@@ -159,7 +159,7 @@ func archinit() {
} }
case obj.Hnacl: case obj.Hnacl:
ld.Elfinit(ld.Ctxt) ld.Elfinit(ctxt)
ld.HEADR = 0x10000 ld.HEADR = 0x10000
ld.Funcalign = 32 ld.Funcalign = 32
if ld.INITTEXT == -1 { if ld.INITTEXT == -1 {
...@@ -173,7 +173,7 @@ func archinit() { ...@@ -173,7 +173,7 @@ func archinit() {
} }
case obj.Hwindows: /* PE executable */ case obj.Hwindows: /* PE executable */
ld.Peinit(ld.Ctxt) ld.Peinit(ctxt)
ld.HEADR = ld.PEFILEHEADR ld.HEADR = ld.PEFILEHEADR
if ld.INITTEXT == -1 { if ld.INITTEXT == -1 {
......
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