Hi -

> Let us say there is a kernel function map_create().
> The source signature:
> 
>     typedef struct {
>        union {
>                 void            *kernel;
>                 void __user     *user;
>         };
>         bool            is_kernel : 1;
>     } sockptr_t;
>     typedef sockptr_t bpfptr_t;
>     static int map_create(union bpf_attr *attr, bpfptr_t uattr) { ... }
> 
> Eventually after optimization, it becomes:
>     static int map_create(union bpf_attr *attr, bool is_kernel) { ... }

Well, no, it doesn't.  There's no equivalent C "signature" generated
by the compiler for a random optimized clone of a function, which you
could use to take ABI heuristic shortcuts to generate interoperable code.


> The dwarf:
> 0x0186acca:     DW_TAG_formal_parameter
>                   DW_AT_location        (indexed (0x2b3) loclist = 0x00256a31:
>                      [0xffffffff814a7f15, 0xffffffff814a7f34):
> DW_OP_piece 0x8, DW_OP_reg4 RSI, DW_OP_piece 0x1
>                      [0xffffffff814a7f34, 0xffffffff814a7f64):
> DW_OP_piece 0x8, DW_OP_reg6 RBP, DW_OP_piece 0x1
>                      [0xffffffff814a7f6a, 0xffffffff814a83fb):
> DW_OP_piece 0x8, DW_OP_reg6 RBP, DW_OP_piece 0x1)
>                   DW_AT_name    ("uattr")
>                   DW_AT_decl_file
> ("/home/yhs/work/bpf-next/kernel/bpf/syscall.c")
>                   DW_AT_decl_line       (1375)
>                   DW_AT_type    (0x0186a002 "bpfptr_t")

Right, 8 bytes of holes for the parts of the structs that didn't need
passing to this particular optimized copy.


> Not sure how to recover the true signature from the above?

Perhaps this is the wrong way to think about it.  There is no "true
signature" per se that is necessarily expressible in C.  Some
parameters are passed somewhere in registers/memory.  By decoding the
location lists, you can enumerate source-level parameters, find what
pieces may be found where.  

Code that to read/write these values has to be deeply aware of where
to look, since compilers are not bound to any particular ABI for these
static functions.  That means the code would also be aware which parts
have been optimized away, and could reject accesses to such pieces.

(systemtap and debuggers have had to do all this for decades. :-)


- FChE

-- 
Dwarf-discuss mailing list
[email protected]
https://lists.dwarfstd.org/mailman/listinfo/dwarf-discuss

Reply via email to