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 3; RUN: llc -march=bpfel -mattr=+alu32 -filetype=asm -o - %s | FileCheck -check-prefixes=CHECK %s 4; RUN: llc -march=bpfeb -mattr=+alu32 -filetype=asm -o - %s | FileCheck -check-prefixes=CHECK %s 5; Source code: 6; struct net_device { 7; int dev_id; 8; int others; 9; }; 10; struct sk_buff { 11; int i; 12; struct net_device dev[10]; 13; }; 14; #define _(x) (__builtin_preserve_access_index(x)) 15; static int (*bpf_probe_read)(void *dst, int size, void *unsafe_ptr) 16; = (void *) 4; 17; 18; int bpf_prog(struct sk_buff *ctx) { 19; int dev_id; 20; bpf_probe_read(&dev_id, sizeof(int), _(&ctx->dev[5].dev_id)); 21; return dev_id; 22; } 23; Compilation flag: 24; clang -target bpf -O2 -g -S -emit-llvm test.c 25 26%struct.sk_buff = type { i32, [10 x %struct.net_device] } 27%struct.net_device = type { i32, i32 } 28 29; Function Attrs: nounwind 30define dso_local i32 @bpf_prog(%struct.sk_buff*) local_unnamed_addr #0 !dbg !15 { 31 %2 = alloca i32, align 4 32 call void @llvm.dbg.value(metadata %struct.sk_buff* %0, metadata !31, metadata !DIExpression()), !dbg !33 33 %3 = bitcast i32* %2 to i8*, !dbg !34 34 call void @llvm.lifetime.start.p0i8(i64 4, i8* nonnull %3) #4, !dbg !34 35 %4 = tail call [10 x %struct.net_device]* @llvm.preserve.struct.access.index.p0a10s_struct.net_devices.p0s_struct.sk_buffs(%struct.sk_buff* %0, i32 1, i32 1), !dbg !35, !llvm.preserve.access.index !19 36 %5 = tail call %struct.net_device* @llvm.preserve.array.access.index.p0s_struct.net_devices.p0a10s_struct.net_devices([10 x %struct.net_device]* %4, i32 1, i32 5), !dbg !35, !llvm.preserve.access.index !23 37 %6 = tail call i32* @llvm.preserve.struct.access.index.p0i32.p0s_struct.net_devices(%struct.net_device* %5, i32 0, i32 0), !dbg !35, !llvm.preserve.access.index !24 38 %7 = bitcast i32* %6 to i8*, !dbg !35 39 %8 = call i32 inttoptr (i64 4 to i32 (i8*, i32, i8*)*)(i8* nonnull %3, i32 4, i8* %7) #4, !dbg !36 40 %9 = load i32, i32* %2, align 4, !dbg !37, !tbaa !38 41 call void @llvm.dbg.value(metadata i32 %9, metadata !32, metadata !DIExpression()), !dbg !33 42 call void @llvm.lifetime.end.p0i8(i64 4, i8* nonnull %3) #4, !dbg !42 43 ret i32 %9, !dbg !43 44} 45 46; CHECK: .section .BTF,"",@progbits 47; CHECK-NEXT: .short 60319 # 0xeb9f 48; CHECK-NEXT: .byte 1 49; CHECK-NEXT: .byte 0 50; CHECK-NEXT: .long 24 51; CHECK-NEXT: .long 0 52; CHECK-NEXT: .long 172 53; CHECK-NEXT: .long 172 54; CHECK-NEXT: .long 128 55; CHECK-NEXT: .long 0 # BTF_KIND_PTR(id = 1) 56; CHECK-NEXT: .long 33554432 # 0x2000000 57; CHECK-NEXT: .long 2 58; CHECK-NEXT: .long 1 # BTF_KIND_STRUCT(id = 2) 59; CHECK-NEXT: .long 67108866 # 0x4000002 60; CHECK-NEXT: .long 84 61; CHECK-NEXT: .long 9 62; CHECK-NEXT: .long 3 63; CHECK-NEXT: .long 0 # 0x0 64; CHECK-NEXT: .long 11 65; CHECK-NEXT: .long 5 66; CHECK-NEXT: .long 32 # 0x20 67; CHECK-NEXT: .long 15 # BTF_KIND_INT(id = 3) 68; CHECK-NEXT: .long 16777216 # 0x1000000 69; CHECK-NEXT: .long 4 70; CHECK-NEXT: .long 16777248 # 0x1000020 71; CHECK-NEXT: .long 19 # BTF_KIND_STRUCT(id = 4) 72; CHECK-NEXT: .long 67108866 # 0x4000002 73; CHECK-NEXT: .long 8 74; CHECK-NEXT: .long 30 75; CHECK-NEXT: .long 3 76; CHECK-NEXT: .long 0 # 0x0 77; CHECK-NEXT: .long 37 78; CHECK-NEXT: .long 3 79; CHECK-NEXT: .long 32 # 0x20 80; CHECK-NEXT: .long 0 # BTF_KIND_ARRAY(id = 5) 81; CHECK-NEXT: .long 50331648 # 0x3000000 82; CHECK-NEXT: .long 0 83; CHECK-NEXT: .long 4 84; CHECK-NEXT: .long 6 85; CHECK-NEXT: .long 10 86; CHECK-NEXT: .long 44 # BTF_KIND_INT(id = 6) 87; CHECK-NEXT: .long 16777216 # 0x1000000 88; CHECK-NEXT: .long 4 89; CHECK-NEXT: .long 32 # 0x20 90; CHECK-NEXT: .long 0 # BTF_KIND_FUNC_PROTO(id = 7) 91; CHECK-NEXT: .long 218103809 # 0xd000001 92; CHECK-NEXT: .long 3 93; CHECK-NEXT: .long 64 94; CHECK-NEXT: .long 1 95; CHECK-NEXT: .long 68 # BTF_KIND_FUNC(id = 8) 96; CHECK-NEXT: .long 201326593 # 0xc000001 97; CHECK-NEXT: .long 7 98; CHECK-NEXT: .byte 0 # string offset=0 99; CHECK-NEXT: .ascii "sk_buff" # string offset=1 100; CHECK-NEXT: .byte 0 101; CHECK-NEXT: .byte 105 # string offset=9 102; CHECK-NEXT: .byte 0 103; CHECK-NEXT: .ascii "dev" # string offset=11 104; CHECK-NEXT: .byte 0 105; CHECK-NEXT: .ascii "int" # string offset=15 106; CHECK-NEXT: .byte 0 107; CHECK-NEXT: .ascii "net_device" # string offset=19 108; CHECK-NEXT: .byte 0 109; CHECK-NEXT: .ascii "dev_id" # string offset=30 110; CHECK-NEXT: .byte 0 111; CHECK-NEXT: .ascii "others" # string offset=37 112; CHECK-NEXT: .byte 0 113; CHECK-NEXT: .ascii "__ARRAY_SIZE_TYPE__" # string offset=44 114; CHECK-NEXT: .byte 0 115; CHECK-NEXT: .ascii "ctx" # string offset=64 116; CHECK-NEXT: .byte 0 117; CHECK-NEXT: .ascii "bpf_prog" # string offset=68 118; CHECK-NEXT: .byte 0 119; CHECK-NEXT: .ascii ".text" # string offset=77 120; CHECK-NEXT: .byte 0 121; CHECK-NEXT: .ascii "/tmp/home/yhs/work/tests/llvm/test.c" # string offset=83 122; CHECK-NEXT: .byte 0 123; CHECK-NEXT: .ascii "0:1:5:0" # string offset=120 124; CHECK-NEXT: .byte 0 125; CHECK-NEXT: .section .BTF.ext,"",@progbits 126; CHECK-NEXT: .short 60319 # 0xeb9f 127; CHECK-NEXT: .byte 1 128; CHECK-NEXT: .byte 0 129; CHECK-NEXT: .long 32 130; CHECK-NEXT: .long 0 131; CHECK-NEXT: .long 20 132; CHECK-NEXT: .long 20 133; CHECK-NEXT: .long {{[0-9]+}} 134; CHECK-NEXT: .long {{[0-9]+}} 135; CHECK-NEXT: .long 28 136; CHECK-NEXT: .long 8 # FuncInfo 137 138; CHECK: .long 16 # FieldReloc 139; CHECK-NEXT: .long 77 # Field reloc section string offset=77 140; CHECK-NEXT: .long 1 141; CHECK-NEXT: .long .Ltmp{{[0-9]+}} 142; CHECK-NEXT: .long 2 143; CHECK-NEXT: .long 120 144; CHECK-NEXT: .long 0 145 146; Function Attrs: argmemonly nounwind 147declare void @llvm.lifetime.start.p0i8(i64 immarg, i8* nocapture) #1 148 149; Function Attrs: nounwind readnone 150declare [10 x %struct.net_device]* @llvm.preserve.struct.access.index.p0a10s_struct.net_devices.p0s_struct.sk_buffs(%struct.sk_buff*, i32 immarg, i32 immarg) #2 151 152; Function Attrs: nounwind readnone 153declare %struct.net_device* @llvm.preserve.array.access.index.p0s_struct.net_devices.p0a10s_struct.net_devices([10 x %struct.net_device]*, i32 immarg, i32 immarg) #2 154 155; Function Attrs: nounwind readnone 156declare i32* @llvm.preserve.struct.access.index.p0i32.p0s_struct.net_devices(%struct.net_device*, i32 immarg, i32 immarg) #2 157 158; Function Attrs: argmemonly nounwind 159declare void @llvm.lifetime.end.p0i8(i64 immarg, i8* nocapture) #1 160 161; Function Attrs: nounwind readnone speculatable 162declare void @llvm.dbg.value(metadata, metadata, metadata) #3 163 164attributes #0 = { nounwind "correctly-rounded-divide-sqrt-fp-math"="false" "disable-tail-calls"="false" "less-precise-fpmad"="false" "min-legal-vector-width"="0" "frame-pointer"="all" "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" } 165attributes #1 = { argmemonly nounwind } 166attributes #2 = { nounwind readnone } 167attributes #3 = { nounwind readnone speculatable } 168attributes #4 = { nounwind } 169 170!llvm.dbg.cu = !{!0} 171!llvm.module.flags = !{!11, !12, !13} 172!llvm.ident = !{!14} 173 174!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) 175!1 = !DIFile(filename: "test.c", directory: "/tmp/home/yhs/work/tests/llvm") 176!2 = !{} 177!3 = !{!4} 178!4 = !DIGlobalVariableExpression(var: !5, expr: !DIExpression()) 179!5 = distinct !DIGlobalVariable(name: "bpf_probe_read", scope: !0, file: !1, line: 10, type: !6, isLocal: true, isDefinition: true) 180!6 = !DIDerivedType(tag: DW_TAG_pointer_type, baseType: !7, size: 64) 181!7 = !DISubroutineType(types: !8) 182!8 = !{!9, !10, !9, !10} 183!9 = !DIBasicType(name: "int", size: 32, encoding: DW_ATE_signed) 184!10 = !DIDerivedType(tag: DW_TAG_pointer_type, baseType: null, size: 64) 185!11 = !{i32 2, !"Dwarf Version", i32 4} 186!12 = !{i32 2, !"Debug Info Version", i32 3} 187!13 = !{i32 1, !"wchar_size", i32 4} 188!14 = !{!"clang version 9.0.0 (trunk 360739) (llvm/trunk 360747)"} 189!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: !30) 190!16 = !DISubroutineType(types: !17) 191!17 = !{!9, !18} 192!18 = !DIDerivedType(tag: DW_TAG_pointer_type, baseType: !19, size: 64) 193!19 = distinct !DICompositeType(tag: DW_TAG_structure_type, name: "sk_buff", file: !1, line: 5, size: 672, elements: !20) 194!20 = !{!21, !22} 195!21 = !DIDerivedType(tag: DW_TAG_member, name: "i", scope: !19, file: !1, line: 6, baseType: !9, size: 32) 196!22 = !DIDerivedType(tag: DW_TAG_member, name: "dev", scope: !19, file: !1, line: 7, baseType: !23, size: 640, offset: 32) 197!23 = !DICompositeType(tag: DW_TAG_array_type, baseType: !24, size: 640, elements: !28) 198!24 = distinct !DICompositeType(tag: DW_TAG_structure_type, name: "net_device", file: !1, line: 1, size: 64, elements: !25) 199!25 = !{!26, !27} 200!26 = !DIDerivedType(tag: DW_TAG_member, name: "dev_id", scope: !24, file: !1, line: 2, baseType: !9, size: 32) 201!27 = !DIDerivedType(tag: DW_TAG_member, name: "others", scope: !24, file: !1, line: 3, baseType: !9, size: 32, offset: 32) 202!28 = !{!29} 203!29 = !DISubrange(count: 10) 204!30 = !{!31, !32} 205!31 = !DILocalVariable(name: "ctx", arg: 1, scope: !15, file: !1, line: 13, type: !18) 206!32 = !DILocalVariable(name: "dev_id", scope: !15, file: !1, line: 14, type: !9) 207!33 = !DILocation(line: 0, scope: !15) 208!34 = !DILocation(line: 14, column: 3, scope: !15) 209!35 = !DILocation(line: 15, column: 40, scope: !15) 210!36 = !DILocation(line: 15, column: 3, scope: !15) 211!37 = !DILocation(line: 16, column: 10, scope: !15) 212!38 = !{!39, !39, i64 0} 213!39 = !{!"int", !40, i64 0} 214!40 = !{!"omnipotent char", !41, i64 0} 215!41 = !{!"Simple C/C++ TBAA"} 216!42 = !DILocation(line: 17, column: 1, scope: !15) 217!43 = !DILocation(line: 16, column: 3, scope: !15) 218