The new name is consistent with ELF.
llvm-svn: 275499
// Newly created memory buffers are owned by this driver.
MemoryBufferRef LinkerDriver::openFile(StringRef Path) {
auto MBOrErr = MemoryBuffer::getFile(Path);
- error(MBOrErr, Twine("Could not open ") + Path);
+ check(MBOrErr, Twine("Could not open ") + Path);
std::unique_ptr<MemoryBuffer> &MB = *MBOrErr;
MemoryBufferRef MBRef = MB->getMemBufferRef();
OwningMBs.push_back(std::move(MB)); // take ownership
if (auto *Arg = Args.getLastArg(OPT_lldmap)) {
std::error_code EC;
llvm::raw_fd_ostream Out(Arg->getValue(), EC, OpenFlags::F_Text);
- error(EC, "Could not create the symbol map");
+ check(EC, "Could not create the symbol map");
Symtab.printMap(Out);
}
// Call exit to avoid calling destructors.
void run() {
ErrorOr<std::string> ExeOrErr = llvm::sys::findProgramByName(Prog);
- error(ExeOrErr, Twine("unable to find ") + Prog + " in PATH: ");
+ check(ExeOrErr, Twine("unable to find ") + Prog + " in PATH: ");
const char *Exe = Saver.save(*ExeOrErr);
Args.insert(Args.begin(), Exe);
Args.push_back(nullptr);
// Create a temporary file.
SmallString<128> Path;
std::error_code EC = sys::fs::createTemporaryFile("tmp", "manifest", Path);
- error(EC, "cannot create a temporary file");
+ check(EC, "cannot create a temporary file");
// Open the temporary file for writing.
llvm::raw_fd_ostream OS(Path, EC, sys::fs::F_Text);
- error(EC, Twine("failed to open ") + Path);
+ check(EC, Twine("failed to open ") + Path);
// Emit the XML. Note that we do *not* verify that the XML attributes are
// syntactically correct. This is intentional for link.exe compatibility.
static std::string readFile(StringRef Path) {
ErrorOr<std::unique_ptr<MemoryBuffer>> BufOrErr = MemoryBuffer::getFile(Path);
- error(BufOrErr, "Could not open " + Path);
+ check(BufOrErr, "Could not open " + Path);
std::unique_ptr<MemoryBuffer> Buf(std::move(*BufOrErr));
return Buf->getBuffer();
}
// option, we need to merge them with the default manifest.
SmallString<128> Path2;
std::error_code EC = sys::fs::createTemporaryFile("tmp", "manifest", Path2);
- error(EC, "cannot create a temporary file");
+ check(EC, "cannot create a temporary file");
FileRemover Remover1(Path1);
FileRemover Remover2(Path2);
// Create a temporary file for the resource script file.
SmallString<128> RCPath;
std::error_code EC = sys::fs::createTemporaryFile("tmp", "rc", RCPath);
- error(EC, "cannot create a temporary file");
+ check(EC, "cannot create a temporary file");
FileRemover RCRemover(RCPath);
// Open the temporary file for writing.
llvm::raw_fd_ostream Out(RCPath, EC, sys::fs::F_Text);
- error(EC, Twine("failed to open ") + RCPath);
+ check(EC, Twine("failed to open ") + RCPath);
// Write resource script to the RC file.
Out << "#define LANG_ENGLISH 9\n"
// Create output resource file.
SmallString<128> ResPath;
EC = sys::fs::createTemporaryFile("tmp", "res", ResPath);
- error(EC, "cannot create a temporary file");
+ check(EC, "cannot create a temporary file");
Executor E("rc.exe");
E.add("/fo");
E.add(RCPath.str());
E.run();
ErrorOr<std::unique_ptr<MemoryBuffer>> Ret = MemoryBuffer::getFile(ResPath);
- error(Ret, Twine("Could not open ") + ResPath);
+ check(Ret, Twine("Could not open ") + ResPath);
return std::move(*Ret);
}
Path = (Twine(Config->OutputFile) + ".manifest").str();
std::error_code EC;
llvm::raw_fd_ostream Out(Path, EC, llvm::sys::fs::F_Text);
- error(EC, "failed to create manifest");
+ check(EC, "failed to create manifest");
Out << createManifestXml();
}
E.add(MB.getBufferIdentifier());
E.run();
ErrorOr<std::unique_ptr<MemoryBuffer>> Ret = MemoryBuffer::getFile(Path);
- error(Ret, Twine("Could not open ") + Path);
+ check(Ret, Twine("Could not open ") + Path);
return std::move(*Ret);
}
exit(1);
}
-void error(std::error_code EC, const Twine &Prefix) {
+void check(std::error_code EC, const Twine &Prefix) {
if (!EC)
return;
error(Prefix + ": " + EC.message());
}
-void error(llvm::Error E, const Twine &Prefix) {
+void check(llvm::Error E, const Twine &Prefix) {
if (!E)
return;
handleAllErrors(std::move(E), [&](const llvm::ErrorInfoBase &EIB) {
namespace coff {
LLVM_ATTRIBUTE_NORETURN void error(const Twine &Msg);
-void error(std::error_code EC, const Twine &Prefix);
-void error(llvm::Error E, const Twine &Prefix);
+void check(std::error_code EC, const Twine &Prefix);
+void check(llvm::Error E, const Twine &Prefix);
-template <typename T> void error(const ErrorOr<T> &V, const Twine &Prefix) {
- error(V.getError(), Prefix);
+template <typename T> void check(const ErrorOr<T> &V, const Twine &Prefix) {
+ check(V.getError(), Prefix);
}
template <class T> T check(Expected<T> E, const Twine &Prefix) {
void ArchiveFile::parse() {
// Parse a MemoryBufferRef as an archive file.
auto ArchiveOrErr = Archive::create(MB);
- error(errorToErrorCode(ArchiveOrErr.takeError()),
+ check(errorToErrorCode(ArchiveOrErr.takeError()),
"Failed to parse static library");
File = std::move(*ArchiveOrErr);
Error Err;
for (auto &Child : File->children(Err))
Seen[Child.getChildOffset()].clear();
- error(std::move(Err), "Failed to parse static library");
+ check(std::move(Err), "Failed to parse static library");
}
// Returns a buffer pointing to a member file containing a given symbol.
// This function is thread-safe.
MemoryBufferRef ArchiveFile::getMember(const Archive::Symbol *Sym) {
auto COrErr = Sym->getMember();
- error(COrErr, Twine("Could not get the member for symbol ") + Sym->getName());
+ check(COrErr, Twine("Could not get the member for symbol ") + Sym->getName());
const Archive::Child &C = *COrErr;
// Return an empty buffer if we have already returned the same buffer.
if (Seen[C.getChildOffset()].test_and_set())
return MemoryBufferRef();
ErrorOr<MemoryBufferRef> Ret = C.getMemoryBufferRef();
- error(Ret, Twine("Could not get the buffer for the member defining symbol ") +
+ check(Ret, Twine("Could not get the buffer for the member defining symbol ") +
Sym->getName());
return *Ret;
}
// Parse a memory buffer as a COFF file.
auto BinOrErr = createBinary(MB);
if (!BinOrErr)
- error(errorToErrorCode(BinOrErr.takeError()),
+ check(errorToErrorCode(BinOrErr.takeError()),
"Failed to parse object file");
std::unique_ptr<Binary> Bin = std::move(*BinOrErr);
const coff_section *Sec;
StringRef Name;
std::error_code EC = COFFObj->getSection(I, Sec);
- error(EC, Twine("getSection failed: #") + Twine(I));
+ check(EC, Twine("getSection failed: #") + Twine(I));
EC = COFFObj->getSectionName(Sec, Name);
- error(EC, Twine("getSectionName failed: #") + Twine(I));
+ check(EC, Twine("getSectionName failed: #") + Twine(I));
if (Name == ".sxdata") {
SXData = Sec;
continue;
for (uint32_t I = 0; I < NumSymbols; ++I) {
// Get a COFFSymbolRef object.
auto SymOrErr = COFFObj->getSymbol(I);
- error(SymOrErr, Twine("broken object file: ") + getName());
+ check(SymOrErr, Twine("broken object file: ") + getName());
COFFSymbolRef Sym = *SymOrErr;
Context.enableDebugTypeODRUniquing();
ErrorOr<std::unique_ptr<LTOModule>> ModOrErr = LTOModule::createFromBuffer(
Context, MB.getBufferStart(), MB.getBufferSize(), llvm::TargetOptions());
- error(ModOrErr, "Could not create lto module");
+ check(ModOrErr, "Could not create lto module");
M = std::move(*ModOrErr);
llvm::StringSaver Saver(Alloc);
std::pair<StringRef, std::error_code> Result =
writeArchive(Path, Members, /*WriteSymtab*/ true, object::Archive::K_GNU,
/*Deterministic*/ true, /*Thin*/ false);
- error(Result.second, Twine("Failed to write ") + Path);
+ check(Result.second, Twine("Failed to write ") + Path);
}
-
size_t FileSize = PageSize * 3;
ErrorOr<std::unique_ptr<FileOutputBuffer>> BufferOrErr =
FileOutputBuffer::create(Path, FileSize);
- error(BufferOrErr, Twine("failed to open ") + Path);
+ check(BufferOrErr, Twine("failed to open ") + Path);
std::unique_ptr<FileOutputBuffer> Buffer = std::move(*BufferOrErr);
// Write the file header.
fixSafeSEHSymbols();
writeSections();
sortExceptionTable();
- error(Buffer->commit(), "Failed to write the output file");
+ check(Buffer->commit(), "Failed to write the output file");
}
static StringRef getOutputSection(StringRef Name) {
void Writer::openFile(StringRef Path) {
ErrorOr<std::unique_ptr<FileOutputBuffer>> BufferOrErr =
FileOutputBuffer::create(Path, FileSize, FileOutputBuffer::F_executable);
- error(BufferOrErr, Twine("failed to open ") + Path);
+ check(BufferOrErr, Twine("failed to open ") + Path);
Buffer = std::move(*BufferOrErr);
}