Fix some things for Mac OSX archives:

* ensure trailing spaces are eliminated so they don't factor into the
  length of a member's name.
* make sure all the bytes of a name are written even if the name ends in
  multiple null characters (bug in OSX ar)
* make sure we provide the full member name when searching for symbols so
  the module name is not accidentally duplicated.

llvm-svn: 17918
This commit is contained in:
Reid Spencer 2004-11-17 18:28:29 +00:00
parent b58bf5fa28
commit 67c46c8d70
1 changed files with 14 additions and 5 deletions

View File

@ -93,9 +93,16 @@ Archive::fillHeader(const ArchiveMember &mbr, ArchiveMemberHeader& hdr,
sprintf(buffer,"%-12u", unsigned(secondsSinceEpoch)); sprintf(buffer,"%-12u", unsigned(secondsSinceEpoch));
memcpy(hdr.date,buffer,12); memcpy(hdr.date,buffer,12);
// Get rid of trailing blanks in the name
std::string mbrPath = mbr.getPath().get();
size_t mbrLen = mbrPath.length();
while (mbrLen > 0 && mbrPath[mbrLen-1] == ' ') {
mbrPath.erase(mbrLen-1,1);
mbrLen--;
}
// Set the name field in one of its various flavors. // Set the name field in one of its various flavors.
bool writeLongName = false; bool writeLongName = false;
const std::string& mbrPath = mbr.getPath().get();
if (mbr.isStringTable()) { if (mbr.isStringTable()) {
memcpy(hdr.name,ARFILE_STRTAB_NAME,16); memcpy(hdr.name,ARFILE_STRTAB_NAME,16);
} else if (mbr.isForeignSymbolTable()) { } else if (mbr.isForeignSymbolTable()) {
@ -115,12 +122,12 @@ Archive::fillHeader(const ArchiveMember &mbr, ArchiveMemberHeader& hdr,
memcpy(hdr.name,nm,len); memcpy(hdr.name,nm,len);
hdr.name[len] = '/'; hdr.name[len] = '/';
} else if (mbrPath.length() < 16 && mbrPath.find('/') == std::string::npos) { } else if (mbrPath.length() < 16 && mbrPath.find('/') == std::string::npos) {
mbrPath.copy(hdr.name,mbrPath.length()); memcpy(hdr.name,mbrPath.c_str(),mbrPath.length());
hdr.name[mbrPath.length()] = '/'; hdr.name[mbrPath.length()] = '/';
} else { } else {
std::string nm = "#1/"; std::string nm = "#1/";
nm += utostr(mbrPath.length()); nm += utostr(mbrPath.length());
nm.copy(hdr.name,nm.length()); memcpy(hdr.name,nm.data(),nm.length());
if (sz < 0) if (sz < 0)
sz -= mbrPath.length(); sz -= mbrPath.length();
else else
@ -203,8 +210,10 @@ Archive::writeMember(
if (CreateSymbolTable && if (CreateSymbolTable &&
(member.isBytecode() || member.isCompressedBytecode())) { (member.isBytecode() || member.isCompressedBytecode())) {
std::vector<std::string> symbols; std::vector<std::string> symbols;
std::string FullMemberName = archPath.get() + "(" + member.getPath().get()
+ ")";
ModuleProvider* MP = GetBytecodeSymbols( ModuleProvider* MP = GetBytecodeSymbols(
(const unsigned char*)data,fSize,member.getPath().get(), symbols); (const unsigned char*)data,fSize,FullMemberName, symbols);
// If the bytecode parsed successfully // If the bytecode parsed successfully
if ( MP ) { if ( MP ) {
@ -270,7 +279,7 @@ Archive::writeMember(
// Write the long filename if its long // Write the long filename if its long
if (writeLongName) { if (writeLongName) {
ARFile << member.getPath().c_str(); ARFile.write(member.getPath().get().data(),member.getPath().get().length());
} }
// Make sure we write the compressed bytecode magic number if we should. // Make sure we write the compressed bytecode magic number if we should.