192 lines · plain
1; RUN: opt -O2 %s | llvm-dis > %t12; RUN: llc -filetype=asm -o - %t1 | FileCheck -check-prefixes=CHECK %s3; RUN: llc -mattr=+alu32 -filetype=asm -o - %t1 | FileCheck -check-prefixes=CHECK %s4; Source code:5; struct net_device {6; int dev_id;7; int others;8; };9; struct sk_buff {10; int i;11; struct net_device dev;12; };13; #define _(x) (__builtin_preserve_access_index(x))14; static int (*bpf_probe_read)(ptr dst, int size, ptr unsafe_ptr)15; = (ptr) 4;16;17; int bpf_prog(struct sk_buff *ctx) {18; int dev_id;19; bpf_probe_read(&dev_id, sizeof(int), _(&ctx->dev.dev_id));20; return dev_id;21; }22; Compilation flag:23; clang -target bpf -O2 -g -S -emit-llvm -Xclang -disable-llvm-passes test.c24 25target triple = "bpf"26 27%struct.sk_buff = type { i32, %struct.net_device }28%struct.net_device = type { i32, i32 }29 30; Function Attrs: nounwind31define dso_local i32 @bpf_prog(ptr) local_unnamed_addr !dbg !15 {32 %2 = alloca i32, align 433 call void @llvm.dbg.value(metadata ptr %0, metadata !28, metadata !DIExpression()), !dbg !3034 call void @llvm.lifetime.start.p0(i64 4, ptr nonnull %2), !dbg !3135 %3 = tail call ptr @llvm.preserve.struct.access.index.p0.net_devices.p0.sk_buffs(ptr elementtype(%struct.sk_buff) %0, i32 1, i32 1), !dbg !32, !llvm.preserve.access.index !1936 %4 = tail call ptr @llvm.preserve.struct.access.index.p0.p0.net_devices(ptr elementtype(%struct.net_device) %3, i32 0, i32 0), !dbg !32, !llvm.preserve.access.index !2337 %5 = call i32 inttoptr (i64 4 to ptr)(ptr nonnull %2, i32 4, ptr %4), !dbg !3338 %6 = load i32, ptr %2, align 4, !dbg !34, !tbaa !3539 call void @llvm.dbg.value(metadata i32 %6, metadata !29, metadata !DIExpression()), !dbg !3040 call void @llvm.lifetime.end.p0(i64 4, ptr nonnull %2), !dbg !3941 ret i32 %6, !dbg !4042}43 44; CHECK: .section .BTF,"",@progbits45; CHECK-NEXT: .short 60319 # 0xeb9f46; CHECK-NEXT: .byte 147; CHECK-NEXT: .byte 048; CHECK-NEXT: .long 2449; CHECK-NEXT: .long 050; CHECK-NEXT: .long 13251; CHECK-NEXT: .long 13252; CHECK-NEXT: .long 10653; CHECK-NEXT: .long 0 # BTF_KIND_PTR(id = 1)54; CHECK-NEXT: .long 33554432 # 0x200000055; CHECK-NEXT: .long 256; CHECK-NEXT: .long 1 # BTF_KIND_STRUCT(id = 2)57; CHECK-NEXT: .long 67108866 # 0x400000258; CHECK-NEXT: .long 1259; CHECK-NEXT: .long 960; CHECK-NEXT: .long 361; CHECK-NEXT: .long 0 # 0x062; CHECK-NEXT: .long 1163; CHECK-NEXT: .long 464; CHECK-NEXT: .long 32 # 0x2065; CHECK-NEXT: .long 15 # BTF_KIND_INT(id = 3)66; CHECK-NEXT: .long 16777216 # 0x100000067; CHECK-NEXT: .long 468; CHECK-NEXT: .long 16777248 # 0x100002069; CHECK-NEXT: .long 19 # BTF_KIND_STRUCT(id = 4)70; CHECK-NEXT: .long 67108866 # 0x400000271; CHECK-NEXT: .long 872; CHECK-NEXT: .long 3073; CHECK-NEXT: .long 374; CHECK-NEXT: .long 0 # 0x075; CHECK-NEXT: .long 3776; CHECK-NEXT: .long 377; CHECK-NEXT: .long 32 # 0x2078; CHECK-NEXT: .long 0 # BTF_KIND_FUNC_PROTO(id = 5)79; CHECK-NEXT: .long 218103809 # 0xd00000180; CHECK-NEXT: .long 381; CHECK-NEXT: .long 4482; CHECK-NEXT: .long 183; CHECK-NEXT: .long 48 # BTF_KIND_FUNC(id = 6)84; CHECK-NEXT: .long 201326593 # 0xc00000185; CHECK-NEXT: .long 586; CHECK-NEXT: .byte 0 # string offset=087; CHECK-NEXT: .ascii "sk_buff" # string offset=188; CHECK-NEXT: .byte 089; CHECK-NEXT: .byte 105 # string offset=990; CHECK-NEXT: .byte 091; CHECK-NEXT: .ascii "dev" # string offset=1192; CHECK-NEXT: .byte 093; CHECK-NEXT: .ascii "int" # string offset=1594; CHECK-NEXT: .byte 095; CHECK-NEXT: .ascii "net_device" # string offset=1996; CHECK-NEXT: .byte 097; CHECK-NEXT: .ascii "dev_id" # string offset=3098; CHECK-NEXT: .byte 099; CHECK-NEXT: .ascii "others" # string offset=37100; CHECK-NEXT: .byte 0101; CHECK-NEXT: .ascii "ctx" # string offset=44102; CHECK-NEXT: .byte 0103; CHECK-NEXT: .ascii "bpf_prog" # string offset=48104; CHECK-NEXT: .byte 0105; CHECK-NEXT: .ascii ".text" # string offset=57106; CHECK-NEXT: .byte 0107; CHECK-NEXT: .ascii "/tmp/home/yhs/work/tests/llvm/test.c" # string offset=63108; CHECK-NEXT: .byte 0109; CHECK-NEXT: .ascii "0:1:0" # string offset=100110; CHECK-NEXT: .byte 0111; CHECK-NEXT: .section .BTF.ext,"",@progbits112; CHECK-NEXT: .short 60319 # 0xeb9f113; CHECK-NEXT: .byte 1114; CHECK-NEXT: .byte 0115; CHECK-NEXT: .long 32116; CHECK-NEXT: .long 0117; CHECK-NEXT: .long 20118; CHECK-NEXT: .long 20119; CHECK-NEXT: .long {{[0-9]+}}120; CHECK-NEXT: .long {{[0-9]+}}121; CHECK-NEXT: .long 28122; CHECK-NEXT: .long 8 # FuncInfo123 124; CHECK: .long 16 # FieldReloc125; CHECK-NEXT: .long 57 # Field reloc section string offset=57126; CHECK-NEXT: .long 1127; CHECK-NEXT: .long .Ltmp{{[0-9]+}}128; CHECK-NEXT: .long 2129; CHECK-NEXT: .long 100130; CHECK-NEXT: .long 0131 132; Function Attrs: argmemonly nounwind133declare void @llvm.lifetime.start.p0(i64 immarg, ptr nocapture)134 135; Function Attrs: nounwind readnone136declare ptr @llvm.preserve.struct.access.index.p0.net_devices.p0.sk_buffs(ptr, i32 immarg, i32 immarg)137 138; Function Attrs: nounwind readnone139declare ptr @llvm.preserve.struct.access.index.p0.p0.net_devices(ptr, i32 immarg, i32 immarg)140 141; Function Attrs: argmemonly nounwind142declare void @llvm.lifetime.end.p0(i64 immarg, ptr nocapture)143 144; Function Attrs: nounwind readnone speculatable145declare void @llvm.dbg.value(metadata, metadata, metadata)146 147!llvm.dbg.cu = !{!0}148!llvm.module.flags = !{!11, !12, !13}149!llvm.ident = !{!14}150 151!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)152!1 = !DIFile(filename: "test.c", directory: "/tmp/home/yhs/work/tests/llvm")153!2 = !{}154!3 = !{!4}155!4 = !DIGlobalVariableExpression(var: !5, expr: !DIExpression())156!5 = distinct !DIGlobalVariable(name: "bpf_probe_read", scope: !0, file: !1, line: 10, type: !6, isLocal: true, isDefinition: true)157!6 = !DIDerivedType(tag: DW_TAG_pointer_type, baseType: !7, size: 64)158!7 = !DISubroutineType(types: !8)159!8 = !{!9, !10, !9, !10}160!9 = !DIBasicType(name: "int", size: 32, encoding: DW_ATE_signed)161!10 = !DIDerivedType(tag: DW_TAG_pointer_type, baseType: null, size: 64)162!11 = !{i32 2, !"Dwarf Version", i32 4}163!12 = !{i32 2, !"Debug Info Version", i32 3}164!13 = !{i32 1, !"wchar_size", i32 4}165!14 = !{!"clang version 9.0.0 (trunk 360739) (llvm/trunk 360747)"}166!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)167!16 = !DISubroutineType(types: !17)168!17 = !{!9, !18}169!18 = !DIDerivedType(tag: DW_TAG_pointer_type, baseType: !19, size: 64)170!19 = distinct !DICompositeType(tag: DW_TAG_structure_type, name: "sk_buff", file: !1, line: 5, size: 96, elements: !20)171!20 = !{!21, !22}172!21 = !DIDerivedType(tag: DW_TAG_member, name: "i", scope: !19, file: !1, line: 6, baseType: !9, size: 32)173!22 = !DIDerivedType(tag: DW_TAG_member, name: "dev", scope: !19, file: !1, line: 7, baseType: !23, size: 64, offset: 32)174!23 = distinct !DICompositeType(tag: DW_TAG_structure_type, name: "net_device", file: !1, line: 1, size: 64, elements: !24)175!24 = !{!25, !26}176!25 = !DIDerivedType(tag: DW_TAG_member, name: "dev_id", scope: !23, file: !1, line: 2, baseType: !9, size: 32)177!26 = !DIDerivedType(tag: DW_TAG_member, name: "others", scope: !23, file: !1, line: 3, baseType: !9, size: 32, offset: 32)178!27 = !{!28, !29}179!28 = !DILocalVariable(name: "ctx", arg: 1, scope: !15, file: !1, line: 13, type: !18)180!29 = !DILocalVariable(name: "dev_id", scope: !15, file: !1, line: 14, type: !9)181!30 = !DILocation(line: 0, scope: !15)182!31 = !DILocation(line: 14, column: 3, scope: !15)183!32 = !DILocation(line: 15, column: 40, scope: !15)184!33 = !DILocation(line: 15, column: 3, scope: !15)185!34 = !DILocation(line: 16, column: 10, scope: !15)186!35 = !{!36, !36, i64 0}187!36 = !{!"int", !37, i64 0}188!37 = !{!"omnipotent char", !38, i64 0}189!38 = !{!"Simple C/C++ TBAA"}190!39 = !DILocation(line: 17, column: 1, scope: !15)191!40 = !DILocation(line: 16, column: 3, scope: !15)192