linux/tools/testing/selftests/bpf/progs/btf_dump_test_case_packing.c
<<
>>
Prefs
   1// SPDX-License-Identifier: (LGPL-2.1 OR BSD-2-Clause)
   2
   3/*
   4 * BTF-to-C dumper tests for struct packing determination.
   5 *
   6 * Copyright (c) 2019 Facebook
   7 */
   8/* ----- START-EXPECTED-OUTPUT ----- */
   9struct packed_trailing_space {
  10        int a;
  11        short b;
  12} __attribute__((packed));
  13
  14struct non_packed_trailing_space {
  15        int a;
  16        short b;
  17};
  18
  19struct packed_fields {
  20        short a;
  21        int b;
  22} __attribute__((packed));
  23
  24struct non_packed_fields {
  25        short a;
  26        int b;
  27};
  28
  29struct nested_packed {
  30        char: 4;
  31        int a: 4;
  32        long int b;
  33        struct {
  34                char c;
  35                int d;
  36        } __attribute__((packed)) e;
  37} __attribute__((packed));
  38
  39union union_is_never_packed {
  40        int a: 4;
  41        char b;
  42        char c: 1;
  43};
  44
  45union union_does_not_need_packing {
  46        struct {
  47                long int a;
  48                int b;
  49        } __attribute__((packed));
  50        int c;
  51};
  52
  53union jump_code_union {
  54        char code[5];
  55        struct {
  56                char jump;
  57                int offset;
  58        } __attribute__((packed));
  59};
  60
  61/*------ END-EXPECTED-OUTPUT ------ */
  62
  63int f(struct {
  64        struct packed_trailing_space _1;
  65        struct non_packed_trailing_space _2;
  66        struct packed_fields _3;
  67        struct non_packed_fields _4;
  68        struct nested_packed _5;
  69        union union_is_never_packed _6;
  70        union union_does_not_need_packing _7;
  71        union jump_code_union _8;
  72} *_)
  73{
  74        return 0;
  75}
  76