[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.

llvm-svn: 200589
This commit is contained in:
Rui Ueyama 2014-01-31 22:58:19 +00:00
parent edb94c70c1
commit 9661bcf2e1
2 changed files with 15 additions and 13 deletions

View File

@ -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))

View File

@ -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