aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorRui Ueyama <ruiu@google.com>2016-01-07 17:33:25 +0000
committerRui Ueyama <ruiu@google.com>2016-01-07 17:33:25 +0000
commitc927cdd14f5b662c28994d8f32352b739835d4b4 (patch)
treed81c79f8179f2b427777676bb9c4634f91b92a60
parent0484dcb10730adc5c8bf9993bbde26b1775a0ab9 (diff)
ELF: Move error checking code of the driver into one place. NFC.
git-svn-id: https://llvm.org/svn/llvm-project/lld/trunk@257076 91177308-0d34-0410-b5e6-96231b3b80d8
-rw-r--r--ELF/Driver.cpp31
1 files changed, 19 insertions, 12 deletions
diff --git a/ELF/Driver.cpp b/ELF/Driver.cpp
index 12ad8ecac..bf902adab 100644
--- a/ELF/Driver.cpp
+++ b/ELF/Driver.cpp
@@ -107,6 +107,24 @@ void LinkerDriver::addFile(StringRef Path) {
}
}
+// Some command line options or some combinations of them are not allowed.
+// This function checks for such errors.
+static void checkOptions(opt::InputArgList &Args) {
+ // Traditional linkers can generate re-linkable object files instead
+ // of executables or DSOs. We don't support that since the feature
+ // does not seem to provide more value than the static archiver.
+ if (Args.hasArg(OPT_relocatable))
+ error("-r option is not supported. Use 'ar' command instead.");
+
+ // The MIPS ABI as of 2016 does not support the GNU-style symbol lookup
+ // table which is a relatively new feature.
+ if (Config->EMachine == EM_MIPS && Config->GnuHash)
+ error("The .gnu.hash section is not compatible with the MIPS target.");
+
+ if (Config->EMachine == EM_AMDGPU && !Config->Entry.empty())
+ error("-e option is not valid for AMDGPU.");
+}
+
static StringRef
getString(opt::InputArgList &Args, unsigned Key, StringRef Default = "") {
if (auto *Arg = Args.getLastArg(Key))
@@ -126,12 +144,7 @@ void LinkerDriver::main(ArrayRef<const char *> ArgsArr) {
opt::InputArgList Args = parseArgs(&Alloc, ArgsArr);
createFiles(Args);
-
- // Traditional linkers can generate re-linkable object files instead
- // of executables or DSOs. We don't support that since the feature
- // does not seem to provide more value than the static archiver.
- if (Args.hasArg(OPT_relocatable))
- error("-r option is not supported. Use 'ar' command instead.");
+ checkOptions(Args);
switch (Config->EKind) {
case ELF32LEKind:
@@ -250,12 +263,6 @@ void LinkerDriver::createFiles(opt::InputArgList &Args) {
if (Files.empty())
error("no input files.");
-
- if (Config->GnuHash && Config->EMachine == EM_MIPS)
- error("The .gnu.hash section is not compatible with the MIPS target.");
-
- if (!Config->Entry.empty() && Config->EMachine == EM_AMDGPU)
- error("-e option is not valid for AMDGPU.");
}
template <class ELFT> void LinkerDriver::link(opt::InputArgList &Args) {