[Dwarf-Discuss] compilers generating ABI non-compliant function calls?

Jakub Jelinek jakub@redhat.com
Tue Mar 9 19:28:57 GMT 2021


On Tue, Mar 09, 2021 at 11:16:01AM -0800, David Blaikie via Dwarf-Discuss wrote:
> void f1(int i) { }
> 
> to include a DW_AT_location with fbreg, nothing about how the ABI
> represents 'i' - so that would be an ABI gap.
> 
> In the cases where the compiler does modify any ABI-relevant properties,
> how would the DWARF consumer know that /that/ location represents the ABI
> calling convention, but the above fbreg location does not?
> 
> At least for Clang - the two cases of DAE described below (either modifying
> a parameter to be unused but present (because the signature must be
> maintained for external callers) and truly removing the parameter (thus
> shifting other parameters down)) would be indistinguishable in any DWARF I
> can imagine - in both cases the parameter would have no DW_AT_location. Any
> idea how GCC handles that, if it does that kind of optimization?

If GCC optimizes away some parameter (of course that is possible only for
functions not exported from TUs or on non-exported copies of the exported
functions), e.g. with
static __attribute__((noinline)) int foo (int x, int y) { return x; }
int bar (void) { return foo (3, 17) + foo (3, 18) + foo (3, 19); }
it will emit:
        .uleb128 0xa    # (DIE (0xb9) DW_TAG_formal_parameter)
        .long   0x85    # DW_AT_abstract_origin
        .byte   0x3     # DW_AT_const_value
for the x case (where the parameter has been optimized away and is known to
be 3 in all cases) and for y uses a GNU extension (that has been added too
late in the DWARF5 cycle so it was too late to propose it for DWARF5)
        .uleb128 0x9    # (DIE (0xad) DW_TAG_formal_parameter)
        .long   0x8d    # DW_AT_abstract_origin
        .uleb128 0x6    # DW_AT_location
        .byte   0xfa    # DW_OP_GNU_parameter_ref
        .long   0x8d
        .byte   0x9f    # DW_OP_stack_value
which has a reference to the formal parameter and value can be (with luck)
found in DW_TAG_call_site_parameter in the callers.

	Jakub




More information about the Dwarf-discuss mailing list