Commit 5a597e2d authored by David Crawshaw's avatar David Crawshaw

cmd/link: replace ld.Link.Diag with ld.Errorf

Instead of using ctxt.Cursym, Errorf takes an explicit *Symbol
parameter. This removes most uses of Cursym and means the *Link
context object is needed in fewer parts of the linker.

All transformations done manually, as wiring Cursym is tricky.

Change-Id: Ief88b00b73904224675c0035684c3a84c19249d7
Reviewed-on: https://go-review.googlesource.com/29369Reviewed-by: default avatarIan Lance Taylor <iant@golang.org>
Reviewed-by: default avatarMichael Hudson-Doyle <michael.hudson@canonical.com>
Run-TryBot: Ian Lance Taylor <iant@golang.org>
TryBot-Result: Gobot Gobot <gobot@golang.org>
parent bd3d00e3
...@@ -103,17 +103,17 @@ func adddynrel(ctxt *ld.Link, s *ld.Symbol, r *ld.Reloc) bool { ...@@ -103,17 +103,17 @@ func adddynrel(ctxt *ld.Link, s *ld.Symbol, r *ld.Reloc) bool {
switch r.Type { switch r.Type {
default: default:
if r.Type >= 256 { if r.Type >= 256 {
ctxt.Diag("unexpected relocation type %d", r.Type) ld.Errorf(s, "unexpected relocation type %d", r.Type)
return false return false
} }
// Handle relocations found in ELF object files. // Handle relocations found in ELF object files.
case 256 + ld.R_X86_64_PC32: case 256 + ld.R_X86_64_PC32:
if targ.Type == obj.SDYNIMPORT { if targ.Type == obj.SDYNIMPORT {
ctxt.Diag("unexpected R_X86_64_PC32 relocation for dynamic symbol %s", targ.Name) ld.Errorf(s, "unexpected R_X86_64_PC32 relocation for dynamic symbol %s", targ.Name)
} }
if targ.Type == 0 || targ.Type == obj.SXREF { if targ.Type == 0 || targ.Type == obj.SXREF {
ctxt.Diag("unknown symbol %s in pcrel", targ.Name) ld.Errorf(s, "unknown symbol %s in pcrel", targ.Name)
} }
r.Type = obj.R_PCREL r.Type = obj.R_PCREL
r.Add += 4 r.Add += 4
...@@ -155,7 +155,7 @@ func adddynrel(ctxt *ld.Link, s *ld.Symbol, r *ld.Reloc) bool { ...@@ -155,7 +155,7 @@ func adddynrel(ctxt *ld.Link, s *ld.Symbol, r *ld.Reloc) bool {
case 256 + ld.R_X86_64_64: case 256 + ld.R_X86_64_64:
if targ.Type == obj.SDYNIMPORT { if targ.Type == obj.SDYNIMPORT {
ctxt.Diag("unexpected R_X86_64_64 relocation for dynamic symbol %s", targ.Name) ld.Errorf(s, "unexpected R_X86_64_64 relocation for dynamic symbol %s", targ.Name)
} }
r.Type = obj.R_ADDR r.Type = obj.R_ADDR
return true return true
...@@ -168,7 +168,7 @@ func adddynrel(ctxt *ld.Link, s *ld.Symbol, r *ld.Reloc) bool { ...@@ -168,7 +168,7 @@ func adddynrel(ctxt *ld.Link, s *ld.Symbol, r *ld.Reloc) bool {
r.Type = obj.R_ADDR r.Type = obj.R_ADDR
if targ.Type == obj.SDYNIMPORT { if targ.Type == obj.SDYNIMPORT {
ctxt.Diag("unexpected reloc for dynamic symbol %s", targ.Name) ld.Errorf(s, "unexpected reloc for dynamic symbol %s", targ.Name)
} }
return true return true
...@@ -191,7 +191,7 @@ func adddynrel(ctxt *ld.Link, s *ld.Symbol, r *ld.Reloc) bool { ...@@ -191,7 +191,7 @@ func adddynrel(ctxt *ld.Link, s *ld.Symbol, r *ld.Reloc) bool {
r.Type = obj.R_PCREL r.Type = obj.R_PCREL
if targ.Type == obj.SDYNIMPORT { if targ.Type == obj.SDYNIMPORT {
ctxt.Diag("unexpected pc-relative reloc for dynamic symbol %s", targ.Name) ld.Errorf(s, "unexpected pc-relative reloc for dynamic symbol %s", targ.Name)
} }
return true return true
...@@ -200,7 +200,7 @@ func adddynrel(ctxt *ld.Link, s *ld.Symbol, r *ld.Reloc) bool { ...@@ -200,7 +200,7 @@ func adddynrel(ctxt *ld.Link, s *ld.Symbol, r *ld.Reloc) bool {
// have symbol // have symbol
// turn MOVQ of GOT entry into LEAQ of symbol itself // turn MOVQ of GOT entry into LEAQ of symbol itself
if r.Off < 2 || s.P[r.Off-2] != 0x8b { if r.Off < 2 || s.P[r.Off-2] != 0x8b {
ctxt.Diag("unexpected GOT_LOAD reloc for non-dynamic symbol %s", targ.Name) ld.Errorf(s, "unexpected GOT_LOAD reloc for non-dynamic symbol %s", targ.Name)
return false return false
} }
...@@ -213,7 +213,7 @@ func adddynrel(ctxt *ld.Link, s *ld.Symbol, r *ld.Reloc) bool { ...@@ -213,7 +213,7 @@ func adddynrel(ctxt *ld.Link, s *ld.Symbol, r *ld.Reloc) bool {
// fall through // fall through
case 512 + ld.MACHO_X86_64_RELOC_GOT*2 + 1: case 512 + ld.MACHO_X86_64_RELOC_GOT*2 + 1:
if targ.Type != obj.SDYNIMPORT { if targ.Type != obj.SDYNIMPORT {
ctxt.Diag("unexpected GOT reloc for non-dynamic symbol %s", targ.Name) ld.Errorf(s, "unexpected GOT reloc for non-dynamic symbol %s", targ.Name)
} }
addgotsym(ctxt, targ) addgotsym(ctxt, targ)
r.Type = obj.R_PCREL r.Type = obj.R_PCREL
...@@ -421,14 +421,14 @@ func elfreloc1(ctxt *ld.Link, r *ld.Reloc, sectoff int64) int { ...@@ -421,14 +421,14 @@ func elfreloc1(ctxt *ld.Link, r *ld.Reloc, sectoff int64) int {
return 0 return 0
} }
func machoreloc1(ctxt *ld.Link, r *ld.Reloc, sectoff int64) int { func machoreloc1(s *ld.Symbol, r *ld.Reloc, sectoff int64) int {
var v uint32 var v uint32
rs := r.Xsym rs := r.Xsym
if rs.Type == obj.SHOSTOBJ || r.Type == obj.R_PCREL { if rs.Type == obj.SHOSTOBJ || r.Type == obj.R_PCREL {
if rs.Dynid < 0 { if rs.Dynid < 0 {
ctxt.Diag("reloc %d to non-macho symbol %s type=%d", r.Type, rs.Name, rs.Type) ld.Errorf(s, "reloc %d to non-macho symbol %s type=%d", r.Type, rs.Name, rs.Type)
return -1 return -1
} }
...@@ -437,7 +437,7 @@ func machoreloc1(ctxt *ld.Link, r *ld.Reloc, sectoff int64) int { ...@@ -437,7 +437,7 @@ func machoreloc1(ctxt *ld.Link, r *ld.Reloc, sectoff int64) int {
} else { } else {
v = uint32(rs.Sect.Extnum) v = uint32(rs.Sect.Extnum)
if v == 0 { if v == 0 {
ctxt.Diag("reloc %d to symbol %s in non-macho section %s type=%d", r.Type, rs.Name, rs.Sect.Name, rs.Type) ld.Errorf(s, "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
} }
} }
...@@ -481,13 +481,13 @@ func machoreloc1(ctxt *ld.Link, r *ld.Reloc, sectoff int64) int { ...@@ -481,13 +481,13 @@ func machoreloc1(ctxt *ld.Link, r *ld.Reloc, sectoff int64) int {
return 0 return 0
} }
func pereloc1(ctxt *ld.Link, r *ld.Reloc, sectoff int64) bool { func pereloc1(s *ld.Symbol, r *ld.Reloc, sectoff int64) bool {
var v uint32 var v uint32
rs := r.Xsym rs := r.Xsym
if rs.Dynid < 0 { if rs.Dynid < 0 {
ctxt.Diag("reloc %d to non-coff symbol %s type=%d", r.Type, rs.Name, rs.Type) ld.Errorf(s, "reloc %d to non-coff symbol %s type=%d", r.Type, rs.Name, rs.Type)
return false return false
} }
...@@ -615,7 +615,7 @@ func addpltsym(ctxt *ld.Link, s *ld.Symbol) { ...@@ -615,7 +615,7 @@ func addpltsym(ctxt *ld.Link, s *ld.Symbol) {
ld.Adduint8(ctxt, plt, 0x25) ld.Adduint8(ctxt, plt, 0x25)
ld.Addpcrelplus(ctxt, plt, ld.Linklookup(ctxt, ".got", 0), int64(s.Got)) ld.Addpcrelplus(ctxt, plt, ld.Linklookup(ctxt, ".got", 0), int64(s.Got))
} else { } else {
ctxt.Diag("addpltsym: unsupported binary format") ld.Errorf(s, "addpltsym: unsupported binary format")
} }
} }
...@@ -637,7 +637,7 @@ func addgotsym(ctxt *ld.Link, s *ld.Symbol) { ...@@ -637,7 +637,7 @@ func addgotsym(ctxt *ld.Link, s *ld.Symbol) {
} else if ld.Headtype == obj.Hdarwin { } else if ld.Headtype == obj.Hdarwin {
ld.Adduint32(ctxt, ld.Linklookup(ctxt, ".linkedit.got", 0), uint32(s.Dynid)) ld.Adduint32(ctxt, ld.Linklookup(ctxt, ".linkedit.got", 0), uint32(s.Dynid))
} else { } else {
ctxt.Diag("addgotsym: unsupported binary format") ld.Errorf(s, "addgotsym: unsupported binary format")
} }
} }
...@@ -695,7 +695,7 @@ func asmb(ctxt *ld.Link) { ...@@ -695,7 +695,7 @@ func asmb(ctxt *ld.Link) {
switch ld.Headtype { switch ld.Headtype {
default: default:
ctxt.Diag("unknown header type %d", ld.Headtype) ld.Errorf(nil, "unknown header type %v", ld.Headtype)
fallthrough fallthrough
case obj.Hplan9: case obj.Hplan9:
......
...@@ -119,7 +119,7 @@ func adddynrel(ctxt *ld.Link, s *ld.Symbol, r *ld.Reloc) bool { ...@@ -119,7 +119,7 @@ func adddynrel(ctxt *ld.Link, s *ld.Symbol, r *ld.Reloc) bool {
switch r.Type { switch r.Type {
default: default:
if r.Type >= 256 { if r.Type >= 256 {
ctxt.Diag("unexpected relocation type %d", r.Type) ld.Errorf(s, "unexpected relocation type %d", r.Type)
return false return false
} }
...@@ -193,7 +193,7 @@ func adddynrel(ctxt *ld.Link, s *ld.Symbol, r *ld.Reloc) bool { ...@@ -193,7 +193,7 @@ func adddynrel(ctxt *ld.Link, s *ld.Symbol, r *ld.Reloc) bool {
case 256 + ld.R_ARM_ABS32: case 256 + ld.R_ARM_ABS32:
if targ.Type == obj.SDYNIMPORT { if targ.Type == obj.SDYNIMPORT {
ctxt.Diag("unexpected R_ARM_ABS32 relocation for dynamic symbol %s", targ.Name) ld.Errorf(s, "unexpected R_ARM_ABS32 relocation for dynamic symbol %s", targ.Name)
} }
r.Type = obj.R_ADDR r.Type = obj.R_ADDR
return true return true
...@@ -327,14 +327,14 @@ func elfsetupplt(ctxt *ld.Link) { ...@@ -327,14 +327,14 @@ func elfsetupplt(ctxt *ld.Link) {
} }
} }
func machoreloc1(ctxt *ld.Link, r *ld.Reloc, sectoff int64) int { func machoreloc1(s *ld.Symbol, r *ld.Reloc, sectoff int64) int {
var v uint32 var v uint32
rs := r.Xsym rs := r.Xsym
if r.Type == obj.R_PCREL { if r.Type == obj.R_PCREL {
if rs.Type == obj.SHOSTOBJ { if rs.Type == obj.SHOSTOBJ {
ctxt.Diag("pc-relative relocation of external symbol is not supported") ld.Errorf(s, "pc-relative relocation of external symbol is not supported")
return -1 return -1
} }
if r.Siz != 4 { if r.Siz != 4 {
...@@ -356,15 +356,15 @@ func machoreloc1(ctxt *ld.Link, r *ld.Reloc, sectoff int64) int { ...@@ -356,15 +356,15 @@ func machoreloc1(ctxt *ld.Link, r *ld.Reloc, sectoff int64) int {
o2 |= 2 << 28 // size = 4 o2 |= 2 << 28 // size = 4
ld.Thearch.Lput(o1) ld.Thearch.Lput(o1)
ld.Thearch.Lput(uint32(ld.Symaddr(ctxt, rs))) ld.Thearch.Lput(uint32(ld.Symaddr(rs)))
ld.Thearch.Lput(o2) ld.Thearch.Lput(o2)
ld.Thearch.Lput(uint32(ctxt.Cursym.Value + int64(r.Off))) ld.Thearch.Lput(uint32(s.Value + int64(r.Off)))
return 0 return 0
} }
if rs.Type == obj.SHOSTOBJ || r.Type == obj.R_CALLARM { if rs.Type == obj.SHOSTOBJ || r.Type == obj.R_CALLARM {
if rs.Dynid < 0 { if rs.Dynid < 0 {
ctxt.Diag("reloc %d to non-macho symbol %s type=%d", r.Type, rs.Name, rs.Type) ld.Errorf(s, "reloc %d to non-macho symbol %s type=%d", r.Type, rs.Name, rs.Type)
return -1 return -1
} }
...@@ -373,7 +373,7 @@ func machoreloc1(ctxt *ld.Link, r *ld.Reloc, sectoff int64) int { ...@@ -373,7 +373,7 @@ func machoreloc1(ctxt *ld.Link, r *ld.Reloc, sectoff int64) int {
} else { } else {
v = uint32(rs.Sect.Extnum) v = uint32(rs.Sect.Extnum)
if v == 0 { if v == 0 {
ctxt.Diag("reloc %d to symbol %s in non-macho section %s type=%d", r.Type, rs.Name, rs.Sect.Name, rs.Type) ld.Errorf(s, "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
} }
} }
...@@ -427,12 +427,12 @@ func archreloc(ctxt *ld.Link, r *ld.Reloc, s *ld.Symbol, val *int64) int { ...@@ -427,12 +427,12 @@ func archreloc(ctxt *ld.Link, r *ld.Reloc, s *ld.Symbol, val *int64) int {
} }
r.Xadd *= 4 r.Xadd *= 4
for rs.Outer != nil { for rs.Outer != nil {
r.Xadd += ld.Symaddr(ctxt, rs) - ld.Symaddr(ctxt, rs.Outer) r.Xadd += ld.Symaddr(rs) - ld.Symaddr(rs.Outer)
rs = rs.Outer rs = rs.Outer
} }
if rs.Type != obj.SHOSTOBJ && rs.Type != obj.SDYNIMPORT && rs.Sect == nil { if rs.Type != obj.SHOSTOBJ && rs.Type != obj.SDYNIMPORT && rs.Sect == nil {
ctxt.Diag("missing section for %s", rs.Name) ld.Errorf(s, "missing section for %s", rs.Name)
} }
r.Xsym = rs r.Xsym = rs
...@@ -442,7 +442,7 @@ func archreloc(ctxt *ld.Link, r *ld.Reloc, s *ld.Symbol, val *int64) int { ...@@ -442,7 +442,7 @@ func archreloc(ctxt *ld.Link, r *ld.Reloc, s *ld.Symbol, val *int64) int {
// we need to compensate that by removing the instruction's address // we need to compensate that by removing the instruction's address
// from addend. // from addend.
if ld.Headtype == obj.Hdarwin { if ld.Headtype == obj.Hdarwin {
r.Xadd -= ld.Symaddr(ctxt, s) + int64(r.Off) r.Xadd -= ld.Symaddr(s) + int64(r.Off)
} }
*val = int64(braddoff(int32(0xff000000&uint32(r.Add)), int32(0xffffff&uint32(r.Xadd/4)))) *val = int64(braddoff(int32(0xff000000&uint32(r.Add)), int32(0xffffff&uint32(r.Xadd/4))))
...@@ -458,30 +458,30 @@ func archreloc(ctxt *ld.Link, r *ld.Reloc, s *ld.Symbol, val *int64) int { ...@@ -458,30 +458,30 @@ func archreloc(ctxt *ld.Link, 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(ctxt, ".got", 0)) *val = ld.Symaddr(r.Sym) + r.Add - ld.Symaddr(ld.Linklookup(ctxt, ".got", 0))
return 0 return 0
// The following three arch specific relocations are only for generation of // The following three arch specific relocations are only for generation of
// Linux/ARM ELF's PLT entry (3 assembler instruction) // Linux/ARM ELF's PLT entry (3 assembler instruction)
case obj.R_PLT0: // add ip, pc, #0xXX00000 case obj.R_PLT0: // add ip, pc, #0xXX00000
if ld.Symaddr(ctxt, ld.Linklookup(ctxt, ".got.plt", 0)) < ld.Symaddr(ctxt, ld.Linklookup(ctxt, ".plt", 0)) { if ld.Symaddr(ld.Linklookup(ctxt, ".got.plt", 0)) < ld.Symaddr(ld.Linklookup(ctxt, ".plt", 0)) {
ctxt.Diag(".got.plt should be placed after .plt section.") ld.Errorf(s, ".got.plt should be placed after .plt section.")
} }
*val = 0xe28fc600 + (0xff & (int64(uint32(ld.Symaddr(ctxt, r.Sym)-(ld.Symaddr(ctxt, ld.Linklookup(ctxt, ".plt", 0))+int64(r.Off))+r.Add)) >> 20)) *val = 0xe28fc600 + (0xff & (int64(uint32(ld.Symaddr(r.Sym)-(ld.Symaddr(ld.Linklookup(ctxt, ".plt", 0))+int64(r.Off))+r.Add)) >> 20))
return 0 return 0
case obj.R_PLT1: // add ip, ip, #0xYY000 case obj.R_PLT1: // add ip, ip, #0xYY000
*val = 0xe28cca00 + (0xff & (int64(uint32(ld.Symaddr(ctxt, r.Sym)-(ld.Symaddr(ctxt, ld.Linklookup(ctxt, ".plt", 0))+int64(r.Off))+r.Add+4)) >> 12)) *val = 0xe28cca00 + (0xff & (int64(uint32(ld.Symaddr(r.Sym)-(ld.Symaddr(ld.Linklookup(ctxt, ".plt", 0))+int64(r.Off))+r.Add+4)) >> 12))
return 0 return 0
case obj.R_PLT2: // ldr pc, [ip, #0xZZZ]! case obj.R_PLT2: // ldr pc, [ip, #0xZZZ]!
*val = 0xe5bcf000 + (0xfff & int64(uint32(ld.Symaddr(ctxt, r.Sym)-(ld.Symaddr(ctxt, ld.Linklookup(ctxt, ".plt", 0))+int64(r.Off))+r.Add+8))) *val = 0xe5bcf000 + (0xfff & int64(uint32(ld.Symaddr(r.Sym)-(ld.Symaddr(ld.Linklookup(ctxt, ".plt", 0))+int64(r.Off))+r.Add+8)))
return 0 return 0
case obj.R_CALLARM: // bl XXXXXX or b YYYYYY case obj.R_CALLARM: // bl XXXXXX or b YYYYYY
*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)))) *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))))
return 0 return 0
} }
...@@ -544,7 +544,7 @@ func addpltsym(ctxt *ld.Link, s *ld.Symbol) { ...@@ -544,7 +544,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)) ld.Adduint32(ctxt, rel, ld.ELF32_R_INFO(uint32(s.Dynid), ld.R_ARM_JUMP_SLOT))
} else { } else {
ctxt.Diag("addpltsym: unsupported binary format") ld.Errorf(s, "addpltsym: unsupported binary format")
} }
} }
...@@ -560,7 +560,7 @@ func addgotsyminternal(ctxt *ld.Link, s *ld.Symbol) { ...@@ -560,7 +560,7 @@ func addgotsyminternal(ctxt *ld.Link, s *ld.Symbol) {
if ld.Iself { if ld.Iself {
} else { } else {
ctxt.Diag("addgotsyminternal: unsupported binary format") ld.Errorf(s, "addgotsyminternal: unsupported binary format")
} }
} }
...@@ -579,7 +579,7 @@ func addgotsym(ctxt *ld.Link, s *ld.Symbol) { ...@@ -579,7 +579,7 @@ func addgotsym(ctxt *ld.Link, s *ld.Symbol) {
ld.Addaddrplus(ctxt, rel, got, int64(s.Got)) ld.Addaddrplus(ctxt, rel, got, int64(s.Got))
ld.Adduint32(ctxt, rel, ld.ELF32_R_INFO(uint32(s.Dynid), ld.R_ARM_GLOB_DAT)) ld.Adduint32(ctxt, rel, ld.ELF32_R_INFO(uint32(s.Dynid), ld.R_ARM_GLOB_DAT))
} else { } else {
ctxt.Diag("addgotsym: unsupported binary format") ld.Errorf(s, "addgotsym: unsupported binary format")
} }
} }
......
...@@ -148,7 +148,7 @@ func elfsetupplt(ctxt *ld.Link) { ...@@ -148,7 +148,7 @@ func elfsetupplt(ctxt *ld.Link) {
return return
} }
func machoreloc1(ctxt *ld.Link, r *ld.Reloc, sectoff int64) int { func machoreloc1(s *ld.Symbol, r *ld.Reloc, sectoff int64) int {
var v uint32 var v uint32
rs := r.Xsym rs := r.Xsym
...@@ -158,7 +158,7 @@ func machoreloc1(ctxt *ld.Link, r *ld.Reloc, sectoff int64) int { ...@@ -158,7 +158,7 @@ func machoreloc1(ctxt *ld.Link, 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 {
ctxt.Diag("reloc %d to non-macho symbol %s type=%d", r.Type, rs.Name, rs.Type) ld.Errorf(s, "reloc %d to non-macho symbol %s type=%d", r.Type, rs.Name, rs.Type)
return -1 return -1
} }
...@@ -167,7 +167,7 @@ func machoreloc1(ctxt *ld.Link, r *ld.Reloc, sectoff int64) int { ...@@ -167,7 +167,7 @@ func machoreloc1(ctxt *ld.Link, r *ld.Reloc, sectoff int64) int {
} else { } else {
v = uint32(rs.Sect.Extnum) v = uint32(rs.Sect.Extnum)
if v == 0 { if v == 0 {
ctxt.Diag("reloc %d to symbol %s in non-macho section %s type=%d", r.Type, rs.Name, rs.Sect.Name, rs.Type) ld.Errorf(s, "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
} }
} }
...@@ -181,7 +181,7 @@ func machoreloc1(ctxt *ld.Link, r *ld.Reloc, sectoff int64) int { ...@@ -181,7 +181,7 @@ func machoreloc1(ctxt *ld.Link, r *ld.Reloc, sectoff int64) int {
case obj.R_CALLARM64: case obj.R_CALLARM64:
if r.Xadd != 0 { if r.Xadd != 0 {
ctxt.Diag("ld64 doesn't allow BR26 reloc with non-zero addend: %s+%d", rs.Name, r.Xadd) ld.Errorf(s, "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
...@@ -252,7 +252,7 @@ func archreloc(ctxt *ld.Link, r *ld.Reloc, s *ld.Symbol, val *int64) int { ...@@ -252,7 +252,7 @@ func archreloc(ctxt *ld.Link, 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 && ctxt.DynlinkingGo() { if !(r.Sym.Version != 0 || (r.Sym.Type&obj.SHIDDEN != 0) || r.Sym.Attr.Local()) && r.Sym.Type == obj.STEXT && ctxt.DynlinkingGo() {
if o2&0xffc00000 != 0xf9400000 { if o2&0xffc00000 != 0xf9400000 {
ctxt.Diag("R_ARM64_GOTPCREL against unexpected instruction %x", o2) ld.Errorf(s, "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
...@@ -271,12 +271,12 @@ func archreloc(ctxt *ld.Link, r *ld.Reloc, s *ld.Symbol, val *int64) int { ...@@ -271,12 +271,12 @@ func archreloc(ctxt *ld.Link, r *ld.Reloc, s *ld.Symbol, val *int64) int {
rs := r.Sym rs := r.Sym
r.Xadd = r.Add r.Xadd = r.Add
for rs.Outer != nil { for rs.Outer != nil {
r.Xadd += ld.Symaddr(ctxt, rs) - ld.Symaddr(ctxt, rs.Outer) r.Xadd += ld.Symaddr(rs) - ld.Symaddr(rs.Outer)
rs = rs.Outer rs = rs.Outer
} }
if rs.Type != obj.SHOSTOBJ && rs.Type != obj.SDYNIMPORT && rs.Sect == nil { if rs.Type != obj.SHOSTOBJ && rs.Type != obj.SDYNIMPORT && rs.Sect == nil {
ctxt.Diag("missing section for %s", rs.Name) ld.Errorf(s, "missing section for %s", rs.Name)
} }
r.Xsym = rs r.Xsym = rs
...@@ -330,13 +330,13 @@ func archreloc(ctxt *ld.Link, r *ld.Reloc, s *ld.Symbol, val *int64) int { ...@@ -330,13 +330,13 @@ func archreloc(ctxt *ld.Link, 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(ctxt, ".got", 0)) *val = ld.Symaddr(r.Sym) + r.Add - ld.Symaddr(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(r.Sym) + r.Add - ((s.Value + int64(r.Off)) &^ 0xfff)
if t >= 1<<32 || t < -1<<32 { if t >= 1<<32 || t < -1<<32 {
ctxt.Diag("program too large, address relocation distance = %d", t) ld.Errorf(s, "program too large, address relocation distance = %d", t)
} }
var o0, o1 uint32 var o0, o1 uint32
...@@ -363,21 +363,21 @@ func archreloc(ctxt *ld.Link, r *ld.Reloc, s *ld.Symbol, val *int64) int { ...@@ -363,21 +363,21 @@ func archreloc(ctxt *ld.Link, 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 {
ctxt.Diag("TLS reloc on unsupported OS %s", ld.Headtype) ld.Errorf(s, "TLS reloc on unsupported OS %v", 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 {
ctxt.Diag("TLS offset out of range %d", v) ld.Errorf(s, "TLS offset out of range %d", v)
} }
*val |= v << 5 *val |= v << 5
return 0 return 0
case obj.R_CALLARM64: case obj.R_CALLARM64:
t := (ld.Symaddr(ctxt, r.Sym) + r.Add) - (s.Value + int64(r.Off)) t := (ld.Symaddr(r.Sym) + r.Add) - (s.Value + int64(r.Off))
if t >= 1<<27 || t < -1<<27 { if t >= 1<<27 || t < -1<<27 {
ctxt.Diag("program too large, call relocation distance = %d", t) ld.Errorf(s, "program too large, call relocation distance = %d", t)
} }
*val |= (t >> 2) & 0x03ffffff *val |= (t >> 2) & 0x03ffffff
return 0 return 0
......
This diff is collapsed.
...@@ -56,7 +56,7 @@ func (c dwctxt) AddSectionOffset(s dwarf.Sym, size int, t interface{}, ofs int64 ...@@ -56,7 +56,7 @@ func (c dwctxt) AddSectionOffset(s dwarf.Sym, size int, t interface{}, ofs int64
ls := s.(*Symbol) ls := s.(*Symbol)
switch size { switch size {
default: default:
c.linkctxt.Diag("invalid size %d in adddwarfref\n", size) Errorf(ls, "invalid size %d in adddwarfref\n", size)
fallthrough fallthrough
case SysArch.PtrSize: case SysArch.PtrSize:
Addaddr(c.linkctxt, ls, t.(*Symbol)) Addaddr(c.linkctxt, ls, t.(*Symbol))
...@@ -220,7 +220,7 @@ func adddwarfref(ctxt *Link, s *Symbol, t *Symbol, size int) int64 { ...@@ -220,7 +220,7 @@ func adddwarfref(ctxt *Link, s *Symbol, t *Symbol, size int) int64 {
var result int64 var result int64
switch size { switch size {
default: default:
ctxt.Diag("invalid size %d in adddwarfref\n", size) Errorf(s, "invalid size %d in adddwarfref\n", size)
fallthrough fallthrough
case SysArch.PtrSize: case SysArch.PtrSize:
result = Addaddr(ctxt, s, t) result = Addaddr(ctxt, s, t)
...@@ -335,7 +335,7 @@ func dotypedef(ctxt *Link, parent *dwarf.DWDie, name string, def *dwarf.DWDie) { ...@@ -335,7 +335,7 @@ func dotypedef(ctxt *Link, parent *dwarf.DWDie, name string, def *dwarf.DWDie) {
return return
} }
if def == nil { if def == nil {
ctxt.Diag("dwarf: bad def in dotypedef") Errorf(nil, "dwarf: bad def in dotypedef")
} }
sym := Linklookup(ctxt, dtolsym(def.Sym).Name+"..def", 0) sym := Linklookup(ctxt, dtolsym(def.Sym).Name+"..def", 0)
...@@ -359,7 +359,7 @@ func defgotype(ctxt *Link, gotype *Symbol) *Symbol { ...@@ -359,7 +359,7 @@ func defgotype(ctxt *Link, gotype *Symbol) *Symbol {
} }
if !strings.HasPrefix(gotype.Name, "type.") { if !strings.HasPrefix(gotype.Name, "type.") {
ctxt.Diag("dwarf: type name doesn't start with \"type.\": %s", gotype.Name) Errorf(gotype, "dwarf: type name doesn't start with \"type.\"")
return mustFind(ctxt, "<unspecified>") return mustFind(ctxt, "<unspecified>")
} }
...@@ -526,7 +526,7 @@ func newtype(ctxt *Link, gotype *Symbol) *dwarf.DWDie { ...@@ -526,7 +526,7 @@ func newtype(ctxt *Link, gotype *Symbol) *dwarf.DWDie {
die = newdie(ctxt, &dwtypes, dwarf.DW_ABRV_BARE_PTRTYPE, name, 0) die = newdie(ctxt, &dwtypes, dwarf.DW_ABRV_BARE_PTRTYPE, name, 0)
default: default:
ctxt.Diag("dwarf: definition of unknown kind %d: %s", kind, gotype.Name) Errorf(gotype, "dwarf: definition of unknown kind %d", kind)
die = newdie(ctxt, &dwtypes, dwarf.DW_ABRV_TYPEDECL, name, 0) die = newdie(ctxt, &dwtypes, dwarf.DW_ABRV_TYPEDECL, name, 0)
newrefattr(die, dwarf.DW_AT_type, mustFind(ctxt, "<unspecified>")) newrefattr(die, dwarf.DW_AT_type, mustFind(ctxt, "<unspecified>"))
} }
...@@ -1535,8 +1535,7 @@ func dwarfaddpeheaders(ctxt *Link) { ...@@ -1535,8 +1535,7 @@ func dwarfaddpeheaders(ctxt *Link) {
h := newPEDWARFSection(ctxt, sect.Name, int64(sect.Length)) h := newPEDWARFSection(ctxt, sect.Name, int64(sect.Length))
fileoff := sect.Vaddr - Segdwarf.Vaddr + Segdwarf.Fileoff fileoff := sect.Vaddr - Segdwarf.Vaddr + Segdwarf.Fileoff
if uint64(h.PointerToRawData) != fileoff { if uint64(h.PointerToRawData) != fileoff {
ctxt.Diag("%s.PointerToRawData = %#x, want %#x", sect.Name, h.PointerToRawData, fileoff) Exitf("%s.PointerToRawData = %#x, want %#x", sect.Name, h.PointerToRawData, fileoff)
errorexit()
} }
} }
} }
This diff is collapsed.
...@@ -311,7 +311,7 @@ func adddynlib(ctxt *Link, lib string) { ...@@ -311,7 +311,7 @@ func adddynlib(ctxt *Link, lib string) {
} }
Elfwritedynent(ctxt, Linklookup(ctxt, ".dynamic", 0), DT_NEEDED, uint64(Addstring(ctxt, s, lib))) Elfwritedynent(ctxt, Linklookup(ctxt, ".dynamic", 0), DT_NEEDED, uint64(Addstring(ctxt, s, lib)))
} else { } else {
ctxt.Diag("adddynlib: unsupported binary format") Errorf(nil, "adddynlib: unsupported binary format")
} }
} }
...@@ -323,11 +323,11 @@ func Adddynsym(ctxt *Link, s *Symbol) { ...@@ -323,11 +323,11 @@ func Adddynsym(ctxt *Link, s *Symbol) {
if Iself { if Iself {
Elfadddynsym(ctxt, s) Elfadddynsym(ctxt, s)
} else if Headtype == obj.Hdarwin { } else if Headtype == obj.Hdarwin {
ctxt.Diag("adddynsym: missed symbol %s (%s)", s.Name, s.Extname) Errorf(s, "adddynsym: missed symbol (Extname=%s)", s.Extname)
} else if Headtype == obj.Hwindows { } else if Headtype == obj.Hwindows {
// already taken care of // already taken care of
} else { } else {
ctxt.Diag("adddynsym: unsupported binary format") Errorf(s, "adddynsym: unsupported binary format")
} }
} }
......
...@@ -118,7 +118,7 @@ func addlibpath(ctxt *Link, srcref string, objref string, file string, pkg strin ...@@ -118,7 +118,7 @@ func addlibpath(ctxt *Link, srcref string, objref string, file string, pkg strin
if shlibnamefile != "" { if shlibnamefile != "" {
shlibbytes, err := ioutil.ReadFile(shlibnamefile) shlibbytes, err := ioutil.ReadFile(shlibnamefile)
if err != nil { if err != nil {
ctxt.Diag("cannot read %s: %v", shlibnamefile, err) Errorf(nil, "cannot read %s: %v", shlibnamefile, err)
} }
l.Shlib = strings.TrimSpace(string(shlibbytes)) l.Shlib = strings.TrimSpace(string(shlibbytes))
} }
......
...@@ -537,54 +537,54 @@ func ldelf(ctxt *Link, f *bio.Reader, pkg string, length int64, pn string) { ...@@ -537,54 +537,54 @@ func ldelf(ctxt *Link, f *bio.Reader, pkg string, length int64, pn string) {
} }
if e.Uint16(hdr.Type[:]) != ElfTypeRelocatable { if e.Uint16(hdr.Type[:]) != ElfTypeRelocatable {
ctxt.Diag("%s: elf but not elf relocatable object", pn) Errorf(nil, "%s: elf but not elf relocatable object", pn)
return return
} }
switch SysArch.Family { switch SysArch.Family {
default: default:
ctxt.Diag("%s: elf %s unimplemented", pn, SysArch.Name) Errorf(nil, "%s: elf %s unimplemented", pn, SysArch.Name)
return return
case sys.MIPS64: case sys.MIPS64:
if elfobj.machine != ElfMachMips || hdr.Ident[4] != ElfClass64 { if elfobj.machine != ElfMachMips || hdr.Ident[4] != ElfClass64 {
ctxt.Diag("%s: elf object but not mips64", pn) Errorf(nil, "%s: elf object but not mips64", pn)
return return
} }
case sys.ARM: case sys.ARM:
if e != binary.LittleEndian || elfobj.machine != ElfMachArm || hdr.Ident[4] != ElfClass32 { if e != binary.LittleEndian || elfobj.machine != ElfMachArm || hdr.Ident[4] != ElfClass32 {
ctxt.Diag("%s: elf object but not arm", pn) Errorf(nil, "%s: elf object but not arm", pn)
return return
} }
case sys.AMD64: case sys.AMD64:
if e != binary.LittleEndian || elfobj.machine != ElfMachAmd64 || hdr.Ident[4] != ElfClass64 { if e != binary.LittleEndian || elfobj.machine != ElfMachAmd64 || hdr.Ident[4] != ElfClass64 {
ctxt.Diag("%s: elf object but not amd64", pn) Errorf(nil, "%s: elf object but not amd64", pn)
return return
} }
case sys.ARM64: case sys.ARM64:
if e != binary.LittleEndian || elfobj.machine != ElfMachArm64 || hdr.Ident[4] != ElfClass64 { if e != binary.LittleEndian || elfobj.machine != ElfMachArm64 || hdr.Ident[4] != ElfClass64 {
ctxt.Diag("%s: elf object but not arm64", pn) Errorf(nil, "%s: elf object but not arm64", pn)
return return
} }
case sys.I386: case sys.I386:
if e != binary.LittleEndian || elfobj.machine != ElfMach386 || hdr.Ident[4] != ElfClass32 { if e != binary.LittleEndian || elfobj.machine != ElfMach386 || hdr.Ident[4] != ElfClass32 {
ctxt.Diag("%s: elf object but not 386", pn) Errorf(nil, "%s: elf object but not 386", pn)
return return
} }
case sys.PPC64: case sys.PPC64:
if elfobj.machine != ElfMachPower64 || hdr.Ident[4] != ElfClass64 { if elfobj.machine != ElfMachPower64 || hdr.Ident[4] != ElfClass64 {
ctxt.Diag("%s: elf object but not ppc64", pn) Errorf(nil, "%s: elf object but not ppc64", pn)
return return
} }
case sys.S390X: case sys.S390X:
if elfobj.machine != ElfMachS390 || hdr.Ident[4] != ElfClass64 { if elfobj.machine != ElfMachS390 || hdr.Ident[4] != ElfClass64 {
ctxt.Diag("%s: elf object but not s390x", pn) Errorf(nil, "%s: elf object but not s390x", pn)
return return
} }
} }
...@@ -660,7 +660,7 @@ func ldelf(ctxt *Link, f *bio.Reader, pkg string, length int64, pn string) { ...@@ -660,7 +660,7 @@ func ldelf(ctxt *Link, f *bio.Reader, pkg string, length int64, pn string) {
} }
if elfobj.symtab.link <= 0 || elfobj.symtab.link >= uint32(elfobj.nsect) { if elfobj.symtab.link <= 0 || elfobj.symtab.link >= uint32(elfobj.nsect) {
ctxt.Diag("%s: elf object has symbol table with invalid string table link", pn) Errorf(nil, "%s: elf object has symbol table with invalid string table link", pn)
return return
} }
...@@ -782,7 +782,7 @@ func ldelf(ctxt *Link, f *bio.Reader, pkg string, length int64, pn string) { ...@@ -782,7 +782,7 @@ func ldelf(ctxt *Link, f *bio.Reader, pkg string, length int64, pn string) {
if strings.HasPrefix(sym.name, ".LASF") { // gcc on s390x does this if strings.HasPrefix(sym.name, ".LASF") { // gcc on s390x does this
continue continue
} }
ctxt.Diag("%s: sym#%d: ignoring %s in section %d (type %d)", pn, i, sym.name, sym.shndx, sym.type_) Errorf(sym.sym, "%s: sym#%d: ignoring symbol in section %d (type %d)", pn, i, sym.shndx, sym.type_)
continue continue
} }
...@@ -805,7 +805,7 @@ func ldelf(ctxt *Link, f *bio.Reader, pkg string, length int64, pn string) { ...@@ -805,7 +805,7 @@ func ldelf(ctxt *Link, f *bio.Reader, pkg string, length int64, pn string) {
s.Outer = sect.sym s.Outer = sect.sym
if sect.sym.Type == obj.STEXT { if sect.sym.Type == obj.STEXT {
if s.Attr.External() && !s.Attr.DuplicateOK() { if s.Attr.External() && !s.Attr.DuplicateOK() {
ctxt.Diag("%s: duplicate definition of %s", pn, s.Name) Errorf(s, "%s: duplicate symbol definition", pn)
} }
s.Attr |= AttrExternal s.Attr |= AttrExternal
} }
...@@ -815,7 +815,7 @@ func ldelf(ctxt *Link, f *bio.Reader, pkg string, length int64, pn string) { ...@@ -815,7 +815,7 @@ func ldelf(ctxt *Link, f *bio.Reader, pkg string, length int64, pn string) {
if 2 <= flag && flag <= 6 { if 2 <= flag && flag <= 6 {
s.Localentry = 1 << uint(flag-2) s.Localentry = 1 << uint(flag-2)
} else if flag == 7 { } else if flag == 7 {
ctxt.Diag("%s: invalid sym.other 0x%x for %s", pn, sym.other, s.Name) Errorf(s, "%s: invalid sym.other 0x%x", pn, sym.other)
} }
} }
} }
...@@ -926,7 +926,7 @@ func ldelf(ctxt *Link, f *bio.Reader, pkg string, length int64, pn string) { ...@@ -926,7 +926,7 @@ func ldelf(ctxt *Link, f *bio.Reader, pkg string, length int64, pn string) {
} else if rp.Siz == 8 { } else if rp.Siz == 8 {
rp.Add = int64(e.Uint64(sect.base[rp.Off:])) rp.Add = int64(e.Uint64(sect.base[rp.Off:]))
} else { } else {
ctxt.Diag("invalid rela size %d", rp.Siz) Errorf(nil, "invalid rela size %d", rp.Siz)
} }
} }
...@@ -950,7 +950,7 @@ func ldelf(ctxt *Link, f *bio.Reader, pkg string, length int64, pn string) { ...@@ -950,7 +950,7 @@ func ldelf(ctxt *Link, f *bio.Reader, pkg string, length int64, pn string) {
return return
bad: bad:
ctxt.Diag("%s: malformed elf file: %v", pn, err) Errorf(nil, "%s: malformed elf file: %v", pn, err)
} }
func section(elfobj *ElfObj, name string) *ElfSect { func section(elfobj *ElfObj, name string) *ElfSect {
...@@ -990,7 +990,7 @@ func readelfsym(ctxt *Link, elfobj *ElfObj, i int, sym *ElfSym, needSym int) (er ...@@ -990,7 +990,7 @@ func readelfsym(ctxt *Link, elfobj *ElfObj, i int, sym *ElfSym, needSym int) (er
} }
if i == 0 { if i == 0 {
ctxt.Diag("readym: read null symbol!") Errorf(nil, "readym: read null symbol!")
} }
if elfobj.is64 != 0 { if elfobj.is64 != 0 {
...@@ -1134,7 +1134,7 @@ func relSize(ctxt *Link, pn string, elftype uint32) uint8 { ...@@ -1134,7 +1134,7 @@ func relSize(ctxt *Link, pn string, elftype uint32) uint8 {
switch uint32(SysArch.Family) | elftype<<24 { switch uint32(SysArch.Family) | elftype<<24 {
default: default:
ctxt.Diag("%s: unknown relocation type %d; compiled without -fpic?", pn, elftype) Errorf(nil, "%s: unknown relocation type %d; compiled without -fpic?", pn, elftype)
fallthrough fallthrough
case S390X | R_390_8<<24: case S390X | R_390_8<<24:
......
...@@ -487,18 +487,18 @@ func ldmacho(ctxt *Link, f *bio.Reader, pkg string, length int64, pn string) { ...@@ -487,18 +487,18 @@ func ldmacho(ctxt *Link, f *bio.Reader, pkg string, length int64, pn string) {
switch SysArch.Family { switch SysArch.Family {
default: default:
ctxt.Diag("%s: mach-o %s unimplemented", pn, SysArch.Name) Errorf(nil, "%s: mach-o %s unimplemented", pn, SysArch.Name)
return return
case sys.AMD64: case sys.AMD64:
if e != binary.LittleEndian || m.cputype != LdMachoCpuAmd64 { if e != binary.LittleEndian || m.cputype != LdMachoCpuAmd64 {
ctxt.Diag("%s: mach-o object but not amd64", pn) Errorf(nil, "%s: mach-o object but not amd64", pn)
return return
} }
case sys.I386: case sys.I386:
if e != binary.LittleEndian || m.cputype != LdMachoCpu386 { if e != binary.LittleEndian || m.cputype != LdMachoCpu386 {
ctxt.Diag("%s: mach-o object but not 386", pn) Errorf(nil, "%s: mach-o object but not 386", pn)
return return
} }
} }
...@@ -673,7 +673,7 @@ func ldmacho(ctxt *Link, f *bio.Reader, pkg string, length int64, pn string) { ...@@ -673,7 +673,7 @@ func ldmacho(ctxt *Link, f *bio.Reader, pkg string, length int64, pn string) {
} }
if outer.Type == obj.STEXT { if outer.Type == obj.STEXT {
if s.Attr.External() && !s.Attr.DuplicateOK() { if s.Attr.External() && !s.Attr.DuplicateOK() {
ctxt.Diag("%s: duplicate definition of %s", pn, s.Name) Errorf(s, "%s: duplicate symbol definition", pn)
} }
s.Attr |= AttrExternal s.Attr |= AttrExternal
} }
...@@ -738,7 +738,7 @@ func ldmacho(ctxt *Link, f *bio.Reader, pkg string, length int64, pn string) { ...@@ -738,7 +738,7 @@ func ldmacho(ctxt *Link, f *bio.Reader, pkg string, length int64, pn string) {
if rel.scattered != 0 { if rel.scattered != 0 {
if SysArch.Family != sys.I386 { if SysArch.Family != sys.I386 {
// mach-o only uses scattered relocation on 32-bit platforms // mach-o only uses scattered relocation on 32-bit platforms
ctxt.Diag("unexpected scattered relocation") Errorf(s, "unexpected scattered relocation")
continue continue
} }
...@@ -900,5 +900,5 @@ func ldmacho(ctxt *Link, f *bio.Reader, pkg string, length int64, pn string) { ...@@ -900,5 +900,5 @@ func ldmacho(ctxt *Link, f *bio.Reader, pkg string, length int64, pn string) {
return return
bad: bad:
ctxt.Diag("%s: malformed mach-o file: %v", pn, err) Errorf(nil, "%s: malformed mach-o file: %v", pn, err)
} }
...@@ -313,7 +313,7 @@ func ldpe(ctxt *Link, f *bio.Reader, pkg string, length int64, pn string) { ...@@ -313,7 +313,7 @@ func ldpe(ctxt *Link, f *bio.Reader, pkg string, length int64, pn string) {
rp.Off = int32(rva) rp.Off = int32(rva)
switch type_ { switch type_ {
default: default:
ctxt.Diag("%s: unknown relocation type %d;", pn, type_) Errorf(rsect.sym, "%s: unknown relocation type %d;", pn, type_)
fallthrough fallthrough
case IMAGE_REL_I386_REL32, IMAGE_REL_AMD64_REL32, case IMAGE_REL_I386_REL32, IMAGE_REL_AMD64_REL32,
...@@ -389,10 +389,10 @@ func ldpe(ctxt *Link, f *bio.Reader, pkg string, length int64, pn string) { ...@@ -389,10 +389,10 @@ func ldpe(ctxt *Link, f *bio.Reader, pkg string, length int64, pn string) {
} else if sym.sectnum > 0 && uint(sym.sectnum) <= peobj.nsect { } else if sym.sectnum > 0 && uint(sym.sectnum) <= peobj.nsect {
sect = &peobj.sect[sym.sectnum-1] sect = &peobj.sect[sym.sectnum-1]
if sect.sym == nil { if sect.sym == nil {
ctxt.Diag("%s: %s sym == 0!", pn, s.Name) Errorf(s, "%s: missing sect.sym", pn)
} }
} else { } else {
ctxt.Diag("%s: %s sectnum < 0!", pn, s.Name) Errorf(s, "%s: sectnum < 0!", pn)
} }
if sect == nil { if sect == nil {
...@@ -414,7 +414,7 @@ func ldpe(ctxt *Link, f *bio.Reader, pkg string, length int64, pn string) { ...@@ -414,7 +414,7 @@ func ldpe(ctxt *Link, f *bio.Reader, pkg string, length int64, pn string) {
s.Outer = sect.sym s.Outer = sect.sym
if sect.sym.Type == obj.STEXT { if sect.sym.Type == obj.STEXT {
if s.Attr.External() && !s.Attr.DuplicateOK() { if s.Attr.External() && !s.Attr.DuplicateOK() {
ctxt.Diag("%s: duplicate definition of %s", pn, s.Name) Errorf(s, "%s: duplicate symbol definition", pn)
} }
s.Attr |= AttrExternal s.Attr |= AttrExternal
} }
...@@ -449,7 +449,7 @@ func ldpe(ctxt *Link, f *bio.Reader, pkg string, length int64, pn string) { ...@@ -449,7 +449,7 @@ func ldpe(ctxt *Link, f *bio.Reader, pkg string, length int64, pn string) {
return return
bad: bad:
ctxt.Diag("%s: malformed pe file: %v", pn, err) Errorf(nil, "%s: malformed pe file: %v", pn, err)
} }
func pemap(peobj *PeObj, sect *PeSect) int { func pemap(peobj *PeObj, sect *PeSect) int {
......
This diff is collapsed.
...@@ -376,7 +376,7 @@ func machoshbits(ctxt *Link, mseg *MachoSeg, sect *Section, segname string) { ...@@ -376,7 +376,7 @@ func machoshbits(ctxt *Link, mseg *MachoSeg, sect *Section, segname string) {
if sect.Vaddr < sect.Seg.Vaddr+sect.Seg.Filelen { if sect.Vaddr < sect.Seg.Vaddr+sect.Seg.Filelen {
// data in file // data in file
if sect.Length > sect.Seg.Vaddr+sect.Seg.Filelen-sect.Vaddr { if sect.Length > sect.Seg.Vaddr+sect.Seg.Filelen-sect.Vaddr {
ctxt.Diag("macho cannot represent section %s crossing data and bss", sect.Name) Errorf(nil, "macho cannot represent section %s crossing data and bss", sect.Name)
} }
msect.off = uint32(sect.Seg.Fileoff + sect.Vaddr - sect.Seg.Vaddr) msect.off = uint32(sect.Seg.Fileoff + sect.Vaddr - sect.Seg.Vaddr)
} else { } else {
...@@ -716,13 +716,13 @@ func machosymtab(ctxt *Link) { ...@@ -716,13 +716,13 @@ func machosymtab(ctxt *Link) {
o = o.Outer o = o.Outer
} }
if o.Sect == nil { if o.Sect == nil {
ctxt.Diag("missing section for %s", s.Name) Errorf(s, "missing section for symbol")
Adduint8(ctxt, symtab, 0) Adduint8(ctxt, symtab, 0)
} else { } else {
Adduint8(ctxt, symtab, uint8(o.Sect.Extnum)) Adduint8(ctxt, symtab, uint8(o.Sect.Extnum))
} }
Adduint16(ctxt, symtab, 0) // desc Adduint16(ctxt, symtab, 0) // desc
adduintxx(ctxt, symtab, uint64(Symaddr(ctxt, s)), SysArch.PtrSize) adduintxx(ctxt, symtab, uint64(Symaddr(s)), SysArch.PtrSize)
} }
} }
} }
...@@ -834,15 +834,20 @@ func machorelocsect(ctxt *Link, sect *Section, syms []*Symbol) { ...@@ -834,15 +834,20 @@ func machorelocsect(ctxt *Link, sect *Section, syms []*Symbol) {
if sym.Value >= int64(eaddr) { if sym.Value >= int64(eaddr) {
break break
} }
ctxt.Cursym = sym
for ri := 0; ri < len(sym.R); ri++ { for ri := 0; ri < len(sym.R); ri++ {
r := &sym.R[ri] r := &sym.R[ri]
if r.Done != 0 { if r.Done != 0 {
continue continue
} }
if Thearch.Machoreloc1(ctxt, r, int64(uint64(sym.Value+int64(r.Off))-sect.Vaddr)) < 0 { if r.Xsym == nil {
ctxt.Diag("unsupported obj reloc %d/%d to %s", r.Type, r.Siz, r.Sym.Name) Errorf(sym, "missing xsym in relocation")
continue
}
if !r.Xsym.Attr.Reachable() {
Errorf(sym, "unreachable reloc %v target %v", r.Type, r.Xsym.Name)
}
if Thearch.Machoreloc1(sym, r, int64(uint64(sym.Value+int64(r.Off))-sect.Vaddr)) < 0 {
Errorf(sym, "unsupported obj reloc %v/%d to %s", r.Type, r.Siz, r.Sym.Name)
} }
} }
} }
......
...@@ -300,7 +300,7 @@ func (ctxt *Link) pclntab() { ...@@ -300,7 +300,7 @@ func (ctxt *Link) pclntab() {
var it Pciter var it Pciter
for pciterinit(ctxt, &it, &pcln.Pcfile); it.done == 0; pciternext(&it) { for pciterinit(ctxt, &it, &pcln.Pcfile); it.done == 0; pciternext(&it) {
if it.value < 1 || it.value > int32(len(ctxt.Filesyms)) { if it.value < 1 || it.value > int32(len(ctxt.Filesyms)) {
ctxt.Diag("bad file number in pcfile: %d not in range [1, %d]\n", it.value, len(ctxt.Filesyms)) Errorf(ctxt.Cursym, "bad file number in pcfile: %d not in range [1, %d]\n", it.value, len(ctxt.Filesyms))
errorexit() errorexit()
} }
} }
...@@ -339,7 +339,7 @@ func (ctxt *Link) pclntab() { ...@@ -339,7 +339,7 @@ func (ctxt *Link) pclntab() {
} }
if off != end { if off != end {
ctxt.Diag("bad math in functab: funcstart=%d off=%d but end=%d (npcdata=%d nfuncdata=%d ptrsize=%d)", funcstart, off, end, len(pcln.Pcdata), len(pcln.Funcdata), SysArch.PtrSize) Errorf(ctxt.Cursym, "bad math in functab: funcstart=%d off=%d but end=%d (npcdata=%d nfuncdata=%d ptrsize=%d)", funcstart, off, end, len(pcln.Pcdata), len(pcln.Funcdata), SysArch.PtrSize)
errorexit() errorexit()
} }
...@@ -457,16 +457,16 @@ func (ctxt *Link) findfunctab() { ...@@ -457,16 +457,16 @@ func (ctxt *Link) findfunctab() {
for i := int32(0); i < nbuckets; i++ { for i := int32(0); i < nbuckets; i++ {
base := indexes[i*SUBBUCKETS] base := indexes[i*SUBBUCKETS]
if base == NOIDX { if base == NOIDX {
ctxt.Diag("hole in findfunctab") Errorf(nil, "hole in findfunctab")
} }
setuint32(ctxt, t, int64(i)*(4+SUBBUCKETS), uint32(base)) setuint32(ctxt, t, int64(i)*(4+SUBBUCKETS), uint32(base))
for j := int32(0); j < SUBBUCKETS && i*SUBBUCKETS+j < n; j++ { for j := int32(0); j < SUBBUCKETS && i*SUBBUCKETS+j < n; j++ {
idx = indexes[i*SUBBUCKETS+j] idx = indexes[i*SUBBUCKETS+j]
if idx == NOIDX { if idx == NOIDX {
ctxt.Diag("hole in findfunctab") Errorf(nil, "hole in findfunctab")
} }
if idx-base >= 256 { if idx-base >= 256 {
ctxt.Diag("too many functions in a findfunc bucket! %d/%d %d %d", i, nbuckets, j, idx-base) Errorf(nil, "too many functions in a findfunc bucket! %d/%d %d %d", i, nbuckets, j, idx-base)
} }
setuint8(ctxt, t, int64(i)*(4+SUBBUCKETS)+4+int64(j), uint8(idx-base)) setuint8(ctxt, t, int64(i)*(4+SUBBUCKETS)+4+int64(j), uint8(idx-base))
......
...@@ -379,7 +379,7 @@ var nexport int ...@@ -379,7 +379,7 @@ var nexport int
func addpesection(ctxt *Link, name string, sectsize int, filesize int) *IMAGE_SECTION_HEADER { func addpesection(ctxt *Link, name string, sectsize int, filesize int) *IMAGE_SECTION_HEADER {
if pensect == 16 { if pensect == 16 {
ctxt.Diag("too many sections") Errorf(nil, "too many sections")
errorexit() errorexit()
} }
...@@ -400,19 +400,19 @@ func addpesection(ctxt *Link, name string, sectsize int, filesize int) *IMAGE_SE ...@@ -400,19 +400,19 @@ func addpesection(ctxt *Link, name string, sectsize int, filesize int) *IMAGE_SE
func chksectoff(ctxt *Link, h *IMAGE_SECTION_HEADER, off int64) { func chksectoff(ctxt *Link, h *IMAGE_SECTION_HEADER, off int64) {
if off != int64(h.PointerToRawData) { if off != int64(h.PointerToRawData) {
ctxt.Diag("%s.PointerToRawData = %#x, want %#x", cstring(h.Name[:]), uint64(int64(h.PointerToRawData)), uint64(off)) Errorf(nil, "%s.PointerToRawData = %#x, want %#x", cstring(h.Name[:]), uint64(int64(h.PointerToRawData)), uint64(off))
errorexit() errorexit()
} }
} }
func chksectseg(ctxt *Link, h *IMAGE_SECTION_HEADER, s *Segment) { func chksectseg(ctxt *Link, h *IMAGE_SECTION_HEADER, s *Segment) {
if s.Vaddr-PEBASE != uint64(h.VirtualAddress) { if s.Vaddr-PEBASE != uint64(h.VirtualAddress) {
ctxt.Diag("%s.VirtualAddress = %#x, want %#x", cstring(h.Name[:]), uint64(int64(h.VirtualAddress)), uint64(int64(s.Vaddr-PEBASE))) Errorf(nil, "%s.VirtualAddress = %#x, want %#x", cstring(h.Name[:]), uint64(int64(h.VirtualAddress)), uint64(int64(s.Vaddr-PEBASE)))
errorexit() errorexit()
} }
if s.Fileoff != uint64(h.PointerToRawData) { if s.Fileoff != uint64(h.PointerToRawData) {
ctxt.Diag("%s.PointerToRawData = %#x, want %#x", cstring(h.Name[:]), uint64(int64(h.PointerToRawData)), uint64(int64(s.Fileoff))) Errorf(nil, "%s.PointerToRawData = %#x, want %#x", cstring(h.Name[:]), uint64(int64(h.PointerToRawData)), uint64(int64(s.Fileoff)))
errorexit() errorexit()
} }
} }
...@@ -505,7 +505,7 @@ func initdynimport(ctxt *Link) *Dll { ...@@ -505,7 +505,7 @@ func initdynimport(ctxt *Link) *Dll {
var err error var err error
m.argsize, err = strconv.Atoi(s.Extname[i+1:]) m.argsize, err = strconv.Atoi(s.Extname[i+1:])
if err != nil { if err != nil {
ctxt.Diag("failed to parse stdcall decoration: %v", err) Errorf(s, "failed to parse stdcall decoration: %v", err)
} }
m.argsize *= SysArch.PtrSize m.argsize *= SysArch.PtrSize
s.Extname = s.Extname[:i] s.Extname = s.Extname[:i]
...@@ -686,7 +686,7 @@ func initdynexport(ctxt *Link) { ...@@ -686,7 +686,7 @@ func initdynexport(ctxt *Link) {
continue continue
} }
if nexport+1 > len(dexport) { if nexport+1 > len(dexport) {
ctxt.Diag("pe dynexport table is full") Errorf(s, "pe dynexport table is full")
errorexit() errorexit()
} }
...@@ -798,15 +798,15 @@ func perelocsect(ctxt *Link, sect *Section, syms []*Symbol) int { ...@@ -798,15 +798,15 @@ func perelocsect(ctxt *Link, sect *Section, syms []*Symbol) int {
continue continue
} }
if r.Xsym == nil { if r.Xsym == nil {
ctxt.Diag("missing xsym in relocation") Errorf(sym, "missing xsym in relocation")
continue continue
} }
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) Errorf(sym, "reloc %d to non-coff symbol %s (outer=%s) %d", r.Type, r.Sym.Name, r.Xsym.Name, r.Sym.Type)
} }
if !Thearch.PEreloc1(ctxt, r, int64(uint64(sym.Value+int64(r.Off))-PEBASE)) { if !Thearch.PEreloc1(sym, 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) Errorf(sym, "unsupported obj reloc %d/%d to %s", r.Type, r.Siz, r.Sym.Name)
} }
relocs++ relocs++
...@@ -969,7 +969,7 @@ func writePESymTableRecords(ctxt *Link) int { ...@@ -969,7 +969,7 @@ func writePESymTableRecords(ctxt *Link) int {
} else if type_ == UndefinedSym { } else if type_ == UndefinedSym {
typ = IMAGE_SYM_DTYPE_FUNCTION typ = IMAGE_SYM_DTYPE_FUNCTION
} else { } else {
ctxt.Diag("addpesym %#x", addr) Errorf(s, "addpesym %#x", addr)
} }
// write COFF symbol table record // write COFF symbol table record
...@@ -1049,7 +1049,7 @@ func addpesymtable(ctxt *Link) { ...@@ -1049,7 +1049,7 @@ func addpesymtable(ctxt *Link) {
func setpersrc(ctxt *Link, sym *Symbol) { func setpersrc(ctxt *Link, sym *Symbol) {
if rsrcsym != nil { if rsrcsym != nil {
ctxt.Diag("too many .rsrc sections") Errorf(sym, "too many .rsrc sections")
} }
rsrcsym = sym rsrcsym = sym
......
...@@ -113,13 +113,11 @@ func putelfsym(ctxt *Link, x *Symbol, s string, t SymbolType, addr int64, go_ *S ...@@ -113,13 +113,11 @@ func putelfsym(ctxt *Link, x *Symbol, s string, t SymbolType, addr int64, go_ *S
elfshnum = SHN_UNDEF elfshnum = SHN_UNDEF
} else { } else {
if xo.Sect == nil { if xo.Sect == nil {
ctxt.Cursym = x Errorf(x, "missing section in putelfsym")
ctxt.Diag("missing section in putelfsym")
return return
} }
if xo.Sect.Elfsect == nil { if xo.Sect.Elfsect == nil {
ctxt.Cursym = x Errorf(x, "missing ELF section in putelfsym")
ctxt.Diag("missing ELF section in putelfsym")
return return
} }
elfshnum = xo.Sect.Elfsect.shnum elfshnum = xo.Sect.Elfsect.shnum
......
...@@ -7,6 +7,7 @@ package ld ...@@ -7,6 +7,7 @@ package ld
import ( import (
"bytes" "bytes"
"encoding/binary" "encoding/binary"
"fmt"
"os" "os"
"strings" "strings"
"time" "time"
...@@ -70,15 +71,45 @@ func AtExit(f func()) { ...@@ -70,15 +71,45 @@ func AtExit(f func()) {
atExitFuncs = append(atExitFuncs, f) atExitFuncs = append(atExitFuncs, f)
} }
// Exit exits with code after executing all atExitFuncs.
func Exit(code int) { func Exit(code int) {
for i := len(atExitFuncs) - 1; i >= 0; i-- { for i := len(atExitFuncs) - 1; i >= 0; i-- {
f := atExitFuncs[i] atExitFuncs[i]()
atExitFuncs = atExitFuncs[:i]
f()
} }
os.Exit(code) os.Exit(code)
} }
// Exitf logs an error message then calls Exit(2).
func Exitf(format string, a ...interface{}) {
fmt.Fprintf(os.Stderr, os.Args[0]+": "+format+"\n", a...)
if coutbuf.f != nil {
coutbuf.f.Close()
mayberemoveoutfile()
}
Exit(2)
}
// Errorf logs an error message.
//
// If more than 20 errors have been printed, exit with an error.
//
// Logging an error means that on exit cmd/link will delete any
// output file and return a non-zero error code.
func Errorf(s *Symbol, format string, args ...interface{}) {
if s != nil {
format = s.Name + ": " + format
}
format += "\n"
fmt.Fprintf(os.Stderr, format, args...)
nerrors++
if *flagH {
panic("error")
}
if nerrors > 20 {
Exitf("too many errors")
}
}
func artrim(x []byte) string { func artrim(x []byte) string {
i := 0 i := 0
j := len(x) j := len(x)
......
...@@ -98,7 +98,7 @@ func elfsetupplt(ctxt *ld.Link) { ...@@ -98,7 +98,7 @@ func elfsetupplt(ctxt *ld.Link) {
return return
} }
func machoreloc1(ctxt *ld.Link, r *ld.Reloc, sectoff int64) int { func machoreloc1(s *ld.Symbol, r *ld.Reloc, sectoff int64) int {
return -1 return -1
} }
...@@ -116,12 +116,12 @@ func archreloc(ctxt *ld.Link, r *ld.Reloc, s *ld.Symbol, val *int64) int { ...@@ -116,12 +116,12 @@ func archreloc(ctxt *ld.Link, r *ld.Reloc, s *ld.Symbol, val *int64) int {
rs := r.Sym rs := r.Sym
r.Xadd = r.Add r.Xadd = r.Add
for rs.Outer != nil { for rs.Outer != nil {
r.Xadd += ld.Symaddr(ctxt, rs) - ld.Symaddr(ctxt, rs.Outer) r.Xadd += ld.Symaddr(rs) - ld.Symaddr(rs.Outer)
rs = rs.Outer rs = rs.Outer
} }
if rs.Type != obj.SHOSTOBJ && rs.Type != obj.SDYNIMPORT && rs.Sect == nil { if rs.Type != obj.SHOSTOBJ && rs.Type != obj.SDYNIMPORT && rs.Sect == nil {
ctxt.Diag("missing section for %s", rs.Name) ld.Errorf(s, "missing section for %s", rs.Name)
} }
r.Xsym = rs r.Xsym = rs
...@@ -143,12 +143,12 @@ func archreloc(ctxt *ld.Link, r *ld.Reloc, s *ld.Symbol, val *int64) int { ...@@ -143,12 +143,12 @@ func archreloc(ctxt *ld.Link, 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(ctxt, ".got", 0)) *val = ld.Symaddr(r.Sym) + r.Add - ld.Symaddr(ld.Linklookup(ctxt, ".got", 0))
return 0 return 0
case obj.R_ADDRMIPS, case obj.R_ADDRMIPS,
obj.R_ADDRMIPSU: obj.R_ADDRMIPSU:
t := ld.Symaddr(ctxt, r.Sym) + r.Add t := ld.Symaddr(r.Sym) + r.Add
o1 := ld.SysArch.ByteOrder.Uint32(s.P[r.Off:]) o1 := ld.SysArch.ByteOrder.Uint32(s.P[r.Off:])
if r.Type == obj.R_ADDRMIPS { if r.Type == obj.R_ADDRMIPS {
*val = int64(o1&0xffff0000 | uint32(t)&0xffff) *val = int64(o1&0xffff0000 | uint32(t)&0xffff)
...@@ -159,9 +159,9 @@ func archreloc(ctxt *ld.Link, r *ld.Reloc, s *ld.Symbol, val *int64) int { ...@@ -159,9 +159,9 @@ func archreloc(ctxt *ld.Link, r *ld.Reloc, s *ld.Symbol, val *int64) int {
case obj.R_ADDRMIPSTLS: case obj.R_ADDRMIPSTLS:
// 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(r.Sym) + r.Add - 0x7000
if t < -32768 || t >= 32678 { if t < -32768 || t >= 32678 {
ctxt.Diag("TLS offset out of range %d", t) ld.Errorf(s, "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)
...@@ -170,7 +170,7 @@ func archreloc(ctxt *ld.Link, r *ld.Reloc, s *ld.Symbol, val *int64) int { ...@@ -170,7 +170,7 @@ func archreloc(ctxt *ld.Link, r *ld.Reloc, s *ld.Symbol, val *int64) int {
case obj.R_CALLMIPS, case obj.R_CALLMIPS,
obj.R_JMPMIPS: obj.R_JMPMIPS:
// Low 26 bits = (S + A) >> 2 // Low 26 bits = (S + A) >> 2
t := ld.Symaddr(ctxt, r.Sym) + r.Add t := ld.Symaddr(r.Sym) + r.Add
o1 := ld.SysArch.ByteOrder.Uint32(s.P[r.Off:]) o1 := ld.SysArch.ByteOrder.Uint32(s.P[r.Off:])
*val = int64(o1&0xfc000000 | uint32(t>>2)&^0xfc000000) *val = int64(o1&0xfc000000 | uint32(t>>2)&^0xfc000000)
return 0 return 0
......
...@@ -247,7 +247,7 @@ func adddynrel(ctxt *ld.Link, s *ld.Symbol, r *ld.Reloc) bool { ...@@ -247,7 +247,7 @@ func adddynrel(ctxt *ld.Link, s *ld.Symbol, r *ld.Reloc) bool {
switch r.Type { switch r.Type {
default: default:
if r.Type >= 256 { if r.Type >= 256 {
ctxt.Diag("unexpected relocation type %d", r.Type) ld.Errorf(s, "unexpected relocation type %d", r.Type)
return false return false
} }
...@@ -264,7 +264,7 @@ func adddynrel(ctxt *ld.Link, s *ld.Symbol, r *ld.Reloc) bool { ...@@ -264,7 +264,7 @@ func adddynrel(ctxt *ld.Link, s *ld.Symbol, r *ld.Reloc) bool {
if targ.Type == obj.SDYNIMPORT { if targ.Type == obj.SDYNIMPORT {
// Should have been handled in elfsetupplt // Should have been handled in elfsetupplt
ctxt.Diag("unexpected R_PPC64_REL24 for dyn import") ld.Errorf(s, "unexpected R_PPC64_REL24 for dyn import")
} }
return true return true
...@@ -274,7 +274,7 @@ func adddynrel(ctxt *ld.Link, s *ld.Symbol, r *ld.Reloc) bool { ...@@ -274,7 +274,7 @@ func adddynrel(ctxt *ld.Link, s *ld.Symbol, r *ld.Reloc) bool {
r.Add += 4 r.Add += 4
if targ.Type == obj.SDYNIMPORT { if targ.Type == obj.SDYNIMPORT {
ctxt.Diag("unexpected R_PPC_REL32 for dyn import") ld.Errorf(s, "unexpected R_PPC_REL32 for dyn import")
} }
return true return true
...@@ -443,7 +443,7 @@ func elfsetupplt(ctxt *ld.Link) { ...@@ -443,7 +443,7 @@ func elfsetupplt(ctxt *ld.Link) {
} }
} }
func machoreloc1(ctxt *ld.Link, r *ld.Reloc, sectoff int64) int { func machoreloc1(s *ld.Symbol, r *ld.Reloc, sectoff int64) int {
return -1 return -1
} }
...@@ -458,7 +458,7 @@ func symtoc(ctxt *ld.Link, s *ld.Symbol) int64 { ...@@ -458,7 +458,7 @@ func symtoc(ctxt *ld.Link, s *ld.Symbol) int64 {
} }
if toc == nil { if toc == nil {
ctxt.Diag("TOC-relative relocation in object without .TOC.") ld.Errorf(s, "TOC-relative relocation in object without .TOC.")
return 0 return 0
} }
...@@ -482,9 +482,9 @@ func archrelocaddr(ctxt *ld.Link, r *ld.Reloc, s *ld.Symbol, val *int64) int { ...@@ -482,9 +482,9 @@ func archrelocaddr(ctxt *ld.Link, r *ld.Reloc, s *ld.Symbol, val *int64) int {
// instruction (it is an error in this case if the low 2 bits of the address // instruction (it is an error in this case if the low 2 bits of the address
// are non-zero). // are non-zero).
t := ld.Symaddr(ctxt, r.Sym) + r.Add t := ld.Symaddr(r.Sym) + r.Add
if t < 0 || t >= 1<<31 { if t < 0 || t >= 1<<31 {
ctxt.Diag("relocation for %s is too big (>=2G): %d", s.Name, ld.Symaddr(ctxt, r.Sym)) ld.Errorf(s, "relocation for %s is too big (>=2G): %d", s.Name, ld.Symaddr(r.Sym))
} }
if t&0x8000 != 0 { if t&0x8000 != 0 {
t += 0x10000 t += 0x10000
...@@ -498,7 +498,7 @@ func archrelocaddr(ctxt *ld.Link, r *ld.Reloc, s *ld.Symbol, val *int64) int { ...@@ -498,7 +498,7 @@ func archrelocaddr(ctxt *ld.Link, r *ld.Reloc, s *ld.Symbol, val *int64) int {
case obj.R_ADDRPOWER_DS: case obj.R_ADDRPOWER_DS:
o1 |= (uint32(t) >> 16) & 0xffff o1 |= (uint32(t) >> 16) & 0xffff
if t&3 != 0 { if t&3 != 0 {
ctxt.Diag("bad DS reloc for %s: %d", s.Name, ld.Symaddr(ctxt, r.Sym)) ld.Errorf(s, "bad DS reloc for %s: %d", s.Name, ld.Symaddr(r.Sym))
} }
o2 |= uint32(t) & 0xfffc o2 |= uint32(t) & 0xfffc
...@@ -539,12 +539,12 @@ func archreloc(ctxt *ld.Link, r *ld.Reloc, s *ld.Symbol, val *int64) int { ...@@ -539,12 +539,12 @@ func archreloc(ctxt *ld.Link, r *ld.Reloc, s *ld.Symbol, val *int64) int {
rs := r.Sym rs := r.Sym
r.Xadd = r.Add r.Xadd = r.Add
for rs.Outer != nil { for rs.Outer != nil {
r.Xadd += ld.Symaddr(ctxt, rs) - ld.Symaddr(ctxt, rs.Outer) r.Xadd += ld.Symaddr(rs) - ld.Symaddr(rs.Outer)
rs = rs.Outer rs = rs.Outer
} }
if rs.Type != obj.SHOSTOBJ && rs.Type != obj.SDYNIMPORT && rs.Sect == nil { if rs.Type != obj.SHOSTOBJ && rs.Type != obj.SDYNIMPORT && rs.Sect == nil {
ctxt.Diag("missing section for %s", rs.Name) ld.Errorf(s, "missing section for %s", rs.Name)
} }
r.Xsym = rs r.Xsym = rs
...@@ -564,7 +564,7 @@ func archreloc(ctxt *ld.Link, r *ld.Reloc, s *ld.Symbol, val *int64) int { ...@@ -564,7 +564,7 @@ func archreloc(ctxt *ld.Link, 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(ctxt, ".got", 0)) *val = ld.Symaddr(r.Sym) + r.Add - ld.Symaddr(ld.Linklookup(ctxt, ".got", 0))
return 0 return 0
case obj.R_ADDRPOWER, obj.R_ADDRPOWER_DS: case obj.R_ADDRPOWER, obj.R_ADDRPOWER_DS:
...@@ -573,21 +573,21 @@ func archreloc(ctxt *ld.Link, r *ld.Reloc, s *ld.Symbol, val *int64) int { ...@@ -573,21 +573,21 @@ func archreloc(ctxt *ld.Link, r *ld.Reloc, s *ld.Symbol, val *int64) int {
case obj.R_CALLPOWER: case obj.R_CALLPOWER:
// Bits 6 through 29 = (S + A - P) >> 2 // Bits 6 through 29 = (S + A - P) >> 2
t := ld.Symaddr(ctxt, r.Sym) + r.Add - (s.Value + int64(r.Off)) t := ld.Symaddr(r.Sym) + r.Add - (s.Value + int64(r.Off))
if t&3 != 0 { if t&3 != 0 {
ctxt.Diag("relocation for %s+%d is not aligned: %d", r.Sym.Name, r.Off, t) ld.Errorf(s, "relocation for %s+%d is not aligned: %d", r.Sym.Name, r.Off, t)
} }
if int64(int32(t<<6)>>6) != t { if int64(int32(t<<6)>>6) != t {
// TODO(austin) This can happen if text > 32M. // TODO(austin) This can happen if text > 32M.
// Add a call trampoline to .text in that case. // Add a call trampoline to .text in that case.
ctxt.Diag("relocation for %s+%d is too big: %d", r.Sym.Name, r.Off, t) ld.Errorf(s, "relocation for %s+%d is too big: %d", r.Sym.Name, r.Off, t)
} }
*val |= int64(uint32(t) &^ 0xfc000003) *val |= int64(uint32(t) &^ 0xfc000003)
return 0 return 0
case obj.R_POWER_TOC: // S + A - .TOC. case obj.R_POWER_TOC: // S + A - .TOC.
*val = ld.Symaddr(ctxt, r.Sym) + r.Add - symtoc(ctxt, s) *val = ld.Symaddr(r.Sym) + r.Add - symtoc(ctxt, s)
return 0 return 0
...@@ -598,7 +598,7 @@ func archreloc(ctxt *ld.Link, r *ld.Reloc, s *ld.Symbol, val *int64) int { ...@@ -598,7 +598,7 @@ func archreloc(ctxt *ld.Link, r *ld.Reloc, s *ld.Symbol, val *int64) int {
// Specification". // Specification".
v := r.Sym.Value - 0x7000 v := r.Sym.Value - 0x7000
if int64(int16(v)) != v { if int64(int16(v)) != v {
ctxt.Diag("TLS offset out of range %d", v) ld.Errorf(s, "TLS offset out of range %d", v)
} }
*val = (*val &^ 0xffff) | (v & 0xffff) *val = (*val &^ 0xffff) | (v & 0xffff)
return 0 return 0
...@@ -610,7 +610,7 @@ func archreloc(ctxt *ld.Link, r *ld.Reloc, s *ld.Symbol, val *int64) int { ...@@ -610,7 +610,7 @@ func archreloc(ctxt *ld.Link, r *ld.Reloc, s *ld.Symbol, val *int64) int {
func archrelocvariant(ctxt *ld.Link, r *ld.Reloc, s *ld.Symbol, t int64) int64 { func archrelocvariant(ctxt *ld.Link, r *ld.Reloc, s *ld.Symbol, t int64) int64 {
switch r.Variant & ld.RV_TYPE_MASK { switch r.Variant & ld.RV_TYPE_MASK {
default: default:
ctxt.Diag("unexpected relocation variant %d", r.Variant) ld.Errorf(s, "unexpected relocation variant %d", r.Variant)
fallthrough fallthrough
case ld.RV_NONE: case ld.RV_NONE:
...@@ -685,7 +685,7 @@ func archrelocvariant(ctxt *ld.Link, r *ld.Reloc, s *ld.Symbol, t int64) int64 { ...@@ -685,7 +685,7 @@ func archrelocvariant(ctxt *ld.Link, r *ld.Reloc, s *ld.Symbol, t int64) int64 {
o1 = uint32(ld.Le16(s.P[r.Off:])) o1 = uint32(ld.Le16(s.P[r.Off:]))
} }
if t&3 != 0 { if t&3 != 0 {
ctxt.Diag("relocation for %s+%d is not aligned: %d", r.Sym.Name, r.Off, t) ld.Errorf(s, "relocation for %s+%d is not aligned: %d", r.Sym.Name, r.Off, t)
} }
if (r.Variant&ld.RV_CHECK_OVERFLOW != 0) && int64(int16(t)) != t { if (r.Variant&ld.RV_CHECK_OVERFLOW != 0) && int64(int16(t)) != t {
goto overflow goto overflow
...@@ -694,7 +694,7 @@ func archrelocvariant(ctxt *ld.Link, r *ld.Reloc, s *ld.Symbol, t int64) int64 { ...@@ -694,7 +694,7 @@ func archrelocvariant(ctxt *ld.Link, r *ld.Reloc, s *ld.Symbol, t int64) int64 {
} }
overflow: overflow:
ctxt.Diag("relocation for %s+%d is too big: %d", r.Sym.Name, r.Off, t) ld.Errorf(s, "relocation for %s+%d is too big: %d", r.Sym.Name, r.Off, t)
return t return t
} }
...@@ -739,7 +739,7 @@ func addpltsym(ctxt *ld.Link, s *ld.Symbol) { ...@@ -739,7 +739,7 @@ func addpltsym(ctxt *ld.Link, s *ld.Symbol) {
ld.Adduint64(ctxt, rela, ld.ELF64_R_INFO(uint32(s.Dynid), ld.R_PPC64_JMP_SLOT)) ld.Adduint64(ctxt, rela, ld.ELF64_R_INFO(uint32(s.Dynid), ld.R_PPC64_JMP_SLOT))
ld.Adduint64(ctxt, rela, 0) ld.Adduint64(ctxt, rela, 0)
} else { } else {
ctxt.Diag("addpltsym: unsupported binary format") ld.Errorf(s, "addpltsym: unsupported binary format")
} }
} }
......
...@@ -100,19 +100,18 @@ func gentext(ctxt *ld.Link) { ...@@ -100,19 +100,18 @@ func gentext(ctxt *ld.Link) {
func adddynrel(ctxt *ld.Link, s *ld.Symbol, r *ld.Reloc) bool { func adddynrel(ctxt *ld.Link, s *ld.Symbol, r *ld.Reloc) bool {
targ := r.Sym targ := r.Sym
ctxt.Cursym = s
switch r.Type { switch r.Type {
default: default:
if r.Type >= 256 { if r.Type >= 256 {
ctxt.Diag("unexpected relocation type %d", r.Type) ld.Errorf(s, "unexpected relocation type %d", r.Type)
return false return false
} }
// Handle relocations found in ELF object files. // Handle relocations found in ELF object files.
case 256 + ld.R_390_12, case 256 + ld.R_390_12,
256 + ld.R_390_GOT12: 256 + ld.R_390_GOT12:
ctxt.Diag("s390x 12-bit relocations have not been implemented (relocation type %d)", r.Type-256) ld.Errorf(s, "s390x 12-bit relocations have not been implemented (relocation type %d)", r.Type-256)
return false return false
case 256 + ld.R_390_8, case 256 + ld.R_390_8,
...@@ -120,7 +119,7 @@ func adddynrel(ctxt *ld.Link, s *ld.Symbol, r *ld.Reloc) bool { ...@@ -120,7 +119,7 @@ func adddynrel(ctxt *ld.Link, s *ld.Symbol, r *ld.Reloc) bool {
256 + ld.R_390_32, 256 + ld.R_390_32,
256 + ld.R_390_64: 256 + ld.R_390_64:
if targ.Type == obj.SDYNIMPORT { if targ.Type == obj.SDYNIMPORT {
ctxt.Diag("unexpected R_390_nn relocation for dynamic symbol %s", targ.Name) ld.Errorf(s, "unexpected R_390_nn relocation for dynamic symbol %s", targ.Name)
} }
r.Type = obj.R_ADDR r.Type = obj.R_ADDR
return true return true
...@@ -129,10 +128,10 @@ func adddynrel(ctxt *ld.Link, s *ld.Symbol, r *ld.Reloc) bool { ...@@ -129,10 +128,10 @@ func adddynrel(ctxt *ld.Link, s *ld.Symbol, r *ld.Reloc) bool {
256 + ld.R_390_PC32, 256 + ld.R_390_PC32,
256 + ld.R_390_PC64: 256 + ld.R_390_PC64:
if targ.Type == obj.SDYNIMPORT { if targ.Type == obj.SDYNIMPORT {
ctxt.Diag("unexpected R_390_PCnn relocation for dynamic symbol %s", targ.Name) ld.Errorf(s, "unexpected R_390_PCnn relocation for dynamic symbol %s", targ.Name)
} }
if targ.Type == 0 || targ.Type == obj.SXREF { if targ.Type == 0 || targ.Type == obj.SXREF {
ctxt.Diag("unknown symbol %s in pcrel", targ.Name) ld.Errorf(s, "unknown symbol %s in pcrel", targ.Name)
} }
r.Type = obj.R_PCREL r.Type = obj.R_PCREL
r.Add += int64(r.Siz) r.Add += int64(r.Siz)
...@@ -141,7 +140,7 @@ func adddynrel(ctxt *ld.Link, s *ld.Symbol, r *ld.Reloc) bool { ...@@ -141,7 +140,7 @@ func adddynrel(ctxt *ld.Link, s *ld.Symbol, r *ld.Reloc) bool {
case 256 + ld.R_390_GOT16, case 256 + ld.R_390_GOT16,
256 + ld.R_390_GOT32, 256 + ld.R_390_GOT32,
256 + ld.R_390_GOT64: 256 + ld.R_390_GOT64:
ctxt.Diag("unimplemented S390x relocation: %v", r.Type-256) ld.Errorf(s, "unimplemented S390x relocation: %v", r.Type-256)
return true return true
case 256 + ld.R_390_PLT16DBL, case 256 + ld.R_390_PLT16DBL,
...@@ -168,24 +167,24 @@ func adddynrel(ctxt *ld.Link, s *ld.Symbol, r *ld.Reloc) bool { ...@@ -168,24 +167,24 @@ func adddynrel(ctxt *ld.Link, s *ld.Symbol, r *ld.Reloc) bool {
return true return true
case 256 + ld.R_390_COPY: case 256 + ld.R_390_COPY:
ctxt.Diag("unimplemented S390x relocation: %v", r.Type-256) ld.Errorf(s, "unimplemented S390x relocation: %v", r.Type-256)
return false return false
case 256 + ld.R_390_GLOB_DAT: case 256 + ld.R_390_GLOB_DAT:
ctxt.Diag("unimplemented S390x relocation: %v", r.Type-256) ld.Errorf(s, "unimplemented S390x relocation: %v", r.Type-256)
return false return false
case 256 + ld.R_390_JMP_SLOT: case 256 + ld.R_390_JMP_SLOT:
ctxt.Diag("unimplemented S390x relocation: %v", r.Type-256) ld.Errorf(s, "unimplemented S390x relocation: %v", r.Type-256)
return false return false
case 256 + ld.R_390_RELATIVE: case 256 + ld.R_390_RELATIVE:
ctxt.Diag("unimplemented S390x relocation: %v", r.Type-256) ld.Errorf(s, "unimplemented S390x relocation: %v", r.Type-256)
return false return false
case 256 + ld.R_390_GOTOFF: case 256 + ld.R_390_GOTOFF:
if targ.Type == obj.SDYNIMPORT { if targ.Type == obj.SDYNIMPORT {
ctxt.Diag("unexpected R_390_GOTOFF relocation for dynamic symbol %s", targ.Name) ld.Errorf(s, "unexpected R_390_GOTOFF relocation for dynamic symbol %s", targ.Name)
} }
r.Type = obj.R_GOTOFF r.Type = obj.R_GOTOFF
return true return true
...@@ -202,7 +201,7 @@ func adddynrel(ctxt *ld.Link, s *ld.Symbol, r *ld.Reloc) bool { ...@@ -202,7 +201,7 @@ func adddynrel(ctxt *ld.Link, s *ld.Symbol, r *ld.Reloc) bool {
r.Variant = ld.RV_390_DBL r.Variant = ld.RV_390_DBL
r.Add += int64(r.Siz) r.Add += int64(r.Siz)
if targ.Type == obj.SDYNIMPORT { if targ.Type == obj.SDYNIMPORT {
ctxt.Diag("unexpected R_390_PCnnDBL relocation for dynamic symbol %s", targ.Name) ld.Errorf(s, "unexpected R_390_PCnnDBL relocation for dynamic symbol %s", targ.Name)
} }
return true return true
...@@ -380,7 +379,7 @@ func elfsetupplt(ctxt *ld.Link) { ...@@ -380,7 +379,7 @@ func elfsetupplt(ctxt *ld.Link) {
} }
} }
func machoreloc1(ctxt *ld.Link, r *ld.Reloc, sectoff int64) int { func machoreloc1(s *ld.Symbol, r *ld.Reloc, sectoff int64) int {
return -1 return -1
} }
...@@ -395,7 +394,7 @@ func archreloc(ctxt *ld.Link, r *ld.Reloc, s *ld.Symbol, val *int64) int { ...@@ -395,7 +394,7 @@ func archreloc(ctxt *ld.Link, 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(ctxt, ".got", 0)) *val = ld.Symaddr(r.Sym) + r.Add - ld.Symaddr(ld.Linklookup(ctxt, ".got", 0))
return 0 return 0
} }
...@@ -405,7 +404,7 @@ func archreloc(ctxt *ld.Link, r *ld.Reloc, s *ld.Symbol, val *int64) int { ...@@ -405,7 +404,7 @@ func archreloc(ctxt *ld.Link, r *ld.Reloc, s *ld.Symbol, val *int64) int {
func archrelocvariant(ctxt *ld.Link, r *ld.Reloc, s *ld.Symbol, t int64) int64 { func archrelocvariant(ctxt *ld.Link, r *ld.Reloc, s *ld.Symbol, t int64) int64 {
switch r.Variant & ld.RV_TYPE_MASK { switch r.Variant & ld.RV_TYPE_MASK {
default: default:
ctxt.Diag("unexpected relocation variant %d", r.Variant) ld.Errorf(s, "unexpected relocation variant %d", r.Variant)
return t return t
case ld.RV_NONE: case ld.RV_NONE:
...@@ -413,7 +412,7 @@ func archrelocvariant(ctxt *ld.Link, r *ld.Reloc, s *ld.Symbol, t int64) int64 { ...@@ -413,7 +412,7 @@ func archrelocvariant(ctxt *ld.Link, r *ld.Reloc, s *ld.Symbol, t int64) int64 {
case ld.RV_390_DBL: case ld.RV_390_DBL:
if (t & 1) != 0 { if (t & 1) != 0 {
ctxt.Diag("%s+%v is not 2-byte aligned", r.Sym.Name, r.Sym.Value) ld.Errorf(s, "%s+%v is not 2-byte aligned", r.Sym.Name, r.Sym.Value)
} }
return t >> 1 return t >> 1
} }
...@@ -478,7 +477,7 @@ func addpltsym(ctxt *ld.Link, s *ld.Symbol) { ...@@ -478,7 +477,7 @@ func addpltsym(ctxt *ld.Link, s *ld.Symbol) {
s.Plt = int32(plt.Size - 32) s.Plt = int32(plt.Size - 32)
} else { } else {
ctxt.Diag("addpltsym: unsupported binary format") ld.Errorf(s, "addpltsym: unsupported binary format")
} }
} }
...@@ -498,7 +497,7 @@ func addgotsym(ctxt *ld.Link, s *ld.Symbol) { ...@@ -498,7 +497,7 @@ func addgotsym(ctxt *ld.Link, s *ld.Symbol) {
ld.Adduint64(ctxt, rela, ld.ELF64_R_INFO(uint32(s.Dynid), ld.R_390_GLOB_DAT)) ld.Adduint64(ctxt, rela, ld.ELF64_R_INFO(uint32(s.Dynid), ld.R_390_GLOB_DAT))
ld.Adduint64(ctxt, rela, 0) ld.Adduint64(ctxt, rela, 0)
} else { } else {
ctxt.Diag("addgotsym: unsupported binary format") ld.Errorf(s, "addgotsym: unsupported binary format")
} }
} }
...@@ -551,7 +550,7 @@ func asmb(ctxt *ld.Link) { ...@@ -551,7 +550,7 @@ func asmb(ctxt *ld.Link) {
symo := uint32(0) symo := uint32(0)
if !*ld.FlagS { if !*ld.FlagS {
if !ld.Iself { if !ld.Iself {
ctxt.Diag("unsupported executable format") ld.Errorf(nil, "unsupported executable format")
} }
if ctxt.Debugvlog != 0 { if ctxt.Debugvlog != 0 {
ctxt.Logf("%5.2f sym\n", obj.Cputime()) ctxt.Logf("%5.2f sym\n", obj.Cputime())
...@@ -583,7 +582,7 @@ func asmb(ctxt *ld.Link) { ...@@ -583,7 +582,7 @@ func asmb(ctxt *ld.Link) {
ld.Cseek(0) ld.Cseek(0)
switch ld.Headtype { switch ld.Headtype {
default: default:
ctxt.Diag("unsupported operating system") ld.Errorf(nil, "unsupported operating system")
case obj.Hlinux: case obj.Hlinux:
ld.Asmbelf(ctxt, int64(symo)) ld.Asmbelf(ctxt, int64(symo))
} }
......
...@@ -169,17 +169,17 @@ func adddynrel(ctxt *ld.Link, s *ld.Symbol, r *ld.Reloc) bool { ...@@ -169,17 +169,17 @@ func adddynrel(ctxt *ld.Link, s *ld.Symbol, r *ld.Reloc) bool {
switch r.Type { switch r.Type {
default: default:
if r.Type >= 256 { if r.Type >= 256 {
ctxt.Diag("unexpected relocation type %d", r.Type) ld.Errorf(s, "unexpected relocation type %d", r.Type)
return false return false
} }
// Handle relocations found in ELF object files. // Handle relocations found in ELF object files.
case 256 + ld.R_386_PC32: case 256 + ld.R_386_PC32:
if targ.Type == obj.SDYNIMPORT { if targ.Type == obj.SDYNIMPORT {
ctxt.Diag("unexpected R_386_PC32 relocation for dynamic symbol %s", targ.Name) ld.Errorf(s, "unexpected R_386_PC32 relocation for dynamic symbol %s", targ.Name)
} }
if targ.Type == 0 || targ.Type == obj.SXREF { if targ.Type == 0 || targ.Type == obj.SXREF {
ctxt.Diag("unknown symbol %s in pcrel", targ.Name) ld.Errorf(s, "unknown symbol %s in pcrel", targ.Name)
} }
r.Type = obj.R_PCREL r.Type = obj.R_PCREL
r.Add += 4 r.Add += 4
...@@ -217,7 +217,7 @@ func adddynrel(ctxt *ld.Link, s *ld.Symbol, r *ld.Reloc) bool { ...@@ -217,7 +217,7 @@ func adddynrel(ctxt *ld.Link, s *ld.Symbol, r *ld.Reloc) bool {
return true return true
} }
ctxt.Diag("unexpected GOT reloc for non-dynamic symbol %s", targ.Name) ld.Errorf(s, "unexpected GOT reloc for non-dynamic symbol %s", targ.Name)
return false return false
} }
...@@ -239,7 +239,7 @@ func adddynrel(ctxt *ld.Link, s *ld.Symbol, r *ld.Reloc) bool { ...@@ -239,7 +239,7 @@ func adddynrel(ctxt *ld.Link, s *ld.Symbol, r *ld.Reloc) bool {
case 256 + ld.R_386_32: case 256 + ld.R_386_32:
if targ.Type == obj.SDYNIMPORT { if targ.Type == obj.SDYNIMPORT {
ctxt.Diag("unexpected R_386_32 relocation for dynamic symbol %s", targ.Name) ld.Errorf(s, "unexpected R_386_32 relocation for dynamic symbol %s", targ.Name)
} }
r.Type = obj.R_ADDR r.Type = obj.R_ADDR
return true return true
...@@ -247,7 +247,7 @@ func adddynrel(ctxt *ld.Link, s *ld.Symbol, r *ld.Reloc) bool { ...@@ -247,7 +247,7 @@ func adddynrel(ctxt *ld.Link, s *ld.Symbol, r *ld.Reloc) bool {
case 512 + ld.MACHO_GENERIC_RELOC_VANILLA*2 + 0: case 512 + ld.MACHO_GENERIC_RELOC_VANILLA*2 + 0:
r.Type = obj.R_ADDR r.Type = obj.R_ADDR
if targ.Type == obj.SDYNIMPORT { if targ.Type == obj.SDYNIMPORT {
ctxt.Diag("unexpected reloc for dynamic symbol %s", targ.Name) ld.Errorf(s, "unexpected reloc for dynamic symbol %s", targ.Name)
} }
return true return true
...@@ -268,7 +268,7 @@ func adddynrel(ctxt *ld.Link, s *ld.Symbol, r *ld.Reloc) bool { ...@@ -268,7 +268,7 @@ func adddynrel(ctxt *ld.Link, s *ld.Symbol, r *ld.Reloc) bool {
// have symbol // have symbol
// turn MOVL of GOT entry into LEAL of symbol itself // turn MOVL of GOT entry into LEAL of symbol itself
if r.Off < 2 || s.P[r.Off-2] != 0x8b { if r.Off < 2 || s.P[r.Off-2] != 0x8b {
ctxt.Diag("unexpected GOT reloc for non-dynamic symbol %s", targ.Name) ld.Errorf(s, "unexpected GOT reloc for non-dynamic symbol %s", targ.Name)
return false return false
} }
...@@ -408,14 +408,14 @@ func elfreloc1(ctxt *ld.Link, r *ld.Reloc, sectoff int64) int { ...@@ -408,14 +408,14 @@ func elfreloc1(ctxt *ld.Link, r *ld.Reloc, sectoff int64) int {
return 0 return 0
} }
func machoreloc1(ctxt *ld.Link, r *ld.Reloc, sectoff int64) int { func machoreloc1(s *ld.Symbol, r *ld.Reloc, sectoff int64) int {
var v uint32 var v uint32
rs := r.Xsym rs := r.Xsym
if rs.Type == obj.SHOSTOBJ { if rs.Type == obj.SHOSTOBJ {
if rs.Dynid < 0 { if rs.Dynid < 0 {
ctxt.Diag("reloc %d to non-macho symbol %s type=%d", r.Type, rs.Name, rs.Type) ld.Errorf(s, "reloc %d to non-macho symbol %s type=%d", r.Type, rs.Name, rs.Type)
return -1 return -1
} }
...@@ -424,7 +424,7 @@ func machoreloc1(ctxt *ld.Link, r *ld.Reloc, sectoff int64) int { ...@@ -424,7 +424,7 @@ func machoreloc1(ctxt *ld.Link, r *ld.Reloc, sectoff int64) int {
} else { } else {
v = uint32(rs.Sect.Extnum) v = uint32(rs.Sect.Extnum)
if v == 0 { if v == 0 {
ctxt.Diag("reloc %d to symbol %s in non-macho section %s type=%d", r.Type, rs.Name, rs.Sect.Name, rs.Type) ld.Errorf(s, "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
} }
} }
...@@ -464,13 +464,13 @@ func machoreloc1(ctxt *ld.Link, r *ld.Reloc, sectoff int64) int { ...@@ -464,13 +464,13 @@ func machoreloc1(ctxt *ld.Link, r *ld.Reloc, sectoff int64) int {
return 0 return 0
} }
func pereloc1(ctxt *ld.Link, r *ld.Reloc, sectoff int64) bool { func pereloc1(s *ld.Symbol, r *ld.Reloc, sectoff int64) bool {
var v uint32 var v uint32
rs := r.Xsym rs := r.Xsym
if rs.Dynid < 0 { if rs.Dynid < 0 {
ctxt.Diag("reloc %d to non-coff symbol %s type=%d", r.Type, rs.Name, rs.Type) ld.Errorf(s, "reloc %d to non-coff symbol %s type=%d", r.Type, rs.Name, rs.Type)
return false return false
} }
...@@ -504,7 +504,7 @@ func archreloc(ctxt *ld.Link, r *ld.Reloc, s *ld.Symbol, val *int64) int { ...@@ -504,7 +504,7 @@ func archreloc(ctxt *ld.Link, 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(ctxt, ".got", 0)) *val = ld.Symaddr(r.Sym) + r.Add - ld.Symaddr(ld.Linklookup(ctxt, ".got", 0))
return 0 return 0
} }
...@@ -599,7 +599,7 @@ func addpltsym(ctxt *ld.Link, s *ld.Symbol) { ...@@ -599,7 +599,7 @@ func addpltsym(ctxt *ld.Link, s *ld.Symbol) {
ld.Adduint8(ctxt, plt, 0x25) ld.Adduint8(ctxt, plt, 0x25)
ld.Addaddrplus(ctxt, plt, ld.Linklookup(ctxt, ".got", 0), int64(s.Got)) ld.Addaddrplus(ctxt, plt, ld.Linklookup(ctxt, ".got", 0), int64(s.Got))
} else { } else {
ctxt.Diag("addpltsym: unsupported binary format") ld.Errorf(s, "addpltsym: unsupported binary format")
} }
} }
...@@ -620,7 +620,7 @@ func addgotsym(ctxt *ld.Link, s *ld.Symbol) { ...@@ -620,7 +620,7 @@ func addgotsym(ctxt *ld.Link, s *ld.Symbol) {
} else if ld.Headtype == obj.Hdarwin { } else if ld.Headtype == obj.Hdarwin {
ld.Adduint32(ctxt, ld.Linklookup(ctxt, ".linkedit.got", 0), uint32(s.Dynid)) ld.Adduint32(ctxt, ld.Linklookup(ctxt, ".linkedit.got", 0), uint32(s.Dynid))
} else { } else {
ctxt.Diag("addgotsym: unsupported binary format") ld.Errorf(s, "addgotsym: unsupported binary format")
} }
} }
......
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