mirror of
https://github.com/RPCS3/llvm-mirror.git
synced 2024-12-02 16:36:40 +00:00
Convert the archive writer to use Error.
This found one place in lld that was not checking the error. llvm-svn: 313937
This commit is contained in:
parent
e00c8617dd
commit
f112256d3c
@ -16,6 +16,7 @@
|
||||
|
||||
#include "llvm/ADT/StringRef.h"
|
||||
#include "llvm/Object/Archive.h"
|
||||
#include "llvm/Support/Error.h"
|
||||
#include "llvm/Support/FileSystem.h"
|
||||
|
||||
namespace llvm {
|
||||
@ -37,10 +38,10 @@ struct NewArchiveMember {
|
||||
bool Deterministic);
|
||||
};
|
||||
|
||||
std::error_code
|
||||
writeArchive(StringRef ArcName, ArrayRef<NewArchiveMember> NewMembers,
|
||||
bool WriteSymtab, object::Archive::Kind Kind, bool Deterministic,
|
||||
bool Thin, std::unique_ptr<MemoryBuffer> OldArchiveBuf = nullptr);
|
||||
Error writeArchive(StringRef ArcName, ArrayRef<NewArchiveMember> NewMembers,
|
||||
bool WriteSymtab, object::Archive::Kind Kind,
|
||||
bool Deterministic, bool Thin,
|
||||
std::unique_ptr<MemoryBuffer> OldArchiveBuf = nullptr);
|
||||
}
|
||||
|
||||
#endif
|
||||
|
@ -96,11 +96,9 @@ struct COFFShortExport {
|
||||
}
|
||||
};
|
||||
|
||||
std::error_code writeImportLibrary(StringRef ImportName,
|
||||
StringRef Path,
|
||||
ArrayRef<COFFShortExport> Exports,
|
||||
COFF::MachineTypes Machine,
|
||||
bool MakeWeakAliases);
|
||||
Error writeImportLibrary(StringRef ImportName, StringRef Path,
|
||||
ArrayRef<COFFShortExport> Exports,
|
||||
COFF::MachineTypes Machine, bool MakeWeakAliases);
|
||||
|
||||
} // namespace object
|
||||
} // namespace llvm
|
||||
|
@ -278,7 +278,7 @@ static sys::TimePoint<std::chrono::seconds> now(bool Deterministic) {
|
||||
}
|
||||
|
||||
// Returns the offset of the first reference to a member offset.
|
||||
static ErrorOr<unsigned>
|
||||
static Expected<unsigned>
|
||||
writeSymbolTable(raw_fd_ostream &Out, object::Archive::Kind Kind,
|
||||
ArrayRef<NewArchiveMember> Members,
|
||||
std::vector<unsigned> &MemberOffsetRefs, bool Deterministic) {
|
||||
@ -320,8 +320,8 @@ writeSymbolTable(raw_fd_ostream &Out, object::Archive::Kind Kind,
|
||||
continue;
|
||||
|
||||
unsigned NameOffset = NameOS.tell();
|
||||
if (auto EC = S.printName(NameOS))
|
||||
return EC;
|
||||
if (std::error_code EC = S.printName(NameOS))
|
||||
return errorCodeToError(EC);
|
||||
NameOS << '\0';
|
||||
MemberOffsetRefs.push_back(MemberNum);
|
||||
if (isBSDLike(Kind))
|
||||
@ -373,17 +373,17 @@ writeSymbolTable(raw_fd_ostream &Out, object::Archive::Kind Kind,
|
||||
return BodyStartOffset + 4;
|
||||
}
|
||||
|
||||
std::error_code
|
||||
llvm::writeArchive(StringRef ArcName, ArrayRef<NewArchiveMember> NewMembers,
|
||||
bool WriteSymtab, object::Archive::Kind Kind,
|
||||
bool Deterministic, bool Thin,
|
||||
std::unique_ptr<MemoryBuffer> OldArchiveBuf) {
|
||||
Error llvm::writeArchive(StringRef ArcName,
|
||||
ArrayRef<NewArchiveMember> NewMembers,
|
||||
bool WriteSymtab, object::Archive::Kind Kind,
|
||||
bool Deterministic, bool Thin,
|
||||
std::unique_ptr<MemoryBuffer> OldArchiveBuf) {
|
||||
assert((!Thin || !isBSDLike(Kind)) && "Only the gnu format has a thin mode");
|
||||
SmallString<128> TmpArchive;
|
||||
int TmpArchiveFD;
|
||||
if (auto EC = sys::fs::createUniqueFile(ArcName + ".temp-archive-%%%%%%%.a",
|
||||
TmpArchiveFD, TmpArchive))
|
||||
return EC;
|
||||
return errorCodeToError(EC);
|
||||
|
||||
tool_output_file Output(TmpArchive, TmpArchiveFD);
|
||||
raw_fd_ostream &Out = Output.os();
|
||||
@ -396,10 +396,10 @@ llvm::writeArchive(StringRef ArcName, ArrayRef<NewArchiveMember> NewMembers,
|
||||
|
||||
unsigned MemberReferenceOffset = 0;
|
||||
if (WriteSymtab) {
|
||||
ErrorOr<unsigned> MemberReferenceOffsetOrErr = writeSymbolTable(
|
||||
Expected<unsigned> MemberReferenceOffsetOrErr = writeSymbolTable(
|
||||
Out, Kind, NewMembers, MemberOffsetRefs, Deterministic);
|
||||
if (auto EC = MemberReferenceOffsetOrErr.getError())
|
||||
return EC;
|
||||
if (auto E = MemberReferenceOffsetOrErr.takeError())
|
||||
return E;
|
||||
MemberReferenceOffset = MemberReferenceOffsetOrErr.get();
|
||||
}
|
||||
|
||||
@ -461,5 +461,5 @@ llvm::writeArchive(StringRef ArcName, ArrayRef<NewArchiveMember> NewMembers,
|
||||
OldArchiveBuf.reset();
|
||||
|
||||
sys::fs::rename(TmpArchive, ArcName);
|
||||
return std::error_code();
|
||||
return Error::success();
|
||||
}
|
||||
|
@ -558,9 +558,9 @@ NewArchiveMember ObjectFactory::createWeakExternal(StringRef Sym,
|
||||
return {MemoryBufferRef(StringRef(Buf, Buffer.size()), ImportName)};
|
||||
}
|
||||
|
||||
std::error_code writeImportLibrary(StringRef ImportName, StringRef Path,
|
||||
ArrayRef<COFFShortExport> Exports,
|
||||
MachineTypes Machine, bool MakeWeakAliases) {
|
||||
Error writeImportLibrary(StringRef ImportName, StringRef Path,
|
||||
ArrayRef<COFFShortExport> Exports,
|
||||
MachineTypes Machine, bool MakeWeakAliases) {
|
||||
|
||||
std::vector<NewArchiveMember> Members;
|
||||
ObjectFactory OF(llvm::sys::path::filename(ImportName), Machine);
|
||||
@ -596,9 +596,8 @@ std::error_code writeImportLibrary(StringRef ImportName, StringRef Path,
|
||||
? SymbolName
|
||||
: replace(SymbolName, E.Name, E.ExtName);
|
||||
|
||||
if (!Name) {
|
||||
return errorToErrorCode(Name.takeError());
|
||||
}
|
||||
if (!Name)
|
||||
return Name.takeError();
|
||||
|
||||
Members.push_back(
|
||||
OF.createShortImport(*Name, E.Ordinal, ImportType, NameType));
|
||||
|
@ -157,13 +157,13 @@ int llvm::libDriverMain(ArrayRef<const char *> ArgsArr) {
|
||||
|
||||
// Create an archive file.
|
||||
std::string OutputPath = getOutputPath(&Args, Members[0]);
|
||||
std::error_code EC =
|
||||
writeArchive(OutputPath, Members,
|
||||
/*WriteSymtab=*/true, object::Archive::K_GNU,
|
||||
/*Deterministic*/ true, Args.hasArg(OPT_llvmlibthin));
|
||||
|
||||
if (EC) {
|
||||
llvm::errs() << OutputPath << ": " << EC.message() << "\n";
|
||||
if (Error E =
|
||||
writeArchive(OutputPath, Members,
|
||||
/*WriteSymtab=*/true, object::Archive::K_GNU,
|
||||
/*Deterministic*/ true, Args.hasArg(OPT_llvmlibthin))) {
|
||||
handleAllErrors(std::move(E), [&](const ErrorInfoBase &EI) {
|
||||
llvm::errs() << OutputPath << ": " << EI.message() << "\n";
|
||||
});
|
||||
return 1;
|
||||
}
|
||||
|
||||
|
@ -681,10 +681,10 @@ performWriteOperation(ArchiveOperation Operation,
|
||||
break;
|
||||
}
|
||||
|
||||
std::error_code EC =
|
||||
Error E =
|
||||
writeArchive(ArchiveName, NewMembersP ? *NewMembersP : NewMembers, Symtab,
|
||||
Kind, Deterministic, Thin, std::move(OldArchiveBuf));
|
||||
failIfError(EC, ArchiveName);
|
||||
failIfError(std::move(E), ArchiveName);
|
||||
}
|
||||
|
||||
static void createSymbolTable(object::Archive *OldArchive) {
|
||||
|
Loading…
Reference in New Issue
Block a user