From fae9d4df8fcff802dc7b0c344c61c70cc2a20697 Mon Sep 17 00:00:00 2001 From: Qiongsi Wu Date: Fri, 28 Apr 2023 08:42:51 -0400 Subject: [PATCH] [AIX][llvm-ar] Use the Correct Kind for Bitcode File Inputs On AIX, when the input files are LLVM bitcode files, `llvm-ar` should set the archive kind to `K_AIXBIG` as well, instead of leaving it to the default `K_GNU`. Reviewed By: daltenty Differential Revision: https://reviews.llvm.org/D149377 --- llvm/lib/Object/ArchiveWriter.cpp | 6 ++++-- llvm/test/tools/llvm-ar/Inputs/aix-foo.ll | 8 ++++++++ llvm/test/tools/llvm-ar/aix-bitcode.test | 7 +++++++ 3 files changed, 19 insertions(+), 2 deletions(-) create mode 100644 llvm/test/tools/llvm-ar/Inputs/aix-foo.ll create mode 100644 llvm/test/tools/llvm-ar/aix-bitcode.test diff --git a/llvm/lib/Object/ArchiveWriter.cpp b/llvm/lib/Object/ArchiveWriter.cpp index e9b8811..1a540e2 100644 --- a/llvm/lib/Object/ArchiveWriter.cpp +++ b/llvm/lib/Object/ArchiveWriter.cpp @@ -76,9 +76,11 @@ object::Archive::Kind NewArchiveMember::detectKindFromObject() const { if (auto ObjOrErr = object::SymbolicFile::createSymbolicFile( MemBufferRef, file_magic::bitcode, &Context)) { auto &IRObject = cast(**ObjOrErr); - return Triple(IRObject.getTargetTriple()).isOSDarwin() + auto TargetTriple = Triple(IRObject.getTargetTriple()); + return TargetTriple.isOSDarwin() ? object::Archive::K_DARWIN - : object::Archive::K_GNU; + : (TargetTriple.isOSAIX() ? object::Archive::K_AIXBIG + : object::Archive::K_GNU); } else { // Squelch the error in case this was not a SymbolicFile. consumeError(ObjOrErr.takeError()); diff --git a/llvm/test/tools/llvm-ar/Inputs/aix-foo.ll b/llvm/test/tools/llvm-ar/Inputs/aix-foo.ll new file mode 100644 index 0000000..a22652d --- /dev/null +++ b/llvm/test/tools/llvm-ar/Inputs/aix-foo.ll @@ -0,0 +1,8 @@ +target datalayout = "E-m:a-Fi64-i64:64-n32:64-S128-v256:256:256-v512:512:512" +target triple = "powerpc64-ibm-aix7.2.0.0" + +define signext i32 @foo() { +entry: + ret i32 42 +} + diff --git a/llvm/test/tools/llvm-ar/aix-bitcode.test b/llvm/test/tools/llvm-ar/aix-bitcode.test new file mode 100644 index 0000000..d3ce6f1 --- /dev/null +++ b/llvm/test/tools/llvm-ar/aix-bitcode.test @@ -0,0 +1,7 @@ +# Check if llvm-ar correctly archives bitcode files for AIX. +# RUN: rm -rf %t && mkdir -p %t +# RUN: llvm-as %S/Inputs/aix-foo.ll -o %t/aix-foo.bc +# RUN: llvm-ar qc %t/aix-foo.a %t/aix-foo.bc +# RUN: FileCheck %s --input-file=%t/aix-foo.a + +# CHECK: bigaf -- 2.7.4