[lld] r256984 - Simplify MipsReginfoInputSection.

Rui Ueyama via llvm-commits llvm-commits at lists.llvm.org
Wed Jan 6 14:42:44 PST 2016


Author: ruiu
Date: Wed Jan  6 16:42:43 2016
New Revision: 256984

URL: http://llvm.org/viewvc/llvm-project?rev=256984&view=rev
Log:
Simplify MipsReginfoInputSection.

MipsReginfoInputSection is basically just a container of Elf_Mips_Reginfo
struct. This patch makes that struct directly accessible from others.

Modified:
    lld/trunk/ELF/InputFiles.cpp
    lld/trunk/ELF/InputSection.cpp
    lld/trunk/ELF/InputSection.h
    lld/trunk/ELF/OutputSections.cpp
    lld/trunk/ELF/OutputSections.h

Modified: lld/trunk/ELF/InputFiles.cpp
URL: http://llvm.org/viewvc/llvm-project/lld/trunk/ELF/InputFiles.cpp?rev=256984&r1=256983&r2=256984&view=diff
==============================================================================
--- lld/trunk/ELF/InputFiles.cpp (original)
+++ lld/trunk/ELF/InputFiles.cpp Wed Jan  6 16:42:43 2016
@@ -92,7 +92,9 @@ typename ObjectFile<ELFT>::Elf_Sym_Range
 }
 
 template <class ELFT> uint32_t ObjectFile<ELFT>::getMipsGp0() const {
-  return MipsReginfo ? MipsReginfo->getGp0() : 0;
+  if (MipsReginfo)
+    return MipsReginfo->Reginfo->ri_gp_value;
+  return 0;
 }
 
 template <class ELFT>

Modified: lld/trunk/ELF/InputSection.cpp
URL: http://llvm.org/viewvc/llvm-project/lld/trunk/ELF/InputSection.cpp?rev=256984&r1=256983&r2=256984&view=diff
==============================================================================
--- lld/trunk/ELF/InputSection.cpp (original)
+++ lld/trunk/ELF/InputSection.cpp Wed Jan  6 16:42:43 2016
@@ -348,22 +348,13 @@ MergeInputSection<ELFT>::getOffset(uintX
 
 template <class ELFT>
 MipsReginfoInputSection<ELFT>::MipsReginfoInputSection(ObjectFile<ELFT> *F,
-                                                       const Elf_Shdr *Header)
-    : InputSectionBase<ELFT>(F, Header, InputSectionBase<ELFT>::MipsReginfo) {}
-
-template <class ELFT>
-uint32_t MipsReginfoInputSection<ELFT>::getGeneralMask() const {
-  ArrayRef<uint8_t> D = this->getSectionData();
-  if (D.size() != sizeof(Elf_Mips_RegInfo))
-    error("Invalid size of .reginfo section");
-  return reinterpret_cast<const Elf_Mips_RegInfo *>(D.data())->ri_gprmask;
-}
-
-template <class ELFT> uint32_t MipsReginfoInputSection<ELFT>::getGp0() const {
+                                                       const Elf_Shdr *Hdr)
+    : InputSectionBase<ELFT>(F, Hdr, InputSectionBase<ELFT>::MipsReginfo) {
+  // Initialize this->Reginfo.
   ArrayRef<uint8_t> D = this->getSectionData();
-  if (D.size() != sizeof(Elf_Mips_RegInfo))
+  if (D.size() != sizeof(Elf_Mips_RegInfo<ELFT>))
     error("Invalid size of .reginfo section");
-  return reinterpret_cast<const Elf_Mips_RegInfo *>(D.data())->ri_gp_value;
+  Reginfo = reinterpret_cast<const Elf_Mips_RegInfo<ELFT> *>(D.data());
 }
 
 template <class ELFT>

Modified: lld/trunk/ELF/InputSection.h
URL: http://llvm.org/viewvc/llvm-project/lld/trunk/ELF/InputSection.h?rev=256984&r1=256983&r2=256984&view=diff
==============================================================================
--- lld/trunk/ELF/InputSection.h (original)
+++ lld/trunk/ELF/InputSection.h Wed Jan  6 16:42:43 2016
@@ -177,16 +177,13 @@ public:
 // ftp://www.linux-mips.org/pub/linux/mips/doc/ABI/mipsabi.pdf
 template <class ELFT>
 class MipsReginfoInputSection : public InputSectionBase<ELFT> {
-  typedef llvm::object::Elf_Mips_RegInfo<ELFT> Elf_Mips_RegInfo;
   typedef typename llvm::object::ELFFile<ELFT>::Elf_Shdr Elf_Shdr;
 
 public:
-  MipsReginfoInputSection(ObjectFile<ELFT> *F, const Elf_Shdr *Header);
-
-  uint32_t getGeneralMask() const;
-  uint32_t getGp0() const;
-
+  MipsReginfoInputSection(ObjectFile<ELFT> *F, const Elf_Shdr *Hdr);
   static bool classof(const InputSectionBase<ELFT> *S);
+
+  const llvm::object::Elf_Mips_RegInfo<ELFT> *Reginfo;
 };
 
 } // namespace elf2

Modified: lld/trunk/ELF/OutputSections.cpp
URL: http://llvm.org/viewvc/llvm-project/lld/trunk/ELF/OutputSections.cpp?rev=256984&r1=256983&r2=256984&view=diff
==============================================================================
--- lld/trunk/ELF/OutputSections.cpp (original)
+++ lld/trunk/ELF/OutputSections.cpp Wed Jan  6 16:42:43 2016
@@ -1412,13 +1412,14 @@ template <class ELFT>
 void MipsReginfoOutputSection<ELFT>::writeTo(uint8_t *Buf) {
   auto *R = reinterpret_cast<Elf_Mips_RegInfo *>(Buf);
   R->ri_gp_value = getMipsGpAddr<ELFT>();
-  R->ri_gprmask = GeneralMask;
+  R->ri_gprmask = GprMask;
 }
 
 template <class ELFT>
 void MipsReginfoOutputSection<ELFT>::addSection(InputSectionBase<ELFT> *C) {
+  // Copy input object file's .reginfo gprmask to output.
   auto *S = cast<MipsReginfoInputSection<ELFT>>(C);
-  GeneralMask |= S->getGeneralMask();
+  GprMask |= S->Reginfo->ri_gprmask;
 }
 
 namespace lld {

Modified: lld/trunk/ELF/OutputSections.h
URL: http://llvm.org/viewvc/llvm-project/lld/trunk/ELF/OutputSections.h?rev=256984&r1=256983&r2=256984&view=diff
==============================================================================
--- lld/trunk/ELF/OutputSections.h (original)
+++ lld/trunk/ELF/OutputSections.h Wed Jan  6 16:42:43 2016
@@ -429,7 +429,7 @@ public:
   void addSection(InputSectionBase<ELFT> *S) override;
 
 private:
-  uint32_t GeneralMask = 0;
+  uint32_t GprMask = 0;
 };
 
 // All output sections that are hadnled by the linker specially are




More information about the llvm-commits mailing list