]> granicus.if.org Git - llvm/commitdiff
[mips] Switch to the `.text` section after emitting asm file preamble
authorSimon Atanasyan <simon@atanasyan.com>
Tue, 3 Sep 2019 10:24:07 +0000 (10:24 +0000)
committerSimon Atanasyan <simon@atanasyan.com>
Tue, 3 Sep 2019 10:24:07 +0000 (10:24 +0000)
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

git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@370735 91177308-0d34-0410-b5e6-96231b3b80d8

lib/Target/Mips/MipsAsmPrinter.cpp
test/CodeGen/Mips/start-asm-file.ll

index d9e478574d1c04f3bdfc0ead402e14af5de9813a..b9e67bb470bb777a0f97ea72f48a26ade5dbe2c3 100644 (file)
@@ -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(Module &M) {
   // 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 {
index b80f20a1f13a641ce91bf3706edf738b23eecbe6..b8270574b6b6d9f0ae80bbbbd81c8b066e51737f 100644 (file)
@@ -71,4 +71,5 @@
 
 ; CHECK: .section .mdebug.abi[[ABI]]
 ; CHECK: .nan [[NAN]]
+; CHECK: .text
 ; CHECK: .file