dwarf_loader: Mark functions that do not use expected registers for params

Calling conventions dictate which registers are used for function
parameters.

When a function is optimized however, we need to ensure that the
non-optimized parameters do not violate expectations about register use
as this would violate expectations for tracing.  At CU initialization,
create a mapping from parameter index to expected DW_OP_reg, and use it
to validate parameters match with expectations.  A parameter which is
passed via the stack, as a constant, or uses an unexpected register,
violates these expectations and it (and the associated function) are
marked as having unexpected register mapping.

Note though that there is as exception here that needs to be handled;
when a (typedef) struct is passed as a parameter, it can use multiple
registers so will throw off later register expectations.  Exempt
functions that have unexpected register usage _and_ struct parameters
(examples are found in the "tracing_struct" test).

Signed-off-by: Alan Maguire <alan.maguire@oracle.com>
Cc: Alexei Starovoitov <ast@kernel.org>
Cc: Andrii Nakryiko <andrii@kernel.org>
Cc: Daniel Borkmann <daniel@iogearbox.net>
Cc: Eduard Zingerman <eddyz87@gmail.com>
Cc: Hao Luo <haoluo@google.com>
Cc: Jiri Olsa <jolsa@kernel.org>
Cc: John Fastabend <john.fastabend@gmail.com>
Cc: KP Singh <kpsingh@chromium.org>
Cc: Kui-Feng Lee <sinquersw@gmail.com>
Cc: Martin KaFai Lau <martin.lau@kernel.org>
Cc: Song Liu <songliubraving@fb.com>
Cc: Stanislav Fomichev <sdf@google.com>
Cc: Timo Beckers <timo@incline.eu>
Cc: Yonghong Song <yhs@fb.com>
Cc: bpf@vger.kernel.org
Link: https://lore.kernel.org/r/1676675433-10583-2-git-send-email-alan.maguire@oracle.com
Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com>
2 files changed