[llvm-branch-commits] [llvm] d034a94 - Revert "[llvm-elfabi] Add flag to preserve timestamp when output is the same"

Haowei Wu via llvm-branch-commits llvm-branch-commits at lists.llvm.org
Tue Dec 29 17:31:34 PST 2020


Author: Haowei Wu
Date: 2020-12-29T17:26:22-08:00
New Revision: d034a94e7b3c8122acc91c4dad13110d15ed97d0

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

LOG: Revert "[llvm-elfabi] Add flag to preserve timestamp when output is the same"

This reverts commit fddb41744958d21635a60622cfb4067122810bcc. which
causes test failures on Mac builders.

Added: 
    

Modified: 
    llvm/include/llvm/InterfaceStub/ELFObjHandler.h
    llvm/lib/InterfaceStub/ELFObjHandler.cpp
    llvm/tools/llvm-elfabi/llvm-elfabi.cpp

Removed: 
    llvm/test/tools/llvm-elfabi/preserve-dates-stub.test
    llvm/test/tools/llvm-elfabi/preserve-dates-tbe.test


################################################################################
diff  --git a/llvm/include/llvm/InterfaceStub/ELFObjHandler.h b/llvm/include/llvm/InterfaceStub/ELFObjHandler.h
index 4ec158c1405f..cbb9420cb666 100644
--- a/llvm/include/llvm/InterfaceStub/ELFObjHandler.h
+++ b/llvm/include/llvm/InterfaceStub/ELFObjHandler.h
@@ -16,7 +16,6 @@
 #include "llvm/InterfaceStub/ELFStub.h"
 #include "llvm/Object/ELFObjectFile.h"
 #include "llvm/Object/ELFTypes.h"
-#include "llvm/Support/FileSystem.h"
 
 namespace llvm {
 
@@ -36,10 +35,8 @@ Expected<std::unique_ptr<ELFStub>> readELFFile(MemoryBufferRef Buf);
 /// @param FilePath File path for writing the ELF binary.
 /// @param Stub Source ELFStub to generate a binary ELF stub from.
 /// @param OutputFormat Target ELFType to write binary as.
-/// @param WriteIfChanged Whether or not to preserve timestamp if
-///        the output stays the same.
 Error writeBinaryStub(StringRef FilePath, const ELFStub &Stub,
-                      ELFTarget OutputFormat, bool WriteIfChanged = false);
+                      ELFTarget OutputFormat);
 
 } // end namespace elfabi
 } // end namespace llvm

diff  --git a/llvm/lib/InterfaceStub/ELFObjHandler.cpp b/llvm/lib/InterfaceStub/ELFObjHandler.cpp
index 40d8afa88ad2..e50ebd7b8ba1 100644
--- a/llvm/lib/InterfaceStub/ELFObjHandler.cpp
+++ b/llvm/lib/InterfaceStub/ELFObjHandler.cpp
@@ -17,7 +17,6 @@
 #include "llvm/Support/FileOutputBuffer.h"
 #include "llvm/Support/MathExtras.h"
 #include "llvm/Support/MemoryBuffer.h"
-#include "llvm/Support/Process.h"
 
 using llvm::MemoryBufferRef;
 using llvm::object::ELFObjectFile;
@@ -664,25 +663,8 @@ buildStub(const ELFObjectFile<ELFT> &ElfObj) {
 /// @param FilePath File path for writing the ELF binary.
 /// @param Stub Source ELFStub to generate a binary ELF stub from.
 template <class ELFT>
-static Error writeELFBinaryToFile(StringRef FilePath, const ELFStub &Stub,
-                                  bool WriteIfChanged) {
+static Error writeELFBinaryToFile(StringRef FilePath, const ELFStub &Stub) {
   ELFStubBuilder<ELFT> Builder{Stub};
-  // Write Stub to memory first.
-  std::vector<uint8_t> Buf(Builder.getSize());
-  Builder.write(Buf.data());
-
-  if (WriteIfChanged) {
-    if (ErrorOr<std::unique_ptr<MemoryBuffer>> BufOrError =
-            MemoryBuffer::getFile(FilePath)) {
-      // Compare Stub output with existing Stub file.
-      // If Stub file unchanged, abort updating.
-      if ((*BufOrError)->getBufferSize() == Builder.getSize() &&
-          !memcmp((*BufOrError)->getBufferStart(), Buf.data(),
-                  Builder.getSize()))
-        return Error::success();
-    }
-  }
-
   Expected<std::unique_ptr<FileOutputBuffer>> BufOrError =
       FileOutputBuffer::create(FilePath, Builder.getSize());
   if (!BufOrError)
@@ -692,10 +674,13 @@ static Error writeELFBinaryToFile(StringRef FilePath, const ELFStub &Stub,
                                  "` for writing");
 
   // Write binary to file.
-  std::unique_ptr<FileOutputBuffer> FileBuf = std::move(*BufOrError);
-  memcpy(FileBuf->getBufferStart(), Buf.data(), Buf.size());
+  std::unique_ptr<FileOutputBuffer> Buf = std::move(*BufOrError);
+  Builder.write(Buf->getBufferStart());
 
-  return FileBuf->commit();
+  if (Error E = Buf->commit())
+    return E;
+
+  return Error::success();
 }
 
 Expected<std::unique_ptr<ELFStub>> readELFFile(MemoryBufferRef Buf) {
@@ -720,15 +705,15 @@ Expected<std::unique_ptr<ELFStub>> readELFFile(MemoryBufferRef Buf) {
 // This function wraps the ELFT writeELFBinaryToFile() so writeBinaryStub()
 // can be called without having to use ELFType templates directly.
 Error writeBinaryStub(StringRef FilePath, const ELFStub &Stub,
-                      ELFTarget OutputFormat, bool WriteIfChanged) {
+                      ELFTarget OutputFormat) {
   if (OutputFormat == ELFTarget::ELF32LE)
-    return writeELFBinaryToFile<ELF32LE>(FilePath, Stub, WriteIfChanged);
+    return writeELFBinaryToFile<ELF32LE>(FilePath, Stub);
   if (OutputFormat == ELFTarget::ELF32BE)
-    return writeELFBinaryToFile<ELF32BE>(FilePath, Stub, WriteIfChanged);
+    return writeELFBinaryToFile<ELF32BE>(FilePath, Stub);
   if (OutputFormat == ELFTarget::ELF64LE)
-    return writeELFBinaryToFile<ELF64LE>(FilePath, Stub, WriteIfChanged);
+    return writeELFBinaryToFile<ELF64LE>(FilePath, Stub);
   if (OutputFormat == ELFTarget::ELF64BE)
-    return writeELFBinaryToFile<ELF64BE>(FilePath, Stub, WriteIfChanged);
+    return writeELFBinaryToFile<ELF64BE>(FilePath, Stub);
   llvm_unreachable("invalid binary output target");
 }
 

diff  --git a/llvm/test/tools/llvm-elfabi/preserve-dates-stub.test b/llvm/test/tools/llvm-elfabi/preserve-dates-stub.test
deleted file mode 100644
index f612fe57aa4d..000000000000
--- a/llvm/test/tools/llvm-elfabi/preserve-dates-stub.test
+++ /dev/null
@@ -1,19 +0,0 @@
-## Test writing unchanged content to ELF Stub file with --write-if-changed flag.
-
-# RUN: llvm-elfabi %s --output-target=elf64-little %t
-# RUN: touch -m -d "1970-01-01 00:00:00" %t
-# RUN: llvm-elfabi %s --output-target=elf64-little %t --write-if-changed
-# RUN: ls -l %t | FileCheck %s
-
---- !tapi-tbe
-TbeVersion: 1.0
-Arch: x86_64
-NeededLibs:
-  - libc.so.6
-Symbols:
-  bar: { Type: Object, Size: 42 }
-  baz: { Type: TLS, Size: 3 }
-  plus: { Type: Func }
-...
-
-# CHECK: {{[[:space:]]1970}}

diff  --git a/llvm/test/tools/llvm-elfabi/preserve-dates-tbe.test b/llvm/test/tools/llvm-elfabi/preserve-dates-tbe.test
deleted file mode 100644
index ec9cf7e1e3d6..000000000000
--- a/llvm/test/tools/llvm-elfabi/preserve-dates-tbe.test
+++ /dev/null
@@ -1,8 +0,0 @@
-## Test writing unchanged content to TBE file with --write-if-changed flag.
-
-# RUN: llvm-elfabi --elf %p/Inputs/gnu_hash.so --emit-tbe=%t
-# RUN: touch -m -d "1970-01-01 00:00:00" %t
-# RUN: llvm-elfabi --elf %p/Inputs/gnu_hash.so --emit-tbe=%t --write-if-changed
-# RUN: ls -l %t | FileCheck %s
-
-# CHECK: {{[[:space:]]1970}}

diff  --git a/llvm/tools/llvm-elfabi/llvm-elfabi.cpp b/llvm/tools/llvm-elfabi/llvm-elfabi.cpp
index 761c6a80b345..6fff54fd9355 100644
--- a/llvm/tools/llvm-elfabi/llvm-elfabi.cpp
+++ b/llvm/tools/llvm-elfabi/llvm-elfabi.cpp
@@ -57,37 +57,22 @@ cl::opt<ELFTarget> BinaryOutputTarget(
                clEnumValN(ELFTarget::ELF64BE, "elf64-big",
                           "64-bit big-endian ELF stub")));
 cl::opt<std::string> BinaryOutputFilePath(cl::Positional, cl::desc("output"));
-cl::opt<bool> WriteIfChanged(
-    "write-if-changed",
-    cl::desc("Write the output file only if it is new or has changed."));
 
 /// writeTBE() writes a Text-Based ELF stub to a file using the latest version
 /// of the YAML parser.
 static Error writeTBE(StringRef FilePath, ELFStub &Stub) {
-  // Write TBE to memory first.
-  std::string TBEStr;
-  raw_string_ostream OutStr(TBEStr);
-  Error YAMLErr = writeTBEToOutputStream(OutStr, Stub);
-  if (YAMLErr)
-    return YAMLErr;
-  OutStr.flush();
-
-  if (WriteIfChanged) {
-    if (ErrorOr<std::unique_ptr<MemoryBuffer>> BufOrError =
-            MemoryBuffer::getFile(FilePath)) {
-      // Compare TBE output with existing TBE file.
-      // If TBE file unchanged, abort updating.
-      if ((*BufOrError)->getBuffer() == TBEStr)
-        return Error::success();
-    }
-  }
-  // Open TBE file for writing.
   std::error_code SysErr;
+
+  // Open file for writing.
   raw_fd_ostream Out(FilePath, SysErr);
   if (SysErr)
     return createStringError(SysErr, "Couldn't open `%s` for writing",
                              FilePath.data());
-  Out << TBEStr;
+  // Write file.
+  Error YAMLErr = writeTBEToOutputStream(Out, Stub);
+  if (YAMLErr)
+    return YAMLErr;
+
   return Error::success();
 }
 
@@ -168,8 +153,8 @@ int main(int argc, char *argv[]) {
     if (BinaryOutputTarget.getNumOccurrences() == 0)
       fatalError(createStringError(errc::not_supported,
                                    "no binary output target specified."));
-    Error BinaryWriteError = writeBinaryStub(
-        BinaryOutputFilePath, *TargetStub, BinaryOutputTarget, WriteIfChanged);
+    Error BinaryWriteError =
+        writeBinaryStub(BinaryOutputFilePath, *TargetStub, BinaryOutputTarget);
     if (BinaryWriteError)
       fatalError(std::move(BinaryWriteError));
   }


        


More information about the llvm-branch-commits mailing list