[ELF] Allows setting section for common symbols in linker script

llvm-svn: 277023
diff --git a/lld/ELF/Symbols.cpp b/lld/ELF/Symbols.cpp
index 0a4805c..6d7e797 100644
--- a/lld/ELF/Symbols.cpp
+++ b/lld/ELF/Symbols.cpp
@@ -63,8 +63,10 @@
       return VA - Out<ELFT>::TlsPhdr->p_vaddr;
     return VA;
   }
-  case SymbolBody::DefinedCommonKind:
-    return Out<ELFT>::Bss->getVA() + cast<DefinedCommon>(Body).OffsetInBss;
+  case SymbolBody::DefinedCommonKind: {
+    auto &D = cast<DefinedCommon<ELFT>>(Body);
+    return D.Section->OutSec->getVA() + D.Section->OutSecOff + D.Offset;
+  }
   case SymbolBody::SharedKind: {
     auto &SS = cast<SharedSymbol<ELFT>>(Body);
     if (!SS.NeedsCopyOrPltAddr)
@@ -175,7 +177,7 @@
 }
 
 template <class ELFT> typename ELFT::uint SymbolBody::getSize() const {
-  if (const auto *C = dyn_cast<DefinedCommon>(this))
+  if (const auto *C = dyn_cast<DefinedCommon<ELFT>>(this))
     return C->Size;
   if (const auto *DR = dyn_cast<DefinedRegular<ELFT>>(this))
     return DR->Size;
@@ -218,8 +220,10 @@
     : Defined(SymbolBody::DefinedSyntheticKind, N, STV_HIDDEN, 0 /* Type */),
       Value(Value), Section(Section) {}
 
-DefinedCommon::DefinedCommon(StringRef N, uint64_t Size, uint64_t Alignment,
-                             uint8_t StOther, uint8_t Type, InputFile *File)
+template <class ELFT>
+DefinedCommon<ELFT>::DefinedCommon(StringRef N, uint64_t Size,
+                                   uint64_t Alignment, uint8_t StOther,
+                                   uint8_t Type, InputFile *File)
     : Defined(SymbolBody::DefinedCommonKind, N, StOther, Type),
       Alignment(Alignment), Size(Size) {
   this->File = File;
@@ -329,3 +333,8 @@
 template class elf::DefinedSynthetic<ELF32BE>;
 template class elf::DefinedSynthetic<ELF64LE>;
 template class elf::DefinedSynthetic<ELF64BE>;
+
+template class elf::DefinedCommon<ELF32LE>;
+template class elf::DefinedCommon<ELF32BE>;
+template class elf::DefinedCommon<ELF64LE>;
+template class elf::DefinedCommon<ELF64BE>;