On Wed, Jan 14, 2026 at 7:44 PM Y Song <[email protected]> wrote:

> Thanks. Now let us say I will not try to add those "changed function
> signatures" to dwarf
> and actually rely on dwarf locations to somehow recover parameters.


That isn't possible, so far as I can see - DWARF only describes how to
access the parameters from inside the function, not how they were passed on
the call. (eg: an unoptimized build will probably describe the parameters
as being in stack memory even though the values were passed in registers -
because the prologue moves the values from registers to memory, and the
DWARF locations only have to be valid after the prologue)


> I understand
> in some cases, it is not easy to recover if dwarf locations are too
> complicated and we
> might ignore those cases.
>
> I actually want to ask how to identify whether the return type is
> changed or not in dwarf.
> The following is an example:
>
> $ cat test.c
> #include <stdio.h>
> unsigned tar(int a);
> __attribute__((noinline)) static int foo(int a, int b)
> {
>   return tar(a) + tar(a + 1);
> }
> __attribute__((noinline)) int bar(int a)
> {
>   foo(a, 1);
>   return 0;
> }
>
> In this particular case, the return value of foo() is actually not used
> and the compiler will optimize it away with returning void in llvm.
>

https://dwarfstd.org/issues/221105.1.html in DWARFv6 might help provide
some of this information & is closer to an ABI-encoding than we have for
parameters.


>
> $ clang -O2 -g -c test.c
> $ llvm-dwarfdump test.o
> ...
> 0x0000004e:   DW_TAG_subprogram
>                 DW_AT_low_pc    (0x0000000000000010)
>                 DW_AT_high_pc   (0x0000000000000022)
>                 DW_AT_frame_base        (DW_OP_reg7 RSP)
>                 DW_AT_call_all_calls    (true)
>                 DW_AT_name      ("foo")
>                 DW_AT_decl_file
> ("/home/yhs/tests/sig-change/deadret/test.c")
>                 DW_AT_decl_line (3)
>                 DW_AT_prototyped        (true)
>                 DW_AT_calling_convention        (DW_CC_nocall)
>                 DW_AT_type      (0x00000096 "int")
>
> 0x0000005e:     DW_TAG_formal_parameter
>                   DW_AT_location        (indexed (0x1) loclist =
> 0x00000022:
>                      [0x0000000000000010, 0x0000000000000018): DW_OP_reg5
> RDI
>                      [0x0000000000000018, 0x000000000000001a): DW_OP_reg3
> RBX
>                      [0x000000000000001a, 0x0000000000000022):
> DW_OP_entry_value(DW_OP_reg5 RDI), DW_OP_stack_value)
>                   DW_AT_name    ("a")
>                   DW_AT_decl_file
> ("/home/yhs/tests/sig-change/deadret/test.c")
>                   DW_AT_decl_line       (3)
>                   DW_AT_type    (0x00000096 "int")
>
> 0x00000067:     DW_TAG_formal_parameter
>                   DW_AT_name    ("b")
>                   DW_AT_decl_file
> ("/home/yhs/tests/sig-change/deadret/test.c")
>                   DW_AT_decl_line       (3)
>                   DW_AT_type    (0x00000096 "int")
> ...
> Assembly code:
> 0000000000000000 <bar>:
>        0: 50                            pushq   %rax
>        1: e8 0a 00 00 00                callq   0x10 <foo>
>        6: 31 c0                         xorl    %eax, %eax
>        8: 59                            popq    %rcx
>        9: c3                            retq
>        a: 66 0f 1f 44 00 00             nopw    (%rax,%rax)
>
> 0000000000000010 <foo>:
>       10: 53                            pushq   %rbx
>       11: 89 fb                         movl    %edi, %ebx
>       13: e8 00 00 00 00                callq   0x18 <foo+0x8>
>       18: ff c3                         incl    %ebx
>       1a: 89 df                         movl    %ebx, %edi
>       1c: 5b                            popq    %rbx
>       1d: e9 00 00 00 00                jmp     0x22 <foo+0x12>
>
> The compiler knows whether the return type has changed or not.
> Unfortunately the information is not available in dwarf.
>
> Any suggestions to add some additional information in dwarf so we can
> find whether the return type is changed or not?
>
-- 
Dwarf-discuss mailing list
[email protected]
https://lists.dwarfstd.org/mailman/listinfo/dwarf-discuss

Reply via email to