Skip to content

Commit c0d5714

Browse files
committed
v2.x64: add endbr64 (0xF3 0x0F 0x1E 0xFA) at the start of every function prologue
Necessary if the binary was linked with glibc compiled with CET (Control-flow Enforcement Technology) support, which adds a .note.gnu.property indicating IBT (Indirect Branch Tracking) is required. When __libc_start_main calls main via an indirect call, the CPU checks that the target starts with endbr64. Since main started with push rbp instead, the CPU raised a Control Protection fault = SIGSEGV (exit code 11).
1 parent 12f6554 commit c0d5714

1 file changed

Lines changed: 5 additions & 0 deletions

File tree

‎vlib/v2/gen/x64/x64.v‎

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -126,6 +126,11 @@ fn (mut g Gen) gen_func(func ssa.Function) {
126126
g.elf.add_symbol(func.name, u64(g.curr_offset), true, 1)
127127

128128
// Prologue
129+
// endbr64 - required for CET/IBT (Indirect Branch Tracking)
130+
g.emit(0xF3)
131+
g.emit(0x0F)
132+
g.emit(0x1E)
133+
g.emit(0xFA)
129134
g.emit(0x55) // push rbp
130135
g.emit(0x48)
131136
g.emit(0x89)

0 commit comments

Comments
 (0)