github.com/kubearmor/cilium@v1.6.12/pkg/alignchecker/testdata/bpf_foo.c (about) 1 /* 2 * Copyright (C) 2019 Authors of Cilium 3 * 4 * This program is free software; you can redistribute it and/or modify 5 * it under the terms of the GNU General Public License as published by 6 * the Free Software Foundation; either version 2 of the License, or 7 * (at your option) any later version. 8 * 9 * This program is distributed in the hope that it will be useful, 10 * but WITHOUT ANY WARRANTY; without even the implied warranty of 11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 12 * GNU General Public License for more details. 13 * 14 * You should have received a copy of the GNU General Public License 15 * along with this program; if not, write to the Free Software 16 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA 17 */ 18 19 /* To compile: 20 * $ clang -I../../../bpf/include -O2 -g -target bpf -emit-llvm \ 21 * -Wall -Werror -Wno-address-of-packed-member \ 22 * -Wno-unknown-warning-option -c bpf_foo.c -o bpf_foo.ll 23 * $ llc -march=bpf -mcpu=probe -mattr=dwarfris -filetype=obj \ 24 * -o bpf_foo.o bpf_foo.ll 25 */ 26 27 #include <linux/type_mapper.h> 28 29 union v6addr { 30 struct { 31 __u32 p1; 32 __u32 p2; 33 __u32 p3; 34 __u32 p4; 35 }; 36 __u8 addr[16]; 37 }; 38 39 struct foo { 40 union { 41 struct { 42 __u32 ip4; 43 __u32 pad1; 44 __u32 pad2; 45 __u32 pad3; 46 }; 47 union v6addr ip6; 48 }; 49 union { 50 __u32 p1; 51 __u32 p2; 52 }; 53 __u8 family; 54 __u8 pad4; 55 __u16 pad5; 56 } __attribute__((packed)); 57 58 int main() { 59 __attribute__((unused)) struct foo f; 60 61 return 0; 62 }