]> granicus.if.org Git - llvm/commitdiff
Add flag to ArchiveWriter to test GNU64 format more efficiently
authorJake Ehrlich <jakehehrlich@google.com>
Fri, 1 Dec 2017 00:54:28 +0000 (00:54 +0000)
committerJake Ehrlich <jakehehrlich@google.com>
Fri, 1 Dec 2017 00:54:28 +0000 (00:54 +0000)
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.

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

git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@319507 91177308-0d34-0410-b5e6-96231b3b80d8

lib/Object/ArchiveWriter.cpp
test/Object/archive-GNU64-write.test [moved from test/Object/archive-SYM64-write.test with 77% similarity]

index 8448b617b78b39b4b3b56e921bf9f6a26fb508de..b3b812daae2efb4c6518315eba9d833f003c80b0 100644 (file)
 
 using namespace llvm;
 
+// The SYM64 format is used when an archive's member offsets are larger than
+// 32-bits can hold. The need for this shift in format is detected by
+// writeArchive. To test this we need to generate a file with a member that has
+// an offset larger than 32-bits but this demands a very slow test. To speed
+// the test up we use this flag to pretend like the cutoff happens before
+// 32-bits and instead happens at some much smaller value.
+static cl::opt<int> Sym64Threshold("sym64-threshold", cl::Hidden,
+                                   cl::init(32));
+
 NewArchiveMember::NewArchiveMember(MemoryBufferRef BufRef)
     : Buf(MemoryBuffer::getMemBuffer(BufRef, false)),
       MemberName(BufRef.getBufferIdentifier()) {}
@@ -484,7 +493,7 @@ Error llvm::writeArchive(StringRef ArcName,
     // 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 >= (1ULL << Sym64Threshold))
       Kind = object::Archive::K_GNU64;
   }
 
similarity index 77%
rename from test/Object/archive-SYM64-write.test
rename to test/Object/archive-GNU64-write.test
index 161d6cb81916051e1013f6e283c46ffd28656801..1ba9c7493e33177b2c9460dda06696ea1db9d1d8 100644 (file)
@@ -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-threshold=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 @@ Sections:
 # 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