llvm.org GIT mirror llvm / 6df9562
[Object] Replace TimeValue with std::chrono Summary: Most of the changes are very straight-forward. The only choice I had to make was to use second-precision time points in the Archive classes. I did this because the archive files use that precision in the on-disk representation anyway. Reviewers: rafael, zturner Subscribers: llvm-commits Differential Revision: https://reviews.llvm.org/D25773 git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@284974 91177308-0d34-0410-b5e6-96231b3b80d8 Pavel Labath 3 years ago
5 changed file(s) with 32 addition(s) and 30 deletion(s). Raw diff Collapse all Expand all
1717 #include "llvm/ADT/StringRef.h"
1818 #include "llvm/ADT/iterator_range.h"
1919 #include "llvm/Object/Binary.h"
20 #include "llvm/Support/Chrono.h"
2021 #include "llvm/Support/Error.h"
2122 #include "llvm/Support/ErrorHandling.h"
2223 #include "llvm/Support/FileSystem.h"
2324 #include "llvm/Support/MemoryBuffer.h"
24 #include "llvm/Support/TimeValue.h"
2525
2626 namespace llvm {
2727 namespace object {
4545 Expected getSize() const;
4646
4747 Expected getAccessMode() const;
48 ExpectedValue> getLastModified() const;
48 ExpectedPoint> getLastModified() const;
4949 llvm::StringRef getRawLastModified() const {
5050 return StringRef(ArMemHdr->LastModified,
5151 sizeof(ArMemHdr->LastModified)).rtrim(' ');
102102 Expected getName() const;
103103 Expected getFullName() const;
104104 Expected getRawName() const { return Header.getRawName(); }
105 ExpectedValue> getLastModified() const {
105 ExpectedPoint> getLastModified() const {
106106 return Header.getLastModified();
107107 }
108108 StringRef getRawLastModified() const {
2121
2222 struct NewArchiveMember {
2323 std::unique_ptr Buf;
24 sys::TimeValue ModTime = sys::TimeValue::PosixZeroTime();
24 sys::TimePoint ModTime;
2525 unsigned UID = 0, GID = 0, Perms = 0644;
2626
2727 NewArchiveMember() = default;
238238 return static_cast(Ret);
239239 }
240240
241 ExpectedValue> ArchiveMemberHeader::getLastModified() const {
241 ExpectedPoint>
242 ArchiveMemberHeader::getLastModified() const {
242243 unsigned Seconds;
243244 if (StringRef(ArMemHdr->LastModified,
244245 sizeof(ArMemHdr->LastModified)).rtrim(' ')
255256 "archive member header at offset " + Twine(Offset));
256257 }
257258
258 sys::TimeValue Ret;
259 Ret.fromEpochTime(Seconds);
260 return Ret;
259 return sys::toTimePoint(Seconds);
261260 }
262261
263262 Expected ArchiveMemberHeader::getUID() const {
4646 NewArchiveMember M;
4747 M.Buf = MemoryBuffer::getMemBuffer(*BufOrErr, false);
4848 if (!Deterministic) {
49 Expected ModTimeOrErr = OldMember.getLastModified();
49 auto ModTimeOrErr = OldMember.getLastModified();
5050 if (!ModTimeOrErr)
5151 return ModTimeOrErr.takeError();
5252 M.ModTime = ModTimeOrErr.get();
9494 NewArchiveMember M;
9595 M.Buf = std::move(*MemberBufferOrErr);
9696 if (!Deterministic) {
97 M.ModTime = Status.getLastModificationTime();
97 M.ModTime = std::chrono::time_point_cast(
98 Status.getLastModificationTime());
9899 M.UID = Status.getUser();
99100 M.GID = Status.getGroup();
100101 M.Perms = Status.permissions();
126127 support::endian::Writer(Out).write(Val);
127128 }
128129
129 static void printRestOfMemberHeader(raw_fd_ostream &Out,
130 const sys::TimeValue &ModTime, unsigned UID,
131 unsigned GID, unsigned Perms,
132 unsigned Size) {
133 printWithSpacePadding(Out, ModTime.toEpochTime(), 12);
130 static void printRestOfMemberHeader(
131 raw_fd_ostream &Out, const sys::TimePoint &ModTime,
132 unsigned UID, unsigned GID, unsigned Perms, unsigned Size) {
133 printWithSpacePadding(Out, sys::toTimeT(ModTime), 12);
134134 printWithSpacePadding(Out, UID, 6, true);
135135 printWithSpacePadding(Out, GID, 6, true);
136136 printWithSpacePadding(Out, format("%o", Perms), 8);
138138 Out << "`\n";
139139 }
140140
141 static void printGNUSmallMemberHeader(raw_fd_ostream &Out, StringRef Name,
142 const sys::TimeValue &ModTime,
143 unsigned UID, unsigned GID,
144 unsigned Perms, unsigned Size) {
141 static void
142 printGNUSmallMemberHeader(raw_fd_ostream &Out, StringRef Name,
143 const sys::TimePoint &ModTime,
144 unsigned UID, unsigned GID, unsigned Perms,
145 unsigned Size) {
145146 printWithSpacePadding(Out, Twine(Name) + "/", 16);
146147 printRestOfMemberHeader(Out, ModTime, UID, GID, Perms, Size);
147148 }
148149
149 static void printBSDMemberHeader(raw_fd_ostream &Out, StringRef Name,
150 const sys::TimeValue &ModTime, unsigned UID,
151 unsigned GID, unsigned Perms, unsigned Size) {
150 static void
151 printBSDMemberHeader(raw_fd_ostream &Out, StringRef Name,
152 const sys::TimePoint &ModTime,
153 unsigned UID, unsigned GID, unsigned Perms,
154 unsigned Size) {
152155 uint64_t PosAfterHeader = Out.tell() + 60 + Name.size();
153156 // Pad so that even 64 bit object files are aligned.
154157 unsigned Pad = OffsetToAlignment(PosAfterHeader, 8);
170173 printMemberHeader(raw_fd_ostream &Out, object::Archive::Kind Kind, bool Thin,
171174 StringRef Name,
172175 std::vector::iterator &StringMapIndexIter,
173 const sys::TimeValue &ModTime, unsigned UID, unsigned GID,
174 unsigned Perms, unsigned Size) {
176 const sys::TimePoint &ModTime,
177 unsigned UID, unsigned GID, unsigned Perms, unsigned Size) {
175178 if (Kind == object::Archive::K_BSD)
176179 return printBSDMemberHeader(Out, Name, ModTime, UID, GID, Perms, Size);
177180 if (!useStringTable(Thin, Name))
238241 Out.seek(Pos);
239242 }
240243
241 static sys::TimeValue now(bool Deterministic) {
244 static sys::TimePoint now(bool Deterministic) {
245 using namespace std::chrono;
246
242247 if (!Deterministic)
243 return sys::TimeValue::now();
244 sys::TimeValue TV;
245 TV.fromEpochTime(0);
246 return TV;
248 return time_point_cast(system_clock::now());
249 return sys::TimePoint();
247250 }
248251
249252 // Returns the offset of the first reference to a member offset.
527527 failIfError(sys::fs::status(*MI, Status), *MI);
528528 auto ModTimeOrErr = Member.getLastModified();
529529 failIfError(ModTimeOrErr.takeError());
530 if (sys::TimeValue(Status.getLastModificationTime()) < ModTimeOrErr.get()) {
530 if (Status.getLastModificationTime() < ModTimeOrErr.get()) {
531531 if (PosName.empty())
532532 return IA_AddOldMember;
533533 return IA_MoveOldMember;