[llvm] r370735 - [mips] Switch to the `.text` section after emitting asm file preamble

Simon Atanasyan via llvm-commits llvm-commits at lists.llvm.org
Tue Sep 3 03:24:08 PDT 2019


Author: atanasyan
Date: Tue Sep  3 03:24:07 2019
New Revision: 370735

URL: http://llvm.org/viewvc/llvm-project?rev=370735&view=rev
Log:
[mips] Switch to the `.text` section after emitting asm file preamble

Now the last `.section` directive in the MIPS asm file preamble
is the `.section .mdebug.abi`. If assembler code injected for example
by the LLVM `module asm` or the C ` __asm` directives do not contain
explicit switching to the `.text` section it goes to the `.mdebug.abi`
section. It might be unexpected to the user and in fact for example
breaks building some existing code like FreeBSD libc [1].

The patch forces switching to the `.text` section after emitting MIPS
assembler file preamble.

[1] https://bugs.llvm.org/show_bug.cgi?id=43119

Fix PR43119.

Differential Revision: https://reviews.llvm.org/D67014

Modified:
    llvm/trunk/lib/Target/Mips/MipsAsmPrinter.cpp
    llvm/trunk/test/CodeGen/Mips/start-asm-file.ll

Modified: llvm/trunk/lib/Target/Mips/MipsAsmPrinter.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/Target/Mips/MipsAsmPrinter.cpp?rev=370735&r1=370734&r2=370735&view=diff
==============================================================================
--- llvm/trunk/lib/Target/Mips/MipsAsmPrinter.cpp (original)
+++ llvm/trunk/lib/Target/Mips/MipsAsmPrinter.cpp Tue Sep  3 03:24:07 2019
@@ -56,6 +56,7 @@
 #include "llvm/Support/ErrorHandling.h"
 #include "llvm/Support/TargetRegistry.h"
 #include "llvm/Support/raw_ostream.h"
+#include "llvm/Target/TargetLoweringObjectFile.h"
 #include "llvm/Target/TargetMachine.h"
 #include <cassert>
 #include <cstdint>
@@ -821,6 +822,9 @@ void MipsAsmPrinter::EmitStartOfAsmFile(
   // option has changed the default (i.e. FPXX) and omit it otherwise.
   if (ABI.IsO32() && (!STI.useOddSPReg() || STI.isABI_FPXX()))
     TS.emitDirectiveModuleOddSPReg();
+
+  // Switch to the .text section.
+  OutStreamer->SwitchSection(getObjFileLowering().getTextSection());
 }
 
 void MipsAsmPrinter::emitInlineAsmStart() const {

Modified: llvm/trunk/test/CodeGen/Mips/start-asm-file.ll
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/test/CodeGen/Mips/start-asm-file.ll?rev=370735&r1=370734&r2=370735&view=diff
==============================================================================
--- llvm/trunk/test/CodeGen/Mips/start-asm-file.ll (original)
+++ llvm/trunk/test/CodeGen/Mips/start-asm-file.ll Tue Sep  3 03:24:07 2019
@@ -71,4 +71,5 @@
 
 ; CHECK: .section .mdebug.abi[[ABI]]
 ; CHECK: .nan [[NAN]]
+; CHECK: .text
 ; CHECK: .file




More information about the llvm-commits mailing list