refactored MipsRldMapSection into RldMapSection
diff --git a/ELF/Driver.cpp b/ELF/Driver.cpp
index dfffc88..4dd9621 100644
--- a/ELF/Driver.cpp
+++ b/ELF/Driver.cpp
@@ -788,6 +788,8 @@
   Config->IsRela = Config->Is64 || IsX32 || Config->MipsN32Abi;
   Config->Pic = Config->Pie || Config->Shared;
   Config->Wordsize = Config->Is64 ? 8 : 4;
+  //MIPS must unconditionally set ReadOnlyDynamic
+  Config->ReadOnlyDynamic = Machine == EM_MIPS ? true : Config->ReadOnlyDynamic;
 }
 
 // Returns a value of "-format" option.
diff --git a/ELF/SyntheticSections.cpp b/ELF/SyntheticSections.cpp
index d593d46..638f98b 100644
--- a/ELF/SyntheticSections.cpp
+++ b/ELF/SyntheticSections.cpp
@@ -999,14 +999,11 @@
   }
 }
 
-//Almost exactly like MipsRldMapSection except not for MIPS
-//this allows .dynamic to be read-only
-DebugIndirectSection::DebugIndirectSection()
+RldMapSection::RldMapSection()
     : SyntheticSection(SHF_ALLOC | SHF_WRITE, SHT_PROGBITS, Config->Wordsize,
-                       ".debug_indirect") {}
+                       ".rld_map") {}
 
-//This is a straight copy of MipsRldMapSection's writeTo
-void DebugIndirectSection::writeTo(uint8_t *Buf) {
+void RldMapSection::writeTo(uint8_t *Buf) {
   // Apply filler from linker script.
   Optional<uint32_t> Fill = Script->getFiller(this->OutSec);
   if (!Fill || *Fill == 0)
@@ -1029,13 +1026,10 @@
   this->Entsize = ELFT::Is64Bits ? 16 : 8;
 
   // For security the user may want to make .dynamic read only.
-  if (Config->ReadOnlyDynamic)
-    this->Flags = SHF_ALLOC;
-
-  // .dynamic section is not writable on MIPS.
+  // Additionally .dynamic section is not writable on MIPS.
   // See "Special Section" in Chapter 4 in the following document:
   // ftp://www.linux-mips.org/pub/linux/mips/doc/ABI/mipsabi.pdf
-  if (Config->EMachine == EM_MIPS)
+  if (Config->ReadOnlyDynamic)
     this->Flags = SHF_ALLOC;
 
   addEntries();
@@ -1080,7 +1074,7 @@
   if (DtFlags1)
     add({DT_FLAGS_1, DtFlags1});
 
-  //if .dynamic is read only then DT_DEBUG will cause a segfault
+  //If .dynamic is read only then DT_DEBUG will cause a segfault.
   if (!Config->Shared && !Config->Relocatable && !Config->ReadOnlyDynamic)
     add({DT_DEBUG, (uint64_t)0});
 }
@@ -1155,9 +1149,6 @@
     add({DT_VERNEED, In<ELFT>::VerNeed});
     add({DT_VERNEEDNUM, In<ELFT>::VerNeed->getNeedNum()});
   }
-  if(In<ELFT>::DebugIndirect) {
-    add({DT_DEBUG_INDIRECT, In<ELFT>::DebugIndirect});
-  }
 
   if (Config->EMachine == EM_MIPS) {
     add({DT_MIPS_RLD_VERSION, 1});
@@ -1170,9 +1161,9 @@
     else
       add({DT_MIPS_GOTSYM, In<ELFT>::DynSymTab->getNumSymbols()});
     add({DT_PLTGOT, InX::MipsGot});
-    if (InX::MipsRldMap)
-      add({DT_MIPS_RLD_MAP, InX::MipsRldMap});
   }
+  if (InX::RldMap)
+    add({DT_DEBUG_INDIRECT, InX::RldMap});
 
   this->OutSec->Link = this->Link;
 
@@ -2203,21 +2194,6 @@
   return Builder.getSize();
 }
 
-MipsRldMapSection::MipsRldMapSection()
-    : SyntheticSection(SHF_ALLOC | SHF_WRITE, SHT_PROGBITS, Config->Wordsize,
-                       ".rld_map") {}
-
-void MipsRldMapSection::writeTo(uint8_t *Buf) {
-  // Apply filler from linker script.
-  Optional<uint32_t> Fill = Script->getFiller(this->OutSec);
-  if (!Fill || *Fill == 0)
-    return;
-
-  uint64_t Filler = *Fill;
-  Filler = (Filler << 32) | Filler;
-  memcpy(Buf, &Filler, getSize());
-}
-
 ARMExidxSentinelSection::ARMExidxSentinelSection()
     : SyntheticSection(SHF_ALLOC | SHF_LINK_ORDER, SHT_ARM_EXIDX,
                        Config->Wordsize, ".ARM.exidx") {}
@@ -2275,8 +2251,7 @@
 GotPltSection *InX::GotPlt;
 IgotPltSection *InX::IgotPlt;
 MipsGotSection *InX::MipsGot;
-MipsRldMapSection *InX::MipsRldMap;
-DebugIndirectSection *InX::DebugIndirect;
+RldMapSection *InX::RldMap;
 PltSection *InX::Plt;
 PltSection *InX::Iplt;
 StringTableSection *InX::ShStrTab;
diff --git a/ELF/SyntheticSections.h b/ELF/SyntheticSections.h
index 32ca1d2..42facb0 100644
--- a/ELF/SyntheticSections.h
+++ b/ELF/SyntheticSections.h
@@ -336,9 +336,15 @@
   int64_t Addend;
 };
 
-class DebugIndirectSection : public SyntheticSection {
+// This is a section to hold a space within the data segment
+// of the executable file which is pointed to by the
+// DT_MIPS_RLD_MAP/DT_DEBUG_INDIRECT entry. This was a MIPS specific
+// section but it has other uses as well.
+// See "Dynamic section" in Chapter 5 in the following document:
+// ftp://www.linux-mips.org/pub/linux/mips/doc/ABI/mipsabi.pdf
+class RldMapSection : public SyntheticSection {
 public:
-  DebugIndirectSection();
+  RldMapSection();
   size_t getSize() const override { return Config->Wordsize; }
   void writeTo(uint8_t *Buf) override;
 };
@@ -708,17 +714,6 @@
   Elf_Mips_RegInfo Reginfo;
 };
 
-// This is a MIPS specific section to hold a space within the data segment
-// of executable file which is pointed to by the DT_MIPS_RLD_MAP entry.
-// See "Dynamic section" in Chapter 5 in the following document:
-// ftp://www.linux-mips.org/pub/linux/mips/doc/ABI/mipsabi.pdf
-class MipsRldMapSection : public SyntheticSection {
-public:
-  MipsRldMapSection();
-  size_t getSize() const override { return Config->Wordsize; }
-  void writeTo(uint8_t *Buf) override;
-};
-
 class ARMExidxSentinelSection : public SyntheticSection {
 public:
   ARMExidxSentinelSection();
@@ -761,7 +756,6 @@
   static BssSection *BssRelRo;
   static BuildIdSection *BuildId;
   static InputSection *Common;
-  static DebugIndirectSection *DebugIndirect;
   static SyntheticSection *Dynamic;
   static StringTableSection *DynStrTab;
   static InputSection *Interp;
@@ -770,7 +764,7 @@
   static GotPltSection *GotPlt;
   static IgotPltSection *IgotPlt;
   static MipsGotSection *MipsGot;
-  static MipsRldMapSection *MipsRldMap;
+  static RldMapSection *RldMap;
   static PltSection *Plt;
   static PltSection *Iplt;
   static StringTableSection *ShStrTab;
diff --git a/ELF/Writer.cpp b/ELF/Writer.cpp
index c92736c..8ab274e 100644
--- a/ELF/Writer.cpp
+++ b/ELF/Writer.cpp
@@ -351,21 +351,14 @@
   InX::BssRelRo = make<BssSection>(".bss.rel.ro");
   Add(InX::BssRelRo);
 
-  //if ReadOnlyDynamic is set then we're going to need to emit a
-  //DebugIndirectSection for DT_DEBUG_INDIRECT to point to
-  if(Config->ReadOnlyDynamic) {
-    In<ELFT>::DebugIndirect = make<DebugIndirectSection>();
-    Add(In<ELFT>::DebugIndirect);
-  }
-
   // Add MIPS-specific sections.
   bool HasDynSymTab = !Symtab<ELFT>::X->getSharedFiles().empty() ||
                       Config->Pic || Config->ExportDynamic;
   if (Config->EMachine == EM_MIPS) {
-    if (!Config->Shared && HasDynSymTab) {
-      InX::MipsRldMap = make<MipsRldMapSection>();
-      Add(InX::MipsRldMap);
-    }
+    //if (!Config->Shared && HasDynSymTab) {
+      //InX::MipsRldMap = make<MipsRldMapSection>();
+      //Add(InX::MipsRldMap);
+    //}
     if (auto *Sec = MipsAbiFlagsSection<ELFT>::create())
       Add(Sec);
     if (auto *Sec = MipsOptionsSection<ELFT>::create())
@@ -374,6 +367,13 @@
       Add(Sec);
   }
 
+  //If ReadOnlyDynamic is set then we're going to need to emit a
+  //RldMapSection for DT_DEBUG_INDIRECT/DT_MIPS_RLD_MAP to point to.
+  if(!Config->Shared && HasDynSymTab && Config->ReadOnlyDynamic) {
+    In<ELFT>::RldMap = make<RldMapSection>();
+    Add(In<ELFT>::RldMap);
+  }
+
   if (HasDynSymTab) {
     In<ELFT>::DynSymTab = make<SymbolTableSection<ELFT>>(*InX::DynStrTab);
     Add(In<ELFT>::DynSymTab);
diff --git a/test/ELF/Inputs/rodynamic.s b/test/ELF/Inputs/rodynamic.s
new file mode 100644
index 0000000..147c895
--- /dev/null
+++ b/test/ELF/Inputs/rodynamic.s
@@ -0,0 +1,4 @@
+  .text
+  .globl _foo
+_foo:
+  ret
diff --git a/test/ELF/rodynamic.s b/test/ELF/rodynamic.s
index 95771b7..4bf79a4 100644
--- a/test/ELF/rodynamic.s
+++ b/test/ELF/rodynamic.s
@@ -1,9 +1,13 @@
-# RUN: llvm-mc -filetype=obj -triple=x86_64-unknown-linux %s -o %t
-# RUN: ld.lld -shared -rodynamic %t -o %t2
-# RUN: llvm-readobj -sections -dynamic-table %t2 | FileCheck %s
+# RUN: llvm-mc -filetype=obj -triple=x86_64-unknown-linux %s -o %t.o
+# RUN: llvm-mc -filetype=obj -triple=x86_64-unknown-linux %p/Inputs/rodynamic.s -o %td.o
+# RUN: ld.lld -shared %td.o -o %td.so
+# RUN: ld.lld -rodynamic %t.o %td.so -o %t.exe
+# RUN: llvm-readobj -sections -dynamic-table %t.exe | FileCheck %s
 
-.globl _start
-_start:
+  .text
+  .globl __start,_foo
+  .type _foo,@function
+__start:
   ret
 
 # CHECK:        Section {
@@ -12,13 +16,12 @@
 # CHECK-NEXT:     Flags [
 # CHECK-NEXT:       SHF_ALLOC
 # CHECK-NEXT:     ]
-# CHECK:        Section {
-# CHECK:          Name: .debug_indirect
+# CHECK:          Name: .rld_map
 # CHECK-NEXT:     Type: SHT_PROGBITS
 # CHECK-NEXT:     Flags [
 # CHECK-NEXT:       SHF_ALLOC
 # CHECK-NEXT:       SHF_WRITE
 # CHECK-NEXT:     ]
-# CHECK-NEXT:     Address: 0x2000
+# CHECK-NEXT:     Address: [[RLDMAPADDR:0x[0-9a-f]+]]
 # CHECK:        DynamicSection [
-# CHECK:          0x0000000070000016 unknown              0x2000
+# CHECK:          0x0000000070000016 unknown [[RLDMAPADDR]]