[PATCH] D84209: [llvm-libtool-darwin] Add support for -D option

Sameer Arora via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Tue Jul 21 10:44:11 PDT 2020


sameerarora101 updated this revision to Diff 279576.
sameerarora101 added a comment.

Rebasing


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D84209/new/

https://reviews.llvm.org/D84209

Files:
  llvm/docs/CommandGuide/llvm-libtool-darwin.rst
  llvm/test/tools/llvm-libtool-darwin/deterministic-library.test
  llvm/tools/llvm-libtool-darwin/llvm-libtool-darwin.cpp


Index: llvm/tools/llvm-libtool-darwin/llvm-libtool-darwin.cpp
===================================================================
--- llvm/tools/llvm-libtool-darwin/llvm-libtool-darwin.cpp
+++ llvm/tools/llvm-libtool-darwin/llvm-libtool-darwin.cpp
@@ -42,6 +42,10 @@
                    "Produce a statically linked library from the input files")),
     cl::Required, cl::cat(LibtoolCategory));
 
+static cl::opt<bool>
+    Deterministic("D", cl::desc("Use zero for timestamps and UIDs/GIDs"),
+                  cl::init(false), cl::cat(LibtoolCategory));
+
 static cl::opt<std::string>
     FileList("filelist",
              cl::desc("Pass in file containing a list of filenames"),
@@ -100,7 +104,7 @@
 static Error addChildMember(std::vector<NewArchiveMember> &Members,
                             const object::Archive::Child &M) {
   Expected<NewArchiveMember> NMOrErr =
-      NewArchiveMember::getOldMember(M, /*Deterministic=*/true);
+      NewArchiveMember::getOldMember(M, Deterministic);
   if (!NMOrErr)
     return NMOrErr.takeError();
 
@@ -116,7 +120,7 @@
 addMember(std::vector<NewArchiveMember> &Members, StringRef FileName,
           std::vector<std::unique_ptr<MemoryBuffer>> &ArchiveBuffers) {
   Expected<NewArchiveMember> NMOrErr =
-      NewArchiveMember::getFile(FileName, /*Deterministic=*/true);
+      NewArchiveMember::getFile(FileName, Deterministic);
   if (!NMOrErr)
     return createFileError(FileName, NMOrErr.takeError());
 
@@ -162,8 +166,7 @@
 
   if (Error E = writeArchive(OutputFile, NewMembers,
                              /*WriteSymtab=*/true,
-                             /*Kind=*/object::Archive::K_DARWIN,
-                             /*Deterministic=*/true,
+                             /*Kind=*/object::Archive::K_DARWIN, Deterministic,
                              /*Thin=*/false))
     return E;
   return Error::success();
Index: llvm/test/tools/llvm-libtool-darwin/deterministic-library.test
===================================================================
--- /dev/null
+++ llvm/test/tools/llvm-libtool-darwin/deterministic-library.test
@@ -0,0 +1,25 @@
+## This test checks that timestamps/etc. are set to 0 when -D option is
+## specified, and preserved otherwise.
+## We only test timestamps as a proxy for full deterministic writing; i.e. we
+## assume UID/GIDs are preserved if timestamps are preserved.
+
+# RUN: yaml2obj %S/Inputs/input1.yaml -o %t-input1.o
+# RUN: touch -t 199505050555.55 %t-input1.o
+
+## Test values are set to 0 (with -D):
+# RUN: llvm-libtool-darwin -static -o %t.lib -D %t-input1.o
+# RUN: env TZ=GMT llvm-ar tv %t.lib | FileCheck %s --check-prefix=CHECK-DETERMINISTIC
+
+# CHECK-DETERMINISTIC: {{[[:space:]]1970[[:space:]]}}
+
+## Test values are preserved (without -D):
+# RUN: llvm-libtool-darwin -static -o %t.lib %t-input1.o
+# RUN: env TZ=GMT llvm-ar tv %t.lib | FileCheck %s --check-prefix=CHECK-NONDETERMINISTIC
+
+# CHECK-NONDETERMINISTIC:  {{[[:space:]]1995[[:space:]]}}
+
+## D Flag specified more than once:
+# RUN: not llvm-libtool-darwin -static -o %t.lib %t-input1.o -D -D 2>&1 | \
+# RUN:   FileCheck %s --check-prefix=CHECK-ERROR
+
+# CHECK-ERROR: for the -D option: may only occur zero or one times!
Index: llvm/docs/CommandGuide/llvm-libtool-darwin.rst
===================================================================
--- llvm/docs/CommandGuide/llvm-libtool-darwin.rst
+++ llvm/docs/CommandGuide/llvm-libtool-darwin.rst
@@ -38,6 +38,10 @@
 
   Display the version of this program.
 
+.. option:: -D
+
+ Use zero for timestamps and UIDs/GIDs.
+
 .. option:: -o <filename>
 
   Specify the output file name. Must be specified exactly once.


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D84209.279576.patch
Type: text/x-patch
Size: 3655 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20200721/eaf677b0/attachment.bin>


More information about the llvm-commits mailing list