-
Notifications
You must be signed in to change notification settings - Fork 15k
[flang][Driver] Support -gsplit-dwarf. #160540
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change | ||||
|---|---|---|---|---|---|---|
|
|
@@ -120,7 +120,11 @@ static bool shouldLoopVersion(const ArgList &Args) { | |||||
| return false; | ||||||
| } | ||||||
|
|
||||||
| void Flang::addOtherOptions(const ArgList &Args, ArgStringList &CmdArgs) const { | ||||||
| void Flang::addDebugOptions(const llvm::opt::ArgList &Args, const JobAction &JA, | ||||||
| const InputInfo &Output, const InputInfo &Input, | ||||||
| llvm::opt::ArgStringList &CmdArgs) const { | ||||||
| const auto &TC = getToolChain(); | ||||||
| const Driver &D = TC.getDriver(); | ||||||
| Args.addAllArgs(CmdArgs, | ||||||
| {options::OPT_module_dir, options::OPT_fdebug_module_writer, | ||||||
| options::OPT_fintrinsic_modules_path, options::OPT_pedantic, | ||||||
|
|
@@ -131,20 +135,60 @@ void Flang::addOtherOptions(const ArgList &Args, ArgStringList &CmdArgs) const { | |||||
| options::OPT_finstrument_functions}); | ||||||
|
|
||||||
| llvm::codegenoptions::DebugInfoKind DebugInfoKind; | ||||||
| bool hasDwarfNArg = getDwarfNArg(Args) != nullptr; | ||||||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Is it necessary to compare to
Suggested change
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Not strictly necessary no because nullptr will be 0==false, but I think this is easier to understand at a glance. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Yes, I added those for readability but have no strong opinion. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. That's fine. I don't have any strong opinion either way. We can leave it as it is. |
||||||
| if (Args.hasArg(options::OPT_gN_Group)) { | ||||||
| Arg *gNArg = Args.getLastArg(options::OPT_gN_Group); | ||||||
| DebugInfoKind = debugLevelToInfoKind(*gNArg); | ||||||
| } else if (Args.hasArg(options::OPT_g_Group)) { | ||||||
| } else if (Args.hasArg(options::OPT_g_Flag) || hasDwarfNArg) { | ||||||
| DebugInfoKind = llvm::codegenoptions::FullDebugInfo; | ||||||
| } else { | ||||||
| DebugInfoKind = llvm::codegenoptions::NoDebugInfo; | ||||||
| } | ||||||
| addDebugInfoKind(CmdArgs, DebugInfoKind); | ||||||
| if (getDwarfNArg(Args)) { | ||||||
| if (hasDwarfNArg) { | ||||||
| const unsigned DwarfVersion = getDwarfVersion(getToolChain(), Args); | ||||||
| CmdArgs.push_back( | ||||||
| Args.MakeArgString("-dwarf-version=" + Twine(DwarfVersion))); | ||||||
| } | ||||||
| if (Args.hasArg(options::OPT_gsplit_dwarf) || | ||||||
| Args.hasArg(options::OPT_gsplit_dwarf_EQ)) { | ||||||
| // FIXME: -gsplit-dwarf on AIX is currently unimplemented. | ||||||
| if (TC.getTriple().isOSAIX()) { | ||||||
| D.Diag(diag::err_drv_unsupported_opt_for_target) | ||||||
| << Args.getLastArg(options::OPT_gsplit_dwarf)->getSpelling() | ||||||
| << TC.getTriple().str(); | ||||||
| return; | ||||||
| } | ||||||
| if (DebugInfoKind == llvm::codegenoptions::NoDebugInfo) | ||||||
| return; | ||||||
|
|
||||||
| Arg *SplitDWARFArg; | ||||||
| DwarfFissionKind DwarfFission = getDebugFissionKind(D, Args, SplitDWARFArg); | ||||||
|
|
||||||
| if (DwarfFission == DwarfFissionKind::None || | ||||||
| !checkDebugInfoOption(SplitDWARFArg, Args, D, TC)) | ||||||
| return; | ||||||
|
|
||||||
| if (!TC.getTriple().isOSBinFormatELF() && | ||||||
| !TC.getTriple().isOSBinFormatWasm() && | ||||||
| !TC.getTriple().isOSBinFormatCOFF()) { | ||||||
| D.Diag(diag::warn_drv_unsupported_debug_info_opt_for_target) | ||||||
| << SplitDWARFArg->getSpelling() << TC.getTriple().str(); | ||||||
| return; | ||||||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Do you think we should warn in cases where split dwarf cannot be done instead of silently ignoring? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I was sort of following what clang was doing here. But happy to add a warning if you think that is better course of action. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Following clang is good and I don't feel too strongly about it but the warnings won't be hard to add and our code structure already deviates from clang a bit anyway. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I have added a warning and updated the test accordingly. |
||||||
| } | ||||||
|
|
||||||
| if (!isa<AssembleJobAction>(JA) && !isa<CompileJobAction>(JA) && | ||||||
| isa<BackendJobAction>(JA)) | ||||||
| return; | ||||||
|
|
||||||
| const char *SplitDWARFOut = SplitDebugName(JA, Args, Input, Output); | ||||||
| CmdArgs.push_back("-split-dwarf-file"); | ||||||
| CmdArgs.push_back(SplitDWARFOut); | ||||||
| if (DwarfFission == DwarfFissionKind::Split) { | ||||||
| CmdArgs.push_back("-split-dwarf-output"); | ||||||
| CmdArgs.push_back(SplitDWARFOut); | ||||||
| } | ||||||
| } | ||||||
| } | ||||||
|
|
||||||
| void Flang::addCodegenOptions(const ArgList &Args, | ||||||
|
|
@@ -936,8 +980,8 @@ void Flang::ConstructJob(Compilation &C, const JobAction &JA, | |||||
| if (willEmitRemarks(Args)) | ||||||
| renderRemarksOptions(Args, CmdArgs, Input); | ||||||
|
|
||||||
| // Add other compile options | ||||||
| addOtherOptions(Args, CmdArgs); | ||||||
| // Add debug compile options | ||||||
| addDebugOptions(Args, JA, Output, Input, CmdArgs); | ||||||
|
|
||||||
| // Disable all warnings | ||||||
| // TODO: Handle interactions between -w, -pedantic, -Wall, -WOption | ||||||
|
|
||||||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,44 @@ | ||
| ! Test -gsplit-dwarf and -gsplit-dwarf={split,single}. | ||
|
|
||
| ! RUN: %flang -### -c -target x86_64 -g -gsplit-dwarf %s 2>&1 | FileCheck %s --check-prefixes=SPLIT | ||
| ! RUN: %flang -### -c -target x86_64 -gsplit-dwarf -g %s 2>&1 | FileCheck %s --check-prefixes=SPLIT | ||
| ! RUN: %flang -### -c -target x86_64 -gsplit-dwarf=split -g %s 2>&1 | FileCheck %s --check-prefixes=SPLIT | ||
|
|
||
| ! SPLIT: "-split-dwarf-file" "split-debug.dwo" "-split-dwarf-output" "split-debug.dwo" | ||
|
|
||
| ! Check warning on non-supported platforms. | ||
| ! RUN: %flang -### -c -target x86_64-apple-darwin -gsplit-dwarf -g %s 2>&1 | FileCheck %s --check-prefix=WARN | ||
| ! WARN: warning: debug information option '-gsplit-dwarf' is not supported for target 'x86_64-apple-darwin' | ||
|
|
||
| ! -gno-split-dwarf disables debug fission. | ||
| ! RUN: %flang -### -c -target x86_64 -gsplit-dwarf -g -gno-split-dwarf %s 2>&1 | FileCheck %s --check-prefix=NOSPLIT | ||
| ! RUN: %flang -### -c -target x86_64 -gsplit-dwarf=single -g -gno-split-dwarf %s 2>&1 | FileCheck %s --check-prefix=NOSPLIT | ||
| ! RUN: %flang -### -c -target x86_64 -gno-split-dwarf -g -gsplit-dwarf %s 2>&1 | FileCheck %s --check-prefixes=SPLIT | ||
|
|
||
| ! NOSPLIT-NOT: "-split-dwarf | ||
|
|
||
| ! Test -gsplit-dwarf=single. | ||
| ! RUN: %flang -### -c -target x86_64 -gsplit-dwarf=single -g %s 2>&1 | FileCheck %s --check-prefix=SINGLE | ||
|
|
||
| ! SINGLE: "-split-dwarf-file" "split-debug.o" | ||
| ! SINGLE-NOT: "-split-dwarf-output" | ||
|
|
||
| ! RUN: %flang -### -c -target x86_64 -gsplit-dwarf=single -g -o %tfoo.o %s 2>&1 | FileCheck %s --check-prefix=SINGLE_WITH_FILENAME | ||
| ! SINGLE_WITH_FILENAME: "-split-dwarf-file" "{{.*}}foo.o" | ||
| ! SINGLE_WITH_FILENAME-NOT: "-split-dwarf-output" | ||
|
|
||
|
|
||
| ! Invoke objcopy if not using the integrated assembler. | ||
| ! RUN: %flang -### -c -target x86_64-unknown-linux-gnu -fno-integrated-as -gsplit-dwarf -g %s 2>&1 | FileCheck %s --check-prefix=OBJCOPY | ||
| ! OBJCOPY: objcopy{{(.exe)?}} | ||
| ! OBJCOPY-SAME: --extract-dwo | ||
| ! OBJCOPY-NEXT: objcopy{{(.exe)?}} | ||
| ! OBJCOPY-SAME: --strip-dwo | ||
|
|
||
| ! RUN: not %flang -target powerpc-ibm-aix -gdwarf-4 -gsplit-dwarf %s 2>&1 \ | ||
| ! RUN: | FileCheck %s --check-prefix=UNSUP_OPT_AIX | ||
| ! RUN: not %flang -target powerpc64-ibm-aix -gdwarf-4 -gsplit-dwarf %s 2>&1 \ | ||
| ! RUN: | FileCheck %s --check-prefix=UNSUP_OPT_AIX64 | ||
|
|
||
| ! UNSUP_OPT_AIX: error: unsupported option '-gsplit-dwarf' for target 'powerpc-ibm-aix' | ||
| ! UNSUP_OPT_AIX64: error: unsupported option '-gsplit-dwarf' for target 'powerpc64-ibm-aix' |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,21 @@ | ||
| ! REQUIRES: x86-registered-target | ||
|
|
||
| ! Testing to ensure that setting only -split-dwarf-file allows to place | ||
| ! .dwo sections into regular output object. | ||
| ! RUN: %flang_fc1 -debug-info-kind=standalone -triple x86_64-unknown-linux \ | ||
| ! RUN: -split-dwarf-file %t.o -emit-obj -o %t.o %s | ||
| ! RUN: llvm-readobj -S %t.o | FileCheck --check-prefix=DWO %s | ||
|
|
||
| ! Testing to ensure that setting both -split-dwarf-file and -split-dwarf-output | ||
| ! does not place .dwo sections into regular output object but in a separate | ||
| ! file. | ||
| ! RUN: %flang_fc1 -debug-info-kind=standalone -triple x86_64-unknown-linux \ | ||
| ! RUN: -split-dwarf-file %t.dwo -split-dwarf-output %t.dwo -emit-obj -o %t.o %s | ||
| ! RUN: llvm-readobj -S %t.dwo | FileCheck --check-prefix=DWO %s | ||
| ! RUN: llvm-readobj -S %t.o | FileCheck --check-prefix=SPLIT %s | ||
|
|
||
| ! DWO: .dwo | ||
| ! SPLIT-NOT: .dwo | ||
|
|
||
| program test | ||
| end program test |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I missed this the first time around. I know that is already existed, but the wording is a bit unclear to me. Is the split dwarf debug info file actually encoded e.g. converted to base64 or something, into the object file? Is it "embedded" in the object file? Or is it something else?
It could be that I have misunderstood it. We don't have to do anything about this.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Some background on how this works. Split dwarf means that part of the dwarf which don't need relocations are put in separate sections (generally they have .dwo in the name). These sections could be put in the same object file (-gsplit-dwarf=single) with rest of the sections or in separate file (-gslit-dwarf=split).
This help string could certainly be improved. I will try to do that in a separate PR as it will need broader agreement on the wording.