From: Cherry Zhang Date: Wed, 9 Dec 2020 17:14:00 +0000 (-0500) Subject: cmd/link: reject too-large relocation addend on darwin/arm64 X-Git-Tag: go1.16beta1~54 X-Git-Url: http://www.git.cypherpunks.su/?a=commitdiff_plain;h=b110733327a66870da9c5f482d8fd3275dae55f3;p=gostls13.git cmd/link: reject too-large relocation addend on darwin/arm64 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 Run-TryBot: Cherry Zhang TryBot-Result: Go Bot Reviewed-by: Than McIntosh --- diff --git a/src/cmd/link/internal/arm64/asm.go b/src/cmd/link/internal/arm64/asm.go index a7af855646..30819db4c6 100644 --- a/src/cmd/link/internal/arm64/asm.go +++ b/src/cmd/link/internal/arm64/asm.go @@ -463,6 +463,9 @@ func elfreloc1(ctxt *ld.Link, out *ld.OutBuf, ldr *loader.Loader, s loader.Sym, 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 @@ -486,6 +489,10 @@ func machoreloc1(arch *sys.Arch, out *ld.OutBuf, ldr *loader.Loader, s loader.Sy } } + 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