ELF: Redefine canBeDefined as a member function of SymbolBody.

We want to make SymbolBody the central place to query symbol information.
This patch also renames canBePreempted to isPreemptible because I feel that
the latter is slightly better (the former is three words and the latter
is two words.)

llvm-svn: 263386
diff --git a/lld/ELF/Symbols.cpp b/lld/ELF/Symbols.cpp
index 8a7a18c..95a5995 100644
--- a/lld/ELF/Symbols.cpp
+++ b/lld/ELF/Symbols.cpp
@@ -81,6 +81,38 @@
   llvm_unreachable("invalid symbol kind");
 }
 
+// Returns true if a symbol can be replaced at load-time by a symbol
+// with the same name defined in other ELF executable or DSO.
+bool SymbolBody::isPreemptible() const {
+  if (isLocal())
+    return false;
+
+  if (isShared())
+    return true;
+
+  if (isUndefined()) {
+    if (!isWeak())
+      return true;
+
+    // Ideally the static linker should see a definition for every symbol, but
+    // shared object are normally allowed to have undefined references that the
+    // static linker never sees a definition for.
+    if (Config->Shared)
+      return true;
+
+    // Otherwise, just resolve to 0.
+    return false;
+  }
+
+  if (!Config->Shared)
+    return false;
+  if (getVisibility() != STV_DEFAULT)
+    return false;
+  if (Config->Bsymbolic || (Config->BsymbolicFunctions && IsFunc))
+    return false;
+  return true;
+}
+
 template <class ELFT> bool SymbolBody::isGnuIfunc() const {
   if (auto *D = dyn_cast<DefinedElf<ELFT>>(this))
     return D->Sym.getType() == STT_GNU_IFUNC;