summaryrefslogtreecommitdiff
path: root/tools
diff options
context:
space:
mode:
authorRafael Espindola <rafael.espindola@gmail.com>2014-01-14 17:02:09 +0000
committerRafael Espindola <rafael.espindola@gmail.com>2014-01-14 17:02:09 +0000
commit0972d2777c7e2e3d10e858738b3a588f64e0d005 (patch)
tree0298a416367599958ef43e828285b8e687d9674d /tools
parentbb34ce84fd25aa978723bef9b84a1048e212bf0f (diff)
downloadllvm-0972d2777c7e2e3d10e858738b3a588f64e0d005.tar.gz
llvm-0972d2777c7e2e3d10e858738b3a588f64e0d005.tar.bz2
llvm-0972d2777c7e2e3d10e858738b3a588f64e0d005.tar.xz
Handle UIDs and GIDs that don't fit in 6 decimal places.
Newer unix systems have 32 bit uid and gid types, but the archive format was not updated. Fortunately, these fields are not normally used. Just truncate the data to fit in 6 chars. git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@199223 91177308-0d34-0410-b5e6-96231b3b80d8
Diffstat (limited to 'tools')
-rw-r--r--tools/llvm-ar/llvm-ar.cpp21
1 files changed, 14 insertions, 7 deletions
diff --git a/tools/llvm-ar/llvm-ar.cpp b/tools/llvm-ar/llvm-ar.cpp
index d70db728f2..8091e3511f 100644
--- a/tools/llvm-ar/llvm-ar.cpp
+++ b/tools/llvm-ar/llvm-ar.cpp
@@ -578,14 +578,21 @@ computeNewArchiveMembers(ArchiveOperation Operation,
}
template <typename T>
-static void printWithSpacePadding(raw_ostream &OS, T Data, unsigned Size) {
+static void printWithSpacePadding(raw_fd_ostream &OS, T Data, unsigned Size,
+ bool MayTruncate = false) {
uint64_t OldPos = OS.tell();
OS << Data;
unsigned SizeSoFar = OS.tell() - OldPos;
- assert(Size >= SizeSoFar && "Data doesn't fit in Size");
- unsigned Remaining = Size - SizeSoFar;
- for (unsigned I = 0; I < Remaining; ++I)
- OS << ' ';
+ if (Size > SizeSoFar) {
+ unsigned Remaining = Size - SizeSoFar;
+ for (unsigned I = 0; I < Remaining; ++I)
+ OS << ' ';
+ } else if (Size < SizeSoFar) {
+ assert(MayTruncate && "Data doesn't fit in Size");
+ // Some of the data this is used for (like UID) can be larger than the
+ // space available in the archive format. Truncate in that case.
+ OS.seek(OldPos + Size);
+ }
}
static void print32BE(raw_fd_ostream &Out, unsigned Val) {
@@ -600,8 +607,8 @@ static void printRestOfMemberHeader(raw_fd_ostream &Out,
unsigned GID, unsigned Perms,
unsigned Size) {
printWithSpacePadding(Out, ModTime.toEpochTime(), 12);
- printWithSpacePadding(Out, UID, 6);
- printWithSpacePadding(Out, GID, 6);
+ printWithSpacePadding(Out, UID, 6, true);
+ printWithSpacePadding(Out, GID, 6, true);
printWithSpacePadding(Out, format("%o", Perms), 8);
printWithSpacePadding(Out, Size, 10);
Out << "`\n";