[PATCH] D45550: Use GetArgumentVector to retrieve the utf-8 encoded arguments on all platforms
Aaron Smith via Phabricator via llvm-commits
llvm-commits at lists.llvm.org
Wed Apr 11 18:49:40 PDT 2018
asmith created this revision.
asmith added reviewers: eli.friedman, ruiu, llvm-commits.
After running the lld unit tests on Windows, it was discovered that various llvm tools on Windows are not handling unicode command lines. An example of a test that does not work on Windows because of this issue is lld/test/ELF/format-binary-non-ascii.s.
This problem was originally fixed in r329468 by modifying Windows/Path.inc to try and use the current codepage. Eli Friedman recommended instead modifying the llvm tools to properly handle unicode command lines by calling sys::Process::GetArgumentVector.
Repository:
rL LLVM
https://reviews.llvm.org/D45550
Files:
tools/lld/lld.cpp
Index: tools/lld/lld.cpp
===================================================================
--- tools/lld/lld.cpp
+++ tools/lld/lld.cpp
@@ -20,9 +20,11 @@
#include "llvm/ADT/STLExtras.h"
#include "llvm/ADT/StringSwitch.h"
#include "llvm/ADT/Twine.h"
+#include "llvm/Support/Error.h"
#include "llvm/Support/ManagedStatic.h"
#include "llvm/Support/Path.h"
#include "llvm/Support/PrettyStackTrace.h"
+#include "llvm/Support/Process.h"
#include "llvm/Support/Signals.h"
#include <cstdlib>
@@ -111,15 +113,25 @@
// and we use it to detect whether we are running tests or not.
static bool canExitEarly() { return StringRef(getenv("LLD_IN_TEST")) != "1"; }
+static ExitOnError ExitOnErr;
+
/// Universal linker main(). This linker emulates the gnu, darwin, or
/// windows linker based on the argv[0] or -flavor option.
-int main(int Argc, const char **Argv) {
- // Standard set up, so program fails gracefully.
- sys::PrintStackTraceOnErrorSignal(Argv[0]);
- PrettyStackTraceProgram StackPrinter(Argc, Argv);
- llvm_shutdown_obj Shutdown;
+int main(int Argc_, const char **Argv_) {
+ // Print a stack trace if we signal out.
+ sys::PrintStackTraceOnErrorSignal(Argv_[0]);
+ PrettyStackTraceProgram X(Argc_, Argv_);
+
+ ExitOnErr.setBanner("lld: ");
+
+ SmallVector<const char *, 256> Argv;
+ SpecificBumpPtrAllocator<char> ArgAllocator;
+ ExitOnErr(errorCodeToError(sys::Process::GetArgumentVector(
+ Argv, makeArrayRef(Argv_, Argc_), ArgAllocator)));
+
+ llvm_shutdown_obj Y; // Call llvm_shutdown() on exit.
- std::vector<const char *> Args(Argv, Argv + Argc);
+ std::vector<const char *> Args(Argv.begin(), Argv.end());
switch (parseFlavor(Args)) {
case Gnu:
if (isPETarget(Args))
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D45550.142103.patch
Type: text/x-patch
Size: 1726 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20180412/4285cb2a/attachment.bin>
More information about the llvm-commits
mailing list