1 ; RUN: llc -march=bpfel -filetype=asm -o - %s | FileCheck -check-prefixes=CHECK %s
2 ; RUN: llc -march=bpfeb -filetype=asm -o - %s | FileCheck -check-prefixes=CHECK %s
10 ; struct net_device dev;
12 ; #define _(x) (__builtin_preserve_access_index(x))
13 ; static int (*bpf_probe_read)(void *dst, int size, void *unsafe_ptr)
16 ; int bpf_prog(struct sk_buff *ctx) {
18 ; bpf_probe_read(&dev_id, sizeof(int), _(&ctx->dev.dev_id));
22 ; clang -target bpf -O2 -g -S -emit-llvm test.c
24 %struct.sk_buff = type { i32, %struct.net_device }
25 %struct.net_device = type { i32, i32 }
27 ; Function Attrs: nounwind
28 define dso_local i32 @bpf_prog(%struct.sk_buff*) local_unnamed_addr #0 !dbg !15 {
29 %2 = alloca i32, align 4
30 call void @llvm.dbg.value(metadata %struct.sk_buff* %0, metadata !28, metadata !DIExpression()), !dbg !30
31 %3 = bitcast i32* %2 to i8*, !dbg !31
32 call void @llvm.lifetime.start.p0i8(i64 4, i8* nonnull %3) #4, !dbg !31
33 %4 = tail call %struct.net_device* @llvm.preserve.struct.access.index.p0s_struct.net_devices.p0s_struct.sk_buffs(%struct.sk_buff* %0, i32 1, i32 1), !dbg !32, !llvm.preserve.access.index !19
34 %5 = tail call i32* @llvm.preserve.struct.access.index.p0i32.p0s_struct.net_devices(%struct.net_device* %4, i32 0, i32 0), !dbg !32, !llvm.preserve.access.index !23
35 %6 = bitcast i32* %5 to i8*, !dbg !32
36 %7 = call i32 inttoptr (i64 4 to i32 (i8*, i32, i8*)*)(i8* nonnull %3, i32 4, i8* %6) #4, !dbg !33
37 %8 = load i32, i32* %2, align 4, !dbg !34, !tbaa !35
38 call void @llvm.dbg.value(metadata i32 %8, metadata !29, metadata !DIExpression()), !dbg !30
39 call void @llvm.lifetime.end.p0i8(i64 4, i8* nonnull %3) #4, !dbg !39
43 ; CHECK: .section .BTF,"",@progbits
44 ; CHECK-NEXT: .short 60319 # 0xeb9f
47 ; CHECK-NEXT: .long 24
49 ; CHECK-NEXT: .long 132
50 ; CHECK-NEXT: .long 132
51 ; CHECK-NEXT: .long 106
52 ; CHECK-NEXT: .long 0 # BTF_KIND_PTR(id = 1)
53 ; CHECK-NEXT: .long 33554432 # 0x2000000
55 ; CHECK-NEXT: .long 1 # BTF_KIND_STRUCT(id = 2)
56 ; CHECK-NEXT: .long 67108866 # 0x4000002
57 ; CHECK-NEXT: .long 12
60 ; CHECK-NEXT: .long 0 # 0x0
61 ; CHECK-NEXT: .long 11
63 ; CHECK-NEXT: .long 32 # 0x20
64 ; CHECK-NEXT: .long 15 # BTF_KIND_INT(id = 3)
65 ; CHECK-NEXT: .long 16777216 # 0x1000000
67 ; CHECK-NEXT: .long 16777248 # 0x1000020
68 ; CHECK-NEXT: .long 19 # BTF_KIND_STRUCT(id = 4)
69 ; CHECK-NEXT: .long 67108866 # 0x4000002
71 ; CHECK-NEXT: .long 30
73 ; CHECK-NEXT: .long 0 # 0x0
74 ; CHECK-NEXT: .long 37
76 ; CHECK-NEXT: .long 32 # 0x20
77 ; CHECK-NEXT: .long 0 # BTF_KIND_FUNC_PROTO(id = 5)
78 ; CHECK-NEXT: .long 218103809 # 0xd000001
80 ; CHECK-NEXT: .long 44
82 ; CHECK-NEXT: .long 48 # BTF_KIND_FUNC(id = 6)
83 ; CHECK-NEXT: .long 201326592 # 0xc000000
85 ; CHECK-NEXT: .byte 0 # string offset=0
86 ; CHECK-NEXT: .ascii "sk_buff" # string offset=1
88 ; CHECK-NEXT: .byte 105 # string offset=9
90 ; CHECK-NEXT: .ascii "dev" # string offset=11
92 ; CHECK-NEXT: .ascii "int" # string offset=15
94 ; CHECK-NEXT: .ascii "net_device" # string offset=19
96 ; CHECK-NEXT: .ascii "dev_id" # string offset=30
98 ; CHECK-NEXT: .ascii "others" # string offset=37
100 ; CHECK-NEXT: .ascii "ctx" # string offset=44
101 ; CHECK-NEXT: .byte 0
102 ; CHECK-NEXT: .ascii "bpf_prog" # string offset=48
103 ; CHECK-NEXT: .byte 0
104 ; CHECK-NEXT: .ascii ".text" # string offset=57
105 ; CHECK-NEXT: .byte 0
106 ; CHECK-NEXT: .ascii "/tmp/home/yhs/work/tests/llvm/test.c" # string offset=63
107 ; CHECK-NEXT: .byte 0
108 ; CHECK-NEXT: .ascii "0:1:0" # string offset=100
109 ; CHECK-NEXT: .byte 0
110 ; CHECK-NEXT: .section .BTF.ext,"",@progbits
111 ; CHECK-NEXT: .short 60319 # 0xeb9f
112 ; CHECK-NEXT: .byte 1
113 ; CHECK-NEXT: .byte 0
114 ; CHECK-NEXT: .long 32
115 ; CHECK-NEXT: .long 0
116 ; CHECK-NEXT: .long 20
117 ; CHECK-NEXT: .long 20
118 ; CHECK-NEXT: .long 76
119 ; CHECK-NEXT: .long 96
120 ; CHECK-NEXT: .long 28
121 ; CHECK-NEXT: .long 8 # FuncInfo
123 ; CHECK: .long 16 # FieldReloc
124 ; CHECK-NEXT: .long 57 # Field reloc section string offset=57
125 ; CHECK-NEXT: .long 1
126 ; CHECK-NEXT: .long .Ltmp{{[0-9]+}}
127 ; CHECK-NEXT: .long 2
128 ; CHECK-NEXT: .long 100
129 ; CHECK-NEXT: .long 0
131 ; Function Attrs: argmemonly nounwind
132 declare void @llvm.lifetime.start.p0i8(i64 immarg, i8* nocapture) #1
134 ; Function Attrs: nounwind readnone
135 declare %struct.net_device* @llvm.preserve.struct.access.index.p0s_struct.net_devices.p0s_struct.sk_buffs(%struct.sk_buff*, i32 immarg, i32 immarg) #2
137 ; Function Attrs: nounwind readnone
138 declare i32* @llvm.preserve.struct.access.index.p0i32.p0s_struct.net_devices(%struct.net_device*, i32 immarg, i32 immarg) #2
140 ; Function Attrs: argmemonly nounwind
141 declare void @llvm.lifetime.end.p0i8(i64 immarg, i8* nocapture) #1
143 ; Function Attrs: nounwind readnone speculatable
144 declare void @llvm.dbg.value(metadata, metadata, metadata) #3
146 attributes #0 = { nounwind "correctly-rounded-divide-sqrt-fp-math"="false" "disable-tail-calls"="false" "less-precise-fpmad"="false" "min-legal-vector-width"="0" "no-frame-pointer-elim"="true" "no-frame-pointer-elim-non-leaf" "no-infs-fp-math"="false" "no-jump-tables"="false" "no-nans-fp-math"="false" "no-signed-zeros-fp-math"="false" "no-trapping-math"="false" "stack-protector-buffer-size"="8" "unsafe-fp-math"="false" "use-soft-float"="false" }
147 attributes #1 = { argmemonly nounwind }
148 attributes #2 = { nounwind readnone }
149 attributes #3 = { nounwind readnone speculatable }
150 attributes #4 = { nounwind }
153 !llvm.module.flags = !{!11, !12, !13}
156 !0 = distinct !DICompileUnit(language: DW_LANG_C99, file: !1, producer: "clang version 9.0.0 (trunk 360739) (llvm/trunk 360747)", isOptimized: true, runtimeVersion: 0, emissionKind: FullDebug, enums: !2, globals: !3, nameTableKind: None)
157 !1 = !DIFile(filename: "test.c", directory: "/tmp/home/yhs/work/tests/llvm")
160 !4 = !DIGlobalVariableExpression(var: !5, expr: !DIExpression())
161 !5 = distinct !DIGlobalVariable(name: "bpf_probe_read", scope: !0, file: !1, line: 10, type: !6, isLocal: true, isDefinition: true)
162 !6 = !DIDerivedType(tag: DW_TAG_pointer_type, baseType: !7, size: 64)
163 !7 = !DISubroutineType(types: !8)
164 !8 = !{!9, !10, !9, !10}
165 !9 = !DIBasicType(name: "int", size: 32, encoding: DW_ATE_signed)
166 !10 = !DIDerivedType(tag: DW_TAG_pointer_type, baseType: null, size: 64)
167 !11 = !{i32 2, !"Dwarf Version", i32 4}
168 !12 = !{i32 2, !"Debug Info Version", i32 3}
169 !13 = !{i32 1, !"wchar_size", i32 4}
170 !14 = !{!"clang version 9.0.0 (trunk 360739) (llvm/trunk 360747)"}
171 !15 = distinct !DISubprogram(name: "bpf_prog", scope: !1, file: !1, line: 13, type: !16, scopeLine: 13, flags: DIFlagPrototyped, isLocal: false, isDefinition: true, isOptimized: true, unit: !0, retainedNodes: !27)
172 !16 = !DISubroutineType(types: !17)
174 !18 = !DIDerivedType(tag: DW_TAG_pointer_type, baseType: !19, size: 64)
175 !19 = distinct !DICompositeType(tag: DW_TAG_structure_type, name: "sk_buff", file: !1, line: 5, size: 96, elements: !20)
177 !21 = !DIDerivedType(tag: DW_TAG_member, name: "i", scope: !19, file: !1, line: 6, baseType: !9, size: 32)
178 !22 = !DIDerivedType(tag: DW_TAG_member, name: "dev", scope: !19, file: !1, line: 7, baseType: !23, size: 64, offset: 32)
179 !23 = distinct !DICompositeType(tag: DW_TAG_structure_type, name: "net_device", file: !1, line: 1, size: 64, elements: !24)
181 !25 = !DIDerivedType(tag: DW_TAG_member, name: "dev_id", scope: !23, file: !1, line: 2, baseType: !9, size: 32)
182 !26 = !DIDerivedType(tag: DW_TAG_member, name: "others", scope: !23, file: !1, line: 3, baseType: !9, size: 32, offset: 32)
184 !28 = !DILocalVariable(name: "ctx", arg: 1, scope: !15, file: !1, line: 13, type: !18)
185 !29 = !DILocalVariable(name: "dev_id", scope: !15, file: !1, line: 14, type: !9)
186 !30 = !DILocation(line: 0, scope: !15)
187 !31 = !DILocation(line: 14, column: 3, scope: !15)
188 !32 = !DILocation(line: 15, column: 40, scope: !15)
189 !33 = !DILocation(line: 15, column: 3, scope: !15)
190 !34 = !DILocation(line: 16, column: 10, scope: !15)
191 !35 = !{!36, !36, i64 0}
192 !36 = !{!"int", !37, i64 0}
193 !37 = !{!"omnipotent char", !38, i64 0}
194 !38 = !{!"Simple C/C++ TBAA"}
195 !39 = !DILocation(line: 17, column: 1, scope: !15)
196 !40 = !DILocation(line: 16, column: 3, scope: !15)