aboutsummaryrefslogtreecommitdiff
path: root/contrib/llvm/lib/ToolDrivers
diff options
context:
space:
mode:
Diffstat (limited to 'contrib/llvm/lib/ToolDrivers')
-rw-r--r--contrib/llvm/lib/ToolDrivers/llvm-dlltool/DlltoolDriver.cpp34
-rw-r--r--contrib/llvm/lib/ToolDrivers/llvm-lib/LibDriver.cpp78
2 files changed, 55 insertions, 57 deletions
diff --git a/contrib/llvm/lib/ToolDrivers/llvm-dlltool/DlltoolDriver.cpp b/contrib/llvm/lib/ToolDrivers/llvm-dlltool/DlltoolDriver.cpp
index 4820b9f7de58..964844922f07 100644
--- a/contrib/llvm/lib/ToolDrivers/llvm-dlltool/DlltoolDriver.cpp
+++ b/contrib/llvm/lib/ToolDrivers/llvm-dlltool/DlltoolDriver.cpp
@@ -12,7 +12,6 @@
//===----------------------------------------------------------------------===//
#include "llvm/ToolDrivers/llvm-dlltool/DlltoolDriver.h"
-#include "llvm/Object/ArchiveWriter.h"
#include "llvm/Object/COFF.h"
#include "llvm/Object/COFFImportFile.h"
#include "llvm/Object/COFFModuleDefinition.h"
@@ -21,7 +20,6 @@
#include "llvm/Option/Option.h"
#include "llvm/Support/Path.h"
-#include <string>
#include <vector>
using namespace llvm;
@@ -41,7 +39,7 @@ enum {
#include "Options.inc"
#undef PREFIX
-static const llvm::opt::OptTable::Info infoTable[] = {
+static const llvm::opt::OptTable::Info InfoTable[] = {
#define OPTION(X1, X2, ID, KIND, GROUP, ALIAS, X7, X8, X9, X10, X11, X12) \
{X1, X2, X10, X11, OPT_##ID, llvm::opt::Option::KIND##Class, \
X9, X8, OPT_##GROUP, OPT_##ALIAS, X7, X12},
@@ -51,26 +49,21 @@ static const llvm::opt::OptTable::Info infoTable[] = {
class DllOptTable : public llvm::opt::OptTable {
public:
- DllOptTable() : OptTable(infoTable, false) {}
+ DllOptTable() : OptTable(InfoTable, false) {}
};
} // namespace
-std::vector<std::unique_ptr<MemoryBuffer>> OwningMBs;
-
// Opens a file. Path has to be resolved already.
-// Newly created memory buffers are owned by this driver.
-Optional<MemoryBufferRef> openFile(StringRef Path) {
+static std::unique_ptr<MemoryBuffer> openFile(const Twine &Path) {
ErrorOr<std::unique_ptr<llvm::MemoryBuffer>> MB = MemoryBuffer::getFile(Path);
if (std::error_code EC = MB.getError()) {
- llvm::errs() << "fail openFile: " << EC.message() << "\n";
- return None;
+ llvm::errs() << "cannot open file " << Path << ": " << EC.message() << "\n";
+ return nullptr;
}
- MemoryBufferRef MBRef = MB.get()->getMemBufferRef();
- OwningMBs.push_back(std::move(MB.get())); // take ownership
- return MBRef;
+ return std::move(*MB);
}
static MachineTypes getEmulation(StringRef S) {
@@ -78,10 +71,11 @@ static MachineTypes getEmulation(StringRef S) {
.Case("i386", IMAGE_FILE_MACHINE_I386)
.Case("i386:x86-64", IMAGE_FILE_MACHINE_AMD64)
.Case("arm", IMAGE_FILE_MACHINE_ARMNT)
+ .Case("arm64", IMAGE_FILE_MACHINE_ARM64)
.Default(IMAGE_FILE_MACHINE_UNKNOWN);
}
-static std::string getImplibPath(std::string Path) {
+static std::string getImplibPath(StringRef Path) {
SmallString<128> Out = StringRef("lib");
Out.append(Path);
sys::path::replace_extension(Out, ".a");
@@ -103,13 +97,13 @@ int llvm::dlltoolDriverMain(llvm::ArrayRef<const char *> ArgsArr) {
if (Args.hasArgNoClaim(OPT_INPUT) ||
(!Args.hasArgNoClaim(OPT_d) && !Args.hasArgNoClaim(OPT_l))) {
Table.PrintHelp(outs(), ArgsArr[0], "dlltool", false);
- llvm::outs() << "\nTARGETS: i386, i386:x86-64, arm\n";
+ llvm::outs() << "\nTARGETS: i386, i386:x86-64, arm, arm64\n";
return 1;
}
if (!Args.hasArgNoClaim(OPT_m) && Args.hasArgNoClaim(OPT_d)) {
llvm::errs() << "error: no target machine specified\n"
- << "supported targets: i386, i386:x86-64, arm\n";
+ << "supported targets: i386, i386:x86-64, arm, arm64\n";
return 1;
}
@@ -121,7 +115,8 @@ int llvm::dlltoolDriverMain(llvm::ArrayRef<const char *> ArgsArr) {
return 1;
}
- Optional<MemoryBufferRef> MB = openFile(Args.getLastArg(OPT_d)->getValue());
+ std::unique_ptr<MemoryBuffer> MB =
+ openFile(Args.getLastArg(OPT_d)->getValue());
if (!MB)
return 1;
@@ -168,8 +163,9 @@ int llvm::dlltoolDriverMain(llvm::ArrayRef<const char *> ArgsArr) {
E.SymbolName = E.Name;
// Trim off the trailing decoration. Symbols will always have a
// starting prefix here (either _ for cdecl/stdcall, @ for fastcall
- // or ? for C++ functions). (Vectorcall functions also will end up having
- // a prefix here, even if they shouldn't.)
+ // or ? for C++ functions). Vectorcall functions won't have any
+ // fixed prefix, but the function base name will still be at least
+ // one char.
E.Name = E.Name.substr(0, E.Name.find('@', 1));
// By making sure E.SymbolName != E.Name for decorated symbols,
// writeImportLibrary writes these symbols with the type
diff --git a/contrib/llvm/lib/ToolDrivers/llvm-lib/LibDriver.cpp b/contrib/llvm/lib/ToolDrivers/llvm-lib/LibDriver.cpp
index f304b9c9a8da..f5cf848aa8c7 100644
--- a/contrib/llvm/lib/ToolDrivers/llvm-lib/LibDriver.cpp
+++ b/contrib/llvm/lib/ToolDrivers/llvm-lib/LibDriver.cpp
@@ -40,31 +40,31 @@ enum {
#include "Options.inc"
#undef PREFIX
-static const llvm::opt::OptTable::Info infoTable[] = {
-#define OPTION(X1, X2, ID, KIND, GROUP, ALIAS, X6, X7, X8, X9, X10, X11) \
- {X1, X2, X9, X10, OPT_##ID, llvm::opt::Option::KIND##Class, \
- X8, X7, OPT_##GROUP, OPT_##ALIAS, X6, X11},
+static const opt::OptTable::Info InfoTable[] = {
+#define OPTION(X1, X2, ID, KIND, GROUP, ALIAS, X7, X8, X9, X10, X11, X12) \
+ {X1, X2, X10, X11, OPT_##ID, opt::Option::KIND##Class, \
+ X9, X8, OPT_##GROUP, OPT_##ALIAS, X7, X12},
#include "Options.inc"
#undef OPTION
};
-class LibOptTable : public llvm::opt::OptTable {
+class LibOptTable : public opt::OptTable {
public:
- LibOptTable() : OptTable(infoTable, true) {}
+ LibOptTable() : OptTable(InfoTable, true) {}
};
}
-static std::string getOutputPath(llvm::opt::InputArgList *Args,
- const llvm::NewArchiveMember &FirstMember) {
+static std::string getOutputPath(opt::InputArgList *Args,
+ const NewArchiveMember &FirstMember) {
if (auto *Arg = Args->getLastArg(OPT_out))
return Arg->getValue();
SmallString<128> Val = StringRef(FirstMember.Buf->getBufferIdentifier());
- llvm::sys::path::replace_extension(Val, ".lib");
+ sys::path::replace_extension(Val, ".lib");
return Val.str();
}
-static std::vector<StringRef> getSearchPaths(llvm::opt::InputArgList *Args,
+static std::vector<StringRef> getSearchPaths(opt::InputArgList *Args,
StringSaver &Saver) {
std::vector<StringRef> Ret;
// Add current directory as first item of the search path.
@@ -87,28 +87,29 @@ static std::vector<StringRef> getSearchPaths(llvm::opt::InputArgList *Args,
return Ret;
}
-static Optional<std::string> findInputFile(StringRef File,
- ArrayRef<StringRef> Paths) {
- for (auto Dir : Paths) {
+static std::string findInputFile(StringRef File, ArrayRef<StringRef> Paths) {
+ for (StringRef Dir : Paths) {
SmallString<128> Path = Dir;
sys::path::append(Path, File);
if (sys::fs::exists(Path))
return Path.str().str();
}
- return Optional<std::string>();
+ return "";
}
-int llvm::libDriverMain(llvm::ArrayRef<const char*> ArgsArr) {
- SmallVector<const char *, 20> NewArgs(ArgsArr.begin(), ArgsArr.end());
+int llvm::libDriverMain(ArrayRef<const char *> ArgsArr) {
BumpPtrAllocator Alloc;
StringSaver Saver(Alloc);
+
+ // Parse command line arguments.
+ SmallVector<const char *, 20> NewArgs(ArgsArr.begin(), ArgsArr.end());
cl::ExpandResponseFiles(Saver, cl::TokenizeWindowsCommandLine, NewArgs);
ArgsArr = NewArgs;
LibOptTable Table;
unsigned MissingIndex;
unsigned MissingCount;
- llvm::opt::InputArgList Args =
+ opt::InputArgList Args =
Table.ParseArgs(ArgsArr.slice(1), MissingIndex, MissingCount);
if (MissingCount) {
llvm::errs() << "missing arg value for \""
@@ -120,32 +121,33 @@ int llvm::libDriverMain(llvm::ArrayRef<const char*> ArgsArr) {
for (auto *Arg : Args.filtered(OPT_UNKNOWN))
llvm::errs() << "ignoring unknown argument: " << Arg->getSpelling() << "\n";
- if (!Args.hasArgNoClaim(OPT_INPUT)) {
- // No input files. To match lib.exe, silently do nothing.
+ // If no input files, silently do nothing to match lib.exe.
+ if (!Args.hasArgNoClaim(OPT_INPUT))
return 0;
- }
std::vector<StringRef> SearchPaths = getSearchPaths(&Args, Saver);
- std::vector<llvm::NewArchiveMember> Members;
+ // Create a NewArchiveMember for each input file.
+ std::vector<NewArchiveMember> Members;
for (auto *Arg : Args.filtered(OPT_INPUT)) {
- Optional<std::string> Path = findInputFile(Arg->getValue(), SearchPaths);
- if (!Path.hasValue()) {
+ std::string Path = findInputFile(Arg->getValue(), SearchPaths);
+ if (Path.empty()) {
llvm::errs() << Arg->getValue() << ": no such file or directory\n";
return 1;
}
+
Expected<NewArchiveMember> MOrErr =
- NewArchiveMember::getFile(Saver.save(*Path), /*Deterministic=*/true);
+ NewArchiveMember::getFile(Saver.save(Path), /*Deterministic=*/true);
if (!MOrErr) {
- handleAllErrors(MOrErr.takeError(), [&](const llvm::ErrorInfoBase &EIB) {
+ handleAllErrors(MOrErr.takeError(), [&](const ErrorInfoBase &EIB) {
llvm::errs() << Arg->getValue() << ": " << EIB.message() << "\n";
});
return 1;
}
- llvm::file_magic Magic = llvm::identify_magic(MOrErr->Buf->getBuffer());
- if (Magic != llvm::file_magic::coff_object &&
- Magic != llvm::file_magic::bitcode &&
- Magic != llvm::file_magic::windows_resource) {
+
+ file_magic Magic = identify_magic(MOrErr->Buf->getBuffer());
+ if (Magic != file_magic::coff_object && Magic != file_magic::bitcode &&
+ Magic != file_magic::windows_resource) {
llvm::errs() << Arg->getValue()
<< ": not a COFF object, bitcode or resource file\n";
return 1;
@@ -153,15 +155,15 @@ int llvm::libDriverMain(llvm::ArrayRef<const char*> ArgsArr) {
Members.emplace_back(std::move(*MOrErr));
}
- std::pair<StringRef, std::error_code> Result =
- llvm::writeArchive(getOutputPath(&Args, Members[0]), Members,
- /*WriteSymtab=*/true, object::Archive::K_GNU,
- /*Deterministic*/ true, Args.hasArg(OPT_llvmlibthin));
-
- if (Result.second) {
- if (Result.first.empty())
- Result.first = ArgsArr[0];
- llvm::errs() << Result.first << ": " << Result.second.message() << "\n";
+ // Create an archive file.
+ std::string OutputPath = getOutputPath(&Args, Members[0]);
+ 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;
}