Index: tools/gold/gold-plugin.cpp =================================================================== --- tools/gold/gold-plugin.cpp +++ tools/gold/gold-plugin.cpp @@ -128,6 +128,7 @@ OT_NORMAL, OT_DISABLE, OT_BC_ONLY, + OT_ASM_ONLY, OT_SAVE_TEMPS }; static OutputType TheOutputType = OT_NORMAL; @@ -229,6 +230,8 @@ TheOutputType = OT_SAVE_TEMPS; } else if (opt == "disable-output") { TheOutputType = OT_DISABLE; + } else if (opt == "emit-asm") { + TheOutputType = OT_ASM_ONLY; } else if (opt == "thinlto") { thinlto = true; } else if (opt == "thinlto-index-only") { @@ -882,6 +885,9 @@ check(Conf.addSaveTemps(output_name + ".", /* UseInputModulePath */ true)); break; + case options::OT_ASM_ONLY: + Conf.CGFileType = TargetMachine::CGFT_AssemblyFile; + break; } if (!options::sample_profile.empty()) @@ -1060,6 +1066,23 @@ options::TheOutputType == options::OT_BC_ONLY) return LDPS_OK; + if (options::TheOutputType == options::OT_ASM_ONLY) { + auto CopyFile = [](const std::string &from, const std::string &to) { + std::error_code EC = sys::fs::copy_file(from, to); + if (EC) + message(LDPL_ERROR, "Failed to copy assembly to '%s': %s", to.c_str(), + EC.message().c_str()); + }; + + if (Files.size() == 1) + CopyFile(Files.front().first.str(), output_name); + else + for (unsigned i = 0; i < Files.size(); ++i) + CopyFile(Files[i].first.str(), output_name + '.' + std::to_string(i)); + + return LDPS_OK; + } + if (options::thinlto_index_only) { llvm_shutdown(); cleanup_hook(); @@ -1082,6 +1105,7 @@ llvm_shutdown(); if (options::TheOutputType == options::OT_BC_ONLY || + options::TheOutputType == options::OT_ASM_ONLY || options::TheOutputType == options::OT_DISABLE) { if (options::TheOutputType == options::OT_DISABLE) { // Remove the output file here since ld.bfd creates the output file