Remove extraneous characters when printing the timestamp for an XCOFF object file.
authorzhijian <zhijian@ca.ibm.com>
Fri, 3 Mar 2023 18:18:58 +0000 (13:18 -0500)
committerzhijian <zhijian@ca.ibm.com>
Fri, 3 Mar 2023 18:18:58 +0000 (13:18 -0500)
Summary:

The llvm-readobj prints extra characters for the timestamp when --file-headers is used with an XCOFF file. This change updates the format string used to print the time. In addition, the timestamp is printed in the local timezone, and a thread-safe call is used to convert the time.

Summit the patch on behalf of Stephen Peckham.

Reviewers: James Henderson, Digger Lin
Differential Revision: https://reviews.llvm.org/D144281

llvm/test/tools/llvm-readobj/XCOFF/file-header.test
llvm/tools/llvm-readobj/XCOFFDumper.cpp

index b7727dc..8cbd847 100644 (file)
@@ -10,7 +10,7 @@
 # FILEHEADER32-NEXT:FileHeader {
 # FILEHEADER32-NEXT:  Magic: 0x1DF
 # FILEHEADER32-NEXT:  NumberOfSections: 1
-# FILEHEADER32-NEXT:  TimeStamp: 1970-01-01T00:00:01Z (0x1)
+# FILEHEADER32-NEXT:  TimeStamp: 1970-01-01 00:00:01 (0x1)
 # FILEHEADER32-NEXT:  SymbolTableOffset: 0x3C
 # FILEHEADER32-NEXT:  SymbolTableEntries: 1
 # FILEHEADER32-NEXT:  OptionalHeaderSize: 0x0
index 56f672b..8f4e55b 100644 (file)
@@ -98,10 +98,11 @@ void XCOFFDumper::printFileHeaders() {
     // tests will let us know.
     time_t TimeDate = TimeStamp;
 
-    char FormattedTime[21] = {};
-    size_t BytesWritten =
-        strftime(FormattedTime, 21, "%Y-%m-%dT%H:%M:%SZ", gmtime(&TimeDate));
-    if (BytesWritten)
+    char FormattedTime[80] = {};
+
+    size_t BytesFormatted =
+      strftime(FormattedTime, sizeof(FormattedTime), "%F %T", gmtime(&TimeDate));
+    if (BytesFormatted)
       W.printHex("TimeStamp", FormattedTime, TimeStamp);
     else
       W.printHex("Timestamp", TimeStamp);