[lld] r200589 - [PECOFF] Handle /machine option before handling all the other options.

Rui Ueyama ruiu at google.com
Fri Jan 31 14:58:19 PST 2014


Author: ruiu
Date: Fri Jan 31 16:58:19 2014
New Revision: 200589

URL: http://llvm.org/viewvc/llvm-project?rev=200589&view=rev
Log:
[PECOFF] Handle /machine option before handling all the other options.

The target machine type affects the meaning of other options, in particular
how to mangle symbols. So we want to handle the option first and then parse
all the other options.

Modified:
    lld/trunk/lib/Driver/WinLinkDriver.cpp
    lld/trunk/test/pecoff/pe32plus.test

Modified: lld/trunk/lib/Driver/WinLinkDriver.cpp
URL: http://llvm.org/viewvc/llvm-project/lld/trunk/lib/Driver/WinLinkDriver.cpp?rev=200589&r1=200588&r2=200589&view=diff
==============================================================================
--- lld/trunk/lib/Driver/WinLinkDriver.cpp (original)
+++ lld/trunk/lib/Driver/WinLinkDriver.cpp Fri Jan 31 16:58:19 2014
@@ -698,6 +698,19 @@ WinLinkDriver::parse(int argc, const cha
     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 cha
       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))

Modified: lld/trunk/test/pecoff/pe32plus.test
URL: http://llvm.org/viewvc/llvm-project/lld/trunk/test/pecoff/pe32plus.test?rev=200589&r1=200588&r2=200589&view=diff
==============================================================================
--- lld/trunk/test/pecoff/pe32plus.test (original)
+++ lld/trunk/test/pecoff/pe32plus.test Fri Jan 31 16:58:19 2014
@@ -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





More information about the llvm-commits mailing list