Mach-O relocation addend is signed 24-bit. If the addend
overflows, it is better to fail the build than emitting an
incorrect binary. (I'm still working on a fix.)
Updates #42738.
Change-Id: I647f0cd4f6b84d9ac75ef3bf36673bea01dfc211
Reviewed-on: https://go-review.googlesource.com/c/go/+/276694
Trust: Cherry Zhang <cherryyz@google.com>
Run-TryBot: Cherry Zhang <cherryyz@google.com>
TryBot-Result: Go Bot <gobot@golang.org>
Reviewed-by: Than McIntosh <thanm@google.com>
return true
}
+// sign-extends from 24-bit.
+func signext24(x int64) int64 { return x << 40 >> 40 }
+
func machoreloc1(arch *sys.Arch, out *ld.OutBuf, ldr *loader.Loader, s loader.Sym, r loader.ExtReloc, sectoff int64) bool {
var v uint32
}
}
+ if r.Xadd != signext24(r.Xadd) {
+ ldr.Errorf(s, "relocation addend overflow: %s+0x%x", ldr.SymName(rs), r.Xadd)
+ }
+
switch rt {
default:
return false