Updates #37610, #37611.
Change-Id: I0a497af03e24ddea40ed3e342f3a9362bf21ac0c
Reviewed-on: https://go-review.googlesource.com/c/go/+/229323
Run-TryBot: Cherry Zhang <cherryyz@google.com>
Reviewed-by: Austin Clements <austin@google.com>
}
func machoreloc1(arch *sys.Arch, out *ld.OutBuf, s *sym.Symbol, r *sym.Reloc, sectoff int64) bool {
- var v uint32
-
- rs := r.Xsym
-
- if r.Type == objabi.R_PCREL {
- if rs.Type == sym.SHOSTOBJ {
- ld.Errorf(s, "pc-relative relocation of external symbol is not supported")
- return false
- }
- if r.Siz != 4 {
- return false
- }
-
- // emit a pair of "scattered" relocations that
- // resolve to the difference of section addresses of
- // the symbol and the instruction
- // this value is added to the field being relocated
- o1 := uint32(sectoff)
- o1 |= 1 << 31 // scattered bit
- o1 |= ld.MACHO_ARM_RELOC_SECTDIFF << 24
- o1 |= 2 << 28 // size = 4
-
- o2 := uint32(0)
- o2 |= 1 << 31 // scattered bit
- o2 |= ld.MACHO_ARM_RELOC_PAIR << 24
- o2 |= 2 << 28 // size = 4
-
- out.Write32(o1)
- out.Write32(uint32(ld.Symaddr(rs)))
- out.Write32(o2)
- out.Write32(uint32(s.Value + int64(r.Off)))
- return true
- }
-
- if rs.Type == sym.SHOSTOBJ || r.Type == objabi.R_CALLARM {
- if rs.Dynid < 0 {
- ld.Errorf(s, "reloc %d (%s) to non-macho symbol %s type=%d (%s)", r.Type, sym.RelocName(arch, r.Type), rs.Name, rs.Type, rs.Type)
- return false
- }
-
- v = uint32(rs.Dynid)
- v |= 1 << 27 // external relocation
- } else {
- v = uint32(rs.Sect.Extnum)
- if v == 0 {
- ld.Errorf(s, "reloc %d (%s) to symbol %s in non-macho section %s type=%d (%s)", r.Type, sym.RelocName(arch, r.Type), rs.Name, rs.Sect.Name, rs.Type, rs.Type)
- return false
- }
- }
-
- switch r.Type {
- default:
- return false
-
- case objabi.R_ADDR:
- v |= ld.MACHO_GENERIC_RELOC_VANILLA << 28
-
- case objabi.R_CALLARM:
- v |= 1 << 24 // pc-relative bit
- v |= ld.MACHO_ARM_RELOC_BR24 << 28
- }
-
- switch r.Siz {
- default:
- return false
- case 1:
- v |= 0 << 25
-
- case 2:
- v |= 1 << 25
-
- case 4:
- v |= 2 << 25
-
- case 8:
- v |= 3 << 25
- }
-
- out.Write32(uint32(sectoff))
- out.Write32(v)
- return true
+ return false
}
func pereloc1(arch *sys.Arch, out *ld.OutBuf, s *sym.Symbol, r *sym.Reloc, sectoff int64) bool {
} else if target.IsDarwin() {
if r.Type == objabi.R_CALL {
if target.IsExternal() && rs.Type == sym.SDYNIMPORT {
- switch target.Arch.Family {
- case sys.AMD64:
+ if target.IsAMD64() {
// AMD64 dynamic relocations are relative to the end of the relocation.
o += int64(r.Siz)
- case sys.I386:
- // I386 dynamic relocations are relative to the start of the section.
- o -= int64(r.Off) // offset in symbol
- o -= int64(s.Value - int64(s.Sect.Vaddr)) // offset of symbol in section
}
} else {
if rs.Type != sym.SHOSTOBJ {
}
o -= int64(r.Off) // relative to section offset, not symbol
}
- } else if target.IsARM() {
- // see ../arm/asm.go:/machoreloc1
- o += Symaddr(rs) - s.Value - int64(r.Off)
} else {
o += int64(r.Siz)
}
}
func machoreloc1(arch *sys.Arch, out *ld.OutBuf, s *sym.Symbol, r *sym.Reloc, sectoff int64) bool {
- var v uint32
-
- rs := r.Xsym
-
- if rs.Type == sym.SHOSTOBJ || r.Type == objabi.R_CALL {
- if rs.Dynid < 0 {
- ld.Errorf(s, "reloc %d (%s) to non-macho symbol %s type=%d (%s)", r.Type, sym.RelocName(arch, r.Type), rs.Name, rs.Type, rs.Type)
- return false
- }
-
- v = uint32(rs.Dynid)
- v |= 1 << 27 // external relocation
- } else {
- v = uint32(rs.Sect.Extnum)
- if v == 0 {
- ld.Errorf(s, "reloc %d (%s) to symbol %s in non-macho section %s type=%d (%s)", r.Type, sym.RelocName(arch, r.Type), rs.Name, rs.Sect.Name, rs.Type, rs.Type)
- return false
- }
- }
-
- switch r.Type {
- default:
- return false
- case objabi.R_ADDR:
- v |= ld.MACHO_GENERIC_RELOC_VANILLA << 28
- case objabi.R_CALL,
- objabi.R_PCREL:
- v |= 1 << 24 // pc-relative bit
- v |= ld.MACHO_GENERIC_RELOC_VANILLA << 28
- }
-
- switch r.Siz {
- default:
- return false
- case 1:
- v |= 0 << 25
- case 2:
- v |= 1 << 25
- case 4:
- v |= 2 << 25
- case 8:
- v |= 3 << 25
- }
-
- out.Write32(uint32(sectoff))
- out.Write32(v)
- return true
+ return false
}
func pereloc1(arch *sys.Arch, out *ld.OutBuf, s *sym.Symbol, r *sym.Reloc, sectoff int64) bool {
}
func machoreloc1(arch *sys.Arch, out *ld.OutBuf, s *sym.Symbol, r *sym.Reloc, sectoff int64) bool {
- var v uint32
-
- rs := r.Xsym
-
- if r.Type == objabi.R_PCREL {
- if rs.Type == sym.SHOSTOBJ {
- ld.Errorf(s, "pc-relative relocation of external symbol is not supported")
- return false
- }
- if r.Siz != 4 {
- return false
- }
-
- // emit a pair of "scattered" relocations that
- // resolve to the difference of section addresses of
- // the symbol and the instruction
- // this value is added to the field being relocated
- o1 := uint32(sectoff)
- o1 |= 1 << 31 // scattered bit
- o1 |= ld.MACHO_ARM_RELOC_SECTDIFF << 24
- o1 |= 2 << 28 // size = 4
-
- o2 := uint32(0)
- o2 |= 1 << 31 // scattered bit
- o2 |= ld.MACHO_ARM_RELOC_PAIR << 24
- o2 |= 2 << 28 // size = 4
-
- out.Write32(o1)
- out.Write32(uint32(ld.Symaddr(rs)))
- out.Write32(o2)
- out.Write32(uint32(s.Value + int64(r.Off)))
- return true
- }
-
- if rs.Type == sym.SHOSTOBJ || r.Type == objabi.R_CALLARM {
- if rs.Dynid < 0 {
- ld.Errorf(s, "reloc %d (%s) to non-macho symbol %s type=%d (%s)", r.Type, sym.RelocName(arch, r.Type), rs.Name, rs.Type, rs.Type)
- return false
- }
-
- v = uint32(rs.Dynid)
- v |= 1 << 27 // external relocation
- } else {
- v = uint32(rs.Sect.Extnum)
- if v == 0 {
- ld.Errorf(s, "reloc %d (%s) to symbol %s in non-macho section %s type=%d (%s)", r.Type, sym.RelocName(arch, r.Type), rs.Name, rs.Sect.Name, rs.Type, rs.Type)
- return false
- }
- }
-
- switch r.Type {
- default:
- return false
-
- case objabi.R_ADDR:
- v |= ld.MACHO_GENERIC_RELOC_VANILLA << 28
-
- case objabi.R_CALLARM:
- v |= 1 << 24 // pc-relative bit
- v |= ld.MACHO_ARM_RELOC_BR24 << 28
- }
-
- switch r.Siz {
- default:
- return false
- case 1:
- v |= 0 << 25
-
- case 2:
- v |= 1 << 25
-
- case 4:
- v |= 2 << 25
-
- case 8:
- v |= 3 << 25
- }
-
- out.Write32(uint32(sectoff))
- out.Write32(v)
- return true
+ return false
}
func pereloc1(arch *sys.Arch, out *ld.OutBuf, s *sym.Symbol, r *sym.Reloc, sectoff int64) bool {
} else if ctxt.HeadType == objabi.Hdarwin {
if r.Type == objabi.R_CALL {
if ctxt.LinkMode == LinkExternal && rs.Type == sym.SDYNIMPORT {
- switch ctxt.Arch.Family {
- case sys.AMD64:
+ if ctxt.Arch.Family == sys.AMD64 {
// AMD64 dynamic relocations are relative to the end of the relocation.
o += int64(r.Siz)
- case sys.I386:
- // I386 dynamic relocations are relative to the start of the section.
- o -= int64(r.Off) // offset in symbol
- o -= int64(s.Value - int64(s.Sect.Vaddr)) // offset of symbol in section
}
} else {
if rs.Type != sym.SHOSTOBJ {
}
o -= int64(r.Off) // relative to section offset, not symbol
}
- } else if ctxt.Arch.Family == sys.ARM {
- // see ../arm/asm.go:/machoreloc1
- o += Symaddr(rs) - s.Value - int64(r.Off)
} else {
o += int64(r.Siz)
}
}
func machoreloc1(arch *sys.Arch, out *ld.OutBuf, s *sym.Symbol, r *sym.Reloc, sectoff int64) bool {
- var v uint32
-
- rs := r.Xsym
-
- if rs.Type == sym.SHOSTOBJ || r.Type == objabi.R_CALL {
- if rs.Dynid < 0 {
- ld.Errorf(s, "reloc %d (%s) to non-macho symbol %s type=%d (%s)", r.Type, sym.RelocName(arch, r.Type), rs.Name, rs.Type, rs.Type)
- return false
- }
-
- v = uint32(rs.Dynid)
- v |= 1 << 27 // external relocation
- } else {
- v = uint32(rs.Sect.Extnum)
- if v == 0 {
- ld.Errorf(s, "reloc %d (%s) to symbol %s in non-macho section %s type=%d (%s)", r.Type, sym.RelocName(arch, r.Type), rs.Name, rs.Sect.Name, rs.Type, rs.Type)
- return false
- }
- }
-
- switch r.Type {
- default:
- return false
- case objabi.R_ADDR:
- v |= ld.MACHO_GENERIC_RELOC_VANILLA << 28
- case objabi.R_CALL,
- objabi.R_PCREL:
- v |= 1 << 24 // pc-relative bit
- v |= ld.MACHO_GENERIC_RELOC_VANILLA << 28
- }
-
- switch r.Siz {
- default:
- return false
- case 1:
- v |= 0 << 25
- case 2:
- v |= 1 << 25
- case 4:
- v |= 2 << 25
- case 8:
- v |= 3 << 25
- }
-
- out.Write32(uint32(sectoff))
- out.Write32(v)
- return true
+ return false
}
func pereloc1(arch *sys.Arch, out *ld.OutBuf, s *sym.Symbol, r *sym.Reloc, sectoff int64) bool {