Why do compilers introduce INT3 statements between routines?

When debugging some software, I noticed that in many cases, INT3 instructions are inserted between routines.

That's an example.

I assume that they are not technically inserted “between” functions, but instead, to pause execution if the routine does not execute retnat the end for any reason.

Are my assumptions correct? What is the purpose of these instructions, if not?

+4
source share
2 answers

On Linux, gcc and clang pad with 0x90 (NOP) to align functions. (Even the linker does this when linking .oto sections of uneven size).

, , , RET . NOP , , , .


RET; JMP (, ). . ( CALL/RET . , RET JMP, jmp [rsp] add rsp, 8).

JMP CALL ( ) . (-, , , , .)

-, CPU , , FP sqrt , , - , . , - TLB, .

INT 3, , . CPU INT , , . IIRC, - JMP, .


16B , RET, . 4 , RET, , . ( ). - (, RET), .

LCP- Intel: AMD L1 . (Intel -uop .)

, Intel , . , Sandybridge :

David Kanter's SnB writeup

( . Sandybridge, .)

. Agar Fog microarch pdf x86 wiki, , ( ).

+4

.

, . , , .

INT 3 . , , , . , . , "debug break". , . retn, , .

+5

Source: https://habr.com/ru/post/1658190/