[Mips] Write .reginfo section into the separate PT_MIPS_REGINFO segment
authorSimon Atanasyan <simon@atanasyan.com>
Tue, 21 Apr 2015 17:02:35 +0000 (17:02 +0000)
committerSimon Atanasyan <simon@atanasyan.com>
Tue, 21 Apr 2015 17:02:35 +0000 (17:02 +0000)
llvm-svn: 235391

lld/lib/ReaderWriter/ELF/Mips/MipsSectionChunks.h
lld/lib/ReaderWriter/ELF/Mips/MipsTargetLayout.h
lld/lib/ReaderWriter/ELF/SectionChunks.h
lld/test/elf/Mips/reginfo-02.test

index cb5d612..9d30407 100644 (file)
@@ -26,7 +26,7 @@ public:
                      const MipsReginfo &reginfo)
       : Section<ELFT>(ctx, ".reginfo", "MipsReginfo"),
         _targetLayout(targetLayout) {
-    this->setOrder(MipsTargetLayout<ELFT>::ORDER_RO_NOTE);
+    this->setOrder(MipsTargetLayout<ELFT>::ORDER_MIPS_REGINFO);
     this->_entSize = sizeof(Elf_RegInfo);
     this->_fsize = sizeof(Elf_RegInfo);
     this->_msize = sizeof(Elf_RegInfo);
@@ -42,6 +42,10 @@ public:
     _reginfo.ri_cprmask[3] = reginfo._cpRegMask[3];
   }
 
+  StringRef segmentKindToStr() const override { return "REGINFO"; }
+
+  bool hasOutputSegment() const override { return true; }
+
   void write(ELFWriter *writer, TargetLayout<ELFT> &layout,
              llvm::FileOutputBuffer &buffer) override {
     uint8_t *dest = buffer.getBufferStart() + this->fileOffset();
index 5d28348..3fc8ba7 100644 (file)
@@ -20,6 +20,10 @@ class MipsLinkingContext;
 /// \brief TargetLayout for Mips
 template <class ELFT> class MipsTargetLayout final : public TargetLayout<ELFT> {
 public:
+  enum MipsSectionOrder {
+    ORDER_MIPS_REGINFO = TargetLayout<ELFT>::ORDER_RO_NOTE + 1
+  };
+
   MipsTargetLayout(MipsLinkingContext &ctx)
       : TargetLayout<ELFT>(ctx),
         _gotSection(new (this->_allocator) MipsGOTSection<ELFT>(ctx)),
@@ -39,6 +43,16 @@ public:
     return TargetLayout<ELFT>::createSection(name, type, permissions, order);
   }
 
+  typename TargetLayout<ELFT>::SegmentType
+  getSegmentType(Section<ELFT> *section) const override {
+    switch (section->order()) {
+    case ORDER_MIPS_REGINFO:
+      return llvm::ELF::PT_MIPS_REGINFO;
+    default:
+      return TargetLayout<ELFT>::getSegmentType(section);
+    }
+  }
+
   /// \brief GP offset relative to .got section.
   uint64_t getGPOffset() const { return 0x7FF0; }
 
index 7b78e26..2c8fe28 100644 (file)
@@ -73,7 +73,7 @@ public:
 
   /// \brief convert the segment type to a String for diagnostics and printing
   /// purposes
-  StringRef segmentKindToStr() const;
+  virtual StringRef segmentKindToStr() const;
 
   /// \brief Records the segmentType, that this section belongs to
   void
index 2b7c207..65651ce 100644 (file)
@@ -3,7 +3,7 @@
 # RUN: yaml2obj -format=elf -docnum 1 %s > %t1.o
 # RUN: yaml2obj -format=elf -docnum 2 %s > %t2.o
 # RUN: lld -flavor gnu -target mipsel -shared -o %t.so %t1.o %t2.o
-# RUN: llvm-readobj -s %t.so | FileCheck -check-prefix=SEC %s
+# RUN: llvm-readobj -program-headers -s %t.so | FileCheck -check-prefix=SEC %s
 # RUN: llvm-objdump -s -t %t.so | FileCheck -check-prefix=RAW %s
 
 # SEC:      Index: 1
 # SEC-NEXT: AddressAlignment: 4
 # SEC-NEXT: EntrySize: 24
 
+# SEC:      ProgramHeader {
+# SEC:        Type: PT_MIPS_REGINFO (0x70000000)
+# SEC-NEXT:   Offset: 0x{{[0-9A-F]+}}
+# SEC-NEXT:   VirtualAddress: 0x{{[0-9A-F]+}}
+# SEC-NEXT:   PhysicalAddress: 0x{{[0-9A-F]+}}
+# SEC-NEXT:   FileSize: 24
+# SEC-NEXT:   MemSize: 24
+# SEC-NEXT:   Flags [ (0x4)
+# SEC-NEXT:     PF_R (0x4)
+# SEC-NEXT:   ]
+# SEC-NEXT:   Alignment: 4
+# SEC-NEXT: }
+
 # RAW:      Contents of section .reginfo:
 # RAW-NEXT:  {{[0-9a-f]+}} f0000001 e0000002 d0000003 c0000004
 # RAW-NEXT:  {{[0-9a-f]+}} b0000005 f08f0000