}
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;
// 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,
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
--- /dev/null
+# 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