Correct the computation of when to add the padding. It is not based on the

member's size. It is based on the oddness/evenness of the file pointer.
This fixes a bug with llvm-ar not being able to read archives produced by
llvm-ranlib when there are members with odd long file name lengths.


git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@17997 91177308-0d34-0410-b5e6-96231b3b80d8
This commit is contained in:
Reid Spencer 2004-11-19 17:08:00 +00:00
parent 7b73a663bc
commit 6405c9ec9f
4 changed files with 18 additions and 18 deletions

View File

@ -227,7 +227,7 @@ Archive::loadArchive() {
// with it. It doesn't count as the "first file". // with it. It doesn't count as the "first file".
foreignST = mbr; foreignST = mbr;
At += mbr->getSize(); At += mbr->getSize();
if ((mbr->getSize() & 1) == 1) if ((intptr_t(At) & 1) == 1)
At++; At++;
} else if (mbr->isStringTable()) { } else if (mbr->isStringTable()) {
// Simply suck the entire string table into a string // Simply suck the entire string table into a string
@ -236,7 +236,7 @@ Archive::loadArchive() {
// (SVR4 style long names). // (SVR4 style long names).
strtab.assign(At,mbr->getSize()); strtab.assign(At,mbr->getSize());
At += mbr->getSize(); At += mbr->getSize();
if ((mbr->getSize() & 1) == 1) if ((intptr_t(At) & 1) == 1)
At++; At++;
delete mbr; delete mbr;
} else if (mbr->isLLVMSymbolTable()) { } else if (mbr->isLLVMSymbolTable()) {
@ -247,7 +247,7 @@ Archive::loadArchive() {
parseSymbolTable(mbr->getData(),mbr->getSize()); parseSymbolTable(mbr->getData(),mbr->getSize());
seenSymbolTable = true; seenSymbolTable = true;
At += mbr->getSize(); At += mbr->getSize();
if ((mbr->getSize() & 1) == 1) if ((intptr_t(At) & 1) == 1)
At++; At++;
delete mbr; // We don't need this member in the list of members. delete mbr; // We don't need this member in the list of members.
} else { } else {
@ -259,7 +259,7 @@ Archive::loadArchive() {
} }
members.push_back(mbr); members.push_back(mbr);
At += mbr->getSize(); At += mbr->getSize();
if ((mbr->getSize() & 1) == 1) if ((intptr_t(At) & 1) == 1)
At++; At++;
} }
} }
@ -317,7 +317,7 @@ Archive::loadSymbolTable() {
if (mbr->isForeignSymbolTable()) { if (mbr->isForeignSymbolTable()) {
// Skip the foreign symbol table, we don't do anything with it // Skip the foreign symbol table, we don't do anything with it
At += mbr->getSize(); At += mbr->getSize();
if ((mbr->getSize() & 1) == 1) if ((intptr_t(At) & 1) == 1)
At++; At++;
delete mbr; delete mbr;
@ -330,7 +330,7 @@ Archive::loadSymbolTable() {
// Process the string table entry // Process the string table entry
strtab.assign((const char*)mbr->getData(),mbr->getSize()); strtab.assign((const char*)mbr->getData(),mbr->getSize());
At += mbr->getSize(); At += mbr->getSize();
if ((mbr->getSize() & 1) == 1) if ((intptr_t(At) & 1) == 1)
At++; At++;
delete mbr; delete mbr;
// Get the next one // Get the next one
@ -342,7 +342,7 @@ Archive::loadSymbolTable() {
if (mbr->isLLVMSymbolTable()) { if (mbr->isLLVMSymbolTable()) {
parseSymbolTable(mbr->getData(),mbr->getSize()); parseSymbolTable(mbr->getData(),mbr->getSize());
FirstFile = At + mbr->getSize(); FirstFile = At + mbr->getSize();
if ((mbr->getSize() & 1) == 1) if ((intptr_t(At) & 1) == 1)
FirstFile++; FirstFile++;
} else { } else {
// There's no symbol table in the file. We have to rebuild it from scratch // There's no symbol table in the file. We have to rebuild it from scratch
@ -454,7 +454,7 @@ Archive::findModulesDefiningSymbols(std::set<std::string>& symbols,
// Go to the next file location // Go to the next file location
At += mbr->getSize(); At += mbr->getSize();
if ((mbr->getSize() & 1) == 1) if ((intptr_t(At) & 1) == 1)
At++; At++;
} }
} }

View File

@ -290,7 +290,7 @@ Archive::writeMember(
ARFile.write(data,fSize); ARFile.write(data,fSize);
// Make sure the member is an even length // Make sure the member is an even length
if (ARFile.tellp() % 2 != 0) if (ARFile.tellp() & 1 == 1)
ARFile << ARFILE_PAD; ARFile << ARFILE_PAD;
// Free the compressed data, if necessary // Free the compressed data, if necessary

View File

@ -227,7 +227,7 @@ Archive::loadArchive() {
// with it. It doesn't count as the "first file". // with it. It doesn't count as the "first file".
foreignST = mbr; foreignST = mbr;
At += mbr->getSize(); At += mbr->getSize();
if ((mbr->getSize() & 1) == 1) if ((intptr_t(At) & 1) == 1)
At++; At++;
} else if (mbr->isStringTable()) { } else if (mbr->isStringTable()) {
// Simply suck the entire string table into a string // Simply suck the entire string table into a string
@ -236,7 +236,7 @@ Archive::loadArchive() {
// (SVR4 style long names). // (SVR4 style long names).
strtab.assign(At,mbr->getSize()); strtab.assign(At,mbr->getSize());
At += mbr->getSize(); At += mbr->getSize();
if ((mbr->getSize() & 1) == 1) if ((intptr_t(At) & 1) == 1)
At++; At++;
delete mbr; delete mbr;
} else if (mbr->isLLVMSymbolTable()) { } else if (mbr->isLLVMSymbolTable()) {
@ -247,7 +247,7 @@ Archive::loadArchive() {
parseSymbolTable(mbr->getData(),mbr->getSize()); parseSymbolTable(mbr->getData(),mbr->getSize());
seenSymbolTable = true; seenSymbolTable = true;
At += mbr->getSize(); At += mbr->getSize();
if ((mbr->getSize() & 1) == 1) if ((intptr_t(At) & 1) == 1)
At++; At++;
delete mbr; // We don't need this member in the list of members. delete mbr; // We don't need this member in the list of members.
} else { } else {
@ -259,7 +259,7 @@ Archive::loadArchive() {
} }
members.push_back(mbr); members.push_back(mbr);
At += mbr->getSize(); At += mbr->getSize();
if ((mbr->getSize() & 1) == 1) if ((intptr_t(At) & 1) == 1)
At++; At++;
} }
} }
@ -317,7 +317,7 @@ Archive::loadSymbolTable() {
if (mbr->isForeignSymbolTable()) { if (mbr->isForeignSymbolTable()) {
// Skip the foreign symbol table, we don't do anything with it // Skip the foreign symbol table, we don't do anything with it
At += mbr->getSize(); At += mbr->getSize();
if ((mbr->getSize() & 1) == 1) if ((intptr_t(At) & 1) == 1)
At++; At++;
delete mbr; delete mbr;
@ -330,7 +330,7 @@ Archive::loadSymbolTable() {
// Process the string table entry // Process the string table entry
strtab.assign((const char*)mbr->getData(),mbr->getSize()); strtab.assign((const char*)mbr->getData(),mbr->getSize());
At += mbr->getSize(); At += mbr->getSize();
if ((mbr->getSize() & 1) == 1) if ((intptr_t(At) & 1) == 1)
At++; At++;
delete mbr; delete mbr;
// Get the next one // Get the next one
@ -342,7 +342,7 @@ Archive::loadSymbolTable() {
if (mbr->isLLVMSymbolTable()) { if (mbr->isLLVMSymbolTable()) {
parseSymbolTable(mbr->getData(),mbr->getSize()); parseSymbolTable(mbr->getData(),mbr->getSize());
FirstFile = At + mbr->getSize(); FirstFile = At + mbr->getSize();
if ((mbr->getSize() & 1) == 1) if ((intptr_t(At) & 1) == 1)
FirstFile++; FirstFile++;
} else { } else {
// There's no symbol table in the file. We have to rebuild it from scratch // There's no symbol table in the file. We have to rebuild it from scratch
@ -454,7 +454,7 @@ Archive::findModulesDefiningSymbols(std::set<std::string>& symbols,
// Go to the next file location // Go to the next file location
At += mbr->getSize(); At += mbr->getSize();
if ((mbr->getSize() & 1) == 1) if ((intptr_t(At) & 1) == 1)
At++; At++;
} }
} }

View File

@ -290,7 +290,7 @@ Archive::writeMember(
ARFile.write(data,fSize); ARFile.write(data,fSize);
// Make sure the member is an even length // Make sure the member is an even length
if (ARFile.tellp() % 2 != 0) if (ARFile.tellp() & 1 == 1)
ARFile << ARFILE_PAD; ARFile << ARFILE_PAD;
// Free the compressed data, if necessary // Free the compressed data, if necessary