|
| 1 | +# UNSUPPORTED: system-windows |
| 2 | +# REQUIRES: aarch64 |
| 3 | + |
| 4 | +# RUN: rm -rf %t; split-file %s %t |
| 5 | + |
| 6 | +# Synthesize raw cgdata without the header (32 byte) from the indexed cgdata. |
| 7 | +# RUN: llvm-cgdata --convert --format binary %t/raw-1.cgtext -o %t/raw-1.cgdata |
| 8 | +# 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 |
| 9 | +# RUN: sed "s/<RAW_BYTES>/$(cat %t/raw-1-bytes.txt)/g" %t/merge-template.s > %t/merge-1.s |
| 10 | +# RUN: llvm-cgdata --convert --format binary %t/raw-2.cgtext -o %t/raw-2.cgdata |
| 11 | +# 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 |
| 12 | +# RUN: sed "s/<RAW_BYTES>/$(cat %t/raw-2-bytes.txt)/g" %t/merge-template.s > %t/merge-2.s |
| 13 | + |
| 14 | +# RUN: llvm-mc -filetype obj -triple arm64-apple-darwin %t/merge-1.s -o %t/merge-1.o |
| 15 | +# RUN: llvm-mc -filetype obj -triple arm64-apple-darwin %t/merge-2.s -o %t/merge-2.o |
| 16 | +# RUN: llvm-mc -filetype obj -triple arm64-apple-darwin %t/main.s -o %t/main.o |
| 17 | + |
| 18 | +# This checks if the codegen data from the linker is identical to the merged codegen data |
| 19 | +# from each object file, which is obtained using the llvm-cgdata tool. |
| 20 | +# RUN: %no-arg-lld -dylib -arch arm64 -platform_version ios 14.0 15.0 -o %t/out \ |
| 21 | +# RUN: %t/merge-1.o %t/merge-2.o %t/main.o --codegen-data-generate-path=%t/out-cgdata |
| 22 | +# RUN: llvm-cgdata --merge %t/merge-1.o %t/merge-2.o %t/main.o -o %t/merge-cgdata |
| 23 | +# RUN: diff %t/out-cgdata %t/merge-cgdata |
| 24 | + |
| 25 | +# Merge order doesn't matter in the yaml format. `main.o` is dropped due to missing __llvm_merge. |
| 26 | +# RUN: llvm-cgdata --merge %t/merge-2.o %t/merge-1.o -o %t/merge-cgdata-shuffle |
| 27 | +# RUN: llvm-cgdata --convert %t/out-cgdata -o %t/out-cgdata.yaml |
| 28 | +# RUN: llvm-cgdata --convert %t/merge-cgdata-shuffle -o %t/merge-cgdata-shuffle.yaml |
| 29 | +# RUN: diff %t/out-cgdata.yaml %t/merge-cgdata-shuffle.yaml |
| 30 | + |
| 31 | +# We can also generate the merged codegen data from the executable that is not dead-stripped. |
| 32 | +# RUN: llvm-objdump -h %t/out| FileCheck %s |
| 33 | +# CHECK: __llvm_merge |
| 34 | +# RUN: llvm-cgdata --merge %t/out -o %t/merge-cgdata-exe |
| 35 | +# RUN: diff %t/merge-cgdata-exe %t/merge-cgdata |
| 36 | + |
| 37 | +# Dead-strip will remove __llvm_merge sections from the final executable. |
| 38 | +# But the codeden data is still correctly produced from the linker. |
| 39 | +# RUN: %no-arg-lld -dylib -arch arm64 -platform_version ios 14.0 15.0 -o %t/out-strip \ |
| 40 | +# RUN: %t/merge-1.o %t/merge-2.o %t/main.o -dead_strip --codegen-data-generate-path=%t/out-cgdata-strip |
| 41 | +# RUN: llvm-cgdata --merge %t/merge-1.o %t/merge-2.o %t/main.o -o %t/merge-cgdata-strip |
| 42 | +# RUN: diff %t/out-cgdata-strip %t/merge-cgdata-strip |
| 43 | +# RUN: diff %t/out-cgdata-strip %t/merge-cgdata |
| 44 | + |
| 45 | +# Ensure no __llvm_merge section remains in the executable. |
| 46 | +# RUN: llvm-objdump -h %t/out-strip | FileCheck %s --check-prefix=STRIP |
| 47 | +# STRIP-NOT: __llvm_merge |
| 48 | + |
| 49 | +#--- raw-1.cgtext |
| 50 | +:stable_function_map |
| 51 | +--- |
| 52 | +- Hash: 123 |
| 53 | + FunctionName: f1 |
| 54 | + ModuleName: 'foo.bc' |
| 55 | + InstCount: 7 |
| 56 | + IndexOperandHashes: |
| 57 | + - InstIndex: 3 |
| 58 | + OpndIndex: 0 |
| 59 | + OpndHash: 456 |
| 60 | +... |
| 61 | + |
| 62 | +#--- raw-2.cgtext |
| 63 | +:stable_function_map |
| 64 | +--- |
| 65 | +- Hash: 123 |
| 66 | + FunctionName: f2 |
| 67 | + ModuleName: 'goo.bc' |
| 68 | + InstCount: 7 |
| 69 | + IndexOperandHashes: |
| 70 | + - InstIndex: 3 |
| 71 | + OpndIndex: 0 |
| 72 | + OpndHash: 789 |
| 73 | +... |
| 74 | + |
| 75 | +#--- merge-template.s |
| 76 | +.section __DATA,__llvm_merge |
| 77 | +_data: |
| 78 | +.byte <RAW_BYTES> |
| 79 | + |
| 80 | +#--- main.s |
| 81 | +.globl _main |
| 82 | + |
| 83 | +.text |
| 84 | +_main: |
| 85 | + ret |
0 commit comments