xref: /llvm-project/llvm/test/tools/llvm-objdump/BPF/core-relo-byte-offset.ll (revision d15f96fe4b64e24d262fcc727dc0eede327804ba)
1; REQUIRES: bpf-registered-target
2
3;; Verify that llvm-objdump can use .BTF.ext to show CO-RE relocation data.
4
5; RUN: llc --mtriple bpfel %s --filetype=obj -o - | \
6; RUN:   llvm-objdump --no-addresses --no-show-raw-insn -dr - | \
7; RUN:   FileCheck %s
8
9; RUN: llc --mtriple bpfeb %s --filetype=obj -o - | \
10; RUN:   llvm-objdump --no-addresses --no-show-raw-insn -dr - | \
11; RUN:   FileCheck %s
12
13;; Input generated from the following C code:
14;;
15;;  #define __pai __attribute__((preserve_access_index))
16;;
17;;  struct buz {
18;;    int a;
19;;    int b;
20;;  } __pai;
21;;
22;;  struct foo {
23;;    int :4;
24;;    int i;
25;;    struct buz k[10];
26;;  } __pai;
27;;
28;;  struct bar {
29;;    struct foo f;
30;;  } __pai;
31;;
32;;  void * volatile g;
33;;
34;;  void root(void) {
35;;    struct bar *bar = (void *)0;
36;;    g = &bar->f;
37;;    g = &bar->f.i;
38;;    g = &bar->f.k;
39;;    g = &bar->f.k[7].a;
40;;    g = &bar->f.k[7].b;
41;;    g = &bar[1].f.k[7].b;
42;;  }
43;;
44;; Using the following command:
45;;
46;;  clang --target=bpf -g -O2 -emit-llvm -S t.c
47
48; CHECK: CO-RE <byte_off> [[[#bar:]]] struct bar::f (0:0)
49; CHECK: CO-RE <byte_off> [[[#bar]]] struct bar::f.i (0:0:0)
50; CHECK: CO-RE <byte_off> [[[#bar]]] struct bar::f.k (0:0:1)
51; CHECK: CO-RE <byte_off> [[[#bar]]] struct bar::f.k[7].a (0:0:1:7:0)
52; CHECK: CO-RE <byte_off> [[[#bar]]] struct bar::f.k[7].b (0:0:1:7:1)
53; CHECK: CO-RE <byte_off> [[[#bar]]] struct bar::[1].f.k[7].b (1:0:1:7:1)
54
55@g = dso_local global ptr null, align 8, !dbg !0
56@"llvm.bar:0:0$0:0" = external global i64, !llvm.preserve.access.index !14 #0
57@"llvm.bar:0:8$0:0:1" = external global i64, !llvm.preserve.access.index !14 #0
58@"llvm.bar:0:4$0:0:0" = external global i64, !llvm.preserve.access.index !14 #0
59@"llvm.bar:0:64$0:0:1:7:0" = external global i64, !llvm.preserve.access.index !14 #0
60@"llvm.bar:0:68$0:0:1:7:1" = external global i64, !llvm.preserve.access.index !14 #0
61@"llvm.bar:0:156$1:0:1:7:1" = external global i64, !llvm.preserve.access.index !14 #0
62
63; Function Attrs: nofree nounwind memory(readwrite, argmem: none)
64define dso_local void @root() local_unnamed_addr #1 !dbg !29 {
65entry:
66  call void @llvm.dbg.value(metadata ptr null, metadata !33, metadata !DIExpression()), !dbg !34
67  %0 = load i64, ptr @"llvm.bar:0:0$0:0", align 8
68  %1 = getelementptr i8, ptr null, i64 %0
69  %2 = tail call ptr @llvm.bpf.passthrough.p0.p0(i32 0, ptr %1)
70  store volatile ptr %2, ptr @g, align 8, !dbg !35, !tbaa !36
71  %3 = load i64, ptr @"llvm.bar:0:4$0:0:0", align 8
72  %4 = getelementptr i8, ptr null, i64 %3
73  %5 = tail call ptr @llvm.bpf.passthrough.p0.p0(i32 2, ptr %4)
74  store volatile ptr %5, ptr @g, align 8, !dbg !40, !tbaa !36
75  %6 = load i64, ptr @"llvm.bar:0:8$0:0:1", align 8
76  %7 = getelementptr i8, ptr null, i64 %6
77  %8 = tail call ptr @llvm.bpf.passthrough.p0.p0(i32 1, ptr %7)
78  store volatile ptr %8, ptr @g, align 8, !dbg !41, !tbaa !36
79  %9 = load i64, ptr @"llvm.bar:0:64$0:0:1:7:0", align 8
80  %10 = getelementptr i8, ptr null, i64 %9
81  %11 = tail call ptr @llvm.bpf.passthrough.p0.p0(i32 3, ptr %10)
82  store volatile ptr %11, ptr @g, align 8, !dbg !42, !tbaa !36
83  %12 = load i64, ptr @"llvm.bar:0:68$0:0:1:7:1", align 8
84  %13 = getelementptr i8, ptr null, i64 %12
85  %14 = tail call ptr @llvm.bpf.passthrough.p0.p0(i32 4, ptr %13)
86  store volatile ptr %14, ptr @g, align 8, !dbg !43, !tbaa !36
87  %15 = load i64, ptr @"llvm.bar:0:156$1:0:1:7:1", align 8
88  %16 = getelementptr i8, ptr null, i64 %15
89  %17 = tail call ptr @llvm.bpf.passthrough.p0.p0(i32 5, ptr %16)
90  store volatile ptr %17, ptr @g, align 8, !dbg !44, !tbaa !36
91  ret void, !dbg !45
92}
93
94; Function Attrs: nofree nosync nounwind memory(none)
95declare ptr @llvm.bpf.passthrough.p0.p0(i32, ptr) #2
96
97; Function Attrs: nocallback nofree nosync nounwind speculatable willreturn memory(none)
98declare void @llvm.dbg.value(metadata, metadata, metadata) #3
99
100attributes #0 = { "btf_ama" }
101attributes #1 = { nofree nounwind memory(readwrite, argmem: none) "frame-pointer"="all" "no-trapping-math"="true" "stack-protector-buffer-size"="8" }
102attributes #2 = { nofree nosync nounwind memory(none) }
103attributes #3 = { nocallback nofree nosync nounwind speculatable willreturn memory(none) }
104
105!llvm.dbg.cu = !{!2}
106!llvm.module.flags = !{!24, !25, !26, !27}
107!llvm.ident = !{!28}
108
109!0 = !DIGlobalVariableExpression(var: !1, expr: !DIExpression())
110!1 = distinct !DIGlobalVariable(name: "g", scope: !2, file: !3, line: 18, type: !22, isLocal: false, isDefinition: true)
111!2 = distinct !DICompileUnit(language: DW_LANG_C11, file: !3, producer: "clang version 17.0.0 (/home/eddy/work/llvm-project/clang 2f8c5c0afd1d79a771dd74c8fb1e5bbae6d04eb7)", isOptimized: true, runtimeVersion: 0, emissionKind: FullDebug, retainedTypes: !4, globals: !21, splitDebugInlining: false, nameTableKind: None)
112!3 = !DIFile(filename: "t.c", directory: "/home/eddy/work/tmp", checksumkind: CSK_MD5, checksum: "f7c638151153f385e69bef98e88c80ef")
113!4 = !{!5, !13}
114!5 = !DICompositeType(tag: DW_TAG_array_type, baseType: !6, size: 640, elements: !11)
115!6 = distinct !DICompositeType(tag: DW_TAG_structure_type, name: "buz", file: !3, line: 3, size: 64, elements: !7)
116!7 = !{!8, !10}
117!8 = !DIDerivedType(tag: DW_TAG_member, name: "a", scope: !6, file: !3, line: 4, baseType: !9, size: 32)
118!9 = !DIBasicType(name: "int", size: 32, encoding: DW_ATE_signed)
119!10 = !DIDerivedType(tag: DW_TAG_member, name: "b", scope: !6, file: !3, line: 5, baseType: !9, size: 32, offset: 32)
120!11 = !{!12}
121!12 = !DISubrange(count: 10)
122!13 = !DIDerivedType(tag: DW_TAG_pointer_type, baseType: !14, size: 64)
123!14 = distinct !DICompositeType(tag: DW_TAG_structure_type, name: "bar", file: !3, line: 14, size: 704, elements: !15)
124!15 = !{!16}
125!16 = !DIDerivedType(tag: DW_TAG_member, name: "f", scope: !14, file: !3, line: 15, baseType: !17, size: 704)
126!17 = distinct !DICompositeType(tag: DW_TAG_structure_type, name: "foo", file: !3, line: 8, size: 704, elements: !18)
127!18 = !{!19, !20}
128!19 = !DIDerivedType(tag: DW_TAG_member, name: "i", scope: !17, file: !3, line: 10, baseType: !9, size: 32, offset: 32)
129!20 = !DIDerivedType(tag: DW_TAG_member, name: "k", scope: !17, file: !3, line: 11, baseType: !5, size: 640, offset: 64)
130!21 = !{!0}
131!22 = !DIDerivedType(tag: DW_TAG_volatile_type, baseType: !23)
132!23 = !DIDerivedType(tag: DW_TAG_pointer_type, baseType: null, size: 64)
133!24 = !{i32 7, !"Dwarf Version", i32 5}
134!25 = !{i32 2, !"Debug Info Version", i32 3}
135!26 = !{i32 1, !"wchar_size", i32 4}
136!27 = !{i32 7, !"frame-pointer", i32 2}
137!28 = !{!"clang version 17.0.0 (/home/eddy/work/llvm-project/clang 2f8c5c0afd1d79a771dd74c8fb1e5bbae6d04eb7)"}
138!29 = distinct !DISubprogram(name: "root", scope: !3, file: !3, line: 20, type: !30, scopeLine: 20, flags: DIFlagPrototyped | DIFlagAllCallsDescribed, spFlags: DISPFlagDefinition | DISPFlagOptimized, unit: !2, retainedNodes: !32)
139!30 = !DISubroutineType(types: !31)
140!31 = !{null}
141!32 = !{!33}
142!33 = !DILocalVariable(name: "bar", scope: !29, file: !3, line: 21, type: !13)
143!34 = !DILocation(line: 0, scope: !29)
144!35 = !DILocation(line: 22, column: 5, scope: !29)
145!36 = !{!37, !37, i64 0}
146!37 = !{!"any pointer", !38, i64 0}
147!38 = !{!"omnipotent char", !39, i64 0}
148!39 = !{!"Simple C/C++ TBAA"}
149!40 = !DILocation(line: 23, column: 5, scope: !29)
150!41 = !DILocation(line: 24, column: 5, scope: !29)
151!42 = !DILocation(line: 25, column: 5, scope: !29)
152!43 = !DILocation(line: 26, column: 5, scope: !29)
153!44 = !DILocation(line: 27, column: 5, scope: !29)
154!45 = !DILocation(line: 28, column: 1, scope: !29)
155