[llvm] ceb9094 - [llvm-ar] -s: don't convert a thin archive to a regular one

Fangrui Song via llvm-commits llvm-commits at lists.llvm.org
Tue Feb 1 09:59:55 PST 2022


Author: Fangrui Song
Date: 2022-02-01T09:59:51-08:00
New Revision: ceb9094a49134d21333150dd876fbb09a165eb3a

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

LOG: [llvm-ar] -s: don't convert a thin archive to a regular one

In binutils, ar -s and randlib don't convert a thin archive to a regular one.
This behavior makes sense and this patch ports the behavior.

Reviewed By: gbreynoo

Differential Revision: https://reviews.llvm.org/D117443

Added: 
    

Modified: 
    llvm/test/tools/llvm-ar/symtab.test
    llvm/tools/llvm-ar/llvm-ar.cpp

Removed: 
    


################################################################################
diff  --git a/llvm/test/tools/llvm-ar/symtab.test b/llvm/test/tools/llvm-ar/symtab.test
index 098b769f4a4e..74d1bee2014c 100644
--- a/llvm/test/tools/llvm-ar/symtab.test
+++ b/llvm/test/tools/llvm-ar/symtab.test
@@ -58,9 +58,23 @@
 # RUN: llvm-nm --print-armap %t-thin.a \
 # RUN:   | FileCheck %s --check-prefix=SYMTAB
 
+## llvm-ranlib does not change a thin archive to a regular one.
+# RUN: rm -f %t-thin.a && llvm-ar rcTS %t-thin.a %t.o
+# RUN: llvm-nm --print-armap %t-thin.a | FileCheck %s --check-prefix=NO-SYMTAB
+# RUN: llvm-ranlib %t-thin.a
+# RUN: llvm-nm --print-armap %t-thin.a | FileCheck %s --check-prefix=SYMTAB
+# RUN: FileCheck --input-file=%t-thin.a %s --check-prefixes=THIN
+
+## llvm-ar -s is identical to ranlib and a duplicated operation does not change the output.
+# RUN: rm -f %t-thin2.a && llvm-ar rcTS %t-thin2.a %t.o
+# RUN: llvm-ar s %t-thin2.a && cmp %t-thin.a %t-thin2.a
+# RUN: llvm-ar s %t-thin2.a && cmp %t-thin.a %t-thin2.a
+
 # SYMTAB:        symbol in
 # NO-SYMTAB-NOT: symbol in
 
+# THIN: !<thin>
+
 --- !ELF
 FileHeader:
   Class:   ELFCLASS64

diff  --git a/llvm/tools/llvm-ar/llvm-ar.cpp b/llvm/tools/llvm-ar/llvm-ar.cpp
index 1ece120c2331..8842162f5216 100644
--- a/llvm/tools/llvm-ar/llvm-ar.cpp
+++ b/llvm/tools/llvm-ar/llvm-ar.cpp
@@ -968,6 +968,8 @@ static void createSymbolTable(object::Archive *OldArchive) {
   if (OldArchive->hasSymbolTable())
     return;
 
+  if (OldArchive->isThin())
+    Thin = true;
   performWriteOperation(CreateSymTab, OldArchive, nullptr, nullptr);
 }
 


        


More information about the llvm-commits mailing list