xref: /llvm-project/lld/test/MachO/cgdata-generate.s (revision ffcf3c8688f57acaf6a404a1238673c9d197ba9a)
1f4763b3dSKyungwoo Lee# UNSUPPORTED: system-windows
2f4763b3dSKyungwoo Lee# REQUIRES: aarch64
3f4763b3dSKyungwoo Lee
4f4763b3dSKyungwoo Lee# RUN: rm -rf %t; split-file %s %t
5f4763b3dSKyungwoo Lee
6*ffcf3c86SKyungwoo Lee# Synthesize raw cgdata without the header (32 byte) from the indexed cgdata.
7f4763b3dSKyungwoo Lee# RUN: llvm-cgdata --convert --format binary %t/raw-1.cgtext -o %t/raw-1.cgdata
8*ffcf3c86SKyungwoo Lee# RUN: od -t x1 -j 32 -An %t/raw-1.cgdata | tr -d '\n\r\t' | sed 's/[ ][ ]*/ /g; s/^[ ]*//; s/[ ]*$//; s/[ ]/,0x/g; s/^/0x/' > %t/raw-1-bytes.txt
9f4763b3dSKyungwoo Lee# RUN: sed "s/<RAW_BYTES>/$(cat %t/raw-1-bytes.txt)/g" %t/merge-template.s > %t/merge-1.s
10f4763b3dSKyungwoo Lee# RUN: llvm-cgdata --convert --format binary %t/raw-2.cgtext -o %t/raw-2.cgdata
11*ffcf3c86SKyungwoo Lee# RUN: od -t x1 -j 32 -An %t/raw-2.cgdata | tr -d '\n\r\t' | sed 's/[ ][ ]*/ /g; s/^[ ]*//; s/[ ]*$//; s/[ ]/,0x/g; s/^/0x/' > %t/raw-2-bytes.txt
12f4763b3dSKyungwoo Lee# RUN: sed "s/<RAW_BYTES>/$(cat %t/raw-2-bytes.txt)/g" %t/merge-template.s > %t/merge-2.s
13f4763b3dSKyungwoo Lee
14f4763b3dSKyungwoo Lee# RUN: llvm-mc -filetype obj -triple arm64-apple-darwin %t/merge-1.s -o %t/merge-1.o
15f4763b3dSKyungwoo Lee# RUN: llvm-mc -filetype obj -triple arm64-apple-darwin %t/merge-2.s -o %t/merge-2.o
16f4763b3dSKyungwoo Lee# RUN: llvm-mc -filetype obj -triple arm64-apple-darwin %t/main.s -o %t/main.o
17f4763b3dSKyungwoo Lee
18f4763b3dSKyungwoo Lee# This checks if the codegen data from the linker is identical to the merged codegen data
19f4763b3dSKyungwoo Lee# from each object file, which is obtained using the llvm-cgdata tool.
20f4763b3dSKyungwoo Lee# RUN: %no-arg-lld -dylib -arch arm64 -platform_version ios 14.0 15.0 -o %t/out \
21f4763b3dSKyungwoo Lee# RUN: %t/merge-1.o %t/merge-2.o %t/main.o --codegen-data-generate-path=%t/out-cgdata
22f4763b3dSKyungwoo Lee# RUN: llvm-cgdata --merge %t/merge-1.o %t/merge-2.o %t/main.o -o %t/merge-cgdata
23f4763b3dSKyungwoo Lee# RUN: diff %t/out-cgdata %t/merge-cgdata
24f4763b3dSKyungwoo Lee
25f4763b3dSKyungwoo Lee# Merge order doesn't matter. `main.o` is dropped due to missing __llvm_outline.
26f4763b3dSKyungwoo Lee# RUN: llvm-cgdata --merge %t/merge-2.o %t/merge-1.o -o %t/merge-cgdata-shuffle
27f4763b3dSKyungwoo Lee# RUN: diff %t/out-cgdata %t/merge-cgdata-shuffle
28f4763b3dSKyungwoo Lee
29f4763b3dSKyungwoo Lee# We can also generate the merged codegen data from the executable that is not dead-stripped.
30f4763b3dSKyungwoo Lee# RUN: llvm-objdump -h %t/out| FileCheck %s
31f4763b3dSKyungwoo Lee# CHECK: __llvm_outline
32f4763b3dSKyungwoo Lee# RUN: llvm-cgdata --merge %t/out -o %t/merge-cgdata-exe
33f4763b3dSKyungwoo Lee# RUN: diff %t/merge-cgdata-exe %t/merge-cgdata
34f4763b3dSKyungwoo Lee
35f4763b3dSKyungwoo Lee# Dead-strip will remove __llvm_outline sections from the final executable.
36f4763b3dSKyungwoo Lee# But the codeden data is still correctly produced from the linker.
37f4763b3dSKyungwoo Lee# RUN: %no-arg-lld -dylib -arch arm64 -platform_version ios 14.0 15.0 -o %t/out-strip \
38f4763b3dSKyungwoo Lee# RUN: %t/merge-1.o %t/merge-2.o %t/main.o -dead_strip --codegen-data-generate-path=%t/out-cgdata-strip
39f4763b3dSKyungwoo Lee# RUN: llvm-cgdata --merge %t/merge-1.o %t/merge-2.o %t/main.o -o %t/merge-cgdata-strip
40f4763b3dSKyungwoo Lee# RUN: diff %t/out-cgdata-strip %t/merge-cgdata-strip
41f4763b3dSKyungwoo Lee# RUN: diff %t/out-cgdata-strip %t/merge-cgdata
42f4763b3dSKyungwoo Lee
43f4763b3dSKyungwoo Lee# Ensure no __llvm_outline section remains in the executable.
44f4763b3dSKyungwoo Lee# RUN: llvm-objdump -h %t/out-strip | FileCheck %s --check-prefix=STRIP
45f4763b3dSKyungwoo Lee# STRIP-NOT: __llvm_outline
46f4763b3dSKyungwoo Lee
47f4763b3dSKyungwoo Lee#--- raw-1.cgtext
48f4763b3dSKyungwoo Lee:outlined_hash_tree
49f4763b3dSKyungwoo Lee0:
50f4763b3dSKyungwoo Lee  Hash:            0x0
51f4763b3dSKyungwoo Lee  Terminals:       0
52f4763b3dSKyungwoo Lee  SuccessorIds:    [ 1 ]
53f4763b3dSKyungwoo Lee1:
54f4763b3dSKyungwoo Lee  Hash:            0x1
55f4763b3dSKyungwoo Lee  Terminals:       0
56f4763b3dSKyungwoo Lee  SuccessorIds:    [ 2 ]
57f4763b3dSKyungwoo Lee2:
58f4763b3dSKyungwoo Lee  Hash:            0x2
59f4763b3dSKyungwoo Lee  Terminals:       4
60f4763b3dSKyungwoo Lee  SuccessorIds:    [  ]
61f4763b3dSKyungwoo Lee...
62f4763b3dSKyungwoo Lee
63f4763b3dSKyungwoo Lee#--- raw-2.cgtext
64f4763b3dSKyungwoo Lee:outlined_hash_tree
65f4763b3dSKyungwoo Lee0:
66f4763b3dSKyungwoo Lee  Hash:            0x0
67f4763b3dSKyungwoo Lee  Terminals:       0
68f4763b3dSKyungwoo Lee  SuccessorIds:    [ 1 ]
69f4763b3dSKyungwoo Lee1:
70f4763b3dSKyungwoo Lee  Hash:            0x1
71f4763b3dSKyungwoo Lee  Terminals:       0
72f4763b3dSKyungwoo Lee  SuccessorIds:    [ 2 ]
73f4763b3dSKyungwoo Lee2:
74f4763b3dSKyungwoo Lee  Hash:            0x3
75f4763b3dSKyungwoo Lee  Terminals:       5
76f4763b3dSKyungwoo Lee  SuccessorIds:    [  ]
77f4763b3dSKyungwoo Lee...
78f4763b3dSKyungwoo Lee
79f4763b3dSKyungwoo Lee#--- merge-template.s
80f4763b3dSKyungwoo Lee.section __DATA,__llvm_outline
81f4763b3dSKyungwoo Lee_data:
82f4763b3dSKyungwoo Lee.byte <RAW_BYTES>
83f4763b3dSKyungwoo Lee
84f4763b3dSKyungwoo Lee#--- main.s
85f4763b3dSKyungwoo Lee.globl _main
86f4763b3dSKyungwoo Lee
87f4763b3dSKyungwoo Lee.text
88f4763b3dSKyungwoo Lee_main:
89f4763b3dSKyungwoo Lee  ret
90