|
| 1 | +// REQUIRES: powerpc-registered-target, system-aix, clang |
| 2 | +// |
| 3 | +// This test verifies correct handling of `#pragma comment(copyright, ...)` |
| 4 | +// on AIX for multiple Translation Units (TUs). |
| 5 | +// |
| 6 | +// Each TU defines one `#pragma comment(copyright, "...")` which should: |
| 7 | +// - Generate a unique read-only `__llvm_copyright` csect containing the string. |
| 8 | +// - Create a `.ref` directive from at least one function in that TU to the |
| 9 | +// corresponding copyright symbol. |
| 10 | +// - Preserve these copyright strings across LTO and ThinLTO linking. |
| 11 | +// |
| 12 | +// ----------------------------------------------------------------------------- |
| 13 | +// Build WITHOUT LTO |
| 14 | +// ----------------------------------------------------------------------------- |
| 15 | +// RUN: split-file %s %t |
| 16 | +// |
| 17 | +// RUN: %clang_cc1 -triple powerpc-ibm-aix -emit-llvm-bc %t/file1.c -o %t/file1.bc |
| 18 | +// RUN: %clang_cc1 -triple powerpc-ibm-aix -emit-llvm-bc %t/file2.c -o %t/file2.bc |
| 19 | +// RUN: %clang_cc1 -triple powerpc-ibm-aix -emit-llvm-bc %t/file3.c -o %t/file3.bc |
| 20 | +// RUN: %clang_cc1 -triple powerpc-ibm-aix -emit-llvm-bc %t/main.c -o %t/main.bc |
| 21 | +// |
| 22 | +// Compile each bitcode file to XCOFF object and link them together: |
| 23 | +// RUN: %clang -c %t/file1.bc -o %t/file1.o |
| 24 | +// RUN: %clang -c %t/file2.bc -o %t/file2.o |
| 25 | +// RUN: %clang -c %t/file3.bc -o %t/file3.o |
| 26 | +// RUN: %clang -c %t/main.bc -o %t/main.o |
| 27 | +// RUN: %clang %t/file1.o %t/file2.o %t/file3.o %t/main.o -o %t/nonlto.exe |
| 28 | +// |
| 29 | +// Verify assembly emission and linked outputs: |
| 30 | +// RUN: llc -mtriple=powerpc-ibm-aix -filetype=asm %t/file1.bc -o - | FileCheck %s --check-prefix=CHECK-ASM |
| 31 | +// RUN: /bin/strings -a %t/nonlto.exe | FileCheck %s --check-prefix=CHECK-STRINGS |
| 32 | +// RUN: llvm-nm %t/nonlto.exe | FileCheck %s --check-prefix=CHECK-NM |
| 33 | +// RUN: llvm-objdump -r %t/nonlto.exe | FileCheck %s --check-prefix=CHECK-OBJDUMP |
| 34 | +// |
| 35 | +// ----------------------------------------------------------------------------- |
| 36 | +// Build WITH Full LTO |
| 37 | +// ----------------------------------------------------------------------------- |
| 38 | +// RUN: %clang -flto %t/file1.bc %t/file2.bc %t/file3.bc %t/main.bc -o %t/lto.exe |
| 39 | +// RUN: /bin/strings -a %t/lto.exe | FileCheck %s --check-prefix=CHECK-STRINGS |
| 40 | +// RUN: llvm-nm %t/lto.exe | FileCheck %s --check-prefix=CHECK-NM |
| 41 | +// RUN: llvm-objdump -r %t/lto.exe | FileCheck %s --check-prefix=CHECK-OBJDUMP |
| 42 | +// |
| 43 | +// ----------------------------------------------------------------------------- |
| 44 | +// Build WITH ThinLTO |
| 45 | +// ----------------------------------------------------------------------------- |
| 46 | +// RUN: %clang -flto=thin %t/file1.bc %t/file2.bc %t/file3.bc %t/main.bc -o %t/lto-thin.exe |
| 47 | +// RUN: /bin/strings -a %t/lto-thin.exe | FileCheck %s --check-prefix=CHECK-STRINGS |
| 48 | +// RUN: llvm-nm %t/lto-thin.exe | FileCheck %s --check-prefix=CHECK-NM |
| 49 | +// RUN: llvm-objdump -r %t/lto-thin.exe | FileCheck %s --check-prefix=CHECK-OBJDUMP |
| 50 | +// |
| 51 | +// ----------------------------------------------------------------------------- |
| 52 | +// Assembly Checks (for a single TU) |
| 53 | +// ----------------------------------------------------------------------------- |
| 54 | +// |
| 55 | +// Verify that the backend: |
| 56 | +// - Emits a `.ref` directive to tie the string to the TU |
| 57 | +// - Emits the string in a dedicated read-only csect |
| 58 | +// |
| 59 | +// CHECK-ASM: .ref __aix_copyright_str |
| 60 | +// CHECK-ASM: .csect __llvm_copyright[RO],2 |
| 61 | +// CHECK-ASM-NEXT: .lglobl __aix_copyright_str |
| 62 | +// CHECK-ASM: __aix_copyright_str |
| 63 | +// CHECK-ASM: .string "Copyright 2025 TU A" |
| 64 | +// |
| 65 | +// ----------------------------------------------------------------------------- |
| 66 | +// Final Binary Checks |
| 67 | +// ----------------------------------------------------------------------------- |
| 68 | +// |
| 69 | +// Ensure all TUs’ copyright strings are preserved. |
| 70 | +// CHECK-STRINGS-DAG: Copyright 2025 TU A |
| 71 | +// CHECK-STRINGS-DAG: Copyright 2025 TU B |
| 72 | +// CHECK-STRINGS-DAG: Copyright 2025 TU C |
| 73 | +// CHECK-STRINGS-DAG: Copyright 2025 Main Program |
| 74 | +// |
| 75 | +// Check that the symbols are visible in the binary symbol table. |
| 76 | +// CHECK-NM: t __aix_copyright_str |
| 77 | +// CHECK-NM: t __llvm_copyright |
| 78 | +// |
| 79 | +// Ensure there’s a relocation record referencing the copyright symbol. |
| 80 | +// CHECK-OBJDUMP-LABEL: RELOCATION RECORDS FOR [.text] |
| 81 | +// CHECK-OBJDUMP: R_REF __aix_copyright_str |
| 82 | +// |
| 83 | + |
| 84 | +//=== file1.c === |
| 85 | +//--- file1.c |
| 86 | +#pragma comment(copyright, "Copyright 2025 TU A") |
| 87 | +void func1(void) {} |
| 88 | + |
| 89 | +//=== file2.c === |
| 90 | +//--- file2.c |
| 91 | +#pragma comment(copyright, "Copyright 2025 TU B") |
| 92 | +void func2(void) {} |
| 93 | + |
| 94 | +//=== file3.c === |
| 95 | +//--- file3.c |
| 96 | +#pragma comment(copyright, "Copyright 2025 TU C") |
| 97 | +void func3(void) {} |
| 98 | + |
| 99 | +//=== main.c === |
| 100 | +//--- main.c |
| 101 | +#pragma comment(copyright, "Copyright 2025 Main Program") |
| 102 | +void func1(void); |
| 103 | +void func2(void); |
| 104 | +void func3(void); |
| 105 | +int main(void) { |
| 106 | + func1(); |
| 107 | + func2(); |
| 108 | + func3(); |
| 109 | + return 0; |
| 110 | +} |
0 commit comments