summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--lld/lib/Driver/WinLinkDriver.cpp24
-rw-r--r--lld/test/pecoff/pe32plus.test4
2 files changed, 15 insertions, 13 deletions
diff --git a/lld/lib/Driver/WinLinkDriver.cpp b/lld/lib/Driver/WinLinkDriver.cpp
index 39643379d78..5e21a3d6624 100644
--- a/lld/lib/Driver/WinLinkDriver.cpp
+++ b/lld/lib/Driver/WinLinkDriver.cpp
@@ -698,6 +698,19 @@ WinLinkDriver::parse(int argc, const char *argv[], PECOFFLinkingContext &ctx,
return false;
}
+ // Handle /machine before parsing all the other options, as the target machine
+ // type affects how to handle other options. For example, x86 needs the
+ // leading underscore to mangle symbols, while x64 doesn't need it.
+ if (llvm::opt::Arg *inputArg = parsedArgs->getLastArg(OPT_machine)) {
+ StringRef arg = inputArg->getValue();
+ llvm::COFF::MachineTypes type = stringToMachineType(arg);
+ if (type == llvm::COFF::IMAGE_FILE_MACHINE_UNKNOWN) {
+ diagnostics << "error: unknown machine type: " << arg << "\n";
+ return false;
+ }
+ ctx.setMachineType(type);
+ }
+
// Handle /nodefaultlib:<lib>. The same option without argument is handled in
// the following for loop.
for (llvm::opt::arg_iterator it = parsedArgs->filtered_begin(OPT_nodefaultlib),
@@ -786,17 +799,6 @@ WinLinkDriver::parse(int argc, const char *argv[], PECOFFLinkingContext &ctx,
break;
}
- case OPT_machine: {
- StringRef arg = inputArg->getValue();
- llvm::COFF::MachineTypes type = stringToMachineType(arg);
- if (type == llvm::COFF::IMAGE_FILE_MACHINE_UNKNOWN) {
- diagnostics << "error: unknown machine type: " << arg << "\n";
- return false;
- }
- ctx.setMachineType(type);
- break;
- }
-
case OPT_version: {
uint32_t major, minor;
if (!parseVersion(inputArg->getValue(), major, minor))
diff --git a/lld/test/pecoff/pe32plus.test b/lld/test/pecoff/pe32plus.test
index ea20d1b851b..f1bc39e8dcf 100644
--- a/lld/test/pecoff/pe32plus.test
+++ b/lld/test/pecoff/pe32plus.test
@@ -1,7 +1,7 @@
# RUN: yaml2obj %p/Inputs/nop64.obj.yaml > %t.obj
-# RUN: lld -flavor link /out:%t.exe /subsystem:console /machine:x64 \
-# RUN: /entry:start -- %t.obj
+# RUN: lld -flavor link /out:%t.exe /subsystem:console /entry:start \
+# RUN: /machine:x64 -- %t.obj
# RUN: llvm-readobj -file-headers %t.exe | FileCheck %s
CHECK: Format: COFF-x86-64
OpenPOWER on IntegriCloud