# In-Class Exercise 10: Unwind Information Consider the following assembly code generated by GCC: func1: /* 0*/ push rbp /* 1*/ movsx rax, edi /* 4*/ mov rbp, rsp /* 7*/ push r12 /* 9*/ push rbx /* a*/ mov rbx, rax /* d*/ lea rax, [15+rax*4] /*15*/ and rax, -16 /*19*/ sub rsp, rax /*1c*/ lea rdi, [rsp+3] /*21*/ mov r12, rdi /*24*/ and rdi, -4 /*28*/ call ext2 /*2d*/ shr r12, 2 /*31*/ mov eax, DWORD PTR [0+r12*4] /*39*/ lea rsp, [rbp-16] /*3d*/ add eax, ebx /*3f*/ pop rbx /*40*/ pop r12 /*42*/ pop rbp /*43*/ ret func2: /* 0*/ push rbp /* 1*/ mov rbp, rsp /* 4*/ push r15 /* 6*/ push r14 /* 8*/ push r13 /* a*/ mov r13d, edi /* d*/ push r12 /* f*/ mov r12d, esi /*12*/ push rbx /*13*/ mov ebx, edi /*15*/ sub rsp, 8 /*19*/ cmp edi, esi /*1b*/ jge .L5 .L11: /*1d*/ mov eax, ebx /*1f*/ and eax, 3 /*22*/ je .L6 /*24*/ cmp eax, 2 /*27*/ je .L7 /*29*/ movsx rax, ebx /*2c*/ mov r14, rsp /*2f*/ lea rax, [15+rax*4] /*37*/ and rax, -16 /*3b*/ sub rsp, rax /*3e*/ lea rdi, [rsp+3] /*43*/ mov r15, rdi /*46*/ and rdi, -4 /*4a*/ call ext2 /*4f*/ shr r15, 2 /*53*/ add ebx, DWORD PTR [0+r15*4] /*5b*/ mov rsp, r14 .L9: /*5e*/ cmp r12d, ebx /*61*/ jg .L11 .L5: /*63*/ lea rsp, [rbp-40] /*67*/ mov eax, r12d /*6a*/ imul eax, ebx /*6d*/ pop rbx /*6e*/ pop r12 /*70*/ pop r13 /*72*/ pop r14 /*74*/ pop r15 /*76*/ pop rbp /*77*/ ret .p2align 4,,10 .p2align 3 .L6: /*80*/ mov edi, ebx /*82*/ mov esi, r12d /*85*/ call ext1 /*8a*/ lea ebx, [rax+r13] /*8e*/ jmp .L9 .p2align 4,,10 .p2align 3 .L7: /*90*/ mov esi, ebx /*92*/ mov edi, r12d /*95*/ call ext1 /*9a*/ lea rsp, [rbp-40] /*9e*/ pop rbx /*9f*/ add eax, r13d /*a2*/ pop r12 /*a4*/ pop r13 /*a6*/ pop r14 /*a8*/ pop r15 /*aa*/ pop rbp /*ab*/ ret 1. What does a typical CIE on x86-64 look like? Use `llvm-dwarfdump --eh-frame` on some binary (`/bin/false` should do). 2. Construct the call frame information (CFI) table for both functions. 3. Encode the CFI tables with DWARF CFI bytecode instructions. Make sure unwind info is correct at every instruction boundary. Refer to the lecture slides and/or the DWARF5 standard (Sec. 6.4.2) and look for viable instructions. 4. Can you reduce the size of the bytecode by changing or omitting instructions while maintaining correctness? 5. Can you optimize for the case that the unwind info only has to be correct at function calls? ## Solution (1–3) ``` # C input base64 -d <