Patch "libbpf: Fix BTF dump of pointer-to-array-of-struct" has been added to the 5.10-stable tree

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

 



This is a note to let you know that I've just added the patch titled

    libbpf: Fix BTF dump of pointer-to-array-of-struct

to the 5.10-stable tree which can be found at:
    http://www.kernel.org/git/?p=linux/kernel/git/stable/stable-queue.git;a=summary

The filename of the patch is:
     libbpf-fix-btf-dump-of-pointer-to-array-of-struct.patch
and it can be found in the queue-5.10 subdirectory.

If you, or anyone else, feels it should not be added to the stable tree,
please let <stable@xxxxxxxxxxxxxxx> know about it.



commit 981b57f442f4853fc4745235dab7540dfa232939
Author: Jean-Philippe Brucker <jean-philippe@xxxxxxxxxx>
Date:   Fri Mar 19 12:25:54 2021 +0100

    libbpf: Fix BTF dump of pointer-to-array-of-struct
    
    [ Upstream commit 901ee1d750f29a335423eeb9463c3ca461ca18c2 ]
    
    The vmlinux.h generated from BTF is invalid when building
    drivers/phy/ti/phy-gmii-sel.c with clang:
    
    vmlinux.h:61702:27: error: array type has incomplete element type â??struct reg_fieldâ??
    61702 |  const struct reg_field (*regfields)[3];
          |                           ^~~~~~~~~
    
    bpftool generates a forward declaration for this struct regfield, which
    compilers aren't happy about. Here's a simplified reproducer:
    
            struct inner {
                    int val;
            };
            struct outer {
                    struct inner (*ptr_to_array)[2];
            } A;
    
    After build with clang -> bpftool btf dump c -> clang/gcc:
    ./def-clang.h:11:23: error: array has incomplete element type 'struct inner'
            struct inner (*ptr_to_array)[2];
    
    Member ptr_to_array of struct outer is a pointer to an array of struct
    inner. In the DWARF generated by clang, struct outer appears before
    struct inner, so when converting BTF of struct outer into C, bpftool
    issues a forward declaration to struct inner. With GCC the DWARF info is
    reversed so struct inner gets fully defined.
    
    That forward declaration is not sufficient when compilers handle an
    array of the struct, even when it's only used through a pointer. Note
    that we can trigger the same issue with an intermediate typedef:
    
            struct inner {
                    int val;
            };
            typedef struct inner inner2_t[2];
            struct outer {
                    inner2_t *ptr_to_array;
            } A;
    
    Becomes:
    
            struct inner;
            typedef struct inner inner2_t[2];
    
    And causes:
    
    ./def-clang.h:10:30: error: array has incomplete element type 'struct inner'
            typedef struct inner inner2_t[2];
    
    To fix this, clear through_ptr whenever we encounter an intermediate
    array, to make the inner struct part of a strong link and force full
    declaration.
    
    Fixes: 351131b51c7a ("libbpf: add btf_dump API for BTF-to-C conversion")
    Signed-off-by: Jean-Philippe Brucker <jean-philippe@xxxxxxxxxx>
    Signed-off-by: Andrii Nakryiko <andrii@xxxxxxxxxx>
    Link: https://lore.kernel.org/bpf/20210319112554.794552-2-jean-philippe@xxxxxxxxxx
    Signed-off-by: Sasha Levin <sashal@xxxxxxxxxx>

diff --git a/tools/lib/bpf/btf_dump.c b/tools/lib/bpf/btf_dump.c
index 2f9d685bd522..0911aea4cdbe 100644
--- a/tools/lib/bpf/btf_dump.c
+++ b/tools/lib/bpf/btf_dump.c
@@ -462,7 +462,7 @@ static int btf_dump_order_type(struct btf_dump *d, __u32 id, bool through_ptr)
 		return err;
 
 	case BTF_KIND_ARRAY:
-		return btf_dump_order_type(d, btf_array(t)->type, through_ptr);
+		return btf_dump_order_type(d, btf_array(t)->type, false);
 
 	case BTF_KIND_STRUCT:
 	case BTF_KIND_UNION: {



[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[Index of Archives]     [Linux USB Devel]     [Linux Audio Users]     [Yosemite News]     [Linux Kernel]     [Linux SCSI]

  Powered by Linux