Re: pahole -J mishandles types in function scope

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



On Tue, 2025-01-14 at 13:14 +0000, Giuliano Procida wrote:
> Tested with pahole v1.24.
> 
> The following code, when compiled with either GCC 14 or Clang 16 or
> several other versions, and post processed with pahole -J, results in
> the private definition of foo in bar being exposed as part of the type
> of baz in BTF - which is definitely wrong.
> 
> struct foo;
> 
> int bar() {
>   struct foo {
>     int x;
>   };
>   struct foo j = { 0 };
>   struct foo k = j;
>   return j.x == k.x;
> }
> 
> int baz(struct foo* j) {
>   return j != 0;
> }
> 
> Note that we had exactly the same bug in STG and I resolved it by
> pushing an anonymous scope before processing the function child DIEs
> (we deal with C++ scopes). You could perhaps push / pop a flag which
> inhibits type definition processing.
> 
> It's not possible to just ignore type DIEs inside functions because
> (at least) Clang sometimes emits references outside the function to
> such DIEs.
> 
> Regards,
> Giuliano.
> 

Hi Giuliano,

Thank you for the report, indeed, the BTF generated for your example is:

    [1] STRUCT 'foo' size=4 vlen=1
            'x' type_id=2 bits_offset=0
    [2] INT 'int' size=4 bits_offset=0 nr_bits=32 encoding=SIGNED
    [3] PTR '(anon)' type_id=1
    [4] FUNC_PROTO '(anon)' ret_type_id=2 vlen=0
    [5] FUNC 'bar' type_id=4 linkage=static
    [6] FUNC_PROTO '(anon)' ret_type_id=2 vlen=1
            'j' type_id=3        // <-------------- this is wrong
    [7] FUNC 'baz' type_id=6 linkage=static

Thanks,
Eduard






[Index of Archives]     [Linux USB Devel]     [Linux Audio Users]     [Yosemite News]     [Linux Kernel]     [Linux SCSI]

  Powered by Linux