feat(asm): emit the amd64 stack-split guard and morestack block

This commit is contained in:
2026-09-14 20:35:55 +02:00
parent 89fa6ea15e
commit 1d8e68c574
5 changed files with 500 additions and 23 deletions
+11 -1
View File
@@ -42,7 +42,8 @@ const (
sttSection = 3
stInfoShift = 4
rX8664PC32 = 2
rX8664PC32 = 2
rX8664TPOFF32 = 20
)
// elfSym is one symbol-table entry in construction.
@@ -125,11 +126,19 @@ func (img *Image) ELFObject() ([]byte, error) {
type elfRela struct {
off uint64
sym int
typ uint32
addend int64
}
var relas []elfRela
for _, fn := range img.Funcs {
for _, r := range fn.Relocs {
var typ uint32 = rX8664PC32
if r.Kind == RelTLSLE {
// R_X86_64_TPOFF32 resolves to the local-exec TLS offset and
// carries no symbol.
relas = append(relas, elfRela{off: uint64(fn.Offset + r.Off), sym: 0, typ: rX8664TPOFF32})
continue
}
idx, ok := symIdx[r.Name]
if !ok {
return nil, fmt.Errorf("relocation references unknown symbol %q", r.Name)
@@ -137,6 +146,7 @@ func (img *Image) ELFObject() ([]byte, error) {
relas = append(relas, elfRela{
off: uint64(fn.Offset + r.Off),
sym: idx,
typ: typ,
// R_X86_64_PC32 computes S + A − P with P the patch site; the
// assembler measures the symbol from the instruction end,
// After − Off bytes past the field, so the addend carries