CFI Directives

Hi Rafael,

I've been staring at the CFI directives and have a question. Some background: I want to generate the compact unwind information using just the CFI directives. I *think* that this should be doable. The issue I'm facing right now is that I need to know how much the stack pointer was adjusted. So when I have something like this:

        .cfi_startproc
Lfunc_begin175:
        pushq %rbp
Ltmp1532:
        .cfi_def_cfa_offset 16
Ltmp1533:
        .cfi_offset %rbp, -16
        movq %rsp, %rbp
Ltmp1534:
        .cfi_def_cfa_register %rbp
        pushq %r15
        pushq %r14
        pushq %rbx
        subq $3224, %rsp ## imm = 0xC98
Ltmp1535:
        .cfi_offset %rbx, -40
Ltmp1536:
        .cfi_offset %r14, -32
Ltmp1537:
        .cfi_offset %r15, -24

I need to be able to know that `%rsp' was adjusted by 3224. However, there are no CFI directives that encode this information. Is this something which cannot be encoded in CFI? or if it can be, what's the best way?

-bw

In this case that is not encoded because what is encoded is that the
call frame in that region is rbp. Without a frame pointer, compiling

void f(void *);
void g(void) {
  f(alloca(100));
}

produces

pushq %rbx
Ltmp2:
.cfi_def_cfa_offset 16
subq $112, %rsp
Ltmp3:
.cfi_def_cfa_offset 128
Ltmp4:
.cfi_offset %rbx, -16

Which does contain the rsp updates. The two places I can think with
some documentation are

http://www.dwarfstd.org/doc/DWARF4.pdf (the 6.4 Call Frame Information
section). This is the old .debug_frame, but that is where the idea
came from.

http://refspecs.linuxfoundation.org/LSB_4.1.0/LSB-Core-generic/LSB-Core-generic/ehframechpt.html
http://refspecs.linuxfoundation.org/LSB_4.1.0/LSB-Core-generic/LSB-Core-generic/dwarfext.html#AEN1154

Cheers,
Rafael

Hi Rafael,

I've been staring at the CFI directives and have a question. Some background: I want to generate the compact unwind information using just the CFI directives. I *think* that this should be doable. The issue I'm facing right now is that I need to know how much the stack pointer was adjusted. So when I have something like this:

       .cfi_startproc
Lfunc_begin175:
       pushq %rbp
Ltmp1532:
       .cfi_def_cfa_offset 16
Ltmp1533:
       .cfi_offset %rbp, -16
       movq %rsp, %rbp
Ltmp1534:
       .cfi_def_cfa_register %rbp
       pushq %r15
       pushq %r14
       pushq %rbx
       subq $3224, %rsp ## imm = 0xC98
Ltmp1535:
       .cfi_offset %rbx, -40
Ltmp1536:
       .cfi_offset %r14, -32
Ltmp1537:
       .cfi_offset %r15, -24

I need to be able to know that `%rsp' was adjusted by 3224. However, there are no CFI directives that encode this information. Is this something which cannot be encoded in CFI? or if it can be, what's the best way?

In this case that is not encoded because what is encoded is that the
call frame in that region is rbp. Without a frame pointer, compiling

void f(void *);
void g(void) {
f(alloca(100));
}

produces

pushq %rbx
Ltmp2:
.cfi_def_cfa_offset 16
subq $112, %rsp
Ltmp3:
.cfi_def_cfa_offset 128
Ltmp4:
.cfi_offset %rbx, -16

Which does contain the rsp updates.

Okay. That makes what I need to do easier. Thanks! :slight_smile:

The two places I can think with
some documentation are

http://www.dwarfstd.org/doc/DWARF4.pdf (the 6.4 Call Frame Information
section). This is the old .debug_frame, but that is where the idea
came from.

Exception Frames
DWARF Extensions

Thanks again. :slight_smile:

-bw