-
Notifications
You must be signed in to change notification settings - Fork 0
[PowerPC][AIX] Support #pragma comment copyright for AIX #1
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: XCOFFAssociatedMetadata
Are you sure you want to change the base?
Changes from 1 commit
fbbb701
cfa6019
82254ee
7af5f2d
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,110 @@ | ||
| // REQUIRES: powerpc-registered-target, system-aix, clang | ||
|
||
| // | ||
| // This test verifies correct handling of `#pragma comment(copyright, ...)` | ||
| // on AIX for multiple Translation Units (TUs). | ||
| // | ||
| // Each TU defines one `#pragma comment(copyright, "...")` which should: | ||
| // - Generate a unique read-only `__llvm_copyright` csect containing the string. | ||
| // - Create a `.ref` directive from at least one function in that TU to the | ||
| // corresponding copyright symbol. | ||
| // - Preserve these copyright strings across LTO and ThinLTO linking. | ||
| // | ||
| // ----------------------------------------------------------------------------- | ||
| // Build WITHOUT LTO | ||
| // ----------------------------------------------------------------------------- | ||
| // RUN: split-file %s %t | ||
| // | ||
| // RUN: %clang_cc1 -triple powerpc-ibm-aix -emit-llvm-bc %t/file1.c -o %t/file1.bc | ||
| // RUN: %clang_cc1 -triple powerpc-ibm-aix -emit-llvm-bc %t/file2.c -o %t/file2.bc | ||
| // RUN: %clang_cc1 -triple powerpc-ibm-aix -emit-llvm-bc %t/file3.c -o %t/file3.bc | ||
| // RUN: %clang_cc1 -triple powerpc-ibm-aix -emit-llvm-bc %t/main.c -o %t/main.bc | ||
| // | ||
| // Compile each bitcode file to XCOFF object and link them together: | ||
| // RUN: %clang -c %t/file1.bc -o %t/file1.o | ||
| // RUN: %clang -c %t/file2.bc -o %t/file2.o | ||
| // RUN: %clang -c %t/file3.bc -o %t/file3.o | ||
| // RUN: %clang -c %t/main.bc -o %t/main.o | ||
| // RUN: %clang %t/file1.o %t/file2.o %t/file3.o %t/main.o -o %t/nonlto.exe | ||
| // | ||
| // Verify assembly emission and linked outputs: | ||
| // RUN: llc -mtriple=powerpc-ibm-aix -filetype=asm %t/file1.bc -o - | FileCheck %s --check-prefix=CHECK-ASM | ||
| // RUN: /bin/strings -a %t/nonlto.exe | FileCheck %s --check-prefix=CHECK-STRINGS | ||
| // RUN: llvm-nm %t/nonlto.exe | FileCheck %s --check-prefix=CHECK-NM | ||
| // RUN: llvm-objdump -r %t/nonlto.exe | FileCheck %s --check-prefix=CHECK-OBJDUMP | ||
| // | ||
| // ----------------------------------------------------------------------------- | ||
| // Build WITH Full LTO | ||
| // ----------------------------------------------------------------------------- | ||
| // RUN: %clang -flto %t/file1.bc %t/file2.bc %t/file3.bc %t/main.bc -o %t/lto.exe | ||
| // RUN: /bin/strings -a %t/lto.exe | FileCheck %s --check-prefix=CHECK-STRINGS | ||
| // RUN: llvm-nm %t/lto.exe | FileCheck %s --check-prefix=CHECK-NM | ||
| // RUN: llvm-objdump -r %t/lto.exe | FileCheck %s --check-prefix=CHECK-OBJDUMP | ||
| // | ||
| // ----------------------------------------------------------------------------- | ||
| // Build WITH ThinLTO | ||
| // ----------------------------------------------------------------------------- | ||
| // RUN: %clang -flto=thin %t/file1.bc %t/file2.bc %t/file3.bc %t/main.bc -o %t/lto-thin.exe | ||
| // RUN: /bin/strings -a %t/lto-thin.exe | FileCheck %s --check-prefix=CHECK-STRINGS | ||
| // RUN: llvm-nm %t/lto-thin.exe | FileCheck %s --check-prefix=CHECK-NM | ||
| // RUN: llvm-objdump -r %t/lto-thin.exe | FileCheck %s --check-prefix=CHECK-OBJDUMP | ||
| // | ||
| // ----------------------------------------------------------------------------- | ||
| // Assembly Checks (for a single TU) | ||
| // ----------------------------------------------------------------------------- | ||
| // | ||
| // Verify that the backend: | ||
| // - Emits a `.ref` directive to tie the string to the TU | ||
| // - Emits the string in a dedicated read-only csect | ||
| // | ||
| // CHECK-ASM: .ref __aix_copyright_str | ||
| // CHECK-ASM: .csect __llvm_copyright[RO],2 | ||
| // CHECK-ASM-NEXT: .lglobl __aix_copyright_str | ||
| // CHECK-ASM: __aix_copyright_str | ||
| // CHECK-ASM: .string "Copyright 2025 TU A" | ||
| // | ||
| // ----------------------------------------------------------------------------- | ||
| // Final Binary Checks | ||
| // ----------------------------------------------------------------------------- | ||
| // | ||
| // Ensure all TUs’ copyright strings are preserved. | ||
| // CHECK-STRINGS-DAG: Copyright 2025 TU A | ||
| // CHECK-STRINGS-DAG: Copyright 2025 TU B | ||
| // CHECK-STRINGS-DAG: Copyright 2025 TU C | ||
| // CHECK-STRINGS-DAG: Copyright 2025 Main Program | ||
| // | ||
| // Check that the symbols are visible in the binary symbol table. | ||
| // CHECK-NM: t __aix_copyright_str | ||
| // CHECK-NM: t __llvm_copyright | ||
| // | ||
| // Ensure there’s a relocation record referencing the copyright symbol. | ||
| // CHECK-OBJDUMP-LABEL: RELOCATION RECORDS FOR [.text] | ||
| // CHECK-OBJDUMP: R_REF __aix_copyright_str | ||
| // | ||
|
|
||
| //=== file1.c === | ||
| //--- file1.c | ||
| #pragma comment(copyright, "Copyright 2025 TU A") | ||
| void func1(void) {} | ||
|
|
||
| //=== file2.c === | ||
| //--- file2.c | ||
| #pragma comment(copyright, "Copyright 2025 TU B") | ||
| void func2(void) {} | ||
|
|
||
| //=== file3.c === | ||
| //--- file3.c | ||
| #pragma comment(copyright, "Copyright 2025 TU C") | ||
| void func3(void) {} | ||
|
|
||
| //=== main.c === | ||
| //--- main.c | ||
| #pragma comment(copyright, "Copyright 2025 Main Program") | ||
| void func1(void); | ||
| void func2(void); | ||
| void func3(void); | ||
| int main(void) { | ||
| func1(); | ||
| func2(); | ||
| func3(); | ||
| return 0; | ||
| } | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,35 @@ | ||
| // REQUIRES: powerpc-registered-target, system-aix | ||
tonykuttai marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| // RUN: %clang_cc1 %s -triple powerpc-ibm-aix -O0 -disable-llvm-passes -emit-llvm -o - | FileCheck %s | ||
| // RUN: %clang_cc1 %s -triple powerpc64-ibm-aix -O0 -disable-llvm-passes -emit-llvm -o - | FileCheck %s | ||
| // RUN: %clang_cc1 %s -triple powerpc-ibm-aix -verify | ||
| // RUN: %clang_cc1 %s -triple powerpc64-ibm-aix -verify | ||
| // RUN: %clang_cc1 %s -DTEST_EMPTY_COPYRIGHT -triple powerpc-ibm-aix -verify | ||
|
|
||
| // RUN: %clang_cc1 %s -x c++ -triple powerpc-ibm-aix -O0 -disable-llvm-passes -emit-llvm -o - | FileCheck %s | ||
| // RUN: %clang_cc1 %s -x c++ -triple powerpc64-ibm-aix -O0 -disable-llvm-passes -emit-llvm -o - | FileCheck %s | ||
| // RUN: %clang_cc1 %s -x c++ -triple powerpc-ibm-aix -verify | ||
| // RUN: %clang_cc1 %s -x c++ -triple powerpc64-ibm-aix -verify | ||
| // RUN: %clang_cc1 %s -x c++ -DTEST_EMPTY_COPYRIGHT -triple powerpc-ibm-aix -verify | ||
|
|
||
| #ifndef TEST_EMPTY_COPYRIGHT | ||
| // Test basic pragma comment types | ||
| #pragma comment(copyright, "@(#) Copyright") | ||
|
|
||
| // Test duplicate copyright - should warn and ignore | ||
| #pragma comment(copyright, "Duplicate Copyright") // expected-warning {{'#pragma comment copyright' can be specified only once per source file - ignored}} | ||
|
|
||
| int main() { return 0; } | ||
|
|
||
| // Check that both metadata sections are present | ||
| // CHECK: !aix.copyright.comment = !{![[copyright:[0-9]+]]} | ||
|
|
||
| // Check individual metadata content | ||
| // CHECK: ![[copyright]] = !{!"@(#) Copyright"} | ||
|
|
||
| #else | ||
| // Test empty copyright string - valid with no warning | ||
| #pragma comment(copyright, "") // expected-no-diagnostics | ||
|
|
||
| int main() { return 0; } | ||
|
|
||
| #endif | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,43 @@ | ||
| //===-- CopyrightMetadataPass.h - Lower AIX copyright metadata -*- C++ -*-===// | ||
| // | ||
| // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. | ||
| // See https://llvm.org/LICENSE.txt for license information. | ||
| // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception | ||
| // | ||
| //===----------------------------------------------------------------------===// | ||
| // | ||
| // The CopyrightMetadataPass lowers the module-level metadata emitted by Clang | ||
| // for `#pragma comment(copyright, "...")` on AIX: | ||
| // | ||
| // !aix.copyright.comment = !{!"Copyright ..."} | ||
| // | ||
| // into an internal constant string global that is preserved across all compiler | ||
| // and linker stages. Each translation unit produces one TU-local string symbol | ||
| // (`__aix_copyright_str`), and the pass attaches `!implicit.ref` metadata to | ||
| // defined functions referencing this symbol. The PowerPC AIX backend recognizes | ||
| // this metadata and emits `.ref` directives in the XCOFF assembly, ensuring the | ||
| // copyright strings: | ||
| // | ||
| // • survive optimization and LTO, | ||
| // • are not removed by linker garbage collection, and | ||
| // • remain visible in the final binary. | ||
| // | ||
tonykuttai marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| //===----------------------------------------------------------------------===// | ||
|
|
||
| #ifndef LLVM_TRANSFORMS_UTILS_COPYRIGHTMETADATAPASS_H | ||
| #define LLVM_TRANSFORMS_UTILS_COPYRIGHTMETADATAPASS_H | ||
|
|
||
| #include "llvm/IR/PassManager.h" | ||
|
|
||
| namespace llvm { | ||
| class CopyrightMetadataPass : public PassInfoMixin<CopyrightMetadataPass> { | ||
| public: | ||
| PreservedAnalyses run(Module &M, ModuleAnalysisManager &AM); | ||
|
|
||
| static bool isRequired() { return true; } | ||
| }; | ||
|
|
||
|
|
||
| } // namespace llvm | ||
|
|
||
| #endif // LLVM_TRANSFORMS_UTILS_WYVERN_COPYRIGHTMETADATAPASS_H | ||
Uh oh!
There was an error while loading. Please reload this page.