diff --git a/llvm/lib/Target/Mips/MipsAsmPrinter.h b/llvm/lib/Target/Mips/MipsAsmPrinter.h --- a/llvm/lib/Target/Mips/MipsAsmPrinter.h +++ b/llvm/lib/Target/Mips/MipsAsmPrinter.h @@ -63,6 +63,11 @@ /// pool entries so we can properly mark them as data regions. bool InConstantPool = false; + /// isFirstFunction - Is it the first function in this build unit? + /// GNU as complains: .module is not permitted after generating code, + /// if we emit some directives after the entry of first function. + bool isFirstFunction = true; + std::map StubsNeeded; diff --git a/llvm/lib/Target/Mips/MipsAsmPrinter.cpp b/llvm/lib/Target/Mips/MipsAsmPrinter.cpp --- a/llvm/lib/Target/Mips/MipsAsmPrinter.cpp +++ b/llvm/lib/Target/Mips/MipsAsmPrinter.cpp @@ -402,11 +402,16 @@ bool IsO32 = (static_cast(TM)).getABI().IsO32(); TS.updateABIInfo(*Subtarget); - if (Subtarget->isNaN2008()) - TS.emitDirectiveNaN2008(); - if ((IsO32 && (Subtarget->isABI_FPXX() || Subtarget->isFP64bit())) || - Subtarget->useSoftFloat()) - TS.emitDirectiveModuleFP(); + // GNU as complains: .module is not permitted after generating code. + // So we can only emit them for the first function. + if (isFirstFunction) { + isFirstFunction = false; + if (Subtarget->isNaN2008()) + TS.emitDirectiveNaN2008(); + if ((IsO32 && (Subtarget->isABI_FPXX() || Subtarget->isFP64bit())) || + Subtarget->useSoftFloat()) + TS.emitDirectiveModuleFP(); + } // NaCl sandboxing requires that indirect call instructions are masked. // This means that function entry points should be bundle-aligned.