mirror of
https://github.com/capstone-engine/llvm-capstone.git
synced 2024-11-23 05:40:09 +00:00
[llvm-driver] Fix usage of InitLLVM
on Windows (#76306)
Previously, some tools such as `clang` or `lld` which require strict order for certain command-line options, such as `clang -cc1` or `lld -flavor`, would not longer work on Windows, when these tools were linked as part of `llvm-driver`. This was caused by `InitLLVM` which was part of the `*_main()` function of these tools, which in turn calls `windows::GetCommandLineArguments`. That function completly replaces argc/argv by new UTF-8 contents, so any ajustements to argc/argv made by `llvm-driver` prior to calling these tools was reset. `InitLLVM` is now called by the `llvm-driver`. Any tool that participates in (or is part of) the `llvm-driver` doesn't call `InitLLVM` anymore.
This commit is contained in:
parent
4cee0e3c88
commit
3c6f47d6b8
@ -20,7 +20,6 @@
|
||||
#include "llvm/Support/CommandLine.h"
|
||||
#include "llvm/Support/FileUtilities.h"
|
||||
#include "llvm/Support/Format.h"
|
||||
#include "llvm/Support/InitLLVM.h"
|
||||
#include "llvm/Support/JSON.h"
|
||||
#include "llvm/Support/LLVMDriver.h"
|
||||
#include "llvm/Support/Program.h"
|
||||
@ -699,7 +698,6 @@ static std::string getModuleCachePath(ArrayRef<std::string> Args) {
|
||||
// form specified command line after the positional parameter "--".
|
||||
static std::unique_ptr<tooling::CompilationDatabase>
|
||||
getCompilationDataBase(int argc, char **argv, std::string &ErrorMessage) {
|
||||
llvm::InitLLVM X(argc, argv);
|
||||
ParseArgs(argc, argv);
|
||||
|
||||
if (!CompilationDB.empty())
|
||||
|
@ -36,7 +36,6 @@
|
||||
#include "llvm/Support/CrashRecoveryContext.h"
|
||||
#include "llvm/Support/ErrorHandling.h"
|
||||
#include "llvm/Support/FileSystem.h"
|
||||
#include "llvm/Support/InitLLVM.h"
|
||||
#include "llvm/Support/LLVMDriver.h"
|
||||
#include "llvm/Support/Path.h"
|
||||
#include "llvm/Support/PrettyStackTrace.h"
|
||||
@ -377,7 +376,6 @@ static int ExecuteCC1Tool(SmallVectorImpl<const char *> &ArgV,
|
||||
|
||||
int clang_main(int Argc, char **Argv, const llvm::ToolContext &ToolContext) {
|
||||
noteBottomOfStack();
|
||||
llvm::InitLLVM X(Argc, Argv);
|
||||
llvm::setBugReportMsg("PLEASE submit a bug report to " BUG_REPORT_URL
|
||||
" and include the crash backtrace, preprocessed "
|
||||
"source, and associated run script.\n");
|
||||
|
@ -16,7 +16,6 @@
|
||||
#include "llvm/ADT/Twine.h"
|
||||
#include "llvm/Support/CommandLine.h"
|
||||
#include "llvm/Support/CrashRecoveryContext.h"
|
||||
#include "llvm/Support/InitLLVM.h"
|
||||
#include "llvm/Support/Path.h"
|
||||
#include "llvm/Support/Process.h"
|
||||
#include "llvm/TargetParser/Host.h"
|
||||
|
@ -33,7 +33,6 @@
|
||||
#include "llvm/ADT/Twine.h"
|
||||
#include "llvm/Support/CommandLine.h"
|
||||
#include "llvm/Support/CrashRecoveryContext.h"
|
||||
#include "llvm/Support/InitLLVM.h"
|
||||
#include "llvm/Support/LLVMDriver.h"
|
||||
#include "llvm/Support/Path.h"
|
||||
#include "llvm/Support/PluginLoader.h"
|
||||
@ -74,7 +73,6 @@ LLD_HAS_DRIVER(macho)
|
||||
LLD_HAS_DRIVER(wasm)
|
||||
|
||||
int lld_main(int argc, char **argv, const llvm::ToolContext &) {
|
||||
InitLLVM x(argc, argv);
|
||||
sys::Process::UseANSIEscapeCodes(true);
|
||||
|
||||
if (::getenv("FORCE_LLD_DIAGNOSTICS_CRASH")) {
|
||||
|
@ -8,9 +8,11 @@
|
||||
|
||||
#include "llvm/Support/LLVMDriver.h"
|
||||
#include "llvm/ADT/ArrayRef.h"
|
||||
#include "llvm/Support/InitLLVM.h"
|
||||
|
||||
int @TOOL_NAME@_main(int argc, char **, const llvm::ToolContext &);
|
||||
|
||||
int main(int argc, char **argv) {
|
||||
llvm::InitLLVM X(argc, argv);
|
||||
return @TOOL_NAME@_main(argc, argv, {argv[0], nullptr, false});
|
||||
}
|
||||
|
@ -38,6 +38,11 @@ using namespace llvm::sys;
|
||||
|
||||
InitLLVM::InitLLVM(int &Argc, const char **&Argv,
|
||||
bool InstallPipeSignalExitHandler) {
|
||||
#ifndef NDEBUG
|
||||
static std::atomic<bool> Initialized{false};
|
||||
assert(!Initialized && "InitLLVM was already initialized!");
|
||||
Initialized = true;
|
||||
#endif
|
||||
#ifdef __MVS__
|
||||
// Bring stdin/stdout/stderr into a known state.
|
||||
sys::AddSignalHandler(CleanupStdHandles, nullptr);
|
||||
|
@ -37,7 +37,6 @@
|
||||
#include "llvm/Support/FileCollector.h"
|
||||
#include "llvm/Support/FileSystem.h"
|
||||
#include "llvm/Support/FormatVariadic.h"
|
||||
#include "llvm/Support/InitLLVM.h"
|
||||
#include "llvm/Support/LLVMDriver.h"
|
||||
#include "llvm/Support/Path.h"
|
||||
#include "llvm/Support/TargetSelect.h"
|
||||
@ -608,8 +607,6 @@ getOutputFileName(StringRef InputFile, const DsymutilOptions &Options) {
|
||||
}
|
||||
|
||||
int dsymutil_main(int argc, char **argv, const llvm::ToolContext &) {
|
||||
InitLLVM X(argc, argv);
|
||||
|
||||
// Parse arguments.
|
||||
DsymutilOptTable T;
|
||||
unsigned MAI;
|
||||
|
@ -25,7 +25,6 @@
|
||||
#include "llvm/Support/FileSystem.h"
|
||||
#include "llvm/Support/Format.h"
|
||||
#include "llvm/Support/FormatVariadic.h"
|
||||
#include "llvm/Support/InitLLVM.h"
|
||||
#include "llvm/Support/LLVMDriver.h"
|
||||
#include "llvm/Support/LineIterator.h"
|
||||
#include "llvm/Support/MemoryBuffer.h"
|
||||
@ -1500,7 +1499,6 @@ static int ranlib_main(int argc, char **argv) {
|
||||
}
|
||||
|
||||
int llvm_ar_main(int argc, char **argv, const llvm::ToolContext &) {
|
||||
InitLLVM X(argc, argv);
|
||||
ToolName = argv[0];
|
||||
|
||||
llvm::InitializeAllTargetInfos();
|
||||
|
@ -13,7 +13,6 @@
|
||||
#include "llvm/Option/ArgList.h"
|
||||
#include "llvm/Option/Option.h"
|
||||
#include "llvm/Support/CommandLine.h"
|
||||
#include "llvm/Support/InitLLVM.h"
|
||||
#include "llvm/Support/LLVMDriver.h"
|
||||
#include "llvm/Support/WithColor.h"
|
||||
#include "llvm/Support/raw_ostream.h"
|
||||
@ -146,7 +145,6 @@ static void demangleLine(llvm::raw_ostream &OS, StringRef Mangled, bool Split) {
|
||||
}
|
||||
|
||||
int llvm_cxxfilt_main(int argc, char **argv, const llvm::ToolContext &) {
|
||||
InitLLVM X(argc, argv);
|
||||
BumpPtrAllocator A;
|
||||
StringSaver Saver(A);
|
||||
CxxfiltOptTable Tbl;
|
||||
|
@ -22,7 +22,6 @@
|
||||
#include "llvm/Option/ArgList.h"
|
||||
#include "llvm/Option/Option.h"
|
||||
#include "llvm/Support/CommandLine.h"
|
||||
#include "llvm/Support/InitLLVM.h"
|
||||
#include "llvm/Support/LLVMDriver.h"
|
||||
#include "llvm/Support/ThreadPool.h"
|
||||
|
||||
@ -121,7 +120,6 @@ static void parseArgs(int argc, char **argv) {
|
||||
}
|
||||
|
||||
int llvm_debuginfod_main(int argc, char **argv, const llvm::ToolContext &) {
|
||||
InitLLVM X(argc, argv);
|
||||
HTTPClient::initialize();
|
||||
parseArgs(argc, argv);
|
||||
|
||||
|
@ -10,6 +10,7 @@
|
||||
#include "llvm/ADT/StringRef.h"
|
||||
#include "llvm/Support/CommandLine.h"
|
||||
#include "llvm/Support/ErrorHandling.h"
|
||||
#include "llvm/Support/InitLLVM.h"
|
||||
#include "llvm/Support/LLVMDriver.h"
|
||||
#include "llvm/Support/Path.h"
|
||||
#include "llvm/Support/WithColor.h"
|
||||
@ -79,4 +80,7 @@ static int findTool(int Argc, char **Argv, const char *Argv0) {
|
||||
return 1;
|
||||
}
|
||||
|
||||
int main(int Argc, char **Argv) { return findTool(Argc, Argv, Argv[0]); }
|
||||
int main(int Argc, char **Argv) {
|
||||
llvm::InitLLVM X(Argc, Argv);
|
||||
return findTool(Argc, Argv, Argv[0]);
|
||||
}
|
||||
|
@ -27,7 +27,6 @@
|
||||
#include "llvm/Option/Option.h"
|
||||
#include "llvm/Support/CommandLine.h"
|
||||
#include "llvm/Support/FileSystem.h"
|
||||
#include "llvm/Support/InitLLVM.h"
|
||||
#include "llvm/Support/LLVMDriver.h"
|
||||
#include "llvm/Support/MemoryBuffer.h"
|
||||
#include "llvm/Support/TargetSelect.h"
|
||||
@ -120,8 +119,6 @@ static Expected<Triple> readTargetTriple(StringRef FileName) {
|
||||
}
|
||||
|
||||
int llvm_dwp_main(int argc, char **argv, const llvm::ToolContext &) {
|
||||
InitLLVM X(argc, argv);
|
||||
|
||||
DwpOptTable Tbl;
|
||||
llvm::BumpPtrAllocator A;
|
||||
llvm::StringSaver Saver{A};
|
||||
|
@ -23,7 +23,6 @@
|
||||
#include "llvm/Option/ArgList.h"
|
||||
#include "llvm/Option/Option.h"
|
||||
#include "llvm/Support/CommandLine.h"
|
||||
#include "llvm/Support/InitLLVM.h"
|
||||
#include "llvm/Support/LLVMDriver.h"
|
||||
#include "llvm/Support/LineIterator.h"
|
||||
#include "llvm/Support/TargetSelect.h"
|
||||
@ -727,7 +726,6 @@ static Expected<Config> parseCommandLine(int Argc, char **Argv) {
|
||||
}
|
||||
|
||||
int llvm_libtool_darwin_main(int Argc, char **Argv, const llvm::ToolContext &) {
|
||||
InitLLVM X(Argc, Argv);
|
||||
Expected<Config> ConfigOrErr = parseCommandLine(Argc, Argv);
|
||||
if (!ConfigOrErr) {
|
||||
WithColor::defaultErrorHandler(ConfigOrErr.takeError());
|
||||
|
@ -26,7 +26,6 @@
|
||||
#include "llvm/Support/CommandLine.h"
|
||||
#include "llvm/Support/Error.h"
|
||||
#include "llvm/Support/FileOutputBuffer.h"
|
||||
#include "llvm/Support/InitLLVM.h"
|
||||
#include "llvm/Support/LLVMDriver.h"
|
||||
#include "llvm/Support/TargetSelect.h"
|
||||
#include "llvm/Support/WithColor.h"
|
||||
@ -724,7 +723,6 @@ replaceSlices(LLVMContext &LLVMCtx,
|
||||
}
|
||||
|
||||
int llvm_lipo_main(int argc, char **argv, const llvm::ToolContext &) {
|
||||
InitLLVM X(argc, argv);
|
||||
llvm::InitializeAllTargetInfos();
|
||||
llvm::InitializeAllTargetMCs();
|
||||
llvm::InitializeAllAsmParsers();
|
||||
|
@ -34,7 +34,6 @@
|
||||
#include "llvm/Support/FileUtilities.h"
|
||||
#include "llvm/Support/FormatVariadic.h"
|
||||
#include "llvm/Support/FormattedStream.h"
|
||||
#include "llvm/Support/InitLLVM.h"
|
||||
#include "llvm/Support/LLVMDriver.h"
|
||||
#include "llvm/Support/MemoryBuffer.h"
|
||||
#include "llvm/Support/Path.h"
|
||||
@ -187,7 +186,6 @@ static int AssembleInput(StringRef ProgName, const Target *TheTarget,
|
||||
}
|
||||
|
||||
int llvm_ml_main(int Argc, char **Argv, const llvm::ToolContext &) {
|
||||
InitLLVM X(Argc, Argv);
|
||||
StringRef ProgName = sys::path::filename(Argv[0]);
|
||||
|
||||
// Initialize targets and assembly printers/parsers.
|
||||
|
@ -16,7 +16,6 @@
|
||||
#include "llvm/Option/Option.h"
|
||||
#include "llvm/Support/Error.h"
|
||||
#include "llvm/Support/FileOutputBuffer.h"
|
||||
#include "llvm/Support/InitLLVM.h"
|
||||
#include "llvm/Support/LLVMDriver.h"
|
||||
#include "llvm/Support/MemoryBuffer.h"
|
||||
#include "llvm/Support/Path.h"
|
||||
@ -77,8 +76,6 @@ static void error(Error EC) {
|
||||
}
|
||||
|
||||
int llvm_mt_main(int Argc, char **Argv, const llvm::ToolContext &) {
|
||||
InitLLVM X(Argc, Argv);
|
||||
|
||||
CvtResOptTable T;
|
||||
unsigned MAI, MAC;
|
||||
ArrayRef<const char *> ArgsArr = ArrayRef(Argv + 1, Argc - 1);
|
||||
|
@ -42,7 +42,6 @@
|
||||
#include "llvm/Support/CommandLine.h"
|
||||
#include "llvm/Support/FileSystem.h"
|
||||
#include "llvm/Support/Format.h"
|
||||
#include "llvm/Support/InitLLVM.h"
|
||||
#include "llvm/Support/LLVMDriver.h"
|
||||
#include "llvm/Support/MemoryBuffer.h"
|
||||
#include "llvm/Support/Program.h"
|
||||
@ -2405,7 +2404,6 @@ exportSymbolNamesFromFiles(const std::vector<std::string> &InputFilenames) {
|
||||
}
|
||||
|
||||
int llvm_nm_main(int argc, char **argv, const llvm::ToolContext &) {
|
||||
InitLLVM X(argc, argv);
|
||||
BumpPtrAllocator A;
|
||||
StringSaver Saver(A);
|
||||
NmOptTable Tbl;
|
||||
|
@ -42,7 +42,6 @@
|
||||
#include "llvm/Support/ErrorHandling.h"
|
||||
#include "llvm/Support/ErrorOr.h"
|
||||
#include "llvm/Support/FileUtilities.h"
|
||||
#include "llvm/Support/InitLLVM.h"
|
||||
#include "llvm/Support/LLVMDriver.h"
|
||||
#include "llvm/Support/Memory.h"
|
||||
#include "llvm/Support/Path.h"
|
||||
@ -224,7 +223,6 @@ static Error executeObjcopy(ConfigManager &ConfigMgr) {
|
||||
}
|
||||
|
||||
int llvm_objcopy_main(int argc, char **argv, const llvm::ToolContext &) {
|
||||
InitLLVM X(argc, argv);
|
||||
ToolName = argv[0];
|
||||
|
||||
// Expand response files.
|
||||
|
@ -71,7 +71,6 @@
|
||||
#include "llvm/Support/Format.h"
|
||||
#include "llvm/Support/FormatVariadic.h"
|
||||
#include "llvm/Support/GraphWriter.h"
|
||||
#include "llvm/Support/InitLLVM.h"
|
||||
#include "llvm/Support/LLVMDriver.h"
|
||||
#include "llvm/Support/MemoryBuffer.h"
|
||||
#include "llvm/Support/SourceMgr.h"
|
||||
@ -3417,7 +3416,6 @@ static void parseObjdumpOptions(const llvm::opt::InputArgList &InputArgs) {
|
||||
|
||||
int llvm_objdump_main(int argc, char **argv, const llvm::ToolContext &) {
|
||||
using namespace llvm;
|
||||
InitLLVM X(argc, argv);
|
||||
|
||||
ToolName = argv[0];
|
||||
std::unique_ptr<CommonOptTable> T;
|
||||
|
@ -30,7 +30,6 @@
|
||||
#include "llvm/Support/FileSystem.h"
|
||||
#include "llvm/Support/Format.h"
|
||||
#include "llvm/Support/FormattedStream.h"
|
||||
#include "llvm/Support/InitLLVM.h"
|
||||
#include "llvm/Support/LLVMDriver.h"
|
||||
#include "llvm/Support/MD5.h"
|
||||
#include "llvm/Support/MemoryBuffer.h"
|
||||
@ -3176,7 +3175,6 @@ static int order_main(int argc, const char *argv[]) {
|
||||
int llvm_profdata_main(int argc, char **argvNonConst,
|
||||
const llvm::ToolContext &) {
|
||||
const char **argv = const_cast<const char **>(argvNonConst);
|
||||
InitLLVM X(argc, argv);
|
||||
|
||||
StringRef ProgName(sys::path::filename(argv[0]));
|
||||
|
||||
|
@ -26,7 +26,6 @@
|
||||
#include "llvm/Support/Error.h"
|
||||
#include "llvm/Support/FileSystem.h"
|
||||
#include "llvm/Support/FileUtilities.h"
|
||||
#include "llvm/Support/InitLLVM.h"
|
||||
#include "llvm/Support/LLVMDriver.h"
|
||||
#include "llvm/Support/MemoryBuffer.h"
|
||||
#include "llvm/Support/Path.h"
|
||||
@ -731,7 +730,6 @@ void doCvtres(std::string Src, std::string Dest, std::string TargetTriple) {
|
||||
} // anonymous namespace
|
||||
|
||||
int llvm_rc_main(int Argc, char **Argv, const llvm::ToolContext &) {
|
||||
InitLLVM X(Argc, Argv);
|
||||
ExitOnErr.setBanner("llvm-rc: ");
|
||||
|
||||
char **DashDash = std::find_if(Argv + 1, Argv + Argc,
|
||||
|
@ -42,7 +42,6 @@
|
||||
#include "llvm/Support/Errc.h"
|
||||
#include "llvm/Support/FileSystem.h"
|
||||
#include "llvm/Support/FormatVariadic.h"
|
||||
#include "llvm/Support/InitLLVM.h"
|
||||
#include "llvm/Support/LLVMDriver.h"
|
||||
#include "llvm/Support/Path.h"
|
||||
#include "llvm/Support/ScopedPrinter.h"
|
||||
@ -633,7 +632,6 @@ std::unique_ptr<ScopedPrinter> createWriter() {
|
||||
}
|
||||
|
||||
int llvm_readobj_main(int argc, char **argv, const llvm::ToolContext &) {
|
||||
InitLLVM X(argc, argv);
|
||||
BumpPtrAllocator A;
|
||||
StringSaver Saver(A);
|
||||
ReadobjOptTable Tbl;
|
||||
|
@ -25,7 +25,6 @@
|
||||
#include "llvm/Support/CommandLine.h"
|
||||
#include "llvm/Support/FileSystem.h"
|
||||
#include "llvm/Support/Format.h"
|
||||
#include "llvm/Support/InitLLVM.h"
|
||||
#include "llvm/Support/LLVMDriver.h"
|
||||
#include "llvm/Support/MemoryBuffer.h"
|
||||
#include "llvm/Support/WithColor.h"
|
||||
@ -863,7 +862,6 @@ static void printBerkeleyTotals() {
|
||||
}
|
||||
|
||||
int llvm_size_main(int argc, char **argv, const llvm::ToolContext &) {
|
||||
InitLLVM X(argc, argv);
|
||||
BumpPtrAllocator A;
|
||||
StringSaver Saver(A);
|
||||
SizeOptTable Tbl;
|
||||
|
@ -34,7 +34,6 @@
|
||||
#include "llvm/Support/Debug.h"
|
||||
#include "llvm/Support/Errc.h"
|
||||
#include "llvm/Support/FileSystem.h"
|
||||
#include "llvm/Support/InitLLVM.h"
|
||||
#include "llvm/Support/LLVMDriver.h"
|
||||
#include "llvm/Support/Path.h"
|
||||
#include "llvm/Support/StringSaver.h"
|
||||
@ -462,7 +461,6 @@ static void filterMarkup(const opt::InputArgList &Args, LLVMSymbolizer &Symboliz
|
||||
}
|
||||
|
||||
int llvm_symbolizer_main(int argc, char **argv, const llvm::ToolContext &) {
|
||||
InitLLVM X(argc, argv);
|
||||
sys::InitializeCOMRAII COM(sys::COMThreadingMode::MultiThreaded);
|
||||
|
||||
ToolName = argv[0];
|
||||
|
@ -36,7 +36,6 @@
|
||||
#include "llvm/Support/Errc.h"
|
||||
#include "llvm/Support/ErrorOr.h"
|
||||
#include "llvm/Support/FileSystem.h"
|
||||
#include "llvm/Support/InitLLVM.h"
|
||||
#include "llvm/Support/JSON.h"
|
||||
#include "llvm/Support/LLVMDriver.h"
|
||||
#include "llvm/Support/MD5.h"
|
||||
@ -1215,8 +1214,6 @@ static void parseArgs(int Argc, char **Argv) {
|
||||
}
|
||||
|
||||
int sancov_main(int Argc, char **Argv, const llvm::ToolContext &) {
|
||||
llvm::InitLLVM X(Argc, Argv);
|
||||
|
||||
llvm::InitializeAllTargetInfos();
|
||||
llvm::InitializeAllTargetMCs();
|
||||
llvm::InitializeAllDisassemblers();
|
||||
|
Loading…
Reference in New Issue
Block a user