forked from OSchip/llvm-project
Revert "CodeGen, Driver: Start using direct split dwarf emission in clang."
This reverts commit r332885 as it broke several greendragon buildbots. llvm-svn: 332973
This commit is contained in:
parent
b6aa52a1c4
commit
f528bcc32a
|
@ -619,8 +619,6 @@ def version : Flag<["-"], "version">,
|
||||||
HelpText<"Print the compiler version">;
|
HelpText<"Print the compiler version">;
|
||||||
def main_file_name : Separate<["-"], "main-file-name">,
|
def main_file_name : Separate<["-"], "main-file-name">,
|
||||||
HelpText<"Main file name to use for debug info">;
|
HelpText<"Main file name to use for debug info">;
|
||||||
def split_dwarf_file : Separate<["-"], "split-dwarf-file">,
|
|
||||||
HelpText<"File name to use for split dwarf debug info output">;
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -630,6 +628,8 @@ def fexternc_nounwind : Flag<["-"], "fexternc-nounwind">,
|
||||||
HelpText<"Assume all functions with C linkage do not unwind">;
|
HelpText<"Assume all functions with C linkage do not unwind">;
|
||||||
def enable_split_dwarf : Flag<["-"], "enable-split-dwarf">,
|
def enable_split_dwarf : Flag<["-"], "enable-split-dwarf">,
|
||||||
HelpText<"Use split dwarf/Fission">;
|
HelpText<"Use split dwarf/Fission">;
|
||||||
|
def split_dwarf_file : Separate<["-"], "split-dwarf-file">,
|
||||||
|
HelpText<"File name to use for split dwarf debug info output">;
|
||||||
def fno_wchar : Flag<["-"], "fno-wchar">,
|
def fno_wchar : Flag<["-"], "fno-wchar">,
|
||||||
HelpText<"Disable C++ builtin type wchar_t">;
|
HelpText<"Disable C++ builtin type wchar_t">;
|
||||||
def fconstant_string_class : Separate<["-"], "fconstant-string-class">,
|
def fconstant_string_class : Separate<["-"], "fconstant-string-class">,
|
||||||
|
|
|
@ -104,17 +104,7 @@ class EmitAssemblyHelper {
|
||||||
///
|
///
|
||||||
/// \return True on success.
|
/// \return True on success.
|
||||||
bool AddEmitPasses(legacy::PassManager &CodeGenPasses, BackendAction Action,
|
bool AddEmitPasses(legacy::PassManager &CodeGenPasses, BackendAction Action,
|
||||||
raw_pwrite_stream &OS, raw_pwrite_stream *DwoOS);
|
raw_pwrite_stream &OS);
|
||||||
|
|
||||||
std::unique_ptr<llvm::ToolOutputFile> openOutputFile(StringRef Path) {
|
|
||||||
std::error_code EC;
|
|
||||||
auto F = make_unique<llvm::ToolOutputFile>(Path, EC, llvm::sys::fs::F_None);
|
|
||||||
if (EC) {
|
|
||||||
Diags.Report(diag::err_fe_unable_to_open_output) << Path << EC.message();
|
|
||||||
F.reset();
|
|
||||||
}
|
|
||||||
return F;
|
|
||||||
}
|
|
||||||
|
|
||||||
public:
|
public:
|
||||||
EmitAssemblyHelper(DiagnosticsEngine &_Diags,
|
EmitAssemblyHelper(DiagnosticsEngine &_Diags,
|
||||||
|
@ -711,8 +701,7 @@ void EmitAssemblyHelper::CreateTargetMachine(bool MustCreateTM) {
|
||||||
|
|
||||||
bool EmitAssemblyHelper::AddEmitPasses(legacy::PassManager &CodeGenPasses,
|
bool EmitAssemblyHelper::AddEmitPasses(legacy::PassManager &CodeGenPasses,
|
||||||
BackendAction Action,
|
BackendAction Action,
|
||||||
raw_pwrite_stream &OS,
|
raw_pwrite_stream &OS) {
|
||||||
raw_pwrite_stream *DwoOS) {
|
|
||||||
// Add LibraryInfo.
|
// Add LibraryInfo.
|
||||||
llvm::Triple TargetTriple(TheModule->getTargetTriple());
|
llvm::Triple TargetTriple(TheModule->getTargetTriple());
|
||||||
std::unique_ptr<TargetLibraryInfoImpl> TLII(
|
std::unique_ptr<TargetLibraryInfoImpl> TLII(
|
||||||
|
@ -729,7 +718,7 @@ bool EmitAssemblyHelper::AddEmitPasses(legacy::PassManager &CodeGenPasses,
|
||||||
if (CodeGenOpts.OptimizationLevel > 0)
|
if (CodeGenOpts.OptimizationLevel > 0)
|
||||||
CodeGenPasses.add(createObjCARCContractPass());
|
CodeGenPasses.add(createObjCARCContractPass());
|
||||||
|
|
||||||
if (TM->addPassesToEmitFile(CodeGenPasses, OS, DwoOS, CGFT,
|
if (TM->addPassesToEmitFile(CodeGenPasses, OS, nullptr, CGFT,
|
||||||
/*DisableVerify=*/!CodeGenOpts.VerifyModule)) {
|
/*DisableVerify=*/!CodeGenOpts.VerifyModule)) {
|
||||||
Diags.Report(diag::err_fe_unable_to_interface_with_target);
|
Diags.Report(diag::err_fe_unable_to_interface_with_target);
|
||||||
return false;
|
return false;
|
||||||
|
@ -768,7 +757,7 @@ void EmitAssemblyHelper::EmitAssembly(BackendAction Action,
|
||||||
CodeGenPasses.add(
|
CodeGenPasses.add(
|
||||||
createTargetTransformInfoWrapperPass(getTargetIRAnalysis()));
|
createTargetTransformInfoWrapperPass(getTargetIRAnalysis()));
|
||||||
|
|
||||||
std::unique_ptr<llvm::ToolOutputFile> ThinLinkOS, DwoOS;
|
std::unique_ptr<raw_fd_ostream> ThinLinkOS;
|
||||||
|
|
||||||
switch (Action) {
|
switch (Action) {
|
||||||
case Backend_EmitNothing:
|
case Backend_EmitNothing:
|
||||||
|
@ -777,12 +766,18 @@ void EmitAssemblyHelper::EmitAssembly(BackendAction Action,
|
||||||
case Backend_EmitBC:
|
case Backend_EmitBC:
|
||||||
if (CodeGenOpts.EmitSummaryIndex) {
|
if (CodeGenOpts.EmitSummaryIndex) {
|
||||||
if (!CodeGenOpts.ThinLinkBitcodeFile.empty()) {
|
if (!CodeGenOpts.ThinLinkBitcodeFile.empty()) {
|
||||||
ThinLinkOS = openOutputFile(CodeGenOpts.ThinLinkBitcodeFile);
|
std::error_code EC;
|
||||||
if (!ThinLinkOS)
|
ThinLinkOS.reset(new llvm::raw_fd_ostream(
|
||||||
|
CodeGenOpts.ThinLinkBitcodeFile, EC,
|
||||||
|
llvm::sys::fs::F_None));
|
||||||
|
if (EC) {
|
||||||
|
Diags.Report(diag::err_fe_unable_to_open_output) << CodeGenOpts.ThinLinkBitcodeFile
|
||||||
|
<< EC.message();
|
||||||
return;
|
return;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
PerModulePasses.add(createWriteThinLTOBitcodePass(
|
PerModulePasses.add(
|
||||||
*OS, ThinLinkOS ? &ThinLinkOS->os() : nullptr));
|
createWriteThinLTOBitcodePass(*OS, ThinLinkOS.get()));
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
PerModulePasses.add(
|
PerModulePasses.add(
|
||||||
|
@ -795,13 +790,7 @@ void EmitAssemblyHelper::EmitAssembly(BackendAction Action,
|
||||||
break;
|
break;
|
||||||
|
|
||||||
default:
|
default:
|
||||||
if (!CodeGenOpts.SplitDwarfFile.empty()) {
|
if (!AddEmitPasses(CodeGenPasses, Action, *OS))
|
||||||
DwoOS = openOutputFile(CodeGenOpts.SplitDwarfFile);
|
|
||||||
if (!DwoOS)
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
if (!AddEmitPasses(CodeGenPasses, Action, *OS,
|
|
||||||
DwoOS ? &DwoOS->os() : nullptr))
|
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -830,11 +819,6 @@ void EmitAssemblyHelper::EmitAssembly(BackendAction Action,
|
||||||
PrettyStackTraceString CrashInfo("Code generation");
|
PrettyStackTraceString CrashInfo("Code generation");
|
||||||
CodeGenPasses.run(*TheModule);
|
CodeGenPasses.run(*TheModule);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (ThinLinkOS)
|
|
||||||
ThinLinkOS->keep();
|
|
||||||
if (DwoOS)
|
|
||||||
DwoOS->keep();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
static PassBuilder::OptimizationLevel mapToLevel(const CodeGenOptions &Opts) {
|
static PassBuilder::OptimizationLevel mapToLevel(const CodeGenOptions &Opts) {
|
||||||
|
@ -987,7 +971,7 @@ void EmitAssemblyHelper::EmitAssemblyWithNewPassManager(
|
||||||
// create that pass manager here and use it as needed below.
|
// create that pass manager here and use it as needed below.
|
||||||
legacy::PassManager CodeGenPasses;
|
legacy::PassManager CodeGenPasses;
|
||||||
bool NeedCodeGen = false;
|
bool NeedCodeGen = false;
|
||||||
std::unique_ptr<llvm::ToolOutputFile> ThinLinkOS, DwoOS;
|
Optional<raw_fd_ostream> ThinLinkOS;
|
||||||
|
|
||||||
// Append any output we need to the pass manager.
|
// Append any output we need to the pass manager.
|
||||||
switch (Action) {
|
switch (Action) {
|
||||||
|
@ -997,12 +981,17 @@ void EmitAssemblyHelper::EmitAssemblyWithNewPassManager(
|
||||||
case Backend_EmitBC:
|
case Backend_EmitBC:
|
||||||
if (CodeGenOpts.EmitSummaryIndex) {
|
if (CodeGenOpts.EmitSummaryIndex) {
|
||||||
if (!CodeGenOpts.ThinLinkBitcodeFile.empty()) {
|
if (!CodeGenOpts.ThinLinkBitcodeFile.empty()) {
|
||||||
ThinLinkOS = openOutputFile(CodeGenOpts.ThinLinkBitcodeFile);
|
std::error_code EC;
|
||||||
if (!ThinLinkOS)
|
ThinLinkOS.emplace(CodeGenOpts.ThinLinkBitcodeFile, EC,
|
||||||
|
llvm::sys::fs::F_None);
|
||||||
|
if (EC) {
|
||||||
|
Diags.Report(diag::err_fe_unable_to_open_output)
|
||||||
|
<< CodeGenOpts.ThinLinkBitcodeFile << EC.message();
|
||||||
return;
|
return;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
MPM.addPass(ThinLTOBitcodeWriterPass(*OS, ThinLinkOS ? &ThinLinkOS->os()
|
MPM.addPass(
|
||||||
: nullptr));
|
ThinLTOBitcodeWriterPass(*OS, ThinLinkOS ? &*ThinLinkOS : nullptr));
|
||||||
} else {
|
} else {
|
||||||
MPM.addPass(BitcodeWriterPass(*OS, CodeGenOpts.EmitLLVMUseLists,
|
MPM.addPass(BitcodeWriterPass(*OS, CodeGenOpts.EmitLLVMUseLists,
|
||||||
CodeGenOpts.EmitSummaryIndex,
|
CodeGenOpts.EmitSummaryIndex,
|
||||||
|
@ -1020,13 +1009,7 @@ void EmitAssemblyHelper::EmitAssemblyWithNewPassManager(
|
||||||
NeedCodeGen = true;
|
NeedCodeGen = true;
|
||||||
CodeGenPasses.add(
|
CodeGenPasses.add(
|
||||||
createTargetTransformInfoWrapperPass(getTargetIRAnalysis()));
|
createTargetTransformInfoWrapperPass(getTargetIRAnalysis()));
|
||||||
if (!CodeGenOpts.SplitDwarfFile.empty()) {
|
if (!AddEmitPasses(CodeGenPasses, Action, *OS))
|
||||||
DwoOS = openOutputFile(CodeGenOpts.SplitDwarfFile);
|
|
||||||
if (!DwoOS)
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
if (!AddEmitPasses(CodeGenPasses, Action, *OS,
|
|
||||||
DwoOS ? &DwoOS->os() : nullptr))
|
|
||||||
// FIXME: Should we handle this error differently?
|
// FIXME: Should we handle this error differently?
|
||||||
return;
|
return;
|
||||||
break;
|
break;
|
||||||
|
@ -1046,11 +1029,6 @@ void EmitAssemblyHelper::EmitAssemblyWithNewPassManager(
|
||||||
PrettyStackTraceString CrashInfo("Code generation");
|
PrettyStackTraceString CrashInfo("Code generation");
|
||||||
CodeGenPasses.run(*TheModule);
|
CodeGenPasses.run(*TheModule);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (ThinLinkOS)
|
|
||||||
ThinLinkOS->keep();
|
|
||||||
if (DwoOS)
|
|
||||||
DwoOS->keep();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
Expected<BitcodeModule> clang::FindThinLTOModule(MemoryBufferRef MBRef) {
|
Expected<BitcodeModule> clang::FindThinLTOModule(MemoryBufferRef MBRef) {
|
||||||
|
|
|
@ -4802,6 +4802,12 @@ void Clang::ConstructJob(Compilation &C, const JobAction &JA,
|
||||||
C.addCommand(llvm::make_unique<Command>(JA, *this, Exec, CmdArgs, Inputs));
|
C.addCommand(llvm::make_unique<Command>(JA, *this, Exec, CmdArgs, Inputs));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Handle the debug info splitting at object creation time if we're
|
||||||
|
// creating an object.
|
||||||
|
// TODO: Currently only works on linux with newer objcopy.
|
||||||
|
if (SplitDWARF && Output.getType() == types::TY_Object)
|
||||||
|
SplitDebugInfo(getToolChain(), C, *this, JA, Args, Output, SplitDWARFOut);
|
||||||
|
|
||||||
if (Arg *A = Args.getLastArg(options::OPT_pg))
|
if (Arg *A = Args.getLastArg(options::OPT_pg))
|
||||||
if (Args.hasArg(options::OPT_fomit_frame_pointer))
|
if (Args.hasArg(options::OPT_fomit_frame_pointer))
|
||||||
D.Diag(diag::err_drv_argument_not_allowed_with) << "-fomit-frame-pointer"
|
D.Diag(diag::err_drv_argument_not_allowed_with) << "-fomit-frame-pointer"
|
||||||
|
@ -5465,17 +5471,19 @@ void ClangAs::ConstructJob(Compilation &C, const JobAction &JA,
|
||||||
CmdArgs.push_back("-o");
|
CmdArgs.push_back("-o");
|
||||||
CmdArgs.push_back(Output.getFilename());
|
CmdArgs.push_back(Output.getFilename());
|
||||||
|
|
||||||
if (Args.hasArg(options::OPT_gsplit_dwarf) &&
|
|
||||||
getToolChain().getTriple().isOSLinux()) {
|
|
||||||
CmdArgs.push_back("-split-dwarf-file");
|
|
||||||
CmdArgs.push_back(SplitDebugName(Args, Input));
|
|
||||||
}
|
|
||||||
|
|
||||||
assert(Input.isFilename() && "Invalid input.");
|
assert(Input.isFilename() && "Invalid input.");
|
||||||
CmdArgs.push_back(Input.getFilename());
|
CmdArgs.push_back(Input.getFilename());
|
||||||
|
|
||||||
const char *Exec = getToolChain().getDriver().getClangProgramPath();
|
const char *Exec = getToolChain().getDriver().getClangProgramPath();
|
||||||
C.addCommand(llvm::make_unique<Command>(JA, *this, Exec, CmdArgs, Inputs));
|
C.addCommand(llvm::make_unique<Command>(JA, *this, Exec, CmdArgs, Inputs));
|
||||||
|
|
||||||
|
// Handle the debug info splitting at object creation time if we're
|
||||||
|
// creating an object.
|
||||||
|
// TODO: Currently only works on linux with newer objcopy.
|
||||||
|
if (Args.hasArg(options::OPT_gsplit_dwarf) &&
|
||||||
|
getToolChain().getTriple().isOSLinux())
|
||||||
|
SplitDebugInfo(getToolChain(), C, *this, JA, Args, Output,
|
||||||
|
SplitDebugName(Args, Input));
|
||||||
}
|
}
|
||||||
|
|
||||||
// Begin OffloadBundler
|
// Begin OffloadBundler
|
||||||
|
|
|
@ -1,8 +1,5 @@
|
||||||
// RUN: %clang_cc1 -debug-info-kind=limited -split-dwarf-file foo.dwo -S -emit-llvm -o - %s | FileCheck %s
|
// RUN: %clang_cc1 -debug-info-kind=limited -split-dwarf-file foo.dwo -S -emit-llvm -o - %s | FileCheck %s
|
||||||
// RUN: %clang_cc1 -debug-info-kind=limited -enable-split-dwarf -split-dwarf-file foo.dwo -S -emit-llvm -o - %s | FileCheck --check-prefix=VANILLA %s
|
// RUN: %clang_cc1 -debug-info-kind=limited -enable-split-dwarf -split-dwarf-file foo.dwo -S -emit-llvm -o - %s | FileCheck --check-prefix=VANILLA %s
|
||||||
// RUN: %clang_cc1 -debug-info-kind=limited -enable-split-dwarf -split-dwarf-file %t.dwo -emit-obj -o - %s | llvm-objdump -section-headers - | FileCheck --check-prefix=O %s
|
|
||||||
// RUN: llvm-objdump -section-headers %t.dwo | FileCheck --check-prefix=DWO %s
|
|
||||||
|
|
||||||
int main (void) {
|
int main (void) {
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
@ -13,6 +10,3 @@ int main (void) {
|
||||||
// Testing to ensure that the dwo name is not output into the compile unit if
|
// Testing to ensure that the dwo name is not output into the compile unit if
|
||||||
// it's for vanilla split-dwarf rather than split-dwarf for implicit modules.
|
// it's for vanilla split-dwarf rather than split-dwarf for implicit modules.
|
||||||
// VANILLA-NOT: splitDebugFilename
|
// VANILLA-NOT: splitDebugFilename
|
||||||
|
|
||||||
// O-NOT: .dwo
|
|
||||||
// DWO: .dwo
|
|
||||||
|
|
|
@ -3,7 +3,8 @@
|
||||||
// RUN: %clang -target x86_64-unknown-linux-gnu -gsplit-dwarf -c -### %s 2> %t
|
// RUN: %clang -target x86_64-unknown-linux-gnu -gsplit-dwarf -c -### %s 2> %t
|
||||||
// RUN: FileCheck -check-prefix=CHECK-ACTIONS < %t %s
|
// RUN: FileCheck -check-prefix=CHECK-ACTIONS < %t %s
|
||||||
//
|
//
|
||||||
// CHECK-ACTIONS: "-split-dwarf-file" "split-debug.dwo"
|
// CHECK-ACTIONS: objcopy{{.*}}--extract-dwo{{.*}}"split-debug.dwo"
|
||||||
|
// CHECK-ACTIONS: objcopy{{.*}}--strip-dwo{{.*}}"split-debug.o"
|
||||||
|
|
||||||
|
|
||||||
// RUN: %clang -target x86_64-macosx -gsplit-dwarf -c -### %s 2> %t
|
// RUN: %clang -target x86_64-macosx -gsplit-dwarf -c -### %s 2> %t
|
||||||
|
|
|
@ -3,7 +3,8 @@
|
||||||
// RUN: %clang -target x86_64-unknown-linux-gnu -gsplit-dwarf -c -### %s 2> %t
|
// RUN: %clang -target x86_64-unknown-linux-gnu -gsplit-dwarf -c -### %s 2> %t
|
||||||
// RUN: FileCheck -check-prefix=CHECK-ACTIONS < %t %s
|
// RUN: FileCheck -check-prefix=CHECK-ACTIONS < %t %s
|
||||||
//
|
//
|
||||||
// CHECK-ACTIONS: "-split-dwarf-file" "split-debug.dwo"
|
// CHECK-ACTIONS: objcopy{{.*}}--extract-dwo{{.*}}"split-debug.dwo"
|
||||||
|
// CHECK-ACTIONS: objcopy{{.*}}--strip-dwo{{.*}}"split-debug.o"
|
||||||
|
|
||||||
|
|
||||||
// RUN: %clang -target x86_64-macosx -gsplit-dwarf -c -### %s 2> %t
|
// RUN: %clang -target x86_64-macosx -gsplit-dwarf -c -### %s 2> %t
|
||||||
|
|
|
@ -1,25 +0,0 @@
|
||||||
// RUN: %clang -cc1as -triple x86_64-pc-linux-gnu %s -filetype obj -o %t1 -split-dwarf-file %t2
|
|
||||||
// RUN: llvm-objdump -s %t1 | FileCheck --check-prefix=O %s
|
|
||||||
// RUN: llvm-objdump -s %t2 | FileCheck --check-prefix=DWO %s
|
|
||||||
|
|
||||||
// O-NOT: Contents of section
|
|
||||||
// O: Contents of section .strtab:
|
|
||||||
// O-NOT: Contents of section
|
|
||||||
// O: Contents of section .text:
|
|
||||||
// O-NEXT: 0000 c3
|
|
||||||
// O-NEXT: Contents of section .symtab:
|
|
||||||
// O-NOT: Contents of section
|
|
||||||
.globl main
|
|
||||||
main:
|
|
||||||
.Ltmp1:
|
|
||||||
ret
|
|
||||||
.Ltmp2:
|
|
||||||
|
|
||||||
// DWO-NOT: Contents of section
|
|
||||||
// DWO: Contents of section .strtab:
|
|
||||||
// DWO-NOT: Contents of section
|
|
||||||
// DWO: Contents of section .foo.dwo:
|
|
||||||
// DWO-NEXT: 0000 01000000
|
|
||||||
// DWO-NOT: Contents of section
|
|
||||||
.section .foo.dwo
|
|
||||||
.long .Ltmp2-.Ltmp1
|
|
|
@ -97,7 +97,6 @@ struct AssemblerInvocation {
|
||||||
llvm::DebugCompressionType CompressDebugSections =
|
llvm::DebugCompressionType CompressDebugSections =
|
||||||
llvm::DebugCompressionType::None;
|
llvm::DebugCompressionType::None;
|
||||||
std::string MainFileName;
|
std::string MainFileName;
|
||||||
std::string SplitDwarfFile;
|
|
||||||
|
|
||||||
/// @}
|
/// @}
|
||||||
/// @name Frontend Options
|
/// @name Frontend Options
|
||||||
|
@ -248,7 +247,6 @@ bool AssemblerInvocation::CreateFromArgs(AssemblerInvocation &Opts,
|
||||||
}
|
}
|
||||||
Opts.LLVMArgs = Args.getAllArgValues(OPT_mllvm);
|
Opts.LLVMArgs = Args.getAllArgValues(OPT_mllvm);
|
||||||
Opts.OutputPath = Args.getLastArgValue(OPT_o);
|
Opts.OutputPath = Args.getLastArgValue(OPT_o);
|
||||||
Opts.SplitDwarfFile = Args.getLastArgValue(OPT_split_dwarf_file);
|
|
||||||
if (Arg *A = Args.getLastArg(OPT_filetype)) {
|
if (Arg *A = Args.getLastArg(OPT_filetype)) {
|
||||||
StringRef Name = A->getValue();
|
StringRef Name = A->getValue();
|
||||||
unsigned OutputType = StringSwitch<unsigned>(Name)
|
unsigned OutputType = StringSwitch<unsigned>(Name)
|
||||||
|
@ -284,17 +282,22 @@ bool AssemblerInvocation::CreateFromArgs(AssemblerInvocation &Opts,
|
||||||
}
|
}
|
||||||
|
|
||||||
static std::unique_ptr<raw_fd_ostream>
|
static std::unique_ptr<raw_fd_ostream>
|
||||||
getOutputStream(StringRef Path, DiagnosticsEngine &Diags, bool Binary) {
|
getOutputStream(AssemblerInvocation &Opts, DiagnosticsEngine &Diags,
|
||||||
|
bool Binary) {
|
||||||
|
if (Opts.OutputPath.empty())
|
||||||
|
Opts.OutputPath = "-";
|
||||||
|
|
||||||
// Make sure that the Out file gets unlinked from the disk if we get a
|
// Make sure that the Out file gets unlinked from the disk if we get a
|
||||||
// SIGINT.
|
// SIGINT.
|
||||||
if (Path != "-")
|
if (Opts.OutputPath != "-")
|
||||||
sys::RemoveFileOnSignal(Path);
|
sys::RemoveFileOnSignal(Opts.OutputPath);
|
||||||
|
|
||||||
std::error_code EC;
|
std::error_code EC;
|
||||||
auto Out = llvm::make_unique<raw_fd_ostream>(
|
auto Out = llvm::make_unique<raw_fd_ostream>(
|
||||||
Path, EC, (Binary ? sys::fs::F_None : sys::fs::F_Text));
|
Opts.OutputPath, EC, (Binary ? sys::fs::F_None : sys::fs::F_Text));
|
||||||
if (EC) {
|
if (EC) {
|
||||||
Diags.Report(diag::err_fe_unable_to_open_output) << Path << EC.message();
|
Diags.Report(diag::err_fe_unable_to_open_output) << Opts.OutputPath
|
||||||
|
<< EC.message();
|
||||||
return nullptr;
|
return nullptr;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -339,15 +342,9 @@ static bool ExecuteAssembler(AssemblerInvocation &Opts,
|
||||||
MAI->setRelaxELFRelocations(Opts.RelaxELFRelocations);
|
MAI->setRelaxELFRelocations(Opts.RelaxELFRelocations);
|
||||||
|
|
||||||
bool IsBinary = Opts.OutputType == AssemblerInvocation::FT_Obj;
|
bool IsBinary = Opts.OutputType == AssemblerInvocation::FT_Obj;
|
||||||
if (Opts.OutputPath.empty())
|
std::unique_ptr<raw_fd_ostream> FDOS = getOutputStream(Opts, Diags, IsBinary);
|
||||||
Opts.OutputPath = "-";
|
|
||||||
std::unique_ptr<raw_fd_ostream> FDOS =
|
|
||||||
getOutputStream(Opts.OutputPath, Diags, IsBinary);
|
|
||||||
if (!FDOS)
|
if (!FDOS)
|
||||||
return true;
|
return true;
|
||||||
std::unique_ptr<raw_fd_ostream> DwoOS;
|
|
||||||
if (!Opts.SplitDwarfFile.empty())
|
|
||||||
DwoOS = getOutputStream(Opts.SplitDwarfFile, Diags, IsBinary);
|
|
||||||
|
|
||||||
// FIXME: This is not pretty. MCContext has a ptr to MCObjectFileInfo and
|
// FIXME: This is not pretty. MCContext has a ptr to MCObjectFileInfo and
|
||||||
// MCObjectFileInfo needs a MCContext reference in order to initialize itself.
|
// MCObjectFileInfo needs a MCContext reference in order to initialize itself.
|
||||||
|
@ -430,9 +427,7 @@ static bool ExecuteAssembler(AssemblerInvocation &Opts,
|
||||||
MCTargetOptions MCOptions;
|
MCTargetOptions MCOptions;
|
||||||
std::unique_ptr<MCAsmBackend> MAB(
|
std::unique_ptr<MCAsmBackend> MAB(
|
||||||
TheTarget->createMCAsmBackend(*STI, *MRI, MCOptions));
|
TheTarget->createMCAsmBackend(*STI, *MRI, MCOptions));
|
||||||
std::unique_ptr<MCObjectWriter> OW =
|
std::unique_ptr<MCObjectWriter> OW = MAB->createObjectWriter(*Out);
|
||||||
DwoOS ? MAB->createDwoObjectWriter(*Out, *DwoOS)
|
|
||||||
: MAB->createObjectWriter(*Out);
|
|
||||||
|
|
||||||
Triple T(Opts.Triple);
|
Triple T(Opts.Triple);
|
||||||
Str.reset(TheTarget->createMCObjectStreamer(
|
Str.reset(TheTarget->createMCObjectStreamer(
|
||||||
|
@ -481,12 +476,8 @@ static bool ExecuteAssembler(AssemblerInvocation &Opts,
|
||||||
FDOS.reset();
|
FDOS.reset();
|
||||||
|
|
||||||
// Delete output file if there were errors.
|
// Delete output file if there were errors.
|
||||||
if (Failed) {
|
if (Failed && Opts.OutputPath != "-")
|
||||||
if (Opts.OutputPath != "-")
|
sys::fs::remove(Opts.OutputPath);
|
||||||
sys::fs::remove(Opts.OutputPath);
|
|
||||||
if (!Opts.SplitDwarfFile.empty() && Opts.SplitDwarfFile != "-")
|
|
||||||
sys::fs::remove(Opts.SplitDwarfFile);
|
|
||||||
}
|
|
||||||
|
|
||||||
return Failed;
|
return Failed;
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue