[PATCH pahole 1/2] btf: recognize BTF_KIND_FUNC in btf_loader

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

 



BTF_KIND_FUNC is generated by llvm (latest trunk, 8.0 or later).
Without BTF_KIND_FUNC support, we will see the following errors,

  -bash-4.4$ cat t.c
  struct t {
    int a;
    char b1:1;
    char b2:3;
    int c;
  } g;
  int main() { return 0; }
  -bash-4.4$ clang -O2 -target bpf -g -c t.c -Xclang -target-feature -Xclang +dwarfris

  -bash-4.4$ pahole -F btf t.o
  BTF: idx: 3, off: 28, Unknown
  struct t {
        int                        a;                    /*     0     4 */

        /* Bitfield combined with previous fields */

        <ERROR(__class__fprintf:1342): 5 not found!>

        /* Bitfield combined with previous fields */

        <ERROR(__class__fprintf:1342): 5 not found!>
        int                        c;                    /*     8     4 */

        /* size: 12, cachelines: 1, members: 4 */
        /* last cacheline: 12 bytes */

        /* BRAIN FART ALERT! 12 != 8 + 0(holes), diff = 4 */

  };
  -bash-4.4$

The reason is that llvm generates BTF_KIND_FUNC which btf_loader does not
recognize.

This patch added support for BTF_KIND_FUNC. Since BTF_KIND_FUNC represents
a defined subprogram and not a real type. A null type is used to
represent BTF_KIND_FUNC to avoid skipping type index.

With this fix,
  -bash-4.4$ pahole -F btf t.o
  struct t {
        int                        a;                    /*     0     4 */
        char                       b1:1;                 /*     4: 0  1 */
        char                       b2:3;                 /*     4: 1  1 */
        int                        c;                    /*     8     4 */

        /* size: 12, cachelines: 1, members: 4 */
        /* last cacheline: 12 bytes */

        /* BRAIN FART ALERT! 12 != 9 + 0(holes), diff = 3 */

  };

Signed-off-by: Yonghong Song <yhs@xxxxxx>
---
 btf_loader.c | 10 ++++++++++
 1 file changed, 10 insertions(+)

diff --git a/btf_loader.c b/btf_loader.c
index eeb0c8b..ad4cd23 100644
--- a/btf_loader.c
+++ b/btf_loader.c
@@ -421,6 +421,16 @@ static int btf__load_types(struct btf *btf)
 			vlen = 0;
 		} else if (type == BTF_KIND_FUNC_PROTO) {
 			vlen = create_new_subroutine_type(btf, ptr, vlen, type_ptr, type_index);
+		} else if (type == BTF_KIND_FUNC) {
+			/* BTF_KIND_FUNC corresponding to a defined subprogram.
+			 * This is not really a type and it won't be referred by any other types
+			 * either. Since types cannot be skipped, let us replace it with
+			 * a nullify_type_entry.
+			 *
+			 * No warning here since BTF_KIND_FUNC is a legal entry in BTF.
+			 */
+			cu__table_nullify_type_entry(btf->priv, type_index);
+			vlen = 0;
 		} else {
 			fprintf(stderr,
 				"BTF: idx: %d, off: %zd, Unknown\n",
-- 
2.17.1




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

  Powered by Linux