aboutsummaryrefslogtreecommitdiff
path: root/llvm/lib/Object/ArchiveWriter.cpp
diff options
context:
space:
mode:
authorzhijian <zhijian@ca.ibm.com>2023-05-16 10:13:57 -0400
committerzhijian <zhijian@ca.ibm.com>2023-05-16 10:13:57 -0400
commitd78a723743b29476c2827801fea6a3a4b29a5240 (patch)
treee98e7ebf78203d3426fa0d26fadfd7bd51f79f48 /llvm/lib/Object/ArchiveWriter.cpp
parent3ce72cd5f6d584d83d47e54edef5c132a6c3703d (diff)
downloadllvm-d78a723743b29476c2827801fea6a3a4b29a5240.zip
llvm-d78a723743b29476c2827801fea6a3a4b29a5240.tar.gz
llvm-d78a723743b29476c2827801fea6a3a4b29a5240.tar.bz2
[AIX] Fixed malformed big archive when total archive file size is large than 4Gbytes
Summary: 1. we use the unsigned type for NextOffset,PrevOffset ,GlobalSymbolOffset , MemberTableSize, it will caused a malform big archive when the archive file size is large than 4G. 2. also fix a NFC comment on https://reviews.llvm.org/D142479#inline-1443927 Reviewers: James Henderson Differential Revision: https://reviews.llvm.org/D150462
Diffstat (limited to 'llvm/lib/Object/ArchiveWriter.cpp')
-rw-r--r--llvm/lib/Object/ArchiveWriter.cpp15
1 files changed, 8 insertions, 7 deletions
diff --git a/llvm/lib/Object/ArchiveWriter.cpp b/llvm/lib/Object/ArchiveWriter.cpp
index 04c7d1d..16763a7 100644
--- a/llvm/lib/Object/ArchiveWriter.cpp
+++ b/llvm/lib/Object/ArchiveWriter.cpp
@@ -252,8 +252,8 @@ static void
printBigArchiveMemberHeader(raw_ostream &Out, StringRef Name,
const sys::TimePoint<std::chrono::seconds> &ModTime,
unsigned UID, unsigned GID, unsigned Perms,
- uint64_t Size, unsigned PrevOffset,
- unsigned NextOffset) {
+ uint64_t Size, uint64_t PrevOffset,
+ uint64_t NextOffset) {
unsigned NameLen = Name.size();
printWithSpacePadding(Out, Size, 20); // File member size
@@ -704,7 +704,8 @@ computeMemberData(raw_ostream &StringTable, raw_ostream &SymNames,
// The big archive format needs to know the offset of the previous member
// header.
- unsigned PrevOffset = 0, Index = 0;
+ uint64_t PrevOffset = 0;
+ uint16_t Index = 0;
for (const NewArchiveMember &M : NewMembers) {
std::string Header;
raw_string_ostream Out(Header);
@@ -740,7 +741,7 @@ computeMemberData(raw_ostream &StringTable, raw_ostream &SymNames,
}
if (isAIXBigArchive(Kind)) {
- unsigned NextOffset = Pos + sizeof(object::BigArMemHdrType) +
+ uint64_t NextOffset = Pos + sizeof(object::BigArMemHdrType) +
alignTo(M.MemberName.size(), 2) + alignTo(Size, 2);
printBigArchiveMemberHeader(Out, M.MemberName, ModTime, M.UID, M.GID,
M.Perms, Size, PrevOffset, NextOffset);
@@ -948,11 +949,11 @@ static Error writeArchiveToStream(raw_ostream &Out,
}
// AIX member table size.
- unsigned MemberTableSize = 20 + // Number of members field
+ uint64_t MemberTableSize = 20 + // Number of members field
20 * MemberOffsets.size() +
MemberTableNameStrTblSize;
- unsigned GlobalSymbolOffset =
+ uint64_t GlobalSymbolOffset =
(WriteSymtab && NumSyms > 0)
? LastMemberEndOffset +
alignTo(sizeof(object::BigArMemHdrType) + MemberTableSize, 2)
@@ -963,7 +964,7 @@ static Error writeArchiveToStream(raw_ostream &Out,
20); // Offset to member table
// If there are no file members in the archive, there will be no global
// symbol table.
- printWithSpacePadding(Out, NewMembers.size() ? GlobalSymbolOffset : 0, 20);
+ printWithSpacePadding(Out, GlobalSymbolOffset, 20);
printWithSpacePadding(
Out, 0,
20); // Offset to 64 bits global symbol table - Not supported yet