$OpenBSD: patch-lib_Target_Mips_MipsAsmPrinter_cpp,v 1.1 2019/07/09 13:21:37 jca Exp $

- Restore previous section after setting the MIPS ABI marker. This keeps
  the .text section in use after the file header, improving compatibility
  with gcc. Without this change, module-level inline assembly blocks could
  end up into wrong section.

Index: lib/Target/Mips/MipsAsmPrinter.cpp
--- lib/Target/Mips/MipsAsmPrinter.cpp.orig
+++ lib/Target/Mips/MipsAsmPrinter.cpp
@@ -795,10 +795,12 @@ void MipsAsmPrinter::EmitStartOfAsmFile(Module &M) {
       TS.emitDirectiveOptionPic0();
   }
 
+  MCSection *CS = OutStreamer->getCurrentSectionOnly();
   // Tell the assembler which ABI we are using
   std::string SectionName = std::string(".mdebug.") + getCurrentABIString();
   OutStreamer->SwitchSection(
       OutContext.getELFSection(SectionName, ELF::SHT_PROGBITS, 0));
+  OutStreamer->SwitchSection(CS);
 
   // NaN: At the moment we only support:
   // 1. .nan legacy (default)
