Commit 7d2c6eb3 authored by Ilya Tocar's avatar Ilya Tocar Committed by Keith Randall

cmd/internal/obj/x86: align functions with trap instruction

Align functions with 0xCC (INT $3) - breakpoint instruction,
instead of 0x00, which can disassemble into valid instruction.

Change-Id: Ieda191886efc4aacb86f58bea1169fd1b3b57636
Reviewed-on: https://go-review.googlesource.com/16102
Run-TryBot: Ilya Tocar <ilya.tocar@intel.com>
Reviewed-by: 's avatarGregory Shimansky <gregory.shimansky@intel.com>
TryBot-Result: Gobot Gobot <gobot@golang.org>
Reviewed-by: 's avatarKeith Randall <khr@golang.org>
parent 77b1fef2
......@@ -1754,7 +1754,16 @@ func span6(ctxt *obj.Link, s *obj.LSym) {
c = naclpad(ctxt, s, c, -c&31)
}
c += -c & (FuncAlign - 1)
// Pad functions with trap instruction, to catch invalid jumps
if c&(FuncAlign-1) != 0 {
v = -c & (FuncAlign - 1)
obj.Symgrow(ctxt, s, int64(c)+int64(v))
for i := c; i < c+v; i++ {
// 0xCC is INT $3 - breakpoint instruction
s.P[i] = uint8(0xCC)
}
c += v
}
s.Size = int64(c)
if false { /* debug['a'] > 1 */
......
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