mirror of
https://github.com/RPCS3/llvm-mirror.git
synced 2024-10-19 11:02:59 +02:00
Remove EH use from the Archive library and adjust its users accordingly.
llvm-svn: 29066
This commit is contained in:
parent
00f6c95af4
commit
9f4deeabf4
@ -438,12 +438,14 @@ class Archive {
|
|||||||
/// name will be truncated at 15 characters. If \p Compress is specified,
|
/// name will be truncated at 15 characters. If \p Compress is specified,
|
||||||
/// all archive members will be compressed before being written. If
|
/// all archive members will be compressed before being written. If
|
||||||
/// \p PrintSymTab is true, the symbol table will be printed to std::cout.
|
/// \p PrintSymTab is true, the symbol table will be printed to std::cout.
|
||||||
/// @throws std::string if an error occurs
|
/// @returns false if an error occurred, \p error set to error message
|
||||||
|
/// @returns true if the writing succeeded.
|
||||||
/// @brief Write (possibly modified) archive contents to disk
|
/// @brief Write (possibly modified) archive contents to disk
|
||||||
void writeToDisk(
|
bool writeToDisk(
|
||||||
bool CreateSymbolTable=false, ///< Create Symbol table
|
bool CreateSymbolTable=false, ///< Create Symbol table
|
||||||
bool TruncateNames=false, ///< Truncate the filename to 15 chars
|
bool TruncateNames=false, ///< Truncate the filename to 15 chars
|
||||||
bool Compress=false ///< Compress files
|
bool Compress=false, ///< Compress files
|
||||||
|
std::string* error = 0 ///< If non-null, where error msg is set
|
||||||
);
|
);
|
||||||
|
|
||||||
/// This method adds a new file to the archive. The \p filename is examined
|
/// This method adds a new file to the archive. The \p filename is examined
|
||||||
@ -481,9 +483,19 @@ class Archive {
|
|||||||
/// @brief Write the symbol table to an ofstream.
|
/// @brief Write the symbol table to an ofstream.
|
||||||
void writeSymbolTable(std::ofstream& ARFile);
|
void writeSymbolTable(std::ofstream& ARFile);
|
||||||
|
|
||||||
/// @brief Write one ArchiveMember to an ofstream.
|
/// Writes one ArchiveMember to an ofstream. If an error occurs, returns
|
||||||
void writeMember(const ArchiveMember& member, std::ofstream& ARFile,
|
/// false, otherwise true. If an error occurs and error is non-null then
|
||||||
bool CreateSymbolTable, bool TruncateNames, bool ShouldCompress);
|
/// it will be set to an error message.
|
||||||
|
/// @returns true Writing member succeeded
|
||||||
|
/// @returns false Writing member failed, \p error set to error message
|
||||||
|
bool writeMember(
|
||||||
|
const ArchiveMember& member, ///< The member to be written
|
||||||
|
std::ofstream& ARFile, ///< The file to write member onto
|
||||||
|
bool CreateSymbolTable, ///< Should symbol table be created?
|
||||||
|
bool TruncateNames, ///< Should names be truncated to 11 chars?
|
||||||
|
bool ShouldCompress, ///< Should the member be compressed?
|
||||||
|
std::string* error = 0 ///< If non-null, place were error msg is set
|
||||||
|
);
|
||||||
|
|
||||||
/// @brief Fill in an ArchiveMemberHeader from ArchiveMember.
|
/// @brief Fill in an ArchiveMemberHeader from ArchiveMember.
|
||||||
bool fillHeader(const ArchiveMember&mbr,
|
bool fillHeader(const ArchiveMember&mbr,
|
||||||
|
@ -184,13 +184,14 @@ Archive::addFileBefore(const sys::Path& filePath, iterator where) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Write one member out to the file.
|
// Write one member out to the file.
|
||||||
void
|
bool
|
||||||
Archive::writeMember(
|
Archive::writeMember(
|
||||||
const ArchiveMember& member,
|
const ArchiveMember& member,
|
||||||
std::ofstream& ARFile,
|
std::ofstream& ARFile,
|
||||||
bool CreateSymbolTable,
|
bool CreateSymbolTable,
|
||||||
bool TruncateNames,
|
bool TruncateNames,
|
||||||
bool ShouldCompress
|
bool ShouldCompress,
|
||||||
|
std::string* error
|
||||||
) {
|
) {
|
||||||
|
|
||||||
unsigned filepos = ARFile.tellp();
|
unsigned filepos = ARFile.tellp();
|
||||||
@ -235,8 +236,12 @@ Archive::writeMember(
|
|||||||
// We don't need this module any more.
|
// We don't need this module any more.
|
||||||
delete MP;
|
delete MP;
|
||||||
} else {
|
} else {
|
||||||
throw std::string("Can't parse bytecode member: ") +
|
if (mFile != 0) {
|
||||||
member.getPath().toString();
|
mFile->close();
|
||||||
|
delete mFile;
|
||||||
|
}
|
||||||
|
if (error)
|
||||||
|
*error = "Can't parse bytecode member: " + member.getPath().toString();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -263,7 +268,9 @@ Archive::writeMember(
|
|||||||
data +=4;
|
data +=4;
|
||||||
fSize -= 4;
|
fSize -= 4;
|
||||||
}
|
}
|
||||||
fSize = Compressor::compressToNewBuffer(data,fSize,output);
|
fSize = Compressor::compressToNewBuffer(data,fSize,output,error);
|
||||||
|
if (fSize == 0)
|
||||||
|
return false;
|
||||||
data = output;
|
data = output;
|
||||||
if (member.isBytecode())
|
if (member.isBytecode())
|
||||||
hdrSize = -fSize-4;
|
hdrSize = -fSize-4;
|
||||||
@ -307,6 +314,7 @@ Archive::writeMember(
|
|||||||
mFile->close();
|
mFile->close();
|
||||||
delete mFile;
|
delete mFile;
|
||||||
}
|
}
|
||||||
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Write out the LLVM symbol table as an archive member to the file.
|
// Write out the LLVM symbol table as an archive member to the file.
|
||||||
@ -364,9 +372,10 @@ Archive::writeSymbolTable(std::ofstream& ARFile) {
|
|||||||
// This writes to a temporary file first. Options are for creating a symbol
|
// This writes to a temporary file first. Options are for creating a symbol
|
||||||
// table, flattening the file names (no directories, 15 chars max) and
|
// table, flattening the file names (no directories, 15 chars max) and
|
||||||
// compressing each archive member.
|
// compressing each archive member.
|
||||||
void
|
bool
|
||||||
Archive::writeToDisk(bool CreateSymbolTable, bool TruncateNames, bool Compress){
|
Archive::writeToDisk(bool CreateSymbolTable, bool TruncateNames, bool Compress,
|
||||||
|
std::string* error)
|
||||||
|
{
|
||||||
// Make sure they haven't opened up the file, not loaded it,
|
// Make sure they haven't opened up the file, not loaded it,
|
||||||
// but are now trying to write it which would wipe out the file.
|
// but are now trying to write it which would wipe out the file.
|
||||||
assert(!(members.empty() && mapfile->size() > 8) &&
|
assert(!(members.empty() && mapfile->size() > 8) &&
|
||||||
@ -379,8 +388,6 @@ Archive::writeToDisk(bool CreateSymbolTable, bool TruncateNames, bool Compress){
|
|||||||
// Make sure the temporary gets removed if we crash
|
// Make sure the temporary gets removed if we crash
|
||||||
sys::RemoveFileOnSignal(TmpArchive);
|
sys::RemoveFileOnSignal(TmpArchive);
|
||||||
|
|
||||||
// Ensure we can remove the temporary even in the face of an exception
|
|
||||||
try {
|
|
||||||
// Create archive file for output.
|
// Create archive file for output.
|
||||||
std::ios::openmode io_mode = std::ios::out | std::ios::trunc |
|
std::ios::openmode io_mode = std::ios::out | std::ios::trunc |
|
||||||
std::ios::binary;
|
std::ios::binary;
|
||||||
@ -388,7 +395,11 @@ Archive::writeToDisk(bool CreateSymbolTable, bool TruncateNames, bool Compress){
|
|||||||
|
|
||||||
// Check for errors opening or creating archive file.
|
// Check for errors opening or creating archive file.
|
||||||
if ( !ArchiveFile.is_open() || ArchiveFile.bad() ) {
|
if ( !ArchiveFile.is_open() || ArchiveFile.bad() ) {
|
||||||
throw std::string("Error opening archive file: ") + archPath.toString();
|
if (TmpArchive.exists())
|
||||||
|
TmpArchive.eraseFromDisk();
|
||||||
|
if (error)
|
||||||
|
*error = "Error opening archive file: " + archPath.toString();
|
||||||
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
// If we're creating a symbol table, reset it now
|
// If we're creating a symbol table, reset it now
|
||||||
@ -403,7 +414,14 @@ Archive::writeToDisk(bool CreateSymbolTable, bool TruncateNames, bool Compress){
|
|||||||
// Loop over all member files, and write them out. Note that this also
|
// Loop over all member files, and write them out. Note that this also
|
||||||
// builds the symbol table, symTab.
|
// builds the symbol table, symTab.
|
||||||
for ( MembersList::iterator I = begin(), E = end(); I != E; ++I) {
|
for ( MembersList::iterator I = begin(), E = end(); I != E; ++I) {
|
||||||
writeMember(*I,ArchiveFile,CreateSymbolTable,TruncateNames,Compress);
|
if (!writeMember(*I,ArchiveFile,CreateSymbolTable,
|
||||||
|
TruncateNames,Compress,error))
|
||||||
|
{
|
||||||
|
if (TmpArchive.exists())
|
||||||
|
TmpArchive.eraseFromDisk();
|
||||||
|
ArchiveFile.close();
|
||||||
|
return false;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// Close archive file.
|
// Close archive file.
|
||||||
@ -421,16 +439,19 @@ Archive::writeToDisk(bool CreateSymbolTable, bool TruncateNames, bool Compress){
|
|||||||
sys::MappedFile arch(TmpArchive);
|
sys::MappedFile arch(TmpArchive);
|
||||||
const char* base = (const char*) arch.map();
|
const char* base = (const char*) arch.map();
|
||||||
|
|
||||||
// Open another temporary file in order to avoid invalidating the mmapped data
|
// Open another temporary file in order to avoid invalidating the
|
||||||
|
// mmapped data
|
||||||
sys::Path FinalFilePath = archPath;
|
sys::Path FinalFilePath = archPath;
|
||||||
FinalFilePath.createTemporaryFileOnDisk();
|
FinalFilePath.createTemporaryFileOnDisk();
|
||||||
sys::RemoveFileOnSignal(FinalFilePath);
|
sys::RemoveFileOnSignal(FinalFilePath);
|
||||||
try {
|
|
||||||
|
|
||||||
|
|
||||||
std::ofstream FinalFile(FinalFilePath.c_str(), io_mode);
|
std::ofstream FinalFile(FinalFilePath.c_str(), io_mode);
|
||||||
if ( !FinalFile.is_open() || FinalFile.bad() ) {
|
if ( !FinalFile.is_open() || FinalFile.bad() ) {
|
||||||
throw std::string("Error opening archive file: ") + FinalFilePath.toString();
|
if (TmpArchive.exists())
|
||||||
|
TmpArchive.eraseFromDisk();
|
||||||
|
if (error)
|
||||||
|
*error = "Error opening archive file: " + FinalFilePath.toString();
|
||||||
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Write the file magic number
|
// Write the file magic number
|
||||||
@ -459,24 +480,14 @@ Archive::writeToDisk(bool CreateSymbolTable, bool TruncateNames, bool Compress){
|
|||||||
|
|
||||||
// Move the final file over top of TmpArchive
|
// Move the final file over top of TmpArchive
|
||||||
FinalFilePath.renamePathOnDisk(TmpArchive);
|
FinalFilePath.renamePathOnDisk(TmpArchive);
|
||||||
} catch (...) {
|
|
||||||
// Make sure we clean up.
|
|
||||||
if (FinalFilePath.exists())
|
|
||||||
FinalFilePath.eraseFromDisk();
|
|
||||||
throw;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// Before we replace the actual archive, we need to forget all the
|
// Before we replace the actual archive, we need to forget all the
|
||||||
// members, since they point to data in that old archive. We need to do
|
// members, since they point to data in that old archive. We need to do
|
||||||
// we cannot replace an open file on Windows.
|
// this because we cannot replace an open file on Windows.
|
||||||
cleanUpMemory();
|
cleanUpMemory();
|
||||||
|
|
||||||
TmpArchive.renamePathOnDisk(archPath);
|
TmpArchive.renamePathOnDisk(archPath);
|
||||||
} catch (...) {
|
|
||||||
// Make sure we clean up.
|
return true;
|
||||||
if (TmpArchive.exists())
|
|
||||||
TmpArchive.eraseFromDisk();
|
|
||||||
throw;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
@ -484,7 +484,9 @@ void doDelete() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// We're done editting, reconstruct the archive.
|
// We're done editting, reconstruct the archive.
|
||||||
TheArchive->writeToDisk(SymTable,TruncateNames,Compression);
|
std::string errmsg;
|
||||||
|
if (!TheArchive->writeToDisk(SymTable,TruncateNames,Compression,&errmsg))
|
||||||
|
throw errmsg;
|
||||||
if (ReallyVerbose)
|
if (ReallyVerbose)
|
||||||
printSymbolTable();
|
printSymbolTable();
|
||||||
}
|
}
|
||||||
@ -536,7 +538,9 @@ void doMove() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// We're done editting, reconstruct the archive.
|
// We're done editting, reconstruct the archive.
|
||||||
TheArchive->writeToDisk(SymTable,TruncateNames,Compression);
|
std::string errmsg;
|
||||||
|
if (!TheArchive->writeToDisk(SymTable,TruncateNames,Compression,&errmsg))
|
||||||
|
throw errmsg;
|
||||||
if (ReallyVerbose)
|
if (ReallyVerbose)
|
||||||
printSymbolTable();
|
printSymbolTable();
|
||||||
}
|
}
|
||||||
@ -555,7 +559,9 @@ void doQuickAppend() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// We're done editting, reconstruct the archive.
|
// We're done editting, reconstruct the archive.
|
||||||
TheArchive->writeToDisk(SymTable,TruncateNames,Compression);
|
std::string errmsg;
|
||||||
|
if (!TheArchive->writeToDisk(SymTable,TruncateNames,Compression,&errmsg))
|
||||||
|
throw errmsg;
|
||||||
if (ReallyVerbose)
|
if (ReallyVerbose)
|
||||||
printSymbolTable();
|
printSymbolTable();
|
||||||
}
|
}
|
||||||
@ -642,7 +648,9 @@ void doReplaceOrInsert() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// We're done editting, reconstruct the archive.
|
// We're done editting, reconstruct the archive.
|
||||||
TheArchive->writeToDisk(SymTable,TruncateNames,Compression);
|
std::string errmsg;
|
||||||
|
if (!TheArchive->writeToDisk(SymTable,TruncateNames,Compression,&errmsg))
|
||||||
|
throw errmsg;
|
||||||
if (ReallyVerbose)
|
if (ReallyVerbose)
|
||||||
printSymbolTable();
|
printSymbolTable();
|
||||||
}
|
}
|
||||||
|
@ -74,7 +74,8 @@ int main(int argc, char **argv) {
|
|||||||
if (!TheArchive)
|
if (!TheArchive)
|
||||||
throw err_msg;
|
throw err_msg;
|
||||||
|
|
||||||
TheArchive->writeToDisk(true, false, false );
|
if (!TheArchive->writeToDisk(true, false, false, &err_msg ))
|
||||||
|
throw err_msg;
|
||||||
|
|
||||||
if (Verbose)
|
if (Verbose)
|
||||||
printSymbolTable(TheArchive);
|
printSymbolTable(TheArchive);
|
||||||
|
Loading…
Reference in New Issue
Block a user