Set output section's st_entsize based on input section's st_entsize.

Each input section knows its sh_entsize value, so we can set output
section's sh_entsize based on input sections values.

llvm-svn: 296577
diff --git a/lld/ELF/OutputSections.cpp b/lld/ELF/OutputSections.cpp
index 39b2fe0..af96052 100644
--- a/lld/ELF/OutputSections.cpp
+++ b/lld/ELF/OutputSections.cpp
@@ -66,42 +66,8 @@
   Shdr->sh_name = ShName;
 }
 
-template <class ELFT> static uint64_t getEntsize(uint32_t Type) {
-  switch (Type) {
-  case SHT_RELA:
-    return sizeof(typename ELFT::Rela);
-  case SHT_REL:
-    return sizeof(typename ELFT::Rel);
-  case SHT_MIPS_REGINFO:
-    return sizeof(Elf_Mips_RegInfo<ELFT>);
-  case SHT_MIPS_OPTIONS:
-    return sizeof(Elf_Mips_Options<ELFT>) + sizeof(Elf_Mips_RegInfo<ELFT>);
-  case SHT_MIPS_ABIFLAGS:
-    return sizeof(Elf_Mips_ABIFlags<ELFT>);
-  default:
-    return 0;
-  }
-}
-
 OutputSection::OutputSection(StringRef Name, uint32_t Type, uint64_t Flags)
-    : Name(Name), Addralign(1), Flags(Flags), Type(Type) {
-  switch (Config->EKind) {
-  case ELFNoneKind:
-    llvm_unreachable("unknown kind");
-  case ELF32LEKind:
-    this->Entsize = getEntsize<ELF32LE>(Type);
-    break;
-  case ELF32BEKind:
-    this->Entsize = getEntsize<ELF32BE>(Type);
-    break;
-  case ELF64LEKind:
-    this->Entsize = getEntsize<ELF64LE>(Type);
-    break;
-  case ELF64BEKind:
-    this->Entsize = getEntsize<ELF64BE>(Type);
-    break;
-  }
-}
+    : Name(Name), Addralign(1), Flags(Flags), Type(Type) {}
 
 template <typename ELFT>
 static bool compareByFilePosition(InputSection *A, InputSection *B) {
@@ -153,10 +119,15 @@
   Sections.push_back(S);
   S->OutSec = this;
   this->updateAlignment(S->Alignment);
-  // Keep sh_entsize value of the input section to be able to perform merging
-  // later during a final linking using the generated relocatable object.
-  if (Config->Relocatable && (S->Flags & SHF_MERGE))
-    this->Entsize = S->Entsize;
+
+  // If this section contains a table of fixed-size entries, sh_entsize
+  // holds the element size. Consequently, if this contains two or more
+  // input sections, all of them must have the same sh_entsize. However,
+  // you can put different types of input sections into one output
+  // sectin by using linker scripts. I don't know what to do here.
+  // Probably we sholuld handle that as an error. But for now we just
+  // pick the largest sh_entsize.
+  this->Entsize = std::max(this->Entsize, S->Entsize);
 }
 
 // This function is called after we sort input sections