forked from OSchip/llvm-project
parent
c377e9aefe
commit
b9dcdb5fc9
|
@ -30,6 +30,8 @@ public:
|
|||
uint64_t StackCommit = 4096;
|
||||
uint64_t HeapReserve = 1024 * 1024;
|
||||
uint64_t HeapCommit = 4096;
|
||||
uint32_t MajorImageVersion = 0;
|
||||
uint32_t MinorImageVersion = 0;
|
||||
|
||||
bool insertFile(llvm::StringRef Path) {
|
||||
return VisitedFiles.insert(Path.lower()).second;
|
||||
|
|
|
@ -152,6 +152,15 @@ bool link(int Argc, const char *Argv[]) {
|
|||
}
|
||||
}
|
||||
|
||||
// Handle /version
|
||||
if (auto *Arg = Args->getLastArg(OPT_version)) {
|
||||
if (auto EC = parseVersion(Arg->getValue(), &Config->MajorImageVersion,
|
||||
&Config->MinorImageVersion)) {
|
||||
llvm::errs() << "/version: " << EC.message() << "\n";
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
// Parse all input files and put all symbols to the symbol table.
|
||||
// The symbol table will take care of name resolution.
|
||||
SymbolTable Symtab;
|
||||
|
|
|
@ -47,6 +47,10 @@ ErrorOr<MachineTypes> getMachineType(llvm::opt::InputArgList *Args);
|
|||
std::error_code parseNumbers(StringRef Arg, uint64_t *Addr,
|
||||
uint64_t *Size = nullptr);
|
||||
|
||||
// Parses a string in the form of "<integer>[.<integer>]".
|
||||
// Minor's default value is 0.
|
||||
std::error_code parseVersion(StringRef Arg, uint32_t *Major, uint32_t *Minor);
|
||||
|
||||
// Create enum with OPT_xxx values for each option in Options.td
|
||||
enum {
|
||||
OPT_INVALID = 0,
|
||||
|
|
|
@ -139,6 +139,19 @@ std::error_code parseNumbers(StringRef Arg, uint64_t *Addr, uint64_t *Size) {
|
|||
return std::error_code();
|
||||
}
|
||||
|
||||
// Parses a string in the form of "<integer>[.<integer>]".
|
||||
// If second number is not present, Minor is set to 0.
|
||||
std::error_code parseVersion(StringRef Arg, uint32_t *Major, uint32_t *Minor) {
|
||||
StringRef S1, S2;
|
||||
std::tie(S1, S2) = Arg.split('.');
|
||||
if (S1.getAsInteger(0, *Major))
|
||||
return make_dynamic_error_code(Twine("invalid number: ") + S1);
|
||||
*Minor = 0;
|
||||
if (!S2.empty() && S2.getAsInteger(0, *Minor))
|
||||
return make_dynamic_error_code(Twine("invalid number: ") + S2);
|
||||
return std::error_code();
|
||||
}
|
||||
|
||||
// Create OptTable
|
||||
|
||||
// Create prefix string literals used in Options.td
|
||||
|
|
|
@ -259,6 +259,8 @@ void Writer::writeHeader() {
|
|||
PE->ImageBase = Config->ImageBase;
|
||||
PE->SectionAlignment = SectionAlignment;
|
||||
PE->FileAlignment = FileAlignment;
|
||||
PE->MajorImageVersion = Config->MajorImageVersion;
|
||||
PE->MinorImageVersion = Config->MinorImageVersion;
|
||||
PE->MajorOperatingSystemVersion = 6;
|
||||
PE->MajorSubsystemVersion = 6;
|
||||
PE->Subsystem = IMAGE_SUBSYSTEM_WINDOWS_CUI;
|
||||
|
|
|
@ -0,0 +1,19 @@
|
|||
# RUN: lld -flavor link2 /entry:main /out:%t.exe %p/Inputs/ret42.obj
|
||||
# RUN: llvm-readobj -file-headers %t.exe | FileCheck -check-prefix=DEFAULT %s
|
||||
|
||||
DEFAULT: MajorImageVersion: 0
|
||||
DEFAULT: MinorImageVersion: 0
|
||||
|
||||
# RUN: lld -flavor link2 /entry:main /out:%t.exe /version:11 \
|
||||
# RUN: %p/Inputs/ret42.obj
|
||||
# RUN: llvm-readobj -file-headers %t.exe | FileCheck -check-prefix=CHECK1 %s
|
||||
|
||||
CHECK1: MajorImageVersion: 11
|
||||
CHECK1: MinorImageVersion: 0
|
||||
|
||||
# RUN: lld -flavor link2 /entry:main /out:%t.exe /version:11.22 \
|
||||
# RUN: %p/Inputs/ret42.obj
|
||||
# RUN: llvm-readobj -file-headers %t.exe | FileCheck -check-prefix=CHECK2 %s
|
||||
|
||||
CHECK2: MajorImageVersion: 11
|
||||
CHECK2: MinorImageVersion: 22
|
Loading…
Reference in New Issue