[PATCH] D40632: Add flag to llvm-ar to test GNU64 format more efficently

Jake Ehrlich via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Wed Nov 29 17:07:49 PST 2017


jakehehrlich created this revision.

Even with the sparse file optimizations the SYM64 test can still be painfully slow. This unnecessarily slows down devs. It's critical that we test that the switch to the SYM64 format occurs at 4GB but there isn't any better of a way to fake the size of the file than sparse files. This change introduces a flag that allows the cutoff to be arbitrarily set to whatever power of two is desired. The flag is hidden as it really isn't meant to be used outside this one test. This is unfortunate but appears necessary, at least until the average hard drive is much faster.

The changes to the test require some explanation. Prior to this change we knew that the SYM64 format was being used because the file was simply too large to have validly handled this case if the SYM64 format were not used. To ensure that the SYM64 format is still being used I am grepping the file for "SYM64". Without changing the filename however this would be pointless because "SYM64" would occur in the file either way. So the filename of the test is also changed in order to avoid this issue.


Repository:
  rL LLVM

https://reviews.llvm.org/D40632

Files:
  include/llvm/Object/ArchiveWriter.h
  lib/Object/ArchiveWriter.cpp
  test/Object/archive-GNU64-write.test
  test/Object/archive-SYM64-write.test
  tools/llvm-ar/llvm-ar.cpp


Index: tools/llvm-ar/llvm-ar.cpp
===================================================================
--- tools/llvm-ar/llvm-ar.cpp
+++ tools/llvm-ar/llvm-ar.cpp
@@ -99,6 +99,8 @@
                          clEnumValN(DARWIN, "darwin", "darwin"),
                          clEnumValN(BSD, "bsd", "bsd")));
 
+static cl::opt<int> Sym64PowerOfTwo("sym64-power-of-two", cl::Hidden);
+
 static std::string Options;
 
 // Provide additional help output explaining the operations and modifiers of
@@ -683,9 +685,16 @@
     break;
   }
 
-  Error E =
-      writeArchive(ArchiveName, NewMembersP ? *NewMembersP : NewMembers, Symtab,
-                   Kind, Deterministic, Thin, std::move(OldArchiveBuf));
+  // The cutoff should always be 2^32 in practice but for testing we'd like it
+  // to be smaller. The Sym64PowerOfTwo flag allows us to change the cutoff to
+  // speed things up.
+  uint64_t CutoffForSym64 = 1ULL << 32;
+  if (Sym64PowerOfTwo != 0)
+    CutoffForSym64 = 1 << (Sym64PowerOfTwo.getValue() - 1);
+
+  Error E = writeArchive(ArchiveName, NewMembersP ? *NewMembersP : NewMembers,
+                         Symtab, Kind, Deterministic, Thin, CutoffForSym64,
+                         std::move(OldArchiveBuf));
   failIfError(std::move(E), ArchiveName);
 }
 
Index: test/Object/archive-GNU64-write.test
===================================================================
--- test/Object/archive-GNU64-write.test
+++ test/Object/archive-GNU64-write.test
@@ -2,11 +2,12 @@
 # REQUIRES: system-linux
 
 # RUN: yaml2obj %s > %t
-# RUN: dd if=%t of=%t bs=1 count=0 seek=2200M
+# RUN: dd if=%t of=%t bs=1 count=0 seek=1M
 # RUN: rm -f %t.lib
 # RUN: cp %t %t2
-# RUN: llvm-ar cr %t.lib %t %t2 %p/Inputs/trivial-object-test.elf-x86-64
+# RUN: llvm-ar -sym64-power-of-two=19 cr %t.lib %t %t2 %p/Inputs/trivial-object-test.elf-x86-64
 # RUN: llvm-nm --print-armap %t.lib | FileCheck %s
+# RUN: grep SYM64 %t.lib
 
 # Delete temp files. They are too large.
 # RUN: rm -f %t %t2 %t.lib
@@ -28,9 +29,9 @@
 # CHECK:      Archive map
 # CHECK-NEXT: main in trivial-object-test.elf-x86-64
 
-# CHECK:    archive-SYM64-write.test.tmp:
+# CHECK:    archive-GNU64-write.test.tmp:
 
-# CHECK:    archive-SYM64-write.test.tmp2:
+# CHECK:    archive-GNU64-write.test.tmp2:
 
 # CHECK:    trivial-object-test.elf-x86-64:
 # CHECK-NEXT:                     U SomeOtherFunction
Index: lib/Object/ArchiveWriter.cpp
===================================================================
--- lib/Object/ArchiveWriter.cpp
+++ lib/Object/ArchiveWriter.cpp
@@ -451,7 +451,7 @@
 Error llvm::writeArchive(StringRef ArcName,
                          ArrayRef<NewArchiveMember> NewMembers,
                          bool WriteSymtab, object::Archive::Kind Kind,
-                         bool Deterministic, bool Thin,
+                         bool Deterministic, bool Thin, uint64_t CutoffForSym64,
                          std::unique_ptr<MemoryBuffer> OldArchiveBuf) {
   assert((!Thin || !isBSDLike(Kind)) && "Only the gnu format has a thin mode");
 
@@ -484,7 +484,7 @@
     // If LastOffset isn't going to fit in a 32-bit varible we need to switch
     // to 64-bit. Note that the file can be larger than 4GB as long as the last
     // member starts before the 4GB offset.
-    if (LastOffset >> 32 != 0)
+    if (LastOffset >= CutoffForSym64)
       Kind = object::Archive::K_GNU64;
   }
 
Index: include/llvm/Object/ArchiveWriter.h
===================================================================
--- include/llvm/Object/ArchiveWriter.h
+++ include/llvm/Object/ArchiveWriter.h
@@ -41,6 +41,7 @@
 Error writeArchive(StringRef ArcName, ArrayRef<NewArchiveMember> NewMembers,
                    bool WriteSymtab, object::Archive::Kind Kind,
                    bool Deterministic, bool Thin,
+                   uint64_t CutoffForSym64 = 1ULL << 32,
                    std::unique_ptr<MemoryBuffer> OldArchiveBuf = nullptr);
 }
 


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D40632.124857.patch
Type: text/x-patch
Size: 3920 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20171130/8260c8a8/attachment.bin>


More information about the llvm-commits mailing list