[PATCH] D47093: CodeGen, Driver: Start using direct split dwarf emission in clang.
This revision was automatically updated to reflect the committed changes. Closed by commit rC332885: CodeGen, Driver: Start using direct split dwarf emission in clang. (authored by pcc, committed by ). Changed prior to commit: https://reviews.llvm.org/D47093?vs=147609=147858#toc Repository: rC Clang https://reviews.llvm.org/D47093 Files: include/clang/Driver/CC1Options.td lib/CodeGen/BackendUtil.cpp lib/Driver/ToolChains/Clang.cpp test/CodeGen/split-debug-filename.c test/Driver/split-debug.c test/Driver/split-debug.s test/Misc/cc1as-split-dwarf.s tools/driver/cc1as_main.cpp Index: test/CodeGen/split-debug-filename.c === --- test/CodeGen/split-debug-filename.c +++ test/CodeGen/split-debug-filename.c @@ -1,5 +1,8 @@ // 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 %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) { return 0; } @@ -10,3 +13,6 @@ // 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. // VANILLA-NOT: splitDebugFilename + +// O-NOT: .dwo +// DWO: .dwo Index: test/Driver/split-debug.s === --- test/Driver/split-debug.s +++ test/Driver/split-debug.s @@ -3,8 +3,7 @@ // RUN: %clang -target x86_64-unknown-linux-gnu -gsplit-dwarf -c -### %s 2> %t // RUN: FileCheck -check-prefix=CHECK-ACTIONS < %t %s // -// CHECK-ACTIONS: objcopy{{.*}}--extract-dwo{{.*}}"split-debug.dwo" -// CHECK-ACTIONS: objcopy{{.*}}--strip-dwo{{.*}}"split-debug.o" +// CHECK-ACTIONS: "-split-dwarf-file" "split-debug.dwo" // RUN: %clang -target x86_64-macosx -gsplit-dwarf -c -### %s 2> %t Index: test/Driver/split-debug.c === --- test/Driver/split-debug.c +++ test/Driver/split-debug.c @@ -3,8 +3,7 @@ // RUN: %clang -target x86_64-unknown-linux-gnu -gsplit-dwarf -c -### %s 2> %t // RUN: FileCheck -check-prefix=CHECK-ACTIONS < %t %s // -// CHECK-ACTIONS: objcopy{{.*}}--extract-dwo{{.*}}"split-debug.dwo" -// CHECK-ACTIONS: objcopy{{.*}}--strip-dwo{{.*}}"split-debug.o" +// CHECK-ACTIONS: "-split-dwarf-file" "split-debug.dwo" // RUN: %clang -target x86_64-macosx -gsplit-dwarf -c -### %s 2> %t Index: test/Misc/cc1as-split-dwarf.s === --- test/Misc/cc1as-split-dwarf.s +++ test/Misc/cc1as-split-dwarf.s @@ -0,0 +1,25 @@ +// 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: 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: 0100 +// DWO-NOT: Contents of section +.section .foo.dwo +.long .Ltmp2-.Ltmp1 Index: lib/CodeGen/BackendUtil.cpp === --- lib/CodeGen/BackendUtil.cpp +++ lib/CodeGen/BackendUtil.cpp @@ -104,7 +104,17 @@ /// /// \return True on success. bool AddEmitPasses(legacy::PassManager , BackendAction Action, - raw_pwrite_stream ); + raw_pwrite_stream , raw_pwrite_stream *DwoOS); + + std::unique_ptr openOutputFile(StringRef Path) { +std::error_code EC; +auto F = make_unique(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: EmitAssemblyHelper(DiagnosticsEngine &_Diags, @@ -701,7 +711,8 @@ bool EmitAssemblyHelper::AddEmitPasses(legacy::PassManager , BackendAction Action, - raw_pwrite_stream ) { + raw_pwrite_stream , + raw_pwrite_stream *DwoOS) { // Add LibraryInfo. llvm::Triple TargetTriple(TheModule->getTargetTriple()); std::unique_ptr TLII( @@ -718,7 +729,7 @@ if (CodeGenOpts.OptimizationLevel > 0) CodeGenPasses.add(createObjCARCContractPass());
[PATCH] D47093: CodeGen, Driver: Start using direct split dwarf emission in clang.
pcc created this revision. pcc added reviewers: dblaikie, echristo. Herald added a subscriber: JDevlieghere. Fixes PR37466. Depends on https://reviews.llvm.org/D47091 https://reviews.llvm.org/D47093 Files: clang/include/clang/Driver/CC1Options.td clang/lib/CodeGen/BackendUtil.cpp clang/lib/Driver/ToolChains/Clang.cpp clang/test/CodeGen/split-debug-filename.c clang/test/Driver/split-debug.c clang/test/Driver/split-debug.s clang/test/Misc/cc1as-split-dwarf.s clang/tools/driver/cc1as_main.cpp Index: clang/tools/driver/cc1as_main.cpp === --- clang/tools/driver/cc1as_main.cpp +++ clang/tools/driver/cc1as_main.cpp @@ -97,6 +97,7 @@ llvm::DebugCompressionType CompressDebugSections = llvm::DebugCompressionType::None; std::string MainFileName; + std::string SplitDwarfFile; /// @} /// @name Frontend Options @@ -247,6 +248,7 @@ } Opts.LLVMArgs = Args.getAllArgValues(OPT_mllvm); Opts.OutputPath = Args.getLastArgValue(OPT_o); + Opts.SplitDwarfFile = Args.getLastArgValue(OPT_split_dwarf_file); if (Arg *A = Args.getLastArg(OPT_filetype)) { StringRef Name = A->getValue(); unsigned OutputType = StringSwitch(Name) @@ -282,22 +284,17 @@ } static std::unique_ptr -getOutputStream(AssemblerInvocation , DiagnosticsEngine , -bool Binary) { - if (Opts.OutputPath.empty()) -Opts.OutputPath = "-"; - +getOutputStream(StringRef Path, DiagnosticsEngine , bool Binary) { // Make sure that the Out file gets unlinked from the disk if we get a // SIGINT. - if (Opts.OutputPath != "-") -sys::RemoveFileOnSignal(Opts.OutputPath); + if (Path != "-") +sys::RemoveFileOnSignal(Path); std::error_code EC; auto Out = llvm::make_unique( - Opts.OutputPath, EC, (Binary ? sys::fs::F_None : sys::fs::F_Text)); + Path, EC, (Binary ? sys::fs::F_None : sys::fs::F_Text)); if (EC) { -Diags.Report(diag::err_fe_unable_to_open_output) << Opts.OutputPath - << EC.message(); +Diags.Report(diag::err_fe_unable_to_open_output) << Path << EC.message(); return nullptr; } @@ -342,9 +339,15 @@ MAI->setRelaxELFRelocations(Opts.RelaxELFRelocations); bool IsBinary = Opts.OutputType == AssemblerInvocation::FT_Obj; - std::unique_ptr FDOS = getOutputStream(Opts, Diags, IsBinary); + if (Opts.OutputPath.empty()) +Opts.OutputPath = "-"; + std::unique_ptr FDOS = + getOutputStream(Opts.OutputPath, Diags, IsBinary); if (!FDOS) return true; + std::unique_ptr DwoOS; + if (!Opts.SplitDwarfFile.empty()) +DwoOS = getOutputStream(Opts.SplitDwarfFile, Diags, IsBinary); // FIXME: This is not pretty. MCContext has a ptr to MCObjectFileInfo and // MCObjectFileInfo needs a MCContext reference in order to initialize itself. @@ -427,7 +430,9 @@ MCTargetOptions MCOptions; std::unique_ptr MAB( TheTarget->createMCAsmBackend(*STI, *MRI, MCOptions)); -std::unique_ptr OW = MAB->createObjectWriter(*Out); +std::unique_ptr OW = +DwoOS ? MAB->createDwoObjectWriter(*Out, *DwoOS) + : MAB->createObjectWriter(*Out); Triple T(Opts.Triple); Str.reset(TheTarget->createMCObjectStreamer( @@ -476,8 +481,12 @@ FDOS.reset(); // Delete output file if there were errors. - if (Failed && Opts.OutputPath != "-") -sys::fs::remove(Opts.OutputPath); + if (Failed) { +if (Opts.OutputPath != "-") + sys::fs::remove(Opts.OutputPath); +if (!Opts.SplitDwarfFile.empty() && Opts.SplitDwarfFile != "-") + sys::fs::remove(Opts.SplitDwarfFile); + } return Failed; } Index: clang/test/Misc/cc1as-split-dwarf.s === --- /dev/null +++ clang/test/Misc/cc1as-split-dwarf.s @@ -0,0 +1,25 @@ +// 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: 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: 0100 +// DWO-NOT: Contents of section +.section .foo.dwo +.long .Ltmp2-.Ltmp1 Index: clang/test/Driver/split-debug.s === --- clang/test/Driver/split-debug.s +++ clang/test/Driver/split-debug.s @@ -3,8 +3,7 @@ // RUN: %clang -target x86_64-unknown-linux-gnu -gsplit-dwarf -c -### %s 2> %t // RUN: FileCheck -check-prefix=CHECK-ACTIONS < %t %s // -// CHECK-ACTIONS: