Commit 0c4d035c authored by Hiroshi Ioka's avatar Hiroshi Ioka Committed by Ian Lance Taylor

cmd/link: refactor *reloc

* use bool instead of int if it's adequate.
* remove blank lines.

Change-Id: Ic4a5644a33ed9fc7ce388ef8ba15f1732446fcfc
Reviewed-on: https://go-review.googlesource.com/59375
Run-TryBot: Ian Lance Taylor <iant@golang.org>
TryBot-Result: Gobot Gobot <gobot@golang.org>
Reviewed-by: default avatarIan Lance Taylor <iant@golang.org>
parent 53c8be4a
...@@ -369,37 +369,33 @@ func adddynrel(ctxt *ld.Link, s *ld.Symbol, r *ld.Reloc) bool { ...@@ -369,37 +369,33 @@ func adddynrel(ctxt *ld.Link, s *ld.Symbol, r *ld.Reloc) bool {
return false return false
} }
func elfreloc1(ctxt *ld.Link, r *ld.Reloc, sectoff int64) int { func elfreloc1(ctxt *ld.Link, r *ld.Reloc, sectoff int64) bool {
ld.Thearch.Vput(uint64(sectoff)) ld.Thearch.Vput(uint64(sectoff))
elfsym := r.Xsym.ElfsymForReloc() elfsym := r.Xsym.ElfsymForReloc()
switch r.Type { switch r.Type {
default: default:
return -1 return false
case objabi.R_ADDR: case objabi.R_ADDR:
if r.Siz == 4 { if r.Siz == 4 {
ld.Thearch.Vput(ld.R_X86_64_32 | uint64(elfsym)<<32) ld.Thearch.Vput(ld.R_X86_64_32 | uint64(elfsym)<<32)
} else if r.Siz == 8 { } else if r.Siz == 8 {
ld.Thearch.Vput(ld.R_X86_64_64 | uint64(elfsym)<<32) ld.Thearch.Vput(ld.R_X86_64_64 | uint64(elfsym)<<32)
} else { } else {
return -1 return false
} }
case objabi.R_TLS_LE: case objabi.R_TLS_LE:
if r.Siz == 4 { if r.Siz == 4 {
ld.Thearch.Vput(ld.R_X86_64_TPOFF32 | uint64(elfsym)<<32) ld.Thearch.Vput(ld.R_X86_64_TPOFF32 | uint64(elfsym)<<32)
} else { } else {
return -1 return false
} }
case objabi.R_TLS_IE: case objabi.R_TLS_IE:
if r.Siz == 4 { if r.Siz == 4 {
ld.Thearch.Vput(ld.R_X86_64_GOTTPOFF | uint64(elfsym)<<32) ld.Thearch.Vput(ld.R_X86_64_GOTTPOFF | uint64(elfsym)<<32)
} else { } else {
return -1 return false
} }
case objabi.R_CALL: case objabi.R_CALL:
if r.Siz == 4 { if r.Siz == 4 {
if r.Xsym.Type == ld.SDYNIMPORT { if r.Xsym.Type == ld.SDYNIMPORT {
...@@ -412,9 +408,8 @@ func elfreloc1(ctxt *ld.Link, r *ld.Reloc, sectoff int64) int { ...@@ -412,9 +408,8 @@ func elfreloc1(ctxt *ld.Link, r *ld.Reloc, sectoff int64) int {
ld.Thearch.Vput(ld.R_X86_64_PC32 | uint64(elfsym)<<32) ld.Thearch.Vput(ld.R_X86_64_PC32 | uint64(elfsym)<<32)
} }
} else { } else {
return -1 return false
} }
case objabi.R_PCREL: case objabi.R_PCREL:
if r.Siz == 4 { if r.Siz == 4 {
if r.Xsym.Type == ld.SDYNIMPORT && r.Xsym.ElfType == elf.STT_FUNC { if r.Xsym.Type == ld.SDYNIMPORT && r.Xsym.ElfType == elf.STT_FUNC {
...@@ -423,22 +418,21 @@ func elfreloc1(ctxt *ld.Link, r *ld.Reloc, sectoff int64) int { ...@@ -423,22 +418,21 @@ func elfreloc1(ctxt *ld.Link, r *ld.Reloc, sectoff int64) int {
ld.Thearch.Vput(ld.R_X86_64_PC32 | uint64(elfsym)<<32) ld.Thearch.Vput(ld.R_X86_64_PC32 | uint64(elfsym)<<32)
} }
} else { } else {
return -1 return false
} }
case objabi.R_GOTPCREL: case objabi.R_GOTPCREL:
if r.Siz == 4 { if r.Siz == 4 {
ld.Thearch.Vput(ld.R_X86_64_GOTPCREL | uint64(elfsym)<<32) ld.Thearch.Vput(ld.R_X86_64_GOTPCREL | uint64(elfsym)<<32)
} else { } else {
return -1 return false
} }
} }
ld.Thearch.Vput(uint64(r.Xadd)) ld.Thearch.Vput(uint64(r.Xadd))
return 0 return true
} }
func machoreloc1(s *ld.Symbol, r *ld.Reloc, sectoff int64) int { func machoreloc1(s *ld.Symbol, r *ld.Reloc, sectoff int64) bool {
var v uint32 var v uint32
rs := r.Xsym rs := r.Xsym
...@@ -446,7 +440,7 @@ func machoreloc1(s *ld.Symbol, r *ld.Reloc, sectoff int64) int { ...@@ -446,7 +440,7 @@ func machoreloc1(s *ld.Symbol, r *ld.Reloc, sectoff int64) int {
if rs.Type == ld.SHOSTOBJ || r.Type == objabi.R_PCREL || r.Type == objabi.R_GOTPCREL { if rs.Type == ld.SHOSTOBJ || r.Type == objabi.R_PCREL || r.Type == objabi.R_GOTPCREL {
if rs.Dynid < 0 { if rs.Dynid < 0 {
ld.Errorf(s, "reloc %d (%s) to non-macho symbol %s type=%d (%s)", r.Type, ld.RelocName(r.Type), rs.Name, rs.Type, rs.Type) ld.Errorf(s, "reloc %d (%s) to non-macho symbol %s type=%d (%s)", r.Type, ld.RelocName(r.Type), rs.Name, rs.Type, rs.Type)
return -1 return false
} }
v = uint32(rs.Dynid) v = uint32(rs.Dynid)
...@@ -455,13 +449,13 @@ func machoreloc1(s *ld.Symbol, r *ld.Reloc, sectoff int64) int { ...@@ -455,13 +449,13 @@ func machoreloc1(s *ld.Symbol, r *ld.Reloc, sectoff int64) int {
v = uint32(rs.Sect.Extnum) v = uint32(rs.Sect.Extnum)
if v == 0 { if v == 0 {
ld.Errorf(s, "reloc %d (%s) to symbol %s in non-macho section %s type=%d (%s)", r.Type, ld.RelocName(r.Type), rs.Name, rs.Sect.Name, rs.Type, rs.Type) ld.Errorf(s, "reloc %d (%s) to symbol %s in non-macho section %s type=%d (%s)", r.Type, ld.RelocName(r.Type), rs.Name, rs.Sect.Name, rs.Type, rs.Type)
return -1 return false
} }
} }
switch r.Type { switch r.Type {
default: default:
return -1 return false
case objabi.R_ADDR: case objabi.R_ADDR:
v |= ld.MACHO_X86_64_RELOC_UNSIGNED << 28 v |= ld.MACHO_X86_64_RELOC_UNSIGNED << 28
...@@ -481,7 +475,7 @@ func machoreloc1(s *ld.Symbol, r *ld.Reloc, sectoff int64) int { ...@@ -481,7 +475,7 @@ func machoreloc1(s *ld.Symbol, r *ld.Reloc, sectoff int64) int {
switch r.Siz { switch r.Siz {
default: default:
return -1 return false
case 1: case 1:
v |= 0 << 25 v |= 0 << 25
...@@ -498,7 +492,7 @@ func machoreloc1(s *ld.Symbol, r *ld.Reloc, sectoff int64) int { ...@@ -498,7 +492,7 @@ func machoreloc1(s *ld.Symbol, r *ld.Reloc, sectoff int64) int {
ld.Thearch.Lput(uint32(sectoff)) ld.Thearch.Lput(uint32(sectoff))
ld.Thearch.Lput(v) ld.Thearch.Lput(v)
return 0 return true
} }
func pereloc1(s *ld.Symbol, r *ld.Reloc, sectoff int64) bool { func pereloc1(s *ld.Symbol, r *ld.Reloc, sectoff int64) bool {
...@@ -538,8 +532,8 @@ func pereloc1(s *ld.Symbol, r *ld.Reloc, sectoff int64) bool { ...@@ -538,8 +532,8 @@ func pereloc1(s *ld.Symbol, r *ld.Reloc, sectoff int64) bool {
return true return true
} }
func archreloc(ctxt *ld.Link, r *ld.Reloc, s *ld.Symbol, val *int64) int { func archreloc(ctxt *ld.Link, r *ld.Reloc, s *ld.Symbol, val *int64) bool {
return -1 return false
} }
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 {
......
...@@ -249,28 +249,25 @@ func adddynrel(ctxt *ld.Link, s *ld.Symbol, r *ld.Reloc) bool { ...@@ -249,28 +249,25 @@ func adddynrel(ctxt *ld.Link, s *ld.Symbol, r *ld.Reloc) bool {
return false return false
} }
func elfreloc1(ctxt *ld.Link, r *ld.Reloc, sectoff int64) int { func elfreloc1(ctxt *ld.Link, r *ld.Reloc, sectoff int64) bool {
ld.Thearch.Lput(uint32(sectoff)) ld.Thearch.Lput(uint32(sectoff))
elfsym := r.Xsym.ElfsymForReloc() elfsym := r.Xsym.ElfsymForReloc()
switch r.Type { switch r.Type {
default: default:
return -1 return false
case objabi.R_ADDR: case objabi.R_ADDR:
if r.Siz == 4 { if r.Siz == 4 {
ld.Thearch.Lput(ld.R_ARM_ABS32 | uint32(elfsym)<<8) ld.Thearch.Lput(ld.R_ARM_ABS32 | uint32(elfsym)<<8)
} else { } else {
return -1 return false
} }
case objabi.R_PCREL: case objabi.R_PCREL:
if r.Siz == 4 { if r.Siz == 4 {
ld.Thearch.Lput(ld.R_ARM_REL32 | uint32(elfsym)<<8) ld.Thearch.Lput(ld.R_ARM_REL32 | uint32(elfsym)<<8)
} else { } else {
return -1 return false
} }
case objabi.R_CALLARM: case objabi.R_CALLARM:
if r.Siz == 4 { if r.Siz == 4 {
if r.Add&0xff000000 == 0xeb000000 { // BL if r.Add&0xff000000 == 0xeb000000 { // BL
...@@ -279,24 +276,21 @@ func elfreloc1(ctxt *ld.Link, r *ld.Reloc, sectoff int64) int { ...@@ -279,24 +276,21 @@ func elfreloc1(ctxt *ld.Link, r *ld.Reloc, sectoff int64) int {
ld.Thearch.Lput(ld.R_ARM_JUMP24 | uint32(elfsym)<<8) ld.Thearch.Lput(ld.R_ARM_JUMP24 | uint32(elfsym)<<8)
} }
} else { } else {
return -1 return false
} }
case objabi.R_TLS_LE: case objabi.R_TLS_LE:
ld.Thearch.Lput(ld.R_ARM_TLS_LE32 | uint32(elfsym)<<8) ld.Thearch.Lput(ld.R_ARM_TLS_LE32 | uint32(elfsym)<<8)
case objabi.R_TLS_IE: case objabi.R_TLS_IE:
ld.Thearch.Lput(ld.R_ARM_TLS_IE32 | uint32(elfsym)<<8) ld.Thearch.Lput(ld.R_ARM_TLS_IE32 | uint32(elfsym)<<8)
case objabi.R_GOTPCREL: case objabi.R_GOTPCREL:
if r.Siz == 4 { if r.Siz == 4 {
ld.Thearch.Lput(ld.R_ARM_GOT_PREL | uint32(elfsym)<<8) ld.Thearch.Lput(ld.R_ARM_GOT_PREL | uint32(elfsym)<<8)
} else { } else {
return -1 return false
} }
} }
return 0 return true
} }
func elfsetupplt(ctxt *ld.Link) { func elfsetupplt(ctxt *ld.Link) {
...@@ -326,7 +320,7 @@ func elfsetupplt(ctxt *ld.Link) { ...@@ -326,7 +320,7 @@ func elfsetupplt(ctxt *ld.Link) {
} }
} }
func machoreloc1(s *ld.Symbol, r *ld.Reloc, sectoff int64) int { func machoreloc1(s *ld.Symbol, r *ld.Reloc, sectoff int64) bool {
var v uint32 var v uint32
rs := r.Xsym rs := r.Xsym
...@@ -334,10 +328,10 @@ func machoreloc1(s *ld.Symbol, r *ld.Reloc, sectoff int64) int { ...@@ -334,10 +328,10 @@ func machoreloc1(s *ld.Symbol, r *ld.Reloc, sectoff int64) int {
if r.Type == objabi.R_PCREL { if r.Type == objabi.R_PCREL {
if rs.Type == ld.SHOSTOBJ { if rs.Type == ld.SHOSTOBJ {
ld.Errorf(s, "pc-relative relocation of external symbol is not supported") ld.Errorf(s, "pc-relative relocation of external symbol is not supported")
return -1 return false
} }
if r.Siz != 4 { if r.Siz != 4 {
return -1 return false
} }
// emit a pair of "scattered" relocations that // emit a pair of "scattered" relocations that
...@@ -358,13 +352,13 @@ func machoreloc1(s *ld.Symbol, r *ld.Reloc, sectoff int64) int { ...@@ -358,13 +352,13 @@ func machoreloc1(s *ld.Symbol, r *ld.Reloc, sectoff int64) int {
ld.Thearch.Lput(uint32(ld.Symaddr(rs))) ld.Thearch.Lput(uint32(ld.Symaddr(rs)))
ld.Thearch.Lput(o2) ld.Thearch.Lput(o2)
ld.Thearch.Lput(uint32(s.Value + int64(r.Off))) ld.Thearch.Lput(uint32(s.Value + int64(r.Off)))
return 0 return true
} }
if rs.Type == ld.SHOSTOBJ || r.Type == objabi.R_CALLARM { if rs.Type == ld.SHOSTOBJ || r.Type == objabi.R_CALLARM {
if rs.Dynid < 0 { if rs.Dynid < 0 {
ld.Errorf(s, "reloc %d (%s) to non-macho symbol %s type=%d (%s)", r.Type, ld.RelocName(r.Type), rs.Name, rs.Type, rs.Type) ld.Errorf(s, "reloc %d (%s) to non-macho symbol %s type=%d (%s)", r.Type, ld.RelocName(r.Type), rs.Name, rs.Type, rs.Type)
return -1 return false
} }
v = uint32(rs.Dynid) v = uint32(rs.Dynid)
...@@ -373,13 +367,13 @@ func machoreloc1(s *ld.Symbol, r *ld.Reloc, sectoff int64) int { ...@@ -373,13 +367,13 @@ func machoreloc1(s *ld.Symbol, r *ld.Reloc, sectoff int64) int {
v = uint32(rs.Sect.Extnum) v = uint32(rs.Sect.Extnum)
if v == 0 { if v == 0 {
ld.Errorf(s, "reloc %d (%s) to symbol %s in non-macho section %s type=%d (%s)", r.Type, ld.RelocName(r.Type), rs.Name, rs.Sect.Name, rs.Type, rs.Type) ld.Errorf(s, "reloc %d (%s) to symbol %s in non-macho section %s type=%d (%s)", r.Type, ld.RelocName(r.Type), rs.Name, rs.Sect.Name, rs.Type, rs.Type)
return -1 return false
} }
} }
switch r.Type { switch r.Type {
default: default:
return -1 return false
case objabi.R_ADDR: case objabi.R_ADDR:
v |= ld.MACHO_GENERIC_RELOC_VANILLA << 28 v |= ld.MACHO_GENERIC_RELOC_VANILLA << 28
...@@ -391,8 +385,7 @@ func machoreloc1(s *ld.Symbol, r *ld.Reloc, sectoff int64) int { ...@@ -391,8 +385,7 @@ func machoreloc1(s *ld.Symbol, r *ld.Reloc, sectoff int64) int {
switch r.Siz { switch r.Siz {
default: default:
return -1 return false
case 1: case 1:
v |= 0 << 25 v |= 0 << 25
...@@ -408,7 +401,7 @@ func machoreloc1(s *ld.Symbol, r *ld.Reloc, sectoff int64) int { ...@@ -408,7 +401,7 @@ func machoreloc1(s *ld.Symbol, r *ld.Reloc, sectoff int64) int {
ld.Thearch.Lput(uint32(sectoff)) ld.Thearch.Lput(uint32(sectoff))
ld.Thearch.Lput(v) ld.Thearch.Lput(v)
return 0 return true
} }
// sign extend a 24-bit integer // sign extend a 24-bit integer
...@@ -478,7 +471,7 @@ func trampoline(ctxt *ld.Link, r *ld.Reloc, s *ld.Symbol) { ...@@ -478,7 +471,7 @@ func trampoline(ctxt *ld.Link, r *ld.Reloc, s *ld.Symbol) {
// modify reloc to point to tramp, which will be resolved later // modify reloc to point to tramp, which will be resolved later
r.Sym = tramp r.Sym = tramp
r.Add = r.Add&0xff000000 | 0xfffffe // clear the offset embedded in the instruction r.Add = r.Add&0xff000000 | 0xfffffe // clear the offset embedded in the instruction
r.Done = 0 r.Done = false
} }
default: default:
ld.Errorf(s, "trampoline called with non-jump reloc: %d (%s)", r.Type, ld.RelocName(r.Type)) ld.Errorf(s, "trampoline called with non-jump reloc: %d (%s)", r.Type, ld.RelocName(r.Type))
...@@ -568,11 +561,11 @@ func gentrampdyn(tramp, target *ld.Symbol, offset int64) { ...@@ -568,11 +561,11 @@ func gentrampdyn(tramp, target *ld.Symbol, offset int64) {
} }
} }
func archreloc(ctxt *ld.Link, r *ld.Reloc, s *ld.Symbol, val *int64) int { func archreloc(ctxt *ld.Link, r *ld.Reloc, s *ld.Symbol, val *int64) bool {
if ld.Linkmode == ld.LinkExternal { if ld.Linkmode == ld.LinkExternal {
switch r.Type { switch r.Type {
case objabi.R_CALLARM: case objabi.R_CALLARM:
r.Done = 0 r.Done = false
// set up addend for eventual relocation via outer symbol. // set up addend for eventual relocation via outer symbol.
rs := r.Sym rs := r.Sym
...@@ -603,20 +596,19 @@ func archreloc(ctxt *ld.Link, r *ld.Reloc, s *ld.Symbol, val *int64) int { ...@@ -603,20 +596,19 @@ func archreloc(ctxt *ld.Link, r *ld.Reloc, s *ld.Symbol, val *int64) int {
} }
*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))))
return 0 return true
} }
return -1 return false
} }
switch r.Type { switch r.Type {
case objabi.R_CONST: case objabi.R_CONST:
*val = r.Add *val = r.Add
return 0 return true
case objabi.R_GOTOFF: case objabi.R_GOTOFF:
*val = ld.Symaddr(r.Sym) + r.Add - ld.Symaddr(ctxt.Syms.Lookup(".got", 0)) *val = ld.Symaddr(r.Sym) + r.Add - ld.Symaddr(ctxt.Syms.Lookup(".got", 0))
return 0 return true
// 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)
...@@ -625,18 +617,15 @@ func archreloc(ctxt *ld.Link, r *ld.Reloc, s *ld.Symbol, val *int64) int { ...@@ -625,18 +617,15 @@ func archreloc(ctxt *ld.Link, r *ld.Reloc, s *ld.Symbol, val *int64) int {
ld.Errorf(s, ".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(r.Sym)-(ld.Symaddr(ctxt.Syms.Lookup(".plt", 0))+int64(r.Off))+r.Add)) >> 20)) *val = 0xe28fc600 + (0xff & (int64(uint32(ld.Symaddr(r.Sym)-(ld.Symaddr(ctxt.Syms.Lookup(".plt", 0))+int64(r.Off))+r.Add)) >> 20))
return 0 return true
case objabi.R_PLT1: // add ip, ip, #0xYY000 case objabi.R_PLT1: // add ip, ip, #0xYY000
*val = 0xe28cca00 + (0xff & (int64(uint32(ld.Symaddr(r.Sym)-(ld.Symaddr(ctxt.Syms.Lookup(".plt", 0))+int64(r.Off))+r.Add+4)) >> 12)) *val = 0xe28cca00 + (0xff & (int64(uint32(ld.Symaddr(r.Sym)-(ld.Symaddr(ctxt.Syms.Lookup(".plt", 0))+int64(r.Off))+r.Add+4)) >> 12))
return 0 return true
case objabi.R_PLT2: // ldr pc, [ip, #0xZZZ]! case objabi.R_PLT2: // ldr pc, [ip, #0xZZZ]!
*val = 0xe5bcf000 + (0xfff & int64(uint32(ld.Symaddr(r.Sym)-(ld.Symaddr(ctxt.Syms.Lookup(".plt", 0))+int64(r.Off))+r.Add+8))) *val = 0xe5bcf000 + (0xfff & int64(uint32(ld.Symaddr(r.Sym)-(ld.Symaddr(ctxt.Syms.Lookup(".plt", 0))+int64(r.Off))+r.Add+8)))
return 0 return true
case objabi.R_CALLARM: // bl XXXXXX or b YYYYYY case objabi.R_CALLARM: // bl XXXXXX or b YYYYYY
// r.Add is the instruction // r.Add is the instruction
// low 24-bit encodes the target address // low 24-bit encodes the target address
...@@ -646,10 +635,10 @@ func archreloc(ctxt *ld.Link, r *ld.Reloc, s *ld.Symbol, val *int64) int { ...@@ -646,10 +635,10 @@ func archreloc(ctxt *ld.Link, r *ld.Reloc, s *ld.Symbol, val *int64) int {
} }
*val = int64(braddoff(int32(0xff000000&uint32(r.Add)), int32(0xffffff&t))) *val = int64(braddoff(int32(0xff000000&uint32(r.Add)), int32(0xffffff&t)))
return 0 return true
} }
return -1 return false
} }
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 {
......
...@@ -91,14 +91,13 @@ func adddynrel(ctxt *ld.Link, s *ld.Symbol, r *ld.Reloc) bool { ...@@ -91,14 +91,13 @@ func adddynrel(ctxt *ld.Link, s *ld.Symbol, r *ld.Reloc) bool {
return false return false
} }
func elfreloc1(ctxt *ld.Link, r *ld.Reloc, sectoff int64) int { func elfreloc1(ctxt *ld.Link, r *ld.Reloc, sectoff int64) bool {
ld.Thearch.Vput(uint64(sectoff)) ld.Thearch.Vput(uint64(sectoff))
elfsym := r.Xsym.ElfsymForReloc() elfsym := r.Xsym.ElfsymForReloc()
switch r.Type { switch r.Type {
default: default:
return -1 return false
case objabi.R_ADDR: case objabi.R_ADDR:
switch r.Siz { switch r.Siz {
case 4: case 4:
...@@ -106,41 +105,36 @@ func elfreloc1(ctxt *ld.Link, r *ld.Reloc, sectoff int64) int { ...@@ -106,41 +105,36 @@ func elfreloc1(ctxt *ld.Link, r *ld.Reloc, sectoff int64) int {
case 8: case 8:
ld.Thearch.Vput(ld.R_AARCH64_ABS64 | uint64(elfsym)<<32) ld.Thearch.Vput(ld.R_AARCH64_ABS64 | uint64(elfsym)<<32)
default: default:
return -1 return false
} }
case objabi.R_ADDRARM64: case objabi.R_ADDRARM64:
// two relocations: R_AARCH64_ADR_PREL_PG_HI21 and R_AARCH64_ADD_ABS_LO12_NC // two relocations: R_AARCH64_ADR_PREL_PG_HI21 and R_AARCH64_ADD_ABS_LO12_NC
ld.Thearch.Vput(ld.R_AARCH64_ADR_PREL_PG_HI21 | uint64(elfsym)<<32) ld.Thearch.Vput(ld.R_AARCH64_ADR_PREL_PG_HI21 | uint64(elfsym)<<32)
ld.Thearch.Vput(uint64(r.Xadd)) ld.Thearch.Vput(uint64(r.Xadd))
ld.Thearch.Vput(uint64(sectoff + 4)) ld.Thearch.Vput(uint64(sectoff + 4))
ld.Thearch.Vput(ld.R_AARCH64_ADD_ABS_LO12_NC | uint64(elfsym)<<32) ld.Thearch.Vput(ld.R_AARCH64_ADD_ABS_LO12_NC | uint64(elfsym)<<32)
case objabi.R_ARM64_TLS_LE: case objabi.R_ARM64_TLS_LE:
ld.Thearch.Vput(ld.R_AARCH64_TLSLE_MOVW_TPREL_G0 | uint64(elfsym)<<32) ld.Thearch.Vput(ld.R_AARCH64_TLSLE_MOVW_TPREL_G0 | uint64(elfsym)<<32)
case objabi.R_ARM64_TLS_IE: case objabi.R_ARM64_TLS_IE:
ld.Thearch.Vput(ld.R_AARCH64_TLSIE_ADR_GOTTPREL_PAGE21 | uint64(elfsym)<<32) ld.Thearch.Vput(ld.R_AARCH64_TLSIE_ADR_GOTTPREL_PAGE21 | uint64(elfsym)<<32)
ld.Thearch.Vput(uint64(r.Xadd)) ld.Thearch.Vput(uint64(r.Xadd))
ld.Thearch.Vput(uint64(sectoff + 4)) ld.Thearch.Vput(uint64(sectoff + 4))
ld.Thearch.Vput(ld.R_AARCH64_TLSIE_LD64_GOTTPREL_LO12_NC | uint64(elfsym)<<32) ld.Thearch.Vput(ld.R_AARCH64_TLSIE_LD64_GOTTPREL_LO12_NC | uint64(elfsym)<<32)
case objabi.R_ARM64_GOTPCREL: case objabi.R_ARM64_GOTPCREL:
ld.Thearch.Vput(ld.R_AARCH64_ADR_GOT_PAGE | uint64(elfsym)<<32) ld.Thearch.Vput(ld.R_AARCH64_ADR_GOT_PAGE | uint64(elfsym)<<32)
ld.Thearch.Vput(uint64(r.Xadd)) ld.Thearch.Vput(uint64(r.Xadd))
ld.Thearch.Vput(uint64(sectoff + 4)) ld.Thearch.Vput(uint64(sectoff + 4))
ld.Thearch.Vput(ld.R_AARCH64_LD64_GOT_LO12_NC | uint64(elfsym)<<32) ld.Thearch.Vput(ld.R_AARCH64_LD64_GOT_LO12_NC | uint64(elfsym)<<32)
case objabi.R_CALLARM64: case objabi.R_CALLARM64:
if r.Siz != 4 { if r.Siz != 4 {
return -1 return false
} }
ld.Thearch.Vput(ld.R_AARCH64_CALL26 | uint64(elfsym)<<32) ld.Thearch.Vput(ld.R_AARCH64_CALL26 | uint64(elfsym)<<32)
} }
ld.Thearch.Vput(uint64(r.Xadd)) ld.Thearch.Vput(uint64(r.Xadd))
return 0 return true
} }
func elfsetupplt(ctxt *ld.Link) { func elfsetupplt(ctxt *ld.Link) {
...@@ -148,7 +142,7 @@ func elfsetupplt(ctxt *ld.Link) { ...@@ -148,7 +142,7 @@ func elfsetupplt(ctxt *ld.Link) {
return return
} }
func machoreloc1(s *ld.Symbol, r *ld.Reloc, sectoff int64) int { func machoreloc1(s *ld.Symbol, r *ld.Reloc, sectoff int64) bool {
var v uint32 var v uint32
rs := r.Xsym rs := r.Xsym
...@@ -159,7 +153,7 @@ func machoreloc1(s *ld.Symbol, r *ld.Reloc, sectoff int64) int { ...@@ -159,7 +153,7 @@ func machoreloc1(s *ld.Symbol, r *ld.Reloc, sectoff int64) int {
if rs.Type == ld.SHOSTOBJ || r.Type == objabi.R_CALLARM64 || r.Type == objabi.R_ADDRARM64 || r.Type == objabi.R_ADDR { if rs.Type == ld.SHOSTOBJ || r.Type == objabi.R_CALLARM64 || r.Type == objabi.R_ADDRARM64 || r.Type == objabi.R_ADDR {
if rs.Dynid < 0 { if rs.Dynid < 0 {
ld.Errorf(s, "reloc %d (%s) to non-macho symbol %s type=%d (%s)", r.Type, ld.RelocName(r.Type), rs.Name, rs.Type, rs.Type) ld.Errorf(s, "reloc %d (%s) to non-macho symbol %s type=%d (%s)", r.Type, ld.RelocName(r.Type), rs.Name, rs.Type, rs.Type)
return -1 return false
} }
v = uint32(rs.Dynid) v = uint32(rs.Dynid)
...@@ -168,17 +162,15 @@ func machoreloc1(s *ld.Symbol, r *ld.Reloc, sectoff int64) int { ...@@ -168,17 +162,15 @@ func machoreloc1(s *ld.Symbol, r *ld.Reloc, sectoff int64) int {
v = uint32(rs.Sect.Extnum) v = uint32(rs.Sect.Extnum)
if v == 0 { if v == 0 {
ld.Errorf(s, "reloc %d (%s) to symbol %s in non-macho section %s type=%d (%s)", r.Type, ld.RelocName(r.Type), rs.Name, rs.Sect.Name, rs.Type, rs.Type) ld.Errorf(s, "reloc %d (%s) to symbol %s in non-macho section %s type=%d (%s)", r.Type, ld.RelocName(r.Type), rs.Name, rs.Sect.Name, rs.Type, rs.Type)
return -1 return false
} }
} }
switch r.Type { switch r.Type {
default: default:
return -1 return false
case objabi.R_ADDR: case objabi.R_ADDR:
v |= ld.MACHO_ARM64_RELOC_UNSIGNED << 28 v |= ld.MACHO_ARM64_RELOC_UNSIGNED << 28
case objabi.R_CALLARM64: case objabi.R_CALLARM64:
if r.Xadd != 0 { if r.Xadd != 0 {
ld.Errorf(s, "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)
...@@ -186,7 +178,6 @@ func machoreloc1(s *ld.Symbol, r *ld.Reloc, sectoff int64) int { ...@@ -186,7 +178,6 @@ func machoreloc1(s *ld.Symbol, r *ld.Reloc, sectoff int64) int {
v |= 1 << 24 // pc-relative bit v |= 1 << 24 // pc-relative bit
v |= ld.MACHO_ARM64_RELOC_BRANCH26 << 28 v |= ld.MACHO_ARM64_RELOC_BRANCH26 << 28
case objabi.R_ADDRARM64: case objabi.R_ADDRARM64:
r.Siz = 4 r.Siz = 4
// Two relocation entries: MACHO_ARM64_RELOC_PAGEOFF12 MACHO_ARM64_RELOC_PAGE21 // Two relocation entries: MACHO_ARM64_RELOC_PAGEOFF12 MACHO_ARM64_RELOC_PAGE21
...@@ -207,32 +198,27 @@ func machoreloc1(s *ld.Symbol, r *ld.Reloc, sectoff int64) int { ...@@ -207,32 +198,27 @@ func machoreloc1(s *ld.Symbol, r *ld.Reloc, sectoff int64) int {
switch r.Siz { switch r.Siz {
default: default:
return -1 return false
case 1: case 1:
v |= 0 << 25 v |= 0 << 25
case 2: case 2:
v |= 1 << 25 v |= 1 << 25
case 4: case 4:
v |= 2 << 25 v |= 2 << 25
case 8: case 8:
v |= 3 << 25 v |= 3 << 25
} }
ld.Thearch.Lput(uint32(sectoff)) ld.Thearch.Lput(uint32(sectoff))
ld.Thearch.Lput(v) ld.Thearch.Lput(v)
return 0 return true
} }
func archreloc(ctxt *ld.Link, r *ld.Reloc, s *ld.Symbol, val *int64) int { func archreloc(ctxt *ld.Link, r *ld.Reloc, s *ld.Symbol, val *int64) bool {
if ld.Linkmode == ld.LinkExternal { if ld.Linkmode == ld.LinkExternal {
switch r.Type { switch r.Type {
default: default:
return -1 return false
case objabi.R_ARM64_GOTPCREL: case objabi.R_ARM64_GOTPCREL:
var o1, o2 uint32 var o1, o2 uint32
if ctxt.Arch.ByteOrder == binary.BigEndian { if ctxt.Arch.ByteOrder == binary.BigEndian {
...@@ -263,9 +249,8 @@ func archreloc(ctxt *ld.Link, r *ld.Reloc, s *ld.Symbol, val *int64) int { ...@@ -263,9 +249,8 @@ func archreloc(ctxt *ld.Link, r *ld.Reloc, s *ld.Symbol, val *int64) int {
*val = int64(o2)<<32 | int64(o1) *val = int64(o2)<<32 | int64(o1)
} }
fallthrough fallthrough
case objabi.R_ADDRARM64: case objabi.R_ADDRARM64:
r.Done = 0 r.Done = false
// set up addend for eventual relocation via outer symbol. // set up addend for eventual relocation via outer symbol.
rs := r.Sym rs := r.Sym
...@@ -312,27 +297,24 @@ func archreloc(ctxt *ld.Link, r *ld.Reloc, s *ld.Symbol, val *int64) int { ...@@ -312,27 +297,24 @@ func archreloc(ctxt *ld.Link, r *ld.Reloc, s *ld.Symbol, val *int64) int {
} }
} }
return 0 return true
case objabi.R_CALLARM64, case objabi.R_CALLARM64,
objabi.R_ARM64_TLS_LE, objabi.R_ARM64_TLS_LE,
objabi.R_ARM64_TLS_IE: objabi.R_ARM64_TLS_IE:
r.Done = 0 r.Done = false
r.Xsym = r.Sym r.Xsym = r.Sym
r.Xadd = r.Add r.Xadd = r.Add
return 0 return true
} }
} }
switch r.Type { switch r.Type {
case objabi.R_CONST: case objabi.R_CONST:
*val = r.Add *val = r.Add
return 0 return true
case objabi.R_GOTOFF: case objabi.R_GOTOFF:
*val = ld.Symaddr(r.Sym) + r.Add - ld.Symaddr(ctxt.Syms.Lookup(".got", 0)) *val = ld.Symaddr(r.Sym) + r.Add - ld.Symaddr(ctxt.Syms.Lookup(".got", 0))
return 0 return true
case objabi.R_ADDRARM64: case objabi.R_ADDRARM64:
t := ld.Symaddr(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 {
...@@ -358,10 +340,9 @@ func archreloc(ctxt *ld.Link, r *ld.Reloc, s *ld.Symbol, val *int64) int { ...@@ -358,10 +340,9 @@ func archreloc(ctxt *ld.Link, r *ld.Reloc, s *ld.Symbol, val *int64) int {
} else { } else {
*val = int64(o1)<<32 | int64(o0) *val = int64(o1)<<32 | int64(o0)
} }
return 0 return true
case objabi.R_ARM64_TLS_LE: case objabi.R_ARM64_TLS_LE:
r.Done = 0 r.Done = false
if ld.Headtype != objabi.Hlinux { if ld.Headtype != objabi.Hlinux {
ld.Errorf(s, "TLS reloc on unsupported OS %v", ld.Headtype) ld.Errorf(s, "TLS reloc on unsupported OS %v", ld.Headtype)
} }
...@@ -372,18 +353,17 @@ func archreloc(ctxt *ld.Link, r *ld.Reloc, s *ld.Symbol, val *int64) int { ...@@ -372,18 +353,17 @@ func archreloc(ctxt *ld.Link, r *ld.Reloc, s *ld.Symbol, val *int64) int {
ld.Errorf(s, "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 true
case objabi.R_CALLARM64: case objabi.R_CALLARM64:
t := (ld.Symaddr(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 {
ld.Errorf(s, "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 true
} }
return -1 return false
} }
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 {
......
...@@ -392,7 +392,7 @@ func relocsym(ctxt *Link, s *Symbol) { ...@@ -392,7 +392,7 @@ func relocsym(ctxt *Link, s *Symbol) {
for ri := int32(0); ri < int32(len(s.R)); ri++ { for ri := int32(0); ri < int32(len(s.R)); ri++ {
r = &s.R[ri] r = &s.R[ri]
r.Done = 1 r.Done = true
off = r.Off off = r.Off
siz = int32(r.Siz) siz = int32(r.Siz)
if off < 0 || off+siz > int32(len(s.P)) { if off < 0 || off+siz > int32(len(s.P)) {
...@@ -464,15 +464,14 @@ func relocsym(ctxt *Link, s *Symbol) { ...@@ -464,15 +464,14 @@ 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(ctxt, r, s, &o) < 0 { if !Thearch.Archreloc(ctxt, r, s, &o) {
Errorf(s, "unknown reloc to %v: %d (%s)", r.Sym.Name, r.Type, RelocName(r.Type)) Errorf(s, "unknown reloc to %v: %d (%s)", r.Sym.Name, r.Type, RelocName(r.Type))
} }
case objabi.R_TLS_LE: case objabi.R_TLS_LE:
isAndroidX86 := objabi.GOOS == "android" && (SysArch.InFamily(sys.AMD64, sys.I386)) isAndroidX86 := objabi.GOOS == "android" && (SysArch.InFamily(sys.AMD64, sys.I386))
if Linkmode == LinkExternal && Iself && !isAndroidX86 { if Linkmode == LinkExternal && Iself && !isAndroidX86 {
r.Done = 0 r.Done = false
if r.Sym == nil { if r.Sym == nil {
r.Sym = ctxt.Tlsg r.Sym = ctxt.Tlsg
} }
...@@ -501,12 +500,11 @@ func relocsym(ctxt *Link, s *Symbol) { ...@@ -501,12 +500,11 @@ func relocsym(ctxt *Link, s *Symbol) {
} else { } else {
log.Fatalf("unexpected R_TLS_LE relocation for %v", Headtype) log.Fatalf("unexpected R_TLS_LE relocation for %v", Headtype)
} }
case objabi.R_TLS_IE: case objabi.R_TLS_IE:
isAndroidX86 := objabi.GOOS == "android" && (SysArch.InFamily(sys.AMD64, sys.I386)) isAndroidX86 := objabi.GOOS == "android" && (SysArch.InFamily(sys.AMD64, sys.I386))
if Linkmode == LinkExternal && Iself && !isAndroidX86 { if Linkmode == LinkExternal && Iself && !isAndroidX86 {
r.Done = 0 r.Done = false
if r.Sym == nil { if r.Sym == nil {
r.Sym = ctxt.Tlsg r.Sym = ctxt.Tlsg
} }
...@@ -532,10 +530,9 @@ func relocsym(ctxt *Link, s *Symbol) { ...@@ -532,10 +530,9 @@ func relocsym(ctxt *Link, s *Symbol) {
} else { } else {
log.Fatalf("cannot handle R_TLS_IE (sym %s) when linking internally", s.Name) log.Fatalf("cannot handle R_TLS_IE (sym %s) when linking internally", s.Name)
} }
case objabi.R_ADDR: case objabi.R_ADDR:
if Linkmode == LinkExternal && r.Sym.Type != SCONST { if Linkmode == LinkExternal && r.Sym.Type != SCONST {
r.Done = 0 r.Done = false
// set up addend for eventual relocation via outer symbol. // set up addend for eventual relocation via outer symbol.
rs = r.Sym rs = r.Sym
...@@ -590,14 +587,13 @@ func relocsym(ctxt *Link, s *Symbol) { ...@@ -590,14 +587,13 @@ func relocsym(ctxt *Link, s *Symbol) {
Errorf(s, "non-pc-relative relocation address for %s is too big: %#x (%#x + %#x)", r.Sym.Name, uint64(o), Symaddr(r.Sym), r.Add) Errorf(s, "non-pc-relative relocation address for %s is too big: %#x (%#x + %#x)", r.Sym.Name, uint64(o), Symaddr(r.Sym), r.Add)
errorexit() errorexit()
} }
case objabi.R_DWARFREF: case objabi.R_DWARFREF:
if r.Sym.Sect == nil { if r.Sym.Sect == nil {
Errorf(s, "missing DWARF section for relocation target %s", r.Sym.Name) Errorf(s, "missing DWARF section for relocation target %s", r.Sym.Name)
} }
if Linkmode == LinkExternal { if Linkmode == LinkExternal {
r.Done = 0 r.Done = false
// PE code emits IMAGE_REL_I386_SECREL and IMAGE_REL_AMD64_SECREL // PE code emits IMAGE_REL_I386_SECREL and IMAGE_REL_AMD64_SECREL
// for R_DWARFREF relocations, while R_ADDR is replaced with // for R_DWARFREF relocations, while R_ADDR is replaced with
// IMAGE_REL_I386_DIR32, IMAGE_REL_AMD64_ADDR64 and IMAGE_REL_AMD64_ADDR32. // IMAGE_REL_I386_DIR32, IMAGE_REL_AMD64_ADDR64 and IMAGE_REL_AMD64_ADDR32.
...@@ -618,7 +614,6 @@ func relocsym(ctxt *Link, s *Symbol) { ...@@ -618,7 +614,6 @@ func relocsym(ctxt *Link, s *Symbol) {
break break
} }
o = Symaddr(r.Sym) + r.Add - int64(r.Sym.Sect.Vaddr) o = Symaddr(r.Sym) + r.Add - int64(r.Sym.Sect.Vaddr)
case objabi.R_WEAKADDROFF: case objabi.R_WEAKADDROFF:
if !r.Sym.Attr.Reachable() { if !r.Sym.Attr.Reachable() {
continue continue
...@@ -637,7 +632,7 @@ func relocsym(ctxt *Link, s *Symbol) { ...@@ -637,7 +632,7 @@ func relocsym(ctxt *Link, s *Symbol) {
// r->sym can be null when CALL $(constant) is transformed from absolute PC to relative PC call. // r->sym can be null when CALL $(constant) is transformed from absolute PC to relative PC call.
case objabi.R_GOTPCREL: case objabi.R_GOTPCREL:
if ctxt.DynlinkingGo() && Headtype == objabi.Hdarwin && r.Sym != nil && r.Sym.Type != SCONST { if ctxt.DynlinkingGo() && Headtype == objabi.Hdarwin && r.Sym != nil && r.Sym.Type != SCONST {
r.Done = 0 r.Done = false
r.Xadd = r.Add r.Xadd = r.Add
r.Xadd -= int64(r.Siz) // relative to address after the relocated chunk r.Xadd -= int64(r.Siz) // relative to address after the relocated chunk
r.Xsym = r.Sym r.Xsym = r.Sym
...@@ -649,7 +644,7 @@ func relocsym(ctxt *Link, s *Symbol) { ...@@ -649,7 +644,7 @@ func relocsym(ctxt *Link, s *Symbol) {
fallthrough fallthrough
case objabi.R_CALL, objabi.R_PCREL: case objabi.R_CALL, objabi.R_PCREL:
if Linkmode == LinkExternal && r.Sym != nil && r.Sym.Type != SCONST && (r.Sym.Sect != s.Sect || r.Type == objabi.R_GOTPCREL) { if Linkmode == LinkExternal && r.Sym != nil && r.Sym.Type != SCONST && (r.Sym.Sect != s.Sect || r.Type == objabi.R_GOTPCREL) {
r.Done = 0 r.Done = false
// set up addend for eventual relocation via outer symbol. // set up addend for eventual relocation via outer symbol.
rs = r.Sym rs = r.Sym
...@@ -700,7 +695,6 @@ func relocsym(ctxt *Link, s *Symbol) { ...@@ -700,7 +695,6 @@ func relocsym(ctxt *Link, s *Symbol) {
} }
o += r.Add - (s.Value + int64(r.Off) + int64(r.Siz)) o += r.Add - (s.Value + int64(r.Off) + int64(r.Siz))
case objabi.R_SIZE: case objabi.R_SIZE:
o = r.Sym.Size + r.Add o = r.Sym.Size + r.Add
} }
...@@ -724,14 +718,12 @@ func relocsym(ctxt *Link, s *Symbol) { ...@@ -724,14 +718,12 @@ func relocsym(ctxt *Link, s *Symbol) {
// TODO(rsc): Remove. // TODO(rsc): Remove.
case 1: case 1:
s.P[off] = byte(int8(o)) s.P[off] = byte(int8(o))
case 2: case 2:
if o != int64(int16(o)) { if o != int64(int16(o)) {
Errorf(s, "relocation address for %s is too big: %#x", r.Sym.Name, o) Errorf(s, "relocation address for %s is too big: %#x", r.Sym.Name, o)
} }
i16 = int16(o) i16 = int16(o)
ctxt.Arch.ByteOrder.PutUint16(s.P[off:], uint16(i16)) ctxt.Arch.ByteOrder.PutUint16(s.P[off:], uint16(i16))
case 4: case 4:
if r.Type == objabi.R_PCREL || r.Type == objabi.R_CALL { if r.Type == objabi.R_PCREL || r.Type == objabi.R_CALL {
if o != int64(int32(o)) { if o != int64(int32(o)) {
...@@ -745,7 +737,6 @@ func relocsym(ctxt *Link, s *Symbol) { ...@@ -745,7 +737,6 @@ func relocsym(ctxt *Link, s *Symbol) {
fl = int32(o) fl = int32(o)
ctxt.Arch.ByteOrder.PutUint32(s.P[off:], uint32(fl)) ctxt.Arch.ByteOrder.PutUint32(s.P[off:], uint32(fl))
case 8: case 8:
ctxt.Arch.ByteOrder.PutUint64(s.P[off:], uint64(o)) ctxt.Arch.ByteOrder.PutUint64(s.P[off:], uint64(o))
} }
......
...@@ -1804,7 +1804,7 @@ func elfrelocsect(ctxt *Link, sect *Section, syms []*Symbol) { ...@@ -1804,7 +1804,7 @@ func elfrelocsect(ctxt *Link, sect *Section, syms []*Symbol) {
} }
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 {
continue continue
} }
if r.Xsym == nil { if r.Xsym == nil {
...@@ -1817,7 +1817,7 @@ func elfrelocsect(ctxt *Link, sect *Section, syms []*Symbol) { ...@@ -1817,7 +1817,7 @@ func elfrelocsect(ctxt *Link, sect *Section, syms []*Symbol) {
if !r.Xsym.Attr.Reachable() { if !r.Xsym.Attr.Reachable() {
Errorf(sym, "unreachable reloc %d (%s) target %v", r.Type, RelocName(r.Type), r.Xsym.Name) Errorf(sym, "unreachable reloc %d (%s) target %v", r.Type, RelocName(r.Type), r.Xsym.Name)
} }
if Thearch.Elfreloc1(ctxt, 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)) {
Errorf(sym, "unsupported obj reloc %d (%s)/%d to %s", r.Type, RelocName(r.Type), r.Siz, r.Sym.Name) Errorf(sym, "unsupported obj reloc %d (%s)/%d to %s", r.Type, RelocName(r.Type), r.Siz, r.Sym.Name)
} }
} }
......
...@@ -98,14 +98,14 @@ type Arch struct { ...@@ -98,14 +98,14 @@ type Arch struct {
Solarisdynld string Solarisdynld string
Adddynrel func(*Link, *Symbol, *Reloc) bool Adddynrel func(*Link, *Symbol, *Reloc) bool
Archinit func(*Link) Archinit func(*Link)
Archreloc func(*Link, *Reloc, *Symbol, *int64) int Archreloc func(*Link, *Reloc, *Symbol, *int64) bool
Archrelocvariant func(*Link, *Reloc, *Symbol, int64) int64 Archrelocvariant func(*Link, *Reloc, *Symbol, int64) int64
Trampoline func(*Link, *Reloc, *Symbol) Trampoline func(*Link, *Reloc, *Symbol)
Asmb func(*Link) Asmb func(*Link)
Elfreloc1 func(*Link, *Reloc, int64) int Elfreloc1 func(*Link, *Reloc, int64) bool
Elfsetupplt func(*Link) Elfsetupplt func(*Link)
Gentext func(*Link) Gentext func(*Link)
Machoreloc1 func(*Symbol, *Reloc, int64) int Machoreloc1 func(*Symbol, *Reloc, int64) bool
PEreloc1 func(*Symbol, *Reloc, int64) bool PEreloc1 func(*Symbol, *Reloc, int64) bool
Wput func(uint16) Wput func(uint16)
Lput func(uint32) Lput func(uint32)
......
...@@ -185,7 +185,7 @@ func (a *Attribute) Set(flag Attribute, value bool) { ...@@ -185,7 +185,7 @@ func (a *Attribute) Set(flag Attribute, value bool) {
type Reloc struct { type Reloc struct {
Off int32 // offset to rewrite Off int32 // offset to rewrite
Siz uint8 // number of bytes to rewrite, 1, 2, or 4 Siz uint8 // number of bytes to rewrite, 1, 2, or 4
Done uint8 // set to 1 when relocation is complete Done bool // set to true when relocation is complete
Variant RelocVariant // variation on Type Variant RelocVariant // variation on Type
Type objabi.RelocType // the relocation type Type objabi.RelocType // the relocation type
Add int64 // addend Add int64 // addend
......
...@@ -922,7 +922,7 @@ func machorelocsect(ctxt *Link, sect *Section, syms []*Symbol) { ...@@ -922,7 +922,7 @@ func machorelocsect(ctxt *Link, sect *Section, syms []*Symbol) {
} }
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 {
continue continue
} }
if r.Xsym == nil { if r.Xsym == nil {
...@@ -932,7 +932,7 @@ func machorelocsect(ctxt *Link, sect *Section, syms []*Symbol) { ...@@ -932,7 +932,7 @@ func machorelocsect(ctxt *Link, sect *Section, syms []*Symbol) {
if !r.Xsym.Attr.Reachable() { if !r.Xsym.Attr.Reachable() {
Errorf(sym, "unreachable reloc %d (%s) target %v", r.Type, RelocName(r.Type), r.Xsym.Name) Errorf(sym, "unreachable reloc %d (%s) target %v", r.Type, RelocName(r.Type), r.Xsym.Name)
} }
if Thearch.Machoreloc1(sym, r, int64(uint64(sym.Value+int64(r.Off))-sect.Vaddr)) < 0 { if !Thearch.Machoreloc1(sym, r, int64(uint64(sym.Value+int64(r.Off))-sect.Vaddr)) {
Errorf(sym, "unsupported obj reloc %d (%s)/%d to %s", r.Type, RelocName(r.Type), r.Siz, r.Sym.Name) Errorf(sym, "unsupported obj reloc %d (%s)/%d to %s", r.Type, RelocName(r.Type), r.Siz, r.Sym.Name)
} }
} }
......
...@@ -926,7 +926,7 @@ func perelocsect(ctxt *Link, sect *Section, syms []*Symbol, base uint64) int { ...@@ -926,7 +926,7 @@ func perelocsect(ctxt *Link, sect *Section, syms []*Symbol, base uint64) int {
} }
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 {
continue continue
} }
if r.Xsym == nil { if r.Xsym == nil {
......
...@@ -46,42 +46,37 @@ func adddynrel(ctxt *ld.Link, s *ld.Symbol, r *ld.Reloc) bool { ...@@ -46,42 +46,37 @@ func adddynrel(ctxt *ld.Link, s *ld.Symbol, r *ld.Reloc) bool {
return false return false
} }
func elfreloc1(ctxt *ld.Link, r *ld.Reloc, sectoff int64) int { func elfreloc1(ctxt *ld.Link, r *ld.Reloc, sectoff int64) bool {
ld.Thearch.Lput(uint32(sectoff)) ld.Thearch.Lput(uint32(sectoff))
elfsym := r.Xsym.ElfsymForReloc() elfsym := r.Xsym.ElfsymForReloc()
switch r.Type { switch r.Type {
default: default:
return -1 return false
case objabi.R_ADDR: case objabi.R_ADDR:
if r.Siz != 4 { if r.Siz != 4 {
return -1 return false
} }
ld.Thearch.Lput(ld.R_MIPS_32 | uint32(elfsym)<<8) ld.Thearch.Lput(ld.R_MIPS_32 | uint32(elfsym)<<8)
case objabi.R_ADDRMIPS: case objabi.R_ADDRMIPS:
ld.Thearch.Lput(ld.R_MIPS_LO16 | uint32(elfsym)<<8) ld.Thearch.Lput(ld.R_MIPS_LO16 | uint32(elfsym)<<8)
case objabi.R_ADDRMIPSU: case objabi.R_ADDRMIPSU:
ld.Thearch.Lput(ld.R_MIPS_HI16 | uint32(elfsym)<<8) ld.Thearch.Lput(ld.R_MIPS_HI16 | uint32(elfsym)<<8)
case objabi.R_ADDRMIPSTLS: case objabi.R_ADDRMIPSTLS:
ld.Thearch.Lput(ld.R_MIPS_TLS_TPREL_LO16 | uint32(elfsym)<<8) ld.Thearch.Lput(ld.R_MIPS_TLS_TPREL_LO16 | uint32(elfsym)<<8)
case objabi.R_CALLMIPS, objabi.R_JMPMIPS: case objabi.R_CALLMIPS, objabi.R_JMPMIPS:
ld.Thearch.Lput(ld.R_MIPS_26 | uint32(elfsym)<<8) ld.Thearch.Lput(ld.R_MIPS_26 | uint32(elfsym)<<8)
} }
return 0 return true
} }
func elfsetupplt(ctxt *ld.Link) { func elfsetupplt(ctxt *ld.Link) {
return return
} }
func machoreloc1(s *ld.Symbol, r *ld.Reloc, sectoff int64) int { func machoreloc1(s *ld.Symbol, r *ld.Reloc, sectoff int64) bool {
return -1 return false
} }
func applyrel(r *ld.Reloc, s *ld.Symbol, val *int64, t int64) { func applyrel(r *ld.Reloc, s *ld.Symbol, val *int64, t int64) {
...@@ -96,15 +91,13 @@ func applyrel(r *ld.Reloc, s *ld.Symbol, val *int64, t int64) { ...@@ -96,15 +91,13 @@ func applyrel(r *ld.Reloc, s *ld.Symbol, val *int64, t int64) {
} }
} }
func archreloc(ctxt *ld.Link, r *ld.Reloc, s *ld.Symbol, val *int64) int { func archreloc(ctxt *ld.Link, r *ld.Reloc, s *ld.Symbol, val *int64) bool {
if ld.Linkmode == ld.LinkExternal { if ld.Linkmode == ld.LinkExternal {
switch r.Type { switch r.Type {
default: default:
return -1 return false
case objabi.R_ADDRMIPS, objabi.R_ADDRMIPSU: case objabi.R_ADDRMIPS, objabi.R_ADDRMIPSU:
r.Done = false
r.Done = 0
// set up addend for eventual relocation via outer symbol. // set up addend for eventual relocation via outer symbol.
rs := r.Sym rs := r.Sym
...@@ -119,31 +112,27 @@ func archreloc(ctxt *ld.Link, r *ld.Reloc, s *ld.Symbol, val *int64) int { ...@@ -119,31 +112,27 @@ func archreloc(ctxt *ld.Link, r *ld.Reloc, s *ld.Symbol, val *int64) int {
} }
r.Xsym = rs r.Xsym = rs
applyrel(r, s, val, r.Xadd) applyrel(r, s, val, r.Xadd)
return 0 return true
case objabi.R_ADDRMIPSTLS, objabi.R_CALLMIPS, objabi.R_JMPMIPS: case objabi.R_ADDRMIPSTLS, objabi.R_CALLMIPS, objabi.R_JMPMIPS:
r.Done = 0 r.Done = false
r.Xsym = r.Sym r.Xsym = r.Sym
r.Xadd = r.Add r.Xadd = r.Add
applyrel(r, s, val, r.Add) applyrel(r, s, val, r.Add)
return 0 return true
} }
} }
switch r.Type { switch r.Type {
case objabi.R_CONST: case objabi.R_CONST:
*val = r.Add *val = r.Add
return 0 return true
case objabi.R_GOTOFF: case objabi.R_GOTOFF:
*val = ld.Symaddr(r.Sym) + r.Add - ld.Symaddr(ctxt.Syms.Lookup(".got", 0)) *val = ld.Symaddr(r.Sym) + r.Add - ld.Symaddr(ctxt.Syms.Lookup(".got", 0))
return 0 return true
case objabi.R_ADDRMIPS, objabi.R_ADDRMIPSU: case objabi.R_ADDRMIPS, objabi.R_ADDRMIPSU:
t := ld.Symaddr(r.Sym) + r.Add t := ld.Symaddr(r.Sym) + r.Add
applyrel(r, s, val, t) applyrel(r, s, val, t)
return 0 return true
case objabi.R_CALLMIPS, objabi.R_JMPMIPS: case objabi.R_CALLMIPS, objabi.R_JMPMIPS:
t := ld.Symaddr(r.Sym) + r.Add t := ld.Symaddr(r.Sym) + r.Add
...@@ -157,8 +146,7 @@ func archreloc(ctxt *ld.Link, r *ld.Reloc, s *ld.Symbol, val *int64) int { ...@@ -157,8 +146,7 @@ func archreloc(ctxt *ld.Link, r *ld.Reloc, s *ld.Symbol, val *int64) int {
} }
applyrel(r, s, val, t) applyrel(r, s, val, t)
return 0 return true
case objabi.R_ADDRMIPSTLS: case objabi.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(r.Sym) + r.Add - 0x7000 t := ld.Symaddr(r.Sym) + r.Add - 0x7000
...@@ -166,10 +154,10 @@ func archreloc(ctxt *ld.Link, r *ld.Reloc, s *ld.Symbol, val *int64) int { ...@@ -166,10 +154,10 @@ func archreloc(ctxt *ld.Link, r *ld.Reloc, s *ld.Symbol, val *int64) int {
ld.Errorf(s, "TLS offset out of range %d", t) ld.Errorf(s, "TLS offset out of range %d", t)
} }
applyrel(r, s, val, t) applyrel(r, s, val, t)
return 0 return true
} }
return -1 return false
} }
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 {
......
...@@ -45,7 +45,7 @@ func adddynrel(ctxt *ld.Link, s *ld.Symbol, r *ld.Reloc) bool { ...@@ -45,7 +45,7 @@ func adddynrel(ctxt *ld.Link, s *ld.Symbol, r *ld.Reloc) bool {
return false return false
} }
func elfreloc1(ctxt *ld.Link, r *ld.Reloc, sectoff int64) int { func elfreloc1(ctxt *ld.Link, r *ld.Reloc, sectoff int64) bool {
// mips64 ELF relocation (endian neutral) // mips64 ELF relocation (endian neutral)
// offset uint64 // offset uint64
// sym uint32 // sym uint32
...@@ -64,8 +64,7 @@ func elfreloc1(ctxt *ld.Link, r *ld.Reloc, sectoff int64) int { ...@@ -64,8 +64,7 @@ func elfreloc1(ctxt *ld.Link, r *ld.Reloc, sectoff int64) int {
ld.Cput(0) ld.Cput(0)
switch r.Type { switch r.Type {
default: default:
return -1 return false
case objabi.R_ADDR: case objabi.R_ADDR:
switch r.Siz { switch r.Siz {
case 4: case 4:
...@@ -73,44 +72,39 @@ func elfreloc1(ctxt *ld.Link, r *ld.Reloc, sectoff int64) int { ...@@ -73,44 +72,39 @@ func elfreloc1(ctxt *ld.Link, r *ld.Reloc, sectoff int64) int {
case 8: case 8:
ld.Cput(ld.R_MIPS_64) ld.Cput(ld.R_MIPS_64)
default: default:
return -1 return false
} }
case objabi.R_ADDRMIPS: case objabi.R_ADDRMIPS:
ld.Cput(ld.R_MIPS_LO16) ld.Cput(ld.R_MIPS_LO16)
case objabi.R_ADDRMIPSU: case objabi.R_ADDRMIPSU:
ld.Cput(ld.R_MIPS_HI16) ld.Cput(ld.R_MIPS_HI16)
case objabi.R_ADDRMIPSTLS: case objabi.R_ADDRMIPSTLS:
ld.Cput(ld.R_MIPS_TLS_TPREL_LO16) ld.Cput(ld.R_MIPS_TLS_TPREL_LO16)
case objabi.R_CALLMIPS, case objabi.R_CALLMIPS,
objabi.R_JMPMIPS: objabi.R_JMPMIPS:
ld.Cput(ld.R_MIPS_26) ld.Cput(ld.R_MIPS_26)
} }
ld.Thearch.Vput(uint64(r.Xadd)) ld.Thearch.Vput(uint64(r.Xadd))
return 0 return true
} }
func elfsetupplt(ctxt *ld.Link) { func elfsetupplt(ctxt *ld.Link) {
return return
} }
func machoreloc1(s *ld.Symbol, r *ld.Reloc, sectoff int64) int { func machoreloc1(s *ld.Symbol, r *ld.Reloc, sectoff int64) bool {
return -1 return false
} }
func archreloc(ctxt *ld.Link, r *ld.Reloc, s *ld.Symbol, val *int64) int { func archreloc(ctxt *ld.Link, r *ld.Reloc, s *ld.Symbol, val *int64) bool {
if ld.Linkmode == ld.LinkExternal { if ld.Linkmode == ld.LinkExternal {
switch r.Type { switch r.Type {
default: default:
return -1 return false
case objabi.R_ADDRMIPS, case objabi.R_ADDRMIPS,
objabi.R_ADDRMIPSU: objabi.R_ADDRMIPSU:
r.Done = 0 r.Done = false
// set up addend for eventual relocation via outer symbol. // set up addend for eventual relocation via outer symbol.
rs := r.Sym rs := r.Sym
...@@ -125,27 +119,24 @@ func archreloc(ctxt *ld.Link, r *ld.Reloc, s *ld.Symbol, val *int64) int { ...@@ -125,27 +119,24 @@ func archreloc(ctxt *ld.Link, r *ld.Reloc, s *ld.Symbol, val *int64) int {
} }
r.Xsym = rs r.Xsym = rs
return 0 return true
case objabi.R_ADDRMIPSTLS, case objabi.R_ADDRMIPSTLS,
objabi.R_CALLMIPS, objabi.R_CALLMIPS,
objabi.R_JMPMIPS: objabi.R_JMPMIPS:
r.Done = 0 r.Done = false
r.Xsym = r.Sym r.Xsym = r.Sym
r.Xadd = r.Add r.Xadd = r.Add
return 0 return true
} }
} }
switch r.Type { switch r.Type {
case objabi.R_CONST: case objabi.R_CONST:
*val = r.Add *val = r.Add
return 0 return true
case objabi.R_GOTOFF: case objabi.R_GOTOFF:
*val = ld.Symaddr(r.Sym) + r.Add - ld.Symaddr(ctxt.Syms.Lookup(".got", 0)) *val = ld.Symaddr(r.Sym) + r.Add - ld.Symaddr(ctxt.Syms.Lookup(".got", 0))
return 0 return true
case objabi.R_ADDRMIPS, case objabi.R_ADDRMIPS,
objabi.R_ADDRMIPSU: objabi.R_ADDRMIPSU:
t := ld.Symaddr(r.Sym) + r.Add t := ld.Symaddr(r.Sym) + r.Add
...@@ -155,8 +146,7 @@ func archreloc(ctxt *ld.Link, r *ld.Reloc, s *ld.Symbol, val *int64) int { ...@@ -155,8 +146,7 @@ func archreloc(ctxt *ld.Link, r *ld.Reloc, s *ld.Symbol, val *int64) int {
} else { } else {
*val = int64(o1&0xffff0000 | uint32((t+1<<15)>>16)&0xffff) *val = int64(o1&0xffff0000 | uint32((t+1<<15)>>16)&0xffff)
} }
return 0 return true
case objabi.R_ADDRMIPSTLS: case objabi.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(r.Sym) + r.Add - 0x7000 t := ld.Symaddr(r.Sym) + r.Add - 0x7000
...@@ -165,18 +155,17 @@ func archreloc(ctxt *ld.Link, r *ld.Reloc, s *ld.Symbol, val *int64) int { ...@@ -165,18 +155,17 @@ func archreloc(ctxt *ld.Link, r *ld.Reloc, s *ld.Symbol, val *int64) int {
} }
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)
return 0 return true
case objabi.R_CALLMIPS, case objabi.R_CALLMIPS,
objabi.R_JMPMIPS: objabi.R_JMPMIPS:
// Low 26 bits = (S + A) >> 2 // Low 26 bits = (S + A) >> 2
t := ld.Symaddr(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 true
} }
return -1 return false
} }
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 {
......
...@@ -358,14 +358,13 @@ func adddynrel(ctxt *ld.Link, s *ld.Symbol, r *ld.Reloc) bool { ...@@ -358,14 +358,13 @@ func adddynrel(ctxt *ld.Link, s *ld.Symbol, r *ld.Reloc) bool {
return false return false
} }
func elfreloc1(ctxt *ld.Link, r *ld.Reloc, sectoff int64) int { func elfreloc1(ctxt *ld.Link, r *ld.Reloc, sectoff int64) bool {
ld.Thearch.Vput(uint64(sectoff)) ld.Thearch.Vput(uint64(sectoff))
elfsym := r.Xsym.ElfsymForReloc() elfsym := r.Xsym.ElfsymForReloc()
switch r.Type { switch r.Type {
default: default:
return -1 return false
case objabi.R_ADDR: case objabi.R_ADDR:
switch r.Siz { switch r.Siz {
case 4: case 4:
...@@ -373,68 +372,58 @@ func elfreloc1(ctxt *ld.Link, r *ld.Reloc, sectoff int64) int { ...@@ -373,68 +372,58 @@ func elfreloc1(ctxt *ld.Link, r *ld.Reloc, sectoff int64) int {
case 8: case 8:
ld.Thearch.Vput(ld.R_PPC64_ADDR64 | uint64(elfsym)<<32) ld.Thearch.Vput(ld.R_PPC64_ADDR64 | uint64(elfsym)<<32)
default: default:
return -1 return false
} }
case objabi.R_POWER_TLS: case objabi.R_POWER_TLS:
ld.Thearch.Vput(ld.R_PPC64_TLS | uint64(elfsym)<<32) ld.Thearch.Vput(ld.R_PPC64_TLS | uint64(elfsym)<<32)
case objabi.R_POWER_TLS_LE: case objabi.R_POWER_TLS_LE:
ld.Thearch.Vput(ld.R_PPC64_TPREL16 | uint64(elfsym)<<32) ld.Thearch.Vput(ld.R_PPC64_TPREL16 | uint64(elfsym)<<32)
case objabi.R_POWER_TLS_IE: case objabi.R_POWER_TLS_IE:
ld.Thearch.Vput(ld.R_PPC64_GOT_TPREL16_HA | uint64(elfsym)<<32) ld.Thearch.Vput(ld.R_PPC64_GOT_TPREL16_HA | uint64(elfsym)<<32)
ld.Thearch.Vput(uint64(r.Xadd)) ld.Thearch.Vput(uint64(r.Xadd))
ld.Thearch.Vput(uint64(sectoff + 4)) ld.Thearch.Vput(uint64(sectoff + 4))
ld.Thearch.Vput(ld.R_PPC64_GOT_TPREL16_LO_DS | uint64(elfsym)<<32) ld.Thearch.Vput(ld.R_PPC64_GOT_TPREL16_LO_DS | uint64(elfsym)<<32)
case objabi.R_ADDRPOWER: case objabi.R_ADDRPOWER:
ld.Thearch.Vput(ld.R_PPC64_ADDR16_HA | uint64(elfsym)<<32) ld.Thearch.Vput(ld.R_PPC64_ADDR16_HA | uint64(elfsym)<<32)
ld.Thearch.Vput(uint64(r.Xadd)) ld.Thearch.Vput(uint64(r.Xadd))
ld.Thearch.Vput(uint64(sectoff + 4)) ld.Thearch.Vput(uint64(sectoff + 4))
ld.Thearch.Vput(ld.R_PPC64_ADDR16_LO | uint64(elfsym)<<32) ld.Thearch.Vput(ld.R_PPC64_ADDR16_LO | uint64(elfsym)<<32)
case objabi.R_ADDRPOWER_DS: case objabi.R_ADDRPOWER_DS:
ld.Thearch.Vput(ld.R_PPC64_ADDR16_HA | uint64(elfsym)<<32) ld.Thearch.Vput(ld.R_PPC64_ADDR16_HA | uint64(elfsym)<<32)
ld.Thearch.Vput(uint64(r.Xadd)) ld.Thearch.Vput(uint64(r.Xadd))
ld.Thearch.Vput(uint64(sectoff + 4)) ld.Thearch.Vput(uint64(sectoff + 4))
ld.Thearch.Vput(ld.R_PPC64_ADDR16_LO_DS | uint64(elfsym)<<32) ld.Thearch.Vput(ld.R_PPC64_ADDR16_LO_DS | uint64(elfsym)<<32)
case objabi.R_ADDRPOWER_GOT: case objabi.R_ADDRPOWER_GOT:
ld.Thearch.Vput(ld.R_PPC64_GOT16_HA | uint64(elfsym)<<32) ld.Thearch.Vput(ld.R_PPC64_GOT16_HA | uint64(elfsym)<<32)
ld.Thearch.Vput(uint64(r.Xadd)) ld.Thearch.Vput(uint64(r.Xadd))
ld.Thearch.Vput(uint64(sectoff + 4)) ld.Thearch.Vput(uint64(sectoff + 4))
ld.Thearch.Vput(ld.R_PPC64_GOT16_LO_DS | uint64(elfsym)<<32) ld.Thearch.Vput(ld.R_PPC64_GOT16_LO_DS | uint64(elfsym)<<32)
case objabi.R_ADDRPOWER_PCREL: case objabi.R_ADDRPOWER_PCREL:
ld.Thearch.Vput(ld.R_PPC64_REL16_HA | uint64(elfsym)<<32) ld.Thearch.Vput(ld.R_PPC64_REL16_HA | uint64(elfsym)<<32)
ld.Thearch.Vput(uint64(r.Xadd)) ld.Thearch.Vput(uint64(r.Xadd))
ld.Thearch.Vput(uint64(sectoff + 4)) ld.Thearch.Vput(uint64(sectoff + 4))
ld.Thearch.Vput(ld.R_PPC64_REL16_LO | uint64(elfsym)<<32) ld.Thearch.Vput(ld.R_PPC64_REL16_LO | uint64(elfsym)<<32)
r.Xadd += 4 r.Xadd += 4
case objabi.R_ADDRPOWER_TOCREL: case objabi.R_ADDRPOWER_TOCREL:
ld.Thearch.Vput(ld.R_PPC64_TOC16_HA | uint64(elfsym)<<32) ld.Thearch.Vput(ld.R_PPC64_TOC16_HA | uint64(elfsym)<<32)
ld.Thearch.Vput(uint64(r.Xadd)) ld.Thearch.Vput(uint64(r.Xadd))
ld.Thearch.Vput(uint64(sectoff + 4)) ld.Thearch.Vput(uint64(sectoff + 4))
ld.Thearch.Vput(ld.R_PPC64_TOC16_LO | uint64(elfsym)<<32) ld.Thearch.Vput(ld.R_PPC64_TOC16_LO | uint64(elfsym)<<32)
case objabi.R_ADDRPOWER_TOCREL_DS: case objabi.R_ADDRPOWER_TOCREL_DS:
ld.Thearch.Vput(ld.R_PPC64_TOC16_HA | uint64(elfsym)<<32) ld.Thearch.Vput(ld.R_PPC64_TOC16_HA | uint64(elfsym)<<32)
ld.Thearch.Vput(uint64(r.Xadd)) ld.Thearch.Vput(uint64(r.Xadd))
ld.Thearch.Vput(uint64(sectoff + 4)) ld.Thearch.Vput(uint64(sectoff + 4))
ld.Thearch.Vput(ld.R_PPC64_TOC16_LO_DS | uint64(elfsym)<<32) ld.Thearch.Vput(ld.R_PPC64_TOC16_LO_DS | uint64(elfsym)<<32)
case objabi.R_CALLPOWER: case objabi.R_CALLPOWER:
if r.Siz != 4 { if r.Siz != 4 {
return -1 return false
} }
ld.Thearch.Vput(ld.R_PPC64_REL24 | uint64(elfsym)<<32) ld.Thearch.Vput(ld.R_PPC64_REL24 | uint64(elfsym)<<32)
} }
ld.Thearch.Vput(uint64(r.Xadd)) ld.Thearch.Vput(uint64(r.Xadd))
return 0 return true
} }
func elfsetupplt(ctxt *ld.Link) { func elfsetupplt(ctxt *ld.Link) {
...@@ -448,8 +437,8 @@ func elfsetupplt(ctxt *ld.Link) { ...@@ -448,8 +437,8 @@ func elfsetupplt(ctxt *ld.Link) {
} }
} }
func machoreloc1(s *ld.Symbol, r *ld.Reloc, sectoff int64) int { func machoreloc1(s *ld.Symbol, r *ld.Reloc, sectoff int64) bool {
return -1 return false
} }
// Return the value of .TOC. for symbol s // Return the value of .TOC. for symbol s
...@@ -470,7 +459,7 @@ func symtoc(ctxt *ld.Link, s *ld.Symbol) int64 { ...@@ -470,7 +459,7 @@ func symtoc(ctxt *ld.Link, s *ld.Symbol) int64 {
return toc.Value return toc.Value
} }
func archrelocaddr(ctxt *ld.Link, r *ld.Reloc, s *ld.Symbol, val *int64) int { func archrelocaddr(ctxt *ld.Link, r *ld.Reloc, s *ld.Symbol, val *int64) bool {
var o1, o2 uint32 var o1, o2 uint32
if ctxt.Arch.ByteOrder == binary.BigEndian { if ctxt.Arch.ByteOrder == binary.BigEndian {
o1 = uint32(*val >> 32) o1 = uint32(*val >> 32)
...@@ -499,16 +488,14 @@ func archrelocaddr(ctxt *ld.Link, r *ld.Reloc, s *ld.Symbol, val *int64) int { ...@@ -499,16 +488,14 @@ func archrelocaddr(ctxt *ld.Link, r *ld.Reloc, s *ld.Symbol, val *int64) int {
case objabi.R_ADDRPOWER: case objabi.R_ADDRPOWER:
o1 |= (uint32(t) >> 16) & 0xffff o1 |= (uint32(t) >> 16) & 0xffff
o2 |= uint32(t) & 0xffff o2 |= uint32(t) & 0xffff
case objabi.R_ADDRPOWER_DS: case objabi.R_ADDRPOWER_DS:
o1 |= (uint32(t) >> 16) & 0xffff o1 |= (uint32(t) >> 16) & 0xffff
if t&3 != 0 { if t&3 != 0 {
ld.Errorf(s, "bad DS reloc for %s: %d", s.Name, ld.Symaddr(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
default: default:
return -1 return false
} }
if ctxt.Arch.ByteOrder == binary.BigEndian { if ctxt.Arch.ByteOrder == binary.BigEndian {
...@@ -516,7 +503,7 @@ func archrelocaddr(ctxt *ld.Link, r *ld.Reloc, s *ld.Symbol, val *int64) int { ...@@ -516,7 +503,7 @@ func archrelocaddr(ctxt *ld.Link, r *ld.Reloc, s *ld.Symbol, val *int64) int {
} else { } else {
*val = int64(o2)<<32 | int64(o1) *val = int64(o2)<<32 | int64(o1)
} }
return 0 return true
} }
// resolve direct jump relocation r in s, and add trampoline if necessary // resolve direct jump relocation r in s, and add trampoline if necessary
...@@ -578,7 +565,7 @@ func trampoline(ctxt *ld.Link, r *ld.Reloc, s *ld.Symbol) { ...@@ -578,7 +565,7 @@ func trampoline(ctxt *ld.Link, r *ld.Reloc, s *ld.Symbol) {
} }
r.Sym = tramp r.Sym = tramp
r.Add = 0 // This was folded into the trampoline target address r.Add = 0 // This was folded into the trampoline target address
r.Done = 0 r.Done = false
} }
default: default:
ld.Errorf(s, "trampoline called with non-jump reloc: %d (%s)", r.Type, ld.RelocName(r.Type)) ld.Errorf(s, "trampoline called with non-jump reloc: %d (%s)", r.Type, ld.RelocName(r.Type))
...@@ -621,26 +608,24 @@ func gentramp(tramp, target *ld.Symbol, offset int64) { ...@@ -621,26 +608,24 @@ func gentramp(tramp, target *ld.Symbol, offset int64) {
ld.SysArch.ByteOrder.PutUint32(tramp.P[12:], o4) ld.SysArch.ByteOrder.PutUint32(tramp.P[12:], o4)
} }
func archreloc(ctxt *ld.Link, r *ld.Reloc, s *ld.Symbol, val *int64) int { func archreloc(ctxt *ld.Link, r *ld.Reloc, s *ld.Symbol, val *int64) bool {
if ld.Linkmode == ld.LinkExternal { if ld.Linkmode == ld.LinkExternal {
switch r.Type { switch r.Type {
default: default:
return -1 return false
case objabi.R_POWER_TLS, objabi.R_POWER_TLS_LE, objabi.R_POWER_TLS_IE: case objabi.R_POWER_TLS, objabi.R_POWER_TLS_LE, objabi.R_POWER_TLS_IE:
r.Done = 0 r.Done = false
// check Outer is nil, Type is TLSBSS? // check Outer is nil, Type is TLSBSS?
r.Xadd = r.Add r.Xadd = r.Add
r.Xsym = r.Sym r.Xsym = r.Sym
return 0 return true
case objabi.R_ADDRPOWER, case objabi.R_ADDRPOWER,
objabi.R_ADDRPOWER_DS, objabi.R_ADDRPOWER_DS,
objabi.R_ADDRPOWER_TOCREL, objabi.R_ADDRPOWER_TOCREL,
objabi.R_ADDRPOWER_TOCREL_DS, objabi.R_ADDRPOWER_TOCREL_DS,
objabi.R_ADDRPOWER_GOT, objabi.R_ADDRPOWER_GOT,
objabi.R_ADDRPOWER_PCREL: objabi.R_ADDRPOWER_PCREL:
r.Done = 0 r.Done = false
// set up addend for eventual relocation via outer symbol. // set up addend for eventual relocation via outer symbol.
rs := r.Sym rs := r.Sym
...@@ -655,28 +640,24 @@ func archreloc(ctxt *ld.Link, r *ld.Reloc, s *ld.Symbol, val *int64) int { ...@@ -655,28 +640,24 @@ func archreloc(ctxt *ld.Link, r *ld.Reloc, s *ld.Symbol, val *int64) int {
} }
r.Xsym = rs r.Xsym = rs
return 0 return true
case objabi.R_CALLPOWER: case objabi.R_CALLPOWER:
r.Done = 0 r.Done = false
r.Xsym = r.Sym r.Xsym = r.Sym
r.Xadd = r.Add r.Xadd = r.Add
return 0 return true
} }
} }
switch r.Type { switch r.Type {
case objabi.R_CONST: case objabi.R_CONST:
*val = r.Add *val = r.Add
return 0 return true
case objabi.R_GOTOFF: case objabi.R_GOTOFF:
*val = ld.Symaddr(r.Sym) + r.Add - ld.Symaddr(ctxt.Syms.Lookup(".got", 0)) *val = ld.Symaddr(r.Sym) + r.Add - ld.Symaddr(ctxt.Syms.Lookup(".got", 0))
return 0 return true
case objabi.R_ADDRPOWER, objabi.R_ADDRPOWER_DS: case objabi.R_ADDRPOWER, objabi.R_ADDRPOWER_DS:
return archrelocaddr(ctxt, r, s, val) return archrelocaddr(ctxt, r, s, val)
case objabi.R_CALLPOWER: case objabi.R_CALLPOWER:
// Bits 6 through 29 = (S + A - P) >> 2 // Bits 6 through 29 = (S + A - P) >> 2
...@@ -691,13 +672,11 @@ func archreloc(ctxt *ld.Link, r *ld.Reloc, s *ld.Symbol, val *int64) int { ...@@ -691,13 +672,11 @@ func archreloc(ctxt *ld.Link, r *ld.Reloc, s *ld.Symbol, val *int64) int {
ld.Errorf(s, "direct call too far: %s %x", r.Sym.Name, t) ld.Errorf(s, "direct call too far: %s %x", r.Sym.Name, t)
} }
*val |= int64(uint32(t) &^ 0xfc000003) *val |= int64(uint32(t) &^ 0xfc000003)
return 0 return true
case objabi.R_POWER_TOC: // S + A - .TOC. case objabi.R_POWER_TOC: // S + A - .TOC.
*val = ld.Symaddr(r.Sym) + r.Add - symtoc(ctxt, s) *val = ld.Symaddr(r.Sym) + r.Add - symtoc(ctxt, s)
return 0 return true
case objabi.R_POWER_TLS_LE: case objabi.R_POWER_TLS_LE:
// The thread pointer points 0x7000 bytes after the start of the the // The thread pointer points 0x7000 bytes after the start of the the
// thread local storage area as documented in section "3.7.2 TLS // thread local storage area as documented in section "3.7.2 TLS
...@@ -708,10 +687,10 @@ func archreloc(ctxt *ld.Link, r *ld.Reloc, s *ld.Symbol, val *int64) int { ...@@ -708,10 +687,10 @@ func archreloc(ctxt *ld.Link, r *ld.Reloc, s *ld.Symbol, val *int64) int {
ld.Errorf(s, "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 true
} }
return -1 return false
} }
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 {
......
...@@ -232,18 +232,17 @@ func adddynrel(ctxt *ld.Link, s *ld.Symbol, r *ld.Reloc) bool { ...@@ -232,18 +232,17 @@ func adddynrel(ctxt *ld.Link, s *ld.Symbol, r *ld.Reloc) bool {
return false return false
} }
func elfreloc1(ctxt *ld.Link, r *ld.Reloc, sectoff int64) int { func elfreloc1(ctxt *ld.Link, r *ld.Reloc, sectoff int64) bool {
ld.Thearch.Vput(uint64(sectoff)) ld.Thearch.Vput(uint64(sectoff))
elfsym := r.Xsym.ElfsymForReloc() elfsym := r.Xsym.ElfsymForReloc()
switch r.Type { switch r.Type {
default: default:
return -1 return false
case objabi.R_TLS_LE: case objabi.R_TLS_LE:
switch r.Siz { switch r.Siz {
default: default:
return -1 return false
case 4: case 4:
// WARNING - silently ignored by linker in ELF64 // WARNING - silently ignored by linker in ELF64
ld.Thearch.Vput(ld.R_390_TLS_LE32 | uint64(elfsym)<<32) ld.Thearch.Vput(ld.R_390_TLS_LE32 | uint64(elfsym)<<32)
...@@ -251,32 +250,28 @@ func elfreloc1(ctxt *ld.Link, r *ld.Reloc, sectoff int64) int { ...@@ -251,32 +250,28 @@ func elfreloc1(ctxt *ld.Link, r *ld.Reloc, sectoff int64) int {
// WARNING - silently ignored by linker in ELF32 // WARNING - silently ignored by linker in ELF32
ld.Thearch.Vput(ld.R_390_TLS_LE64 | uint64(elfsym)<<32) ld.Thearch.Vput(ld.R_390_TLS_LE64 | uint64(elfsym)<<32)
} }
case objabi.R_TLS_IE: case objabi.R_TLS_IE:
switch r.Siz { switch r.Siz {
default: default:
return -1 return false
case 4: case 4:
ld.Thearch.Vput(ld.R_390_TLS_IEENT | uint64(elfsym)<<32) ld.Thearch.Vput(ld.R_390_TLS_IEENT | uint64(elfsym)<<32)
} }
case objabi.R_ADDR: case objabi.R_ADDR:
switch r.Siz { switch r.Siz {
default: default:
return -1 return false
case 4: case 4:
ld.Thearch.Vput(ld.R_390_32 | uint64(elfsym)<<32) ld.Thearch.Vput(ld.R_390_32 | uint64(elfsym)<<32)
case 8: case 8:
ld.Thearch.Vput(ld.R_390_64 | uint64(elfsym)<<32) ld.Thearch.Vput(ld.R_390_64 | uint64(elfsym)<<32)
} }
case objabi.R_GOTPCREL: case objabi.R_GOTPCREL:
if r.Siz == 4 { if r.Siz == 4 {
ld.Thearch.Vput(ld.R_390_GOTENT | uint64(elfsym)<<32) ld.Thearch.Vput(ld.R_390_GOTENT | uint64(elfsym)<<32)
} else { } else {
return -1 return false
} }
case objabi.R_PCREL, objabi.R_PCRELDBL, objabi.R_CALL: case objabi.R_PCREL, objabi.R_PCRELDBL, objabi.R_CALL:
elfrel := ld.R_390_NONE elfrel := ld.R_390_NONE
isdbl := r.Variant&ld.RV_TYPE_MASK == ld.RV_390_DBL isdbl := r.Variant&ld.RV_TYPE_MASK == ld.RV_390_DBL
...@@ -322,13 +317,13 @@ func elfreloc1(ctxt *ld.Link, r *ld.Reloc, sectoff int64) int { ...@@ -322,13 +317,13 @@ func elfreloc1(ctxt *ld.Link, r *ld.Reloc, sectoff int64) int {
} }
} }
if elfrel == ld.R_390_NONE { if elfrel == ld.R_390_NONE {
return -1 // unsupported size/dbl combination return false // unsupported size/dbl combination
} }
ld.Thearch.Vput(uint64(elfrel) | uint64(elfsym)<<32) ld.Thearch.Vput(uint64(elfrel) | uint64(elfsym)<<32)
} }
ld.Thearch.Vput(uint64(r.Xadd)) ld.Thearch.Vput(uint64(r.Xadd))
return 0 return true
} }
func elfsetupplt(ctxt *ld.Link) { func elfsetupplt(ctxt *ld.Link) {
...@@ -381,26 +376,25 @@ func elfsetupplt(ctxt *ld.Link) { ...@@ -381,26 +376,25 @@ func elfsetupplt(ctxt *ld.Link) {
} }
} }
func machoreloc1(s *ld.Symbol, r *ld.Reloc, sectoff int64) int { func machoreloc1(s *ld.Symbol, r *ld.Reloc, sectoff int64) bool {
return -1 return false
} }
func archreloc(ctxt *ld.Link, r *ld.Reloc, s *ld.Symbol, val *int64) int { func archreloc(ctxt *ld.Link, r *ld.Reloc, s *ld.Symbol, val *int64) bool {
if ld.Linkmode == ld.LinkExternal { if ld.Linkmode == ld.LinkExternal {
return -1 return false
} }
switch r.Type { switch r.Type {
case objabi.R_CONST: case objabi.R_CONST:
*val = r.Add *val = r.Add
return 0 return true
case objabi.R_GOTOFF: case objabi.R_GOTOFF:
*val = ld.Symaddr(r.Sym) + r.Add - ld.Symaddr(ctxt.Syms.Lookup(".got", 0)) *val = ld.Symaddr(r.Sym) + r.Add - ld.Symaddr(ctxt.Syms.Lookup(".got", 0))
return 0 return true
} }
return -1 return false
} }
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 {
......
...@@ -345,21 +345,19 @@ func adddynrel(ctxt *ld.Link, s *ld.Symbol, r *ld.Reloc) bool { ...@@ -345,21 +345,19 @@ func adddynrel(ctxt *ld.Link, s *ld.Symbol, r *ld.Reloc) bool {
return false return false
} }
func elfreloc1(ctxt *ld.Link, r *ld.Reloc, sectoff int64) int { func elfreloc1(ctxt *ld.Link, r *ld.Reloc, sectoff int64) bool {
ld.Thearch.Lput(uint32(sectoff)) ld.Thearch.Lput(uint32(sectoff))
elfsym := r.Xsym.ElfsymForReloc() elfsym := r.Xsym.ElfsymForReloc()
switch r.Type { switch r.Type {
default: default:
return -1 return false
case objabi.R_ADDR: case objabi.R_ADDR:
if r.Siz == 4 { if r.Siz == 4 {
ld.Thearch.Lput(ld.R_386_32 | uint32(elfsym)<<8) ld.Thearch.Lput(ld.R_386_32 | uint32(elfsym)<<8)
} else { } else {
return -1 return false
} }
case objabi.R_GOTPCREL: case objabi.R_GOTPCREL:
if r.Siz == 4 { if r.Siz == 4 {
ld.Thearch.Lput(ld.R_386_GOTPC) ld.Thearch.Lput(ld.R_386_GOTPC)
...@@ -368,9 +366,8 @@ func elfreloc1(ctxt *ld.Link, r *ld.Reloc, sectoff int64) int { ...@@ -368,9 +366,8 @@ func elfreloc1(ctxt *ld.Link, r *ld.Reloc, sectoff int64) int {
ld.Thearch.Lput(ld.R_386_GOT32 | uint32(elfsym)<<8) ld.Thearch.Lput(ld.R_386_GOT32 | uint32(elfsym)<<8)
} }
} else { } else {
return -1 return false
} }
case objabi.R_CALL: case objabi.R_CALL:
if r.Siz == 4 { if r.Siz == 4 {
if r.Xsym.Type == ld.SDYNIMPORT { if r.Xsym.Type == ld.SDYNIMPORT {
...@@ -379,37 +376,34 @@ func elfreloc1(ctxt *ld.Link, r *ld.Reloc, sectoff int64) int { ...@@ -379,37 +376,34 @@ func elfreloc1(ctxt *ld.Link, r *ld.Reloc, sectoff int64) int {
ld.Thearch.Lput(ld.R_386_PC32 | uint32(elfsym)<<8) ld.Thearch.Lput(ld.R_386_PC32 | uint32(elfsym)<<8)
} }
} else { } else {
return -1 return false
} }
case objabi.R_PCREL: case objabi.R_PCREL:
if r.Siz == 4 { if r.Siz == 4 {
ld.Thearch.Lput(ld.R_386_PC32 | uint32(elfsym)<<8) ld.Thearch.Lput(ld.R_386_PC32 | uint32(elfsym)<<8)
} else { } else {
return -1 return false
} }
case objabi.R_TLS_LE: case objabi.R_TLS_LE:
if r.Siz == 4 { if r.Siz == 4 {
ld.Thearch.Lput(ld.R_386_TLS_LE | uint32(elfsym)<<8) ld.Thearch.Lput(ld.R_386_TLS_LE | uint32(elfsym)<<8)
} else { } else {
return -1 return false
} }
case objabi.R_TLS_IE: case objabi.R_TLS_IE:
if r.Siz == 4 { if r.Siz == 4 {
ld.Thearch.Lput(ld.R_386_GOTPC) ld.Thearch.Lput(ld.R_386_GOTPC)
ld.Thearch.Lput(uint32(sectoff)) ld.Thearch.Lput(uint32(sectoff))
ld.Thearch.Lput(ld.R_386_TLS_GOTIE | uint32(elfsym)<<8) ld.Thearch.Lput(ld.R_386_TLS_GOTIE | uint32(elfsym)<<8)
} else { } else {
return -1 return false
} }
} }
return 0 return true
} }
func machoreloc1(s *ld.Symbol, r *ld.Reloc, sectoff int64) int { func machoreloc1(s *ld.Symbol, r *ld.Reloc, sectoff int64) bool {
var v uint32 var v uint32
rs := r.Xsym rs := r.Xsym
...@@ -417,7 +411,7 @@ func machoreloc1(s *ld.Symbol, r *ld.Reloc, sectoff int64) int { ...@@ -417,7 +411,7 @@ func machoreloc1(s *ld.Symbol, r *ld.Reloc, sectoff int64) int {
if rs.Type == ld.SHOSTOBJ { if rs.Type == ld.SHOSTOBJ {
if rs.Dynid < 0 { if rs.Dynid < 0 {
ld.Errorf(s, "reloc %d (%s) to non-macho symbol %s type=%d (%s)", r.Type, ld.RelocName(r.Type), rs.Name, rs.Type, rs.Type) ld.Errorf(s, "reloc %d (%s) to non-macho symbol %s type=%d (%s)", r.Type, ld.RelocName(r.Type), rs.Name, rs.Type, rs.Type)
return -1 return false
} }
v = uint32(rs.Dynid) v = uint32(rs.Dynid)
...@@ -426,17 +420,15 @@ func machoreloc1(s *ld.Symbol, r *ld.Reloc, sectoff int64) int { ...@@ -426,17 +420,15 @@ func machoreloc1(s *ld.Symbol, r *ld.Reloc, sectoff int64) int {
v = uint32(rs.Sect.Extnum) v = uint32(rs.Sect.Extnum)
if v == 0 { if v == 0 {
ld.Errorf(s, "reloc %d (%s) to symbol %s in non-macho section %s type=%d (%s)", r.Type, ld.RelocName(r.Type), rs.Name, rs.Sect.Name, rs.Type, rs.Type) ld.Errorf(s, "reloc %d (%s) to symbol %s in non-macho section %s type=%d (%s)", r.Type, ld.RelocName(r.Type), rs.Name, rs.Sect.Name, rs.Type, rs.Type)
return -1 return false
} }
} }
switch r.Type { switch r.Type {
default: default:
return -1 return false
case objabi.R_ADDR: case objabi.R_ADDR:
v |= ld.MACHO_GENERIC_RELOC_VANILLA << 28 v |= ld.MACHO_GENERIC_RELOC_VANILLA << 28
case objabi.R_CALL, case objabi.R_CALL,
objabi.R_PCREL: objabi.R_PCREL:
v |= 1 << 24 // pc-relative bit v |= 1 << 24 // pc-relative bit
...@@ -445,24 +437,20 @@ func machoreloc1(s *ld.Symbol, r *ld.Reloc, sectoff int64) int { ...@@ -445,24 +437,20 @@ func machoreloc1(s *ld.Symbol, r *ld.Reloc, sectoff int64) int {
switch r.Siz { switch r.Siz {
default: default:
return -1 return false
case 1: case 1:
v |= 0 << 25 v |= 0 << 25
case 2: case 2:
v |= 1 << 25 v |= 1 << 25
case 4: case 4:
v |= 2 << 25 v |= 2 << 25
case 8: case 8:
v |= 3 << 25 v |= 3 << 25
} }
ld.Thearch.Lput(uint32(sectoff)) ld.Thearch.Lput(uint32(sectoff))
ld.Thearch.Lput(v) ld.Thearch.Lput(v)
return 0 return true
} }
func pereloc1(s *ld.Symbol, r *ld.Reloc, sectoff int64) bool { func pereloc1(s *ld.Symbol, r *ld.Reloc, sectoff int64) bool {
...@@ -498,21 +486,20 @@ func pereloc1(s *ld.Symbol, r *ld.Reloc, sectoff int64) bool { ...@@ -498,21 +486,20 @@ func pereloc1(s *ld.Symbol, r *ld.Reloc, sectoff int64) bool {
return true return true
} }
func archreloc(ctxt *ld.Link, r *ld.Reloc, s *ld.Symbol, val *int64) int { func archreloc(ctxt *ld.Link, r *ld.Reloc, s *ld.Symbol, val *int64) bool {
if ld.Linkmode == ld.LinkExternal { if ld.Linkmode == ld.LinkExternal {
return -1 return false
} }
switch r.Type { switch r.Type {
case objabi.R_CONST: case objabi.R_CONST:
*val = r.Add *val = r.Add
return 0 return true
case objabi.R_GOTOFF: case objabi.R_GOTOFF:
*val = ld.Symaddr(r.Sym) + r.Add - ld.Symaddr(ctxt.Syms.Lookup(".got", 0)) *val = ld.Symaddr(r.Sym) + r.Add - ld.Symaddr(ctxt.Syms.Lookup(".got", 0))
return 0 return true
} }
return -1 return false
} }
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 {
......
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