[llvm-branch-commits] [llvm] 12573c7 - Revert "[llvm-ar] Use COFF archive format for COFF targets. (#82642)"

via llvm-branch-commits llvm-branch-commits at lists.llvm.org
Sat Feb 24 08:41:26 PST 2024


Author: Jacek Caban
Date: 2024-02-24T17:41:21+01:00
New Revision: 12573c717e2e4b7c8cafe008b8fff8922295fe4a

URL: https://github.com/llvm/llvm-project/commit/12573c717e2e4b7c8cafe008b8fff8922295fe4a
DIFF: https://github.com/llvm/llvm-project/commit/12573c717e2e4b7c8cafe008b8fff8922295fe4a.diff

LOG: Revert "[llvm-ar] Use COFF archive format for COFF targets. (#82642)"

This reverts commit cf9201cfdbc10f4606fc4ca22bf1ccaf5ee841b3.

Added: 
    

Modified: 
    llvm/include/llvm/Object/Archive.h
    llvm/lib/Object/Archive.cpp
    llvm/lib/Object/ArchiveWriter.cpp
    llvm/tools/llvm-ar/llvm-ar.cpp

Removed: 
    llvm/test/tools/llvm-ar/coff-symtab.test


################################################################################
diff  --git a/llvm/include/llvm/Object/Archive.h b/llvm/include/llvm/Object/Archive.h
index 66f07939b11050..3dd99a46507a24 100644
--- a/llvm/include/llvm/Object/Archive.h
+++ b/llvm/include/llvm/Object/Archive.h
@@ -339,7 +339,6 @@ class Archive : public Binary {
   Kind kind() const { return (Kind)Format; }
   bool isThin() const { return IsThin; }
   static object::Archive::Kind getDefaultKindForHost();
-  static object::Archive::Kind getDefaultKindForTriple(Triple &T);
 
   child_iterator child_begin(Error &Err, bool SkipInternal = true) const;
   child_iterator child_end() const;

diff  --git a/llvm/lib/Object/Archive.cpp b/llvm/lib/Object/Archive.cpp
index d3fdcd9ee88111..e447e5b23316f1 100644
--- a/llvm/lib/Object/Archive.cpp
+++ b/llvm/lib/Object/Archive.cpp
@@ -969,19 +969,12 @@ Archive::Archive(MemoryBufferRef Source, Error &Err)
   Err = Error::success();
 }
 
-object::Archive::Kind Archive::getDefaultKindForTriple(Triple &T) {
-  if (T.isOSDarwin())
-    return object::Archive::K_DARWIN;
-  if (T.isOSAIX())
-    return object::Archive::K_AIXBIG;
-  if (T.isOSWindows())
-    return object::Archive::K_COFF;
-  return object::Archive::K_GNU;
-}
-
 object::Archive::Kind Archive::getDefaultKindForHost() {
   Triple HostTriple(sys::getProcessTriple());
-  return getDefaultKindForTriple(HostTriple);
+  return HostTriple.isOSDarwin()
+             ? object::Archive::K_DARWIN
+             : (HostTriple.isOSAIX() ? object::Archive::K_AIXBIG
+                                     : object::Archive::K_GNU);
 }
 
 Archive::child_iterator Archive::child_begin(Error &Err,

diff  --git a/llvm/lib/Object/ArchiveWriter.cpp b/llvm/lib/Object/ArchiveWriter.cpp
index 02f72521c8b544..155926a8c5949d 100644
--- a/llvm/lib/Object/ArchiveWriter.cpp
+++ b/llvm/lib/Object/ArchiveWriter.cpp
@@ -62,16 +62,12 @@ object::Archive::Kind NewArchiveMember::detectKindFromObject() const {
   Expected<std::unique_ptr<object::ObjectFile>> OptionalObject =
       object::ObjectFile::createObjectFile(MemBufferRef);
 
-  if (OptionalObject) {
-    if (isa<object::MachOObjectFile>(**OptionalObject))
-      return object::Archive::K_DARWIN;
-    if (isa<object::XCOFFObjectFile>(**OptionalObject))
-      return object::Archive::K_AIXBIG;
-    if (isa<object::COFFObjectFile>(**OptionalObject) ||
-        isa<object::COFFImportFile>(**OptionalObject))
-      return object::Archive::K_COFF;
-    return object::Archive::K_GNU;
-  }
+  if (OptionalObject)
+    return isa<object::MachOObjectFile>(**OptionalObject)
+               ? object::Archive::K_DARWIN
+               : (isa<object::XCOFFObjectFile>(**OptionalObject)
+                      ? object::Archive::K_AIXBIG
+                      : object::Archive::K_GNU);
 
   // Squelch the error in case we had a non-object file.
   consumeError(OptionalObject.takeError());
@@ -84,7 +80,10 @@ object::Archive::Kind NewArchiveMember::detectKindFromObject() const {
             MemBufferRef, file_magic::bitcode, &Context)) {
       auto &IRObject = cast<object::IRObjectFile>(**ObjOrErr);
       auto TargetTriple = Triple(IRObject.getTargetTriple());
-      return object::Archive::getDefaultKindForTriple(TargetTriple);
+      return TargetTriple.isOSDarwin()
+                 ? object::Archive::K_DARWIN
+                 : (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/coff-symtab.test b/llvm/test/tools/llvm-ar/coff-symtab.test
deleted file mode 100644
index 50d08fba3b02f6..00000000000000
--- a/llvm/test/tools/llvm-ar/coff-symtab.test
+++ /dev/null
@@ -1,85 +0,0 @@
-Verify that llvm-ar uses COFF archive format by ensuring that archive map is sorted.
-
-RUN: rm -rf %t.dif && split-file %s %t.dir && cd %t.dir
-
-RUN: yaml2obj coff-symtab.yaml -o coff-symtab.obj
-RUN: llvm-ar crs out.a coff-symtab.obj
-RUN: llvm-nm --print-armap out.a | FileCheck %s
-
-RUN: llvm-as coff-symtab.ll -o coff-symtab.bc
-RUN: llvm-ar crs out2.a coff-symtab.bc
-RUN: llvm-nm --print-armap out2.a | FileCheck %s
-
-RUN: yaml2obj elf.yaml -o coff-symtab.o
-RUN: llvm-ar crs --format coff out3.a coff-symtab.o
-RUN: llvm-nm --print-armap out3.a | FileCheck %s
-
-CHECK: Archive map
-CHECK-NEXT: a in coff-symtab
-CHECK-NEXT: b in coff-symtab
-CHECK-NEXT: c in coff-symtab
-CHECK-EMPTY:
-
-#--- coff-symtab.yaml
---- !COFF
-header:
-  Machine:           IMAGE_FILE_MACHINE_UNKNOWN
-  Characteristics:   [  ]
-sections:
-  - Name:            .text
-    Characteristics: [ IMAGE_SCN_CNT_CODE, IMAGE_SCN_MEM_EXECUTE, IMAGE_SCN_MEM_READ ]
-    Alignment:       4
-    SectionData:     ''
-symbols:
-  - Name:            b
-    Value:           0
-    SectionNumber:   1
-    SimpleType:      IMAGE_SYM_TYPE_NULL
-    ComplexType:     IMAGE_SYM_DTYPE_FUNCTION
-    StorageClass:    IMAGE_SYM_CLASS_EXTERNAL
-  - Name:            c
-    Value:           0
-    SectionNumber:   1
-    SimpleType:      IMAGE_SYM_TYPE_NULL
-    ComplexType:     IMAGE_SYM_DTYPE_FUNCTION
-    StorageClass:    IMAGE_SYM_CLASS_EXTERNAL
-  - Name:            a
-    Value:           0
-    SectionNumber:   1
-    SimpleType:      IMAGE_SYM_TYPE_NULL
-    ComplexType:     IMAGE_SYM_DTYPE_FUNCTION
-    StorageClass:    IMAGE_SYM_CLASS_EXTERNAL
-...
-
-
-#--- coff-symtab.ll
-target triple = "x86_64-unknown-windows-msvc"
-
-define void @b() { ret void }
-define void @c() { ret void }
-define void @a() { ret void }
-
-#--- elf.yaml
---- !ELF
-FileHeader:
-  Class:             ELFCLASS64
-  Data  :            ELFDATA2LSB
-  Type:              ET_REL
-  Machine:           EM_X86_64
-Sections:
-  - Name:            .text
-    Type:            SHT_PROGBITS
-    Flags:           [ SHF_ALLOC, SHF_EXECINSTR ]
-    AddressAlign:    0x0000000000000004
-    Content:         ''
-Symbols:
-  - Name:            b
-    Binding:         STB_GLOBAL
-    Section:         .text
-  - Name:            c
-    Binding:         STB_GLOBAL
-    Section:         .text
-  - Name:            a
-    Binding:         STB_GLOBAL
-    Section:         .text
-...

diff  --git a/llvm/tools/llvm-ar/llvm-ar.cpp b/llvm/tools/llvm-ar/llvm-ar.cpp
index c58a85c695dacf..c8800303bc1e42 100644
--- a/llvm/tools/llvm-ar/llvm-ar.cpp
+++ b/llvm/tools/llvm-ar/llvm-ar.cpp
@@ -82,7 +82,6 @@ static void printArHelp(StringRef ToolName) {
     =darwin             -   darwin
     =bsd                -   bsd
     =bigarchive         -   big archive (AIX OS)
-    =coff               -   coff
   --plugin=<string>     - ignored for compatibility
   -h --help             - display this help and exit
   --output              - the directory to extract archive members to
@@ -194,7 +193,7 @@ static SmallVector<const char *, 256> PositionalArgs;
 static bool MRI;
 
 namespace {
-enum Format { Default, GNU, COFF, BSD, DARWIN, BIGARCHIVE, Unknown };
+enum Format { Default, GNU, BSD, DARWIN, BIGARCHIVE, Unknown };
 }
 
 static Format FormatType = Default;
@@ -1045,9 +1044,6 @@ static void performWriteOperation(ArchiveOperation Operation,
   case GNU:
     Kind = object::Archive::K_GNU;
     break;
-  case COFF:
-    Kind = object::Archive::K_COFF;
-    break;
   case BSD:
     if (Thin)
       fail("only the gnu format has a thin mode");
@@ -1380,7 +1376,6 @@ static int ar_main(int argc, char **argv) {
                        .Case("darwin", DARWIN)
                        .Case("bsd", BSD)
                        .Case("bigarchive", BIGARCHIVE)
-                       .Case("coff", COFF)
                        .Default(Unknown);
       if (FormatType == Unknown)
         fail(std::string("Invalid format ") + Match);


        


More information about the llvm-branch-commits mailing list