diff --git a/llvm/lib/Target/RISCV/RISCVAsmPrinter.cpp b/llvm/lib/Target/RISCV/RISCVAsmPrinter.cpp --- a/llvm/lib/Target/RISCV/RISCVAsmPrinter.cpp +++ b/llvm/lib/Target/RISCV/RISCVAsmPrinter.cpp @@ -70,6 +70,7 @@ private: void emitAttributes(); + void emitDirectiveOption(); }; } @@ -178,8 +179,10 @@ } void RISCVAsmPrinter::emitStartOfAsmFile(Module &M) { - if (TM.getTargetTriple().isOSBinFormatELF()) - emitAttributes(); + if (!TM.getTargetTriple().isOSBinFormatELF()) + return; + emitAttributes(); + emitDirectiveOption(); } void RISCVAsmPrinter::emitEndOfAsmFile(Module &M) { @@ -196,6 +199,20 @@ RTS.emitTargetAttributes(*STI); } +void RISCVAsmPrinter::emitDirectiveOption() { + RISCVTargetStreamer &RTS = + static_cast(*OutStreamer->getTargetStreamer()); + + if (!isPositionIndependent()) + RTS.emitDirectiveOptionNoPIC(); + + if (!STI->hasFeature(RISCV::FeatureRelax)) + RTS.emitDirectiveOptionNoRelax(); + + if (!STI->hasFeature(RISCV::FeatureStdExtC)) + RTS.emitDirectiveOptionNoRVC(); +} + // Force static initialization. extern "C" LLVM_EXTERNAL_VISIBILITY void LLVMInitializeRISCVAsmPrinter() { RegisterAsmPrinter X(getTheRISCV32Target());