mirror of
https://github.com/golang/go
synced 2024-09-29 19:14:28 -06:00
cmd/link: put padding between functions, not at the end of a function
Functions should be declared to end after the last real instruction, not after the last padding byte. We achieve this by adding the padding while assembling the text section in the linker instead of adding the padding to the function symbol in the compiler. This change makes dtrace happy. TODO: check that this works with external linking Fixes #15969 Change-Id: I973e478d0cd34b61be1ddc55410552cbd645ad62 Reviewed-on: https://go-review.googlesource.com/24040 Run-TryBot: Keith Randall <khr@golang.org> TryBot-Result: Gobot Gobot <gobot@golang.org> Reviewed-by: Ian Lance Taylor <iant@golang.org>
This commit is contained in:
parent
595426c0d9
commit
5701174c52
@ -1986,16 +1986,6 @@ func span6(ctxt *obj.Link, s *obj.LSym) {
|
|||||||
c = naclpad(ctxt, s, c, -c&31)
|
c = naclpad(ctxt, s, c, -c&31)
|
||||||
}
|
}
|
||||||
|
|
||||||
// Pad functions with trap instruction, to catch invalid jumps
|
|
||||||
if c&(FuncAlign-1) != 0 {
|
|
||||||
v := -c & (FuncAlign - 1)
|
|
||||||
s.Grow(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)
|
s.Size = int64(c)
|
||||||
|
|
||||||
if false { /* debug['a'] > 1 */
|
if false { /* debug['a'] > 1 */
|
||||||
|
@ -615,7 +615,8 @@ func asmb() {
|
|||||||
|
|
||||||
sect := ld.Segtext.Sect
|
sect := ld.Segtext.Sect
|
||||||
ld.Cseek(int64(sect.Vaddr - ld.Segtext.Vaddr + ld.Segtext.Fileoff))
|
ld.Cseek(int64(sect.Vaddr - ld.Segtext.Vaddr + ld.Segtext.Fileoff))
|
||||||
ld.Codeblk(int64(sect.Vaddr), int64(sect.Length))
|
// 0xCC is INT $3 - breakpoint instruction
|
||||||
|
ld.CodeblkPad(int64(sect.Vaddr), int64(sect.Length), []byte{0xCC})
|
||||||
for sect = sect.Next; sect != nil; sect = sect.Next {
|
for sect = sect.Next; sect != nil; sect = sect.Next {
|
||||||
ld.Cseek(int64(sect.Vaddr - ld.Segtext.Vaddr + ld.Segtext.Fileoff))
|
ld.Cseek(int64(sect.Vaddr - ld.Segtext.Vaddr + ld.Segtext.Fileoff))
|
||||||
ld.Datblk(int64(sect.Vaddr), int64(sect.Length))
|
ld.Datblk(int64(sect.Vaddr), int64(sect.Length))
|
||||||
|
@ -790,11 +790,14 @@ func blk(start *LSym, addr int64, size int64) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func Codeblk(addr int64, size int64) {
|
func Codeblk(addr int64, size int64) {
|
||||||
|
CodeblkPad(addr, size, zeros[:])
|
||||||
|
}
|
||||||
|
func CodeblkPad(addr int64, size int64, pad []byte) {
|
||||||
if Debug['a'] != 0 {
|
if Debug['a'] != 0 {
|
||||||
fmt.Fprintf(Bso, "codeblk [%#x,%#x) at offset %#x\n", addr, addr+size, Cpos())
|
fmt.Fprintf(Bso, "codeblk [%#x,%#x) at offset %#x\n", addr, addr+size, Cpos())
|
||||||
}
|
}
|
||||||
|
|
||||||
blkSlice(Ctxt.Textp, addr, size)
|
blkSlice(Ctxt.Textp, addr, size, pad)
|
||||||
|
|
||||||
/* again for printing */
|
/* again for printing */
|
||||||
if Debug['a'] == 0 {
|
if Debug['a'] == 0 {
|
||||||
@ -858,7 +861,7 @@ func Codeblk(addr int64, size int64) {
|
|||||||
// blkSlice is a variant of blk that processes slices.
|
// blkSlice is a variant of blk that processes slices.
|
||||||
// After text symbols are converted from a linked list to a slice,
|
// After text symbols are converted from a linked list to a slice,
|
||||||
// delete blk and give this function its name.
|
// delete blk and give this function its name.
|
||||||
func blkSlice(syms []*LSym, addr, size int64) {
|
func blkSlice(syms []*LSym, addr, size int64, pad []byte) {
|
||||||
for i, s := range syms {
|
for i, s := range syms {
|
||||||
if s.Type&obj.SSUB == 0 && s.Value >= addr {
|
if s.Type&obj.SSUB == 0 && s.Value >= addr {
|
||||||
syms = syms[i:]
|
syms = syms[i:]
|
||||||
@ -880,13 +883,13 @@ func blkSlice(syms []*LSym, addr, size int64) {
|
|||||||
errorexit()
|
errorexit()
|
||||||
}
|
}
|
||||||
if addr < s.Value {
|
if addr < s.Value {
|
||||||
strnput("", int(s.Value-addr))
|
strnputPad("", int(s.Value-addr), pad)
|
||||||
addr = s.Value
|
addr = s.Value
|
||||||
}
|
}
|
||||||
Cwrite(s.P)
|
Cwrite(s.P)
|
||||||
addr += int64(len(s.P))
|
addr += int64(len(s.P))
|
||||||
if addr < s.Value+s.Size {
|
if addr < s.Value+s.Size {
|
||||||
strnput("", int(s.Value+s.Size-addr))
|
strnputPad("", int(s.Value+s.Size-addr), pad)
|
||||||
addr = s.Value + s.Size
|
addr = s.Value + s.Size
|
||||||
}
|
}
|
||||||
if addr != s.Value+s.Size {
|
if addr != s.Value+s.Size {
|
||||||
@ -899,7 +902,7 @@ func blkSlice(syms []*LSym, addr, size int64) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
if addr < eaddr {
|
if addr < eaddr {
|
||||||
strnput("", int(eaddr-addr))
|
strnputPad("", int(eaddr-addr), pad)
|
||||||
}
|
}
|
||||||
Cflush()
|
Cflush()
|
||||||
}
|
}
|
||||||
@ -909,7 +912,7 @@ func Datblk(addr int64, size int64) {
|
|||||||
fmt.Fprintf(Bso, "datblk [%#x,%#x) at offset %#x\n", addr, addr+size, Cpos())
|
fmt.Fprintf(Bso, "datblk [%#x,%#x) at offset %#x\n", addr, addr+size, Cpos())
|
||||||
}
|
}
|
||||||
|
|
||||||
blkSlice(datap, addr, size)
|
blkSlice(datap, addr, size, zeros[:])
|
||||||
|
|
||||||
/* again for printing */
|
/* again for printing */
|
||||||
if Debug['a'] == 0 {
|
if Debug['a'] == 0 {
|
||||||
@ -986,23 +989,27 @@ func Dwarfblk(addr int64, size int64) {
|
|||||||
var zeros [512]byte
|
var zeros [512]byte
|
||||||
|
|
||||||
// strnput writes the first n bytes of s.
|
// strnput writes the first n bytes of s.
|
||||||
// If n is larger then len(s),
|
// If n is larger than len(s),
|
||||||
// it is padded with NUL bytes.
|
// it is padded with NUL bytes.
|
||||||
func strnput(s string, n int) {
|
func strnput(s string, n int) {
|
||||||
|
strnputPad(s, n, zeros[:])
|
||||||
|
}
|
||||||
|
|
||||||
|
// strnput writes the first n bytes of s.
|
||||||
|
// If n is larger than len(s),
|
||||||
|
// it is padded with the bytes in pad (repeated as needed).
|
||||||
|
func strnputPad(s string, n int, pad []byte) {
|
||||||
if len(s) >= n {
|
if len(s) >= n {
|
||||||
Cwritestring(s[:n])
|
Cwritestring(s[:n])
|
||||||
} else {
|
} else {
|
||||||
Cwritestring(s)
|
Cwritestring(s)
|
||||||
n -= len(s)
|
n -= len(s)
|
||||||
for n > 0 {
|
for n > len(pad) {
|
||||||
if len(zeros) >= n {
|
Cwrite(pad)
|
||||||
Cwrite(zeros[:n])
|
n -= len(pad)
|
||||||
return
|
|
||||||
} else {
|
|
||||||
Cwrite(zeros[:])
|
|
||||||
n -= len(zeros)
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
Cwrite(pad[:n])
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -609,7 +609,8 @@ func asmb() {
|
|||||||
|
|
||||||
sect := ld.Segtext.Sect
|
sect := ld.Segtext.Sect
|
||||||
ld.Cseek(int64(sect.Vaddr - ld.Segtext.Vaddr + ld.Segtext.Fileoff))
|
ld.Cseek(int64(sect.Vaddr - ld.Segtext.Vaddr + ld.Segtext.Fileoff))
|
||||||
ld.Codeblk(int64(sect.Vaddr), int64(sect.Length))
|
// 0xCC is INT $3 - breakpoint instruction
|
||||||
|
ld.CodeblkPad(int64(sect.Vaddr), int64(sect.Length), []byte{0xCC})
|
||||||
for sect = sect.Next; sect != nil; sect = sect.Next {
|
for sect = sect.Next; sect != nil; sect = sect.Next {
|
||||||
ld.Cseek(int64(sect.Vaddr - ld.Segtext.Vaddr + ld.Segtext.Fileoff))
|
ld.Cseek(int64(sect.Vaddr - ld.Segtext.Vaddr + ld.Segtext.Fileoff))
|
||||||
ld.Datblk(int64(sect.Vaddr), int64(sect.Length))
|
ld.Datblk(int64(sect.Vaddr), int64(sect.Length))
|
||||||
|
Loading…
Reference in New Issue
Block a user