From c5dd543d8b17bb9c985561a6d7732e0e71700f71 Mon Sep 17 00:00:00 2001 From: Rui Ueyama Date: Wed, 26 Oct 2016 04:34:16 +0000 Subject: [PATCH] Split LinkerDriver::link. NFC. llvm-svn: 285169 --- lld/ELF/Driver.cpp | 32 +++++++++++++++++++++----------- 1 file changed, 21 insertions(+), 11 deletions(-) diff --git a/lld/ELF/Driver.cpp b/lld/ELF/Driver.cpp index f3dcf1f..5cb0746 100644 --- a/lld/ELF/Driver.cpp +++ b/lld/ELF/Driver.cpp @@ -652,6 +652,26 @@ void LinkerDriver::inferMachineType() { error("target emulation unknown: -m or at least one .o file required"); } +// Parses -image-base option. +static uint64_t getImageBase(opt::InputArgList &Args) { + // Use default if no -image-base option is given. + // Because we are using "Target" here, this function + // has to be called after the variable is initialized. + auto *Arg = Args.getLastArg(OPT_image_base); + if (!Arg) + return Config->Pic ? 0 : Target->DefaultImageBase; + + StringRef S = Arg->getValue(); + uint64_t V; + if (S.getAsInteger(0, V)) { + error("-image-base: number expected, but got " + S); + return 0; + } + if ((V % Target->MaxPageSize) != 0) + warn("-image-base: address isn't multiple of page size: " + S); + return V; +} + // Do actual linking. Note that when this function is called, // all linker scripts have already been parsed. template void LinkerDriver::link(opt::InputArgList &Args) { @@ -666,6 +686,7 @@ template void LinkerDriver::link(opt::InputArgList &Args) { Config->Rela = ELFT::Is64Bits || Config->EMachine == EM_X86_64; Config->Mips64EL = (Config->EMachine == EM_MIPS && Config->EKind == ELF64LEKind); + Config->ImageBase = getImageBase(Args); // Default output filename is "a.out" by the Unix tradition. if (Config->OutputFile.empty()) @@ -675,17 +696,6 @@ template void LinkerDriver::link(opt::InputArgList &Args) { for (auto *Arg : Args.filtered(OPT_trace_symbol)) Symtab.trace(Arg->getValue()); - // Initialize Config->ImageBase. - if (auto *Arg = Args.getLastArg(OPT_image_base)) { - StringRef S = Arg->getValue(); - if (S.getAsInteger(0, Config->ImageBase)) - error(Arg->getSpelling() + ": number expected, but got " + S); - else if ((Config->ImageBase % Target->MaxPageSize) != 0) - warn(Arg->getSpelling() + ": address isn't multiple of page size"); - } else { - Config->ImageBase = Config->Pic ? 0 : Target->DefaultImageBase; - } - // Initialize Config->MaxPageSize. The default value is defined by // the target, but it can be overriden using the option. Config->MaxPageSize = -- 2.7.4