[PECOFF] Use Windows style options instead of Unix style as primary options.

LLD still accepts both Unix and Windows style options when it's run as
link.exe. This patch does not change functionality.

llvm-svn: 187086
This commit is contained in:
Rui Ueyama 2013-07-24 23:18:02 +00:00
parent b64e95f49e
commit d1d116aa89
12 changed files with 64 additions and 64 deletions

View File

@ -80,7 +80,7 @@ bool checkNumber(StringRef version, const char *errorMessage,
return true;
}
// Parse an argument for -base, -stack or -heap. The expected string
// Parse an argument for /base, /stack or /heap. The expected string
// is "<integer>[,<integer>]".
bool parseMemoryOption(const StringRef &arg, raw_ostream &diagnostics,
uint64_t &reserve, uint64_t &commit) {
@ -97,7 +97,7 @@ bool parseMemoryOption(const StringRef &arg, raw_ostream &diagnostics,
return true;
}
// Parse -base command line option. The argument for the parameter is in the
// Parse /base command line option. The argument for the parameter is in the
// form of "<address>[:<size>]".
bool parseBaseOption(PECOFFTargetInfo &info, const StringRef &arg,
raw_ostream &diagnostics) {
@ -117,7 +117,7 @@ bool parseBaseOption(PECOFFTargetInfo &info, const StringRef &arg,
return true;
}
// Parse -stack command line option
// Parse /stack command line option
bool parseStackOption(PECOFFTargetInfo &info, const StringRef &arg,
raw_ostream &diagnostics) {
uint64_t reserve;
@ -129,7 +129,7 @@ bool parseStackOption(PECOFFTargetInfo &info, const StringRef &arg,
return true;
}
// Parse -heap command line option.
// Parse /heap command line option.
bool parseHeapOption(PECOFFTargetInfo &info, const StringRef &arg,
raw_ostream &diagnostics) {
uint64_t reserve;
@ -166,7 +166,7 @@ bool parseMinOSVersion(PECOFFTargetInfo &info, const StringRef &osVersion,
return true;
}
// Parse -subsystem command line option. The form of -subsystem is
// Parse /subsystem command line option. The form of /subsystem is
// "subsystem_name[,majorOSVersion[.minorOSVersion]]".
bool parseSubsystemOption(PECOFFTargetInfo &info, std::string arg,
raw_ostream &diagnostics) {
@ -280,7 +280,7 @@ bool WinLinkDriver::parse(int argc, const char *argv[],
return true;
}
// Handle -help
// handle /help
if (parsedArgs->getLastArg(OPT_help)) {
table.PrintHelp(llvm::outs(), argv[0], "LLVM Linker", false);
return true;
@ -300,66 +300,66 @@ bool WinLinkDriver::parse(int argc, const char *argv[],
info.appendLLVMOption((*it)->getValue());
}
// Handle -base
// handle /base
if (llvm::opt::Arg *arg = parsedArgs->getLastArg(OPT_base))
if (!parseBaseOption(info, arg->getValue(), diagnostics))
return true;
// Handle -stack
// handle /stack
if (llvm::opt::Arg *arg = parsedArgs->getLastArg(OPT_stack))
if (!parseStackOption(info, arg->getValue(), diagnostics))
return true;
// Handle -heap
// handle /heap
if (llvm::opt::Arg *arg = parsedArgs->getLastArg(OPT_heap))
if (!parseHeapOption(info, arg->getValue(), diagnostics))
return true;
// Handle -subsystem
// handle /subsystem
if (llvm::opt::Arg *arg = parsedArgs->getLastArg(OPT_subsystem))
if (!parseSubsystemOption(info, arg->getValue(), diagnostics))
return true;
// Handle -entry
// handle /entry
if (llvm::opt::Arg *arg = parsedArgs->getLastArg(OPT_entry))
info.setEntrySymbolName(arg->getValue());
// Handle -libpath
// handle /libpath
for (llvm::opt::arg_iterator it = parsedArgs->filtered_begin(OPT_libpath),
ie = parsedArgs->filtered_end();
it != ie; ++it) {
info.appendInputSearchPath((*it)->getValue());
}
// Handle -force
// handle /force
if (parsedArgs->getLastArg(OPT_force))
info.setAllowRemainingUndefines(true);
// Handle -nxcompat:no
// handle /nxcompat:no
if (parsedArgs->getLastArg(OPT_no_nxcompat))
info.setNxCompat(false);
// Handle -largeaddressaware
// handle /largeaddressaware
if (parsedArgs->getLastArg(OPT_largeaddressaware))
info.setLargeAddressAware(true);
// Handle -fixed
// handle /fixed
if (parsedArgs->getLastArg(OPT_fixed))
info.setBaseRelocationEnabled(false);
// Handle -tsaware:no
// handle /tsaware:no
if (parsedArgs->getLastArg(OPT_no_tsaware))
info.setTerminalServerAware(false);
// Handle -include
// handle /include
if (llvm::opt::Arg *sym = parsedArgs->getLastArg(OPT_incl))
info.addInitialUndefinedSymbol(sym->getValue());
// Handle -out
// handle /out
if (llvm::opt::Arg *outpath = parsedArgs->getLastArg(OPT_out))
info.setOutputPath(outpath->getValue());
// Handle -defaultlib
// handle /defaultlib
std::vector<StringRef> defaultLibs;
for (llvm::opt::arg_iterator it = parsedArgs->filtered_begin(OPT_defaultlib),
ie = parsedArgs->filtered_end();
@ -384,13 +384,13 @@ bool WinLinkDriver::parse(int argc, const char *argv[],
for (const StringRef path : inputPaths)
info.appendInputFileOrLibrary(path);
// Add the library files specified by -defaultlib option. The files
// Add the library files specified by /defaultlib option. The files
// specified by the option should have lower precedence than the other files
// added above, which is important for link.exe compatibility.
for (const StringRef path : defaultLibs)
info.appendLibraryFile(path);
// If -out option was not specified, the default output file name is
// If /out option was not specified, the default output file name is
// constructed by replacing an extension of the first input file
// with ".exe".
if (info.outputPath().empty() && !inputPaths.empty())

View File

@ -1,9 +1,9 @@
# RUN: yaml2obj %p/Inputs/hello.obj.yaml > %t.obj
#
# RUN: lld -flavor link -out %t1 -subsystem console -force -- %t.obj \
# RUN: lld -flavor link /out:%t1 /subsystem:console /force -- %t.obj \
# RUN: && llvm-objdump -s %t1 | FileCheck %s --check-prefix=BASEREL
#
# RUN: lld -flavor link -out %t1 -subsystem console -force -fixed -- %t.obj \
# RUN: lld -flavor link /out:%t1 /subsystem:console /force /fixed -- %t.obj \
# RUN: && llvm-objdump -s %t1 | FileCheck %s --check-prefix=NOBASEREL
# Because llvm-objdump cannot pretty-print the contents of .reloc section, we

View File

@ -1,9 +1,9 @@
# RUN: yaml2obj %p/Inputs/nop.obj.yaml > %t.obj
#
# RUN: lld -flavor link -out %t1 -- %t.obj \
# RUN: lld -flavor link /out:%t1 -- %t.obj \
# RUN: && llvm-readobj -file-headers %t1 | FileCheck -check-prefix=DEFAULT %s
#
# RUN: lld -flavor link -out %t1 -base 8388608 -- %t.obj \
# RUN: lld -flavor link /out:%t1 /base:8388608 -- %t.obj \
# RUN: && llvm-readobj -file-headers %t1 | FileCheck -check-prefix=BASE %s
DEFAULT: ImageBase: 0x400000

View File

@ -1,6 +1,6 @@
# RUN: yaml2obj %p/Inputs/grouped-sections.obj.yaml > %t.obj
#
# RUN: lld -flavor link -out %t1 -subsystem console -force -- %t.obj \
# RUN: lld -flavor link /out:%t1 /subsystem:console /force -- %t.obj \
# RUN: && llvm-objdump -s %t1 | FileCheck %s
#
# The file "grouped-sections.obj" has three data sections in the following

View File

@ -1,13 +1,13 @@
# RUN: yaml2obj %p/Inputs/hello.obj.yaml > %t.obj
# RUN: lld -flavor link -out %t1 -subsystem console -force -- %t.obj \
# RUN: lld -flavor link /out:%t1 /subsystem:console /force -- %t.obj \
# RUN: && llvm-readobj -file-headers %t1 | FileCheck -check-prefix=FILE %s
FILE: ImageOptionalHeader {
FILE: SizeOfInitializedData: 512
FILE: }
# RUN: lld -flavor link -out %t1 -subsystem console -force -- %t.obj \
# RUN: lld -flavor link /out:%t1 /subsystem:console /force -- %t.obj \
# RUN: && llvm-readobj -sections %t1 | FileCheck -check-prefix=SECTIONS %s
SECTIONS: Format: COFF-i386

View File

@ -3,19 +3,19 @@
#
# RUN: yaml2obj %p/Inputs/vars-main.obj.yaml > %t.obj
#
# RUN: lld -flavor link -out %t1 -subsystem console -- %t.obj \
# RUN: lld -flavor link /out:%t1 /subsystem:console -- %t.obj \
# RUN: %p/Inputs/vars.lib && llvm-objdump -d %t1 | FileCheck %s
#
# RUN: lld -flavor link -out %t1 -subsystem console -libpath %p/Inputs \
# RUN: lld -flavor link /out:%t1 /subsystem:console /libpath:%p/Inputs \
# RUN: -- %t.obj vars.lib && llvm-objdump -d %t1 | FileCheck %s
#
# RUN: lld -flavor link -out %t1 -subsystem console -libpath %p/Inputs \
# RUN: -defaultlib vars.lib -- %t.obj && llvm-objdump -d %t1 | FileCheck %s
# RUN: lld -flavor link /out:%t1 /subsystem:console /libpath:%p/Inputs \
# RUN: /defaultlib:vars.lib -- %t.obj && llvm-objdump -d %t1 | FileCheck %s
#
# RUN: LIB=%p/Inputs lld -flavor link -out %t1 -subsystem console \
# RUN: LIB=%p/Inputs lld -flavor link /out:%t1 /subsystem:console \
# RUN: -- %t.obj vars.lib && llvm-objdump -d %t1 | FileCheck %s
#
# RUN: LINK="-out %t1 -subsystem console -- %t.obj" lld -flavor link \
# RUN: LINK="/out:%t1 /subsystem:console -- %t.obj" lld -flavor link \
# RUN: %p/Inputs/vars.lib && llvm-objdump -d %t1 | FileCheck %s
CHECK: Disassembly of section .text:

View File

@ -1,7 +1,7 @@
# RUN: yaml2obj %p/Inputs/nop.obj.yaml > %t.obj
#
# RUN: not lld -flavor link -out %t1 -subsystem console \
# RUN: -include nosuchsym -- %t.obj 2> %t1
# RUN: not lld -flavor link /out:%t1 /subsystem:console \
# RUN: /include:nosuchsym -- %t.obj 2> %t1
# RUN: FileCheck %s < %t1
CHECK: Undefined Symbol: Linker Internal File : nosuchsym

View File

@ -2,7 +2,7 @@
#
# RUN: yaml2obj %p/Inputs/main.obj.yaml > %t.obj
#
# RUN: lld -flavor link -out %t1 -subsystem console -- %t.obj \
# RUN: lld -flavor link /out:%t1 /subsystem:console -- %t.obj \
# RUN: %p/Inputs/static.lib && llvm-objdump -d %t1 | FileCheck %s
CHECK: Disassembly of section .text:

View File

@ -4,7 +4,7 @@
# RUN: yaml2obj %p/Inputs/static-data1.obj.yaml > %t2.obj
# RUN: yaml2obj %p/Inputs/static-data2.obj.yaml > %t3.obj
#
# RUN: lld -flavor link -out %t1 -subsystem console -- %t1.obj %t2.obj %t3.obj \
# RUN: lld -flavor link /out:%t1 /subsystem:console -- %t1.obj %t2.obj %t3.obj \
# RUN: && llvm-objdump -d %t1 | FileCheck %s
CHECK: Disassembly of section .text:

View File

@ -2,7 +2,7 @@
#
# RUN: llvm-objdump -d %t.obj | FileCheck -check-prefix=BEFORE %s
#
# RUN: lld -flavor link -out %t1 -subsystem console -force -- %t.obj \
# RUN: lld -flavor link /out:%t1 /subsystem:console /force -- %t.obj \
# RUN: && llvm-objdump -d %t1 | FileCheck -check-prefix=AFTER %s
BEFORE: Disassembly of section .text:

View File

@ -4,10 +4,10 @@
#
# RUN: yaml2obj %p/Inputs/nop.obj.yaml > %t.obj
#
# RUN: lld -flavor link -out %t1 -subsystem console,3.11 -- %t.obj \
# RUN: lld -flavor link /out:%t1 /subsystem:console,3.11 -- %t.obj \
# RUN: && llvm-readobj -file-headers %t1 | FileCheck -check-prefix=FILE %s
#
# RUN: lld -flavor link -out %t1 -- %t.obj \
# RUN: lld -flavor link /out:%t1 -- %t.obj \
# RUN: && llvm-readobj -sections %t1 | FileCheck -check-prefix=SECTIONS %s
FILE: Format: COFF-i386

View File

@ -32,8 +32,8 @@ protected:
};
TEST_F(WinLinkParserTest, Basic) {
EXPECT_FALSE(parse("link.exe", "-subsystem", "console", "-out", "a.exe",
"-entry", "_start", "a.obj", "b.obj", "c.obj", nullptr));
EXPECT_FALSE(parse("link.exe", "/subsystem:console", "/out:a.exe",
"-entry:_start", "a.obj", "b.obj", "c.obj", nullptr));
EXPECT_EQ(llvm::COFF::IMAGE_SUBSYSTEM_WINDOWS_CUI, _info.getSubsystem());
EXPECT_EQ("a.exe", _info.outputPath());
EXPECT_EQ("_start", _info.entrySymbolName());
@ -57,9 +57,9 @@ TEST_F(WinLinkParserTest, Basic) {
EXPECT_TRUE(_info.initialUndefinedSymbols().empty());
}
TEST_F(WinLinkParserTest, WindowsStyleOption) {
EXPECT_FALSE(parse("link.exe", "/subsystem:console", "/out:a.exe", "a.obj",
nullptr));
TEST_F(WinLinkParserTest, UnixStyleOption) {
EXPECT_FALSE(parse("link.exe", "-subsystem", "console", "-out", "a.exe",
"a.obj", nullptr));
EXPECT_EQ(llvm::COFF::IMAGE_SUBSYSTEM_WINDOWS_CUI, _info.getSubsystem());
EXPECT_EQ("a.exe", _info.outputPath());
EXPECT_EQ(1, inputFileCount());
@ -82,7 +82,7 @@ TEST_F(WinLinkParserTest, NonStandardFileExtension) {
}
TEST_F(WinLinkParserTest, Libpath) {
EXPECT_FALSE(parse("link.exe", "-libpath", "dir1", "-libpath", "dir2",
EXPECT_FALSE(parse("link.exe", "/libpath:dir1", "/libpath:dir2",
"a.obj", nullptr));
const std::vector<StringRef> &paths = _info.getInputSearchPaths();
EXPECT_EQ(2U, paths.size());
@ -91,90 +91,90 @@ TEST_F(WinLinkParserTest, Libpath) {
}
TEST_F(WinLinkParserTest, MinMajorOSVersion) {
EXPECT_FALSE(parse("link.exe", "-subsystem", "windows,3", "foo.o", nullptr));
EXPECT_FALSE(parse("link.exe", "/subsystem:windows,3", "foo.o", nullptr));
EXPECT_EQ(llvm::COFF::IMAGE_SUBSYSTEM_WINDOWS_GUI, _info.getSubsystem());
EXPECT_EQ(3, _info.getMinOSVersion().majorVersion);
EXPECT_EQ(0, _info.getMinOSVersion().minorVersion);
}
TEST_F(WinLinkParserTest, MinMajorMinorOSVersion) {
EXPECT_FALSE(parse("link.exe", "-subsystem", "windows,3.1", "foo.o", nullptr));
EXPECT_FALSE(parse("link.exe", "/subsystem:windows,3.1", "foo.o", nullptr));
EXPECT_EQ(llvm::COFF::IMAGE_SUBSYSTEM_WINDOWS_GUI, _info.getSubsystem());
EXPECT_EQ(3, _info.getMinOSVersion().majorVersion);
EXPECT_EQ(1, _info.getMinOSVersion().minorVersion);
}
TEST_F(WinLinkParserTest, Base) {
EXPECT_FALSE(parse("link.exe", "-base", "8388608", "a.obj", nullptr));
EXPECT_FALSE(parse("link.exe", "/base:8388608", "a.obj", nullptr));
EXPECT_EQ(0x800000U, _info.getBaseAddress());
}
TEST_F(WinLinkParserTest, StackReserve) {
EXPECT_FALSE(parse("link.exe", "-stack", "8192", "a.obj", nullptr));
EXPECT_FALSE(parse("link.exe", "/stack:8192", "a.obj", nullptr));
EXPECT_EQ(8192U, _info.getStackReserve());
EXPECT_EQ(4096U, _info.getStackCommit());
}
TEST_F(WinLinkParserTest, StackReserveAndCommit) {
EXPECT_FALSE(parse("link.exe", "-stack", "16384,8192", "a.obj", nullptr));
EXPECT_FALSE(parse("link.exe", "/stack:16384,8192", "a.obj", nullptr));
EXPECT_EQ(16384U, _info.getStackReserve());
EXPECT_EQ(8192U, _info.getStackCommit());
}
TEST_F(WinLinkParserTest, HeapReserve) {
EXPECT_FALSE(parse("link.exe", "-heap", "8192", "a.obj", nullptr));
EXPECT_FALSE(parse("link.exe", "/heap:8192", "a.obj", nullptr));
EXPECT_EQ(8192U, _info.getHeapReserve());
EXPECT_EQ(4096U, _info.getHeapCommit());
}
TEST_F(WinLinkParserTest, HeapReserveAndCommit) {
EXPECT_FALSE(parse("link.exe", "-heap", "16384,8192", "a.obj", nullptr));
EXPECT_FALSE(parse("link.exe", "/heap:16384,8192", "a.obj", nullptr));
EXPECT_EQ(16384U, _info.getHeapReserve());
EXPECT_EQ(8192U, _info.getHeapCommit());
}
TEST_F(WinLinkParserTest, Force) {
EXPECT_FALSE(parse("link.exe", "-force", "a.obj", nullptr));
EXPECT_FALSE(parse("link.exe", "/force", "a.obj", nullptr));
EXPECT_TRUE(_info.allowRemainingUndefines());
}
TEST_F(WinLinkParserTest, NoNxCompat) {
EXPECT_FALSE(parse("link.exe", "-nxcompat:no", "a.obj", nullptr));
EXPECT_FALSE(parse("link.exe", "/nxcompat:no", "a.obj", nullptr));
EXPECT_FALSE(_info.isNxCompat());
}
TEST_F(WinLinkParserTest, LargeAddressAware) {
EXPECT_FALSE(parse("link.exe", "-largeaddressaware", "a.obj", nullptr));
EXPECT_FALSE(parse("link.exe", "/largeaddressaware", "a.obj", nullptr));
EXPECT_TRUE(_info.getLargeAddressAware());
}
TEST_F(WinLinkParserTest, NoLargeAddressAware) {
EXPECT_FALSE(parse("link.exe", "-largeaddressaware:no", "a.obj", nullptr));
EXPECT_FALSE(parse("link.exe", "/largeaddressaware:no", "a.obj", nullptr));
EXPECT_FALSE(_info.getLargeAddressAware());
}
TEST_F(WinLinkParserTest, Fixed) {
EXPECT_FALSE(parse("link.exe", "-fixed", "a.out", nullptr));
EXPECT_FALSE(parse("link.exe", "/fixed", "a.out", nullptr));
EXPECT_FALSE(_info.getBaseRelocationEnabled());
}
TEST_F(WinLinkParserTest, NoFixed) {
EXPECT_FALSE(parse("link.exe", "-fixed:no", "a.out", nullptr));
EXPECT_FALSE(parse("link.exe", "/fixed:no", "a.out", nullptr));
EXPECT_TRUE(_info.getBaseRelocationEnabled());
}
TEST_F(WinLinkParserTest, TerminalServerAware) {
EXPECT_FALSE(parse("link.exe", "-tsaware", "a.out", nullptr));
EXPECT_FALSE(parse("link.exe", "/tsaware", "a.out", nullptr));
EXPECT_TRUE(_info.isTerminalServerAware());
}
TEST_F(WinLinkParserTest, NoTerminalServerAware) {
EXPECT_FALSE(parse("link.exe", "-tsaware:no", "a.out", nullptr));
EXPECT_FALSE(parse("link.exe", "/tsaware:no", "a.out", nullptr));
EXPECT_FALSE(_info.isTerminalServerAware());
}
TEST_F(WinLinkParserTest, Include) {
EXPECT_FALSE(parse("link.exe", "-include", "foo", "a.out", nullptr));
EXPECT_FALSE(parse("link.exe", "/include:foo", "a.out", nullptr));
auto symbols = _info.initialUndefinedSymbols();
EXPECT_FALSE(symbols.empty());
EXPECT_EQ("foo", symbols[0]);