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

David Blaikie dblaikie@gmail.com
Tue Mar 9 23:22:35 GMT 2021


On Tue, Mar 9, 2021 at 11:52 AM Jakub Jelinek <jakub at redhat.com> wrote:

> On Tue, Mar 09, 2021 at 11:43:54AM -0800, David Blaikie wrote:
> > Thanks for the details! So in this case GCC changes the ABI of foo(int x,
> > int y) to be equivalent to foo(int y) and the parameter description of
> 'y'
>
> No, it is actually equivalent to foo(void)


Ah, I see - the used parameter is constant, so it doesn't need to be passed
(it was constant propagated from all callers to the callee) and the varied
parameter was unused so it didn't need to be passed either.


> but DW_TAG_call_site_parameter
> in those cases holds the value the optimized away parameter would have if
> it
> would be passed.

So, when the consumer evaluates DW_OP_GNU_parameter_ref, it handles it
> similarly to DW_OP_entry_value, unwinds to caller if it can identify it,
> and just looks up if some value is specified for it in that particular
> caller.
>

Could you help me understand more how DW_OP_GNU_parameter_ref
works/differently from DW_OP_entry_value?

> Does GCC do anything like the LLVM optimization when the function is
> > externally visible, but some callers are visible to the optimizer - and
> the
> > compiler concludes that since the parameter is unused inside the function
> > implementation those callers can be modified to pass effectively garbage
> in
> > that parameter? And what sort of DWARF does GCC use to describe that?
>
> I think GCC doesn't do that, instead it would if considered beneficial
> copy the function to a non-exported one and optimize away the parameters in
> there (etc.).


Ah, OK - in which case there would be no DWARF for the copy? And the
original function would look as though it were "optimized away" (ie: not
have any DW_AT_low/high_pc, etc)?


> Also note that the callee is exported, there is the question
> if it can be semantically interposed (for GCC yes by default with
> -fpic/-fPIC unless playing e.g. with visibility attributes) and in that
> case
> you don't know if the parameter will be unused there.
>

Ah, yeah, this only applies in the non-interposable case.

- Dave
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.dwarfstd.org/pipermail/dwarf-discuss-dwarfstd.org/attachments/20210309/9918219f/attachment.html>



More information about the Dwarf-discuss mailing list