COFF: Add /base option.

llvm-svn: 238567
This commit is contained in:
Rui Ueyama 2015-05-29 16:18:15 +00:00
parent 92907c2ab9
commit 804a8b6361
4 changed files with 33 additions and 0 deletions

View File

@ -126,6 +126,14 @@ bool link(int Argc, const char *Argv[]) {
}
Config->MachineType = MTOrErr.get();
// Handle /base
if (auto *Arg = Args->getLastArg(OPT_base)) {
if (auto EC = parseNumbers(Arg->getValue(), &Config->ImageBase)) {
llvm::errs() << 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;

View File

@ -43,6 +43,10 @@ std::string findFile(StringRef Filename);
// For /machine option.
ErrorOr<MachineTypes> getMachineType(llvm::opt::InputArgList *Args);
// Parses a string in the form of "<integer>[,<integer>]".
std::error_code parseNumbers(StringRef Arg, uint64_t *Addr,
uint64_t *Size = nullptr);
// Create enum with OPT_xxx values for each option in Options.td
enum {
OPT_INVALID = 0,

View File

@ -128,6 +128,17 @@ ErrorOr<MachineTypes> getMachineType(llvm::opt::InputArgList *Args) {
return IMAGE_FILE_MACHINE_UNKNOWN;
}
// Parses a string in the form of "<integer>[,<integer>]".
std::error_code parseNumbers(StringRef Arg, uint64_t *Addr, uint64_t *Size) {
StringRef S1, S2;
std::tie(S1, S2) = Arg.split(',');
if (S1.getAsInteger(0, *Addr))
return make_dynamic_error_code(Twine("invalid number: ") + S1);
if (Size && !S2.empty() && S2.getAsInteger(0, *Size))
return make_dynamic_error_code(Twine("invalid number: ") + S2);
return std::error_code();
}
// Create OptTable
// Create prefix string literals used in Options.td

10
lld/test/COFF/base.test Normal file
View File

@ -0,0 +1,10 @@
# 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: ImageBase: 0x140000000
# RUN: lld -flavor link2 /entry:main /out:%t.exe /base:0x280000000 \
# RUN: %p/Inputs/ret42.obj
# RUN: llvm-readobj -file-headers %t.exe | FileCheck -check-prefix=BASE %s
BASE: ImageBase: 0x280000000