1266630SdimMerge -fstandalone-debug from Clang r198655: 2266630Sdim 3266630Sdim Implement a new -fstandalone-debug option. rdar://problem/15685848 4266630Sdim It controls everything that -flimit-debug-info used to, plus the 5266630Sdim vtable type optimization. The old -fno-limit-debug-info option is now an 6266630Sdim alias to -fstandalone-debug and vice versa. 7266630Sdim 8266630Sdim Standalone is the default on Darwin until dtrace is updated to work with 9266630Sdim non-standalone debug info (rdar://problem/15758808). 10266630Sdim 11266630Sdim Note: I kept the LimitedDebugInfo name in CodeGenOptions::DebugInfoKind 12266630Sdim because NoStandaloneDebugInfo sounded even more confusing. 13266630Sdim 14266630SdimIntroduced here: http://svnweb.freebsd.org/changeset/base/265477 15266630Sdim 16266630SdimIndex: tools/clang/lib/CodeGen/CGDebugInfo.cpp 17266630Sdim=================================================================== 18266630Sdim--- tools/clang/lib/CodeGen/CGDebugInfo.cpp 19266630Sdim+++ tools/clang/lib/CodeGen/CGDebugInfo.cpp 20266630Sdim@@ -1456,13 +1456,13 @@ llvm::DIType CGDebugInfo::CreateType(const RecordT 21266630Sdim // declaration. The completeType, completeRequiredType, and completeClassData 22266630Sdim // callbacks will handle promoting the declaration to a definition. 23266630Sdim if (T || 24266630Sdim+ // Under -flimit-debug-info: 25266630Sdim (DebugKind <= CodeGenOptions::LimitedDebugInfo && 26266630Sdim- // Under -flimit-debug-info, emit only a declaration unless the type is 27266630Sdim- // required to be complete. 28266630Sdim- !RD->isCompleteDefinitionRequired() && CGM.getLangOpts().CPlusPlus) || 29266630Sdim- // If the class is dynamic, only emit a declaration. A definition will be 30266630Sdim- // emitted whenever the vtable is emitted. 31266630Sdim- (CXXDecl && CXXDecl->hasDefinition() && CXXDecl->isDynamicClass()) || T) { 32266630Sdim+ // Emit only a forward declaration unless the type is required. 33266630Sdim+ ((!RD->isCompleteDefinitionRequired() && CGM.getLangOpts().CPlusPlus) || 34266630Sdim+ // If the class is dynamic, only emit a declaration. A definition will be 35266630Sdim+ // emitted whenever the vtable is emitted. 36266630Sdim+ (CXXDecl && CXXDecl->hasDefinition() && CXXDecl->isDynamicClass())))) { 37266630Sdim llvm::DIDescriptor FDContext = 38266630Sdim getContextDescriptor(cast<Decl>(RD->getDeclContext())); 39266630Sdim if (!T) 40266630SdimIndex: tools/clang/lib/Frontend/CompilerInvocation.cpp 41266630Sdim=================================================================== 42266630Sdim--- tools/clang/lib/Frontend/CompilerInvocation.cpp 43266630Sdim+++ tools/clang/lib/Frontend/CompilerInvocation.cpp 44266630Sdim@@ -295,7 +295,8 @@ static void ParseCommentArgs(CommentOptions &Opts, 45266630Sdim } 46266630Sdim 47266630Sdim static bool ParseCodeGenArgs(CodeGenOptions &Opts, ArgList &Args, InputKind IK, 48266630Sdim- DiagnosticsEngine &Diags) { 49266630Sdim+ DiagnosticsEngine &Diags, 50266630Sdim+ const TargetOptions &TargetOpts) { 51266630Sdim using namespace options; 52266630Sdim bool Success = true; 53266630Sdim 54266630Sdim@@ -322,10 +323,16 @@ static bool ParseCodeGenArgs(CodeGenOptions &Opts, 55266630Sdim Opts.setDebugInfo(CodeGenOptions::DebugLineTablesOnly); 56266630Sdim } else if (Args.hasArg(OPT_g_Flag) || Args.hasArg(OPT_gdwarf_2) || 57266630Sdim Args.hasArg(OPT_gdwarf_3) || Args.hasArg(OPT_gdwarf_4)) { 58266630Sdim- if (Args.hasFlag(OPT_flimit_debug_info, OPT_fno_limit_debug_info, true)) 59266630Sdim+ bool Default = false; 60266630Sdim+ // Until dtrace (via CTF) can deal with distributed debug info, 61266630Sdim+ // Darwin defaults to standalone/full debug info. 62266630Sdim+ if (llvm::Triple(TargetOpts.Triple).isOSDarwin()) 63266630Sdim+ Default = true; 64266630Sdim+ 65266630Sdim+ if (Args.hasFlag(OPT_fstandalone_debug, OPT_fno_standalone_debug, Default)) 66266630Sdim+ Opts.setDebugInfo(CodeGenOptions::FullDebugInfo); 67266630Sdim+ else 68266630Sdim Opts.setDebugInfo(CodeGenOptions::LimitedDebugInfo); 69266630Sdim- else 70266630Sdim- Opts.setDebugInfo(CodeGenOptions::FullDebugInfo); 71266630Sdim } 72266630Sdim Opts.DebugColumnInfo = Args.hasArg(OPT_dwarf_column_info); 73266630Sdim Opts.SplitDwarfFile = Args.getLastArgValue(OPT_split_dwarf_file); 74266630Sdim@@ -1657,8 +1664,9 @@ bool CompilerInvocation::CreateFromArgs(CompilerIn 75266630Sdim ParseFileSystemArgs(Res.getFileSystemOpts(), *Args); 76266630Sdim // FIXME: We shouldn't have to pass the DashX option around here 77266630Sdim InputKind DashX = ParseFrontendArgs(Res.getFrontendOpts(), *Args, Diags); 78266630Sdim- Success = ParseCodeGenArgs(Res.getCodeGenOpts(), *Args, DashX, Diags) 79266630Sdim- && Success; 80266630Sdim+ ParseTargetArgs(Res.getTargetOpts(), *Args); 81266630Sdim+ Success = ParseCodeGenArgs(Res.getCodeGenOpts(), *Args, DashX, Diags, 82266630Sdim+ Res.getTargetOpts()) && Success; 83266630Sdim ParseHeaderSearchArgs(Res.getHeaderSearchOpts(), *Args); 84266630Sdim if (DashX != IK_AST && DashX != IK_LLVM_IR) { 85266630Sdim ParseLangArgs(*Res.getLangOpts(), *Args, DashX, Diags); 86266630Sdim@@ -1673,8 +1681,6 @@ bool CompilerInvocation::CreateFromArgs(CompilerIn 87266630Sdim ParsePreprocessorArgs(Res.getPreprocessorOpts(), *Args, FileMgr, Diags); 88266630Sdim ParsePreprocessorOutputArgs(Res.getPreprocessorOutputOpts(), *Args, 89266630Sdim Res.getFrontendOpts().ProgramAction); 90266630Sdim- ParseTargetArgs(Res.getTargetOpts(), *Args); 91266630Sdim- 92266630Sdim return Success; 93266630Sdim } 94266630Sdim 95266630SdimIndex: tools/clang/lib/Driver/Tools.cpp 96266630Sdim=================================================================== 97266630Sdim--- tools/clang/lib/Driver/Tools.cpp 98266630Sdim+++ tools/clang/lib/Driver/Tools.cpp 99266630Sdim@@ -2995,8 +2995,8 @@ void Clang::ConstructJob(Compilation &C, const Job 100266630Sdim Args.AddLastArg(CmdArgs, options::OPT_femit_all_decls); 101266630Sdim Args.AddLastArg(CmdArgs, options::OPT_fformat_extensions); 102266630Sdim Args.AddLastArg(CmdArgs, options::OPT_fheinous_gnu_extensions); 103266630Sdim- Args.AddLastArg(CmdArgs, options::OPT_flimit_debug_info); 104266630Sdim- Args.AddLastArg(CmdArgs, options::OPT_fno_limit_debug_info); 105266630Sdim+ Args.AddLastArg(CmdArgs, options::OPT_fstandalone_debug); 106266630Sdim+ Args.AddLastArg(CmdArgs, options::OPT_fno_standalone_debug); 107266630Sdim Args.AddLastArg(CmdArgs, options::OPT_fno_operator_names); 108266630Sdim // AltiVec language extensions aren't relevant for assembling. 109266630Sdim if (!isa<PreprocessJobAction>(JA) || 110266630SdimIndex: tools/clang/test/CodeGenCXX/debug-info-template-member.cpp 111266630Sdim=================================================================== 112266630Sdim--- tools/clang/test/CodeGenCXX/debug-info-template-member.cpp 113266630Sdim+++ tools/clang/test/CodeGenCXX/debug-info-template-member.cpp 114266630Sdim@@ -1,4 +1,4 @@ 115266630Sdim-// RUN: %clang_cc1 -emit-llvm -g -triple x86_64-apple-darwin %s -o - | FileCheck %s 116266630Sdim+// RUN: %clang_cc1 -emit-llvm -g -fno-standalone-debug -triple x86_64-apple-darwin %s -o - | FileCheck %s 117266630Sdim 118266630Sdim struct MyClass { 119266630Sdim template <int i> int add(int j) { 120266630SdimIndex: tools/clang/test/CodeGenCXX/debug-info-vtable-optzn.cpp 121266630Sdim=================================================================== 122266630Sdim--- tools/clang/test/CodeGenCXX/debug-info-vtable-optzn.cpp 123266630Sdim+++ tools/clang/test/CodeGenCXX/debug-info-vtable-optzn.cpp 124266630Sdim@@ -0,0 +1,21 @@ 125266630Sdim+// RUN: %clang_cc1 -emit-llvm -g -triple x86_64-apple-darwin %s -o - | FileCheck %s 126266630Sdim+// 127266630Sdim+// This tests that the "emit debug info for a C++ class only in the 128266630Sdim+// module that has its vtable" optimization is disabled by default on 129266630Sdim+// Darwin. 130266630Sdim+// 131266630Sdim+// CHECK: [ DW_TAG_member ] [lost] 132266630Sdim+class A 133266630Sdim+{ 134266630Sdim+ virtual bool f() = 0; 135266630Sdim+ int lost; 136266630Sdim+}; 137266630Sdim+ 138266630Sdim+class B : public A 139266630Sdim+{ 140266630Sdim+ B *g(); 141266630Sdim+}; 142266630Sdim+ 143266630Sdim+B *B::g() { 144266630Sdim+ return this; 145266630Sdim+} 146266630SdimIndex: tools/clang/test/CodeGenCXX/debug-info-namespace.cpp 147266630Sdim=================================================================== 148266630Sdim--- tools/clang/test/CodeGenCXX/debug-info-namespace.cpp 149266630Sdim+++ tools/clang/test/CodeGenCXX/debug-info-namespace.cpp 150266630Sdim@@ -1,6 +1,6 @@ 151266630Sdim-// RUN: %clang -g -S -emit-llvm %s -o - | FileCheck %s 152266630Sdim-// RUN: %clang -g -gline-tables-only -S -emit-llvm %s -o - | FileCheck -check-prefix=CHECK-GMLT %s 153266630Sdim-// RUN: %clang -g -fno-limit-debug-info -S -emit-llvm %s -o - | FileCheck -check-prefix=CHECK-NOLIMIT %s 154266630Sdim+// RUN: %clang -g -fno-standalone-debug -S -emit-llvm %s -o - | FileCheck %s 155266630Sdim+// RUN: %clang -g -gline-tables-only -S -emit-llvm %s -o - | FileCheck -check-prefix=CHECK-GMLT %s 156266630Sdim+// RUN: %clang -g -fstandalone-debug -S -emit-llvm %s -o - | FileCheck -check-prefix=CHECK-NOLIMIT %s 157266630Sdim 158266630Sdim namespace A { 159266630Sdim #line 1 "foo.cpp" 160266630SdimIndex: tools/clang/test/CodeGenCXX/debug-info-class-limited.cpp 161266630Sdim=================================================================== 162266630Sdim--- tools/clang/test/CodeGenCXX/debug-info-class-limited.cpp 163266630Sdim+++ tools/clang/test/CodeGenCXX/debug-info-class-limited.cpp 164266630Sdim@@ -1,4 +1,4 @@ 165266630Sdim-// RUN: %clang -emit-llvm -g -S %s -o - | FileCheck %s 166266630Sdim+// RUN: %clang -emit-llvm -fno-standalone-debug -g -S %s -o - | FileCheck %s 167266630Sdim 168266630Sdim namespace PR16214_1 { 169266630Sdim // CHECK-DAG: [ DW_TAG_structure_type ] [foo] [line [[@LINE+1]], {{.*}} [def] 170266630SdimIndex: tools/clang/test/CodeGenCXX/debug-info-method2.cpp 171266630Sdim=================================================================== 172266630Sdim--- tools/clang/test/CodeGenCXX/debug-info-method2.cpp 173266630Sdim+++ tools/clang/test/CodeGenCXX/debug-info-method2.cpp 174266630Sdim@@ -1,4 +1,4 @@ 175266630Sdim-// RUN: %clang_cc1 -flimit-debug-info -x c++ -g -S -emit-llvm < %s | FileCheck %s 176266630Sdim+// RUN: %clang_cc1 -fno-standalone-debug -x c++ -g -S -emit-llvm < %s | FileCheck %s 177266630Sdim // rdar://10336845 178266630Sdim // Preserve type qualifiers in -flimit-debug-info mode. 179266630Sdim 180266630SdimIndex: tools/clang/test/CodeGenCXX/debug-info-dup-fwd-decl.cpp 181266630Sdim=================================================================== 182266630Sdim--- tools/clang/test/CodeGenCXX/debug-info-dup-fwd-decl.cpp 183266630Sdim+++ tools/clang/test/CodeGenCXX/debug-info-dup-fwd-decl.cpp 184266630Sdim@@ -1,4 +1,4 @@ 185266630Sdim-// RUN: %clang_cc1 -emit-llvm -g -triple x86_64-apple-darwin -fno-limit-debug-info %s -o - | FileCheck %s 186266630Sdim+// RUN: %clang_cc1 -emit-llvm -g -triple x86_64-apple-darwin -fstandalone-debug %s -o - | FileCheck %s 187266630Sdim 188266630Sdim class Test 189266630Sdim { 190266630SdimIndex: tools/clang/test/CodeGenCXX/debug-info-class-nolimit.cpp 191266630Sdim=================================================================== 192266630Sdim--- tools/clang/test/CodeGenCXX/debug-info-class-nolimit.cpp 193266630Sdim+++ tools/clang/test/CodeGenCXX/debug-info-class-nolimit.cpp 194266630Sdim@@ -1,4 +1,6 @@ 195266630Sdim-// RUN: %clang_cc1 -triple x86_64-unk-unk -fno-limit-debug-info -o - -emit-llvm -g %s | FileCheck %s 196266630Sdim+// RUN: %clang_cc1 -triple x86_64-unk-unk -fstandalone-debug -o - -emit-llvm -g %s | FileCheck %s 197266630Sdim+// On Darwin, this should be the default: 198266630Sdim+// RUN: %clang_cc1 -triple x86_64-apple-darwin -o - -emit-llvm -g %s | FileCheck %s 199266630Sdim 200266630Sdim namespace rdar14101097_1 { // see also PR16214 201266630Sdim // Check that we emit debug info for the definition of a struct if the 202266630SdimIndex: tools/clang/test/CodeGenCXX/debug-info-template-limit.cpp 203266630Sdim=================================================================== 204266630Sdim--- tools/clang/test/CodeGenCXX/debug-info-template-limit.cpp 205266630Sdim+++ tools/clang/test/CodeGenCXX/debug-info-template-limit.cpp 206266630Sdim@@ -1,4 +1,4 @@ 207266630Sdim-// RUN: %clang -flimit-debug-info -emit-llvm -g -S %s -o - | FileCheck %s 208266630Sdim+// RUN: %clang -fno-standalone-debug -emit-llvm -g -S %s -o - | FileCheck %s 209266630Sdim 210266630Sdim // Check that this pointer type is TC<int> 211266630Sdim // CHECK: ![[LINE:[0-9]+]] = {{.*}}"TC<int>", {{.*}} metadata !"_ZTS2TCIiE"} ; [ DW_TAG_class_type ] 212266630SdimIndex: tools/clang/test/CodeGenCXX/debug-info-pubtypes.cpp 213266630Sdim=================================================================== 214266630Sdim--- tools/clang/test/CodeGenCXX/debug-info-pubtypes.cpp 215266630Sdim+++ tools/clang/test/CodeGenCXX/debug-info-pubtypes.cpp 216266630Sdim@@ -1,5 +1,5 @@ 217266630Sdim // REQUIRES: x86-64-registered-target 218266630Sdim-// RUN: %clang_cc1 -triple x86_64-apple-darwin10 -g -fno-limit-debug-info -S -mllvm -generate-dwarf-pub-sections=Enable %s -o - | FileCheck %s 219266630Sdim+// RUN: %clang_cc1 -triple x86_64-apple-darwin10 -g -fstandalone-debug -S -mllvm -generate-dwarf-pub-sections=Enable %s -o - | FileCheck %s 220266630Sdim 221266630Sdim // FIXME: This testcase shouldn't rely on assembly emission. 222266630Sdim //CHECK: Lpubtypes_begin[[SECNUM:[0-9]:]] 223266630SdimIndex: tools/clang/include/clang/Frontend/CodeGenOptions.h 224266630Sdim=================================================================== 225266630Sdim--- tools/clang/include/clang/Frontend/CodeGenOptions.h 226266630Sdim+++ tools/clang/include/clang/Frontend/CodeGenOptions.h 227266630Sdim@@ -50,12 +50,20 @@ class CodeGenOptions : public CodeGenOptionsBase { 228266630Sdim }; 229266630Sdim 230266630Sdim enum DebugInfoKind { 231266630Sdim- NoDebugInfo, // Don't generate debug info. 232266630Sdim- DebugLineTablesOnly, // Emit only debug info necessary for generating 233266630Sdim- // line number tables (-gline-tables-only). 234266630Sdim- LimitedDebugInfo, // Limit generated debug info to reduce size 235266630Sdim- // (-flimit-debug-info). 236266630Sdim- FullDebugInfo // Generate complete debug info. 237266630Sdim+ NoDebugInfo, /// Don't generate debug info. 238266630Sdim+ 239266630Sdim+ DebugLineTablesOnly, /// Emit only debug info necessary for generating 240266630Sdim+ /// line number tables (-gline-tables-only). 241266630Sdim+ 242266630Sdim+ LimitedDebugInfo, /// Limit generated debug info to reduce size 243266630Sdim+ /// (-fno-standalone-debug). This emits 244266630Sdim+ /// forward decls for types that could be 245266630Sdim+ /// replaced with forward decls in the source 246266630Sdim+ /// code. For dynamic C++ classes type info 247266630Sdim+ /// is only emitted int the module that 248266630Sdim+ /// contains the classe's vtable. 249266630Sdim+ 250266630Sdim+ FullDebugInfo /// Generate complete debug info. 251266630Sdim }; 252266630Sdim 253266630Sdim enum TLSModel { 254266630SdimIndex: tools/clang/include/clang/Driver/Options.td 255266630Sdim=================================================================== 256266630Sdim--- tools/clang/include/clang/Driver/Options.td 257266630Sdim+++ tools/clang/include/clang/Driver/Options.td 258266630Sdim@@ -549,8 +549,6 @@ def finstrument_functions : Flag<["-"], "finstrume 259266630Sdim def fkeep_inline_functions : Flag<["-"], "fkeep-inline-functions">, Group<clang_ignored_f_Group>; 260266630Sdim def flat__namespace : Flag<["-"], "flat_namespace">; 261266630Sdim def flax_vector_conversions : Flag<["-"], "flax-vector-conversions">, Group<f_Group>; 262266630Sdim-def flimit_debug_info : Flag<["-"], "flimit-debug-info">, Group<f_Group>, Flags<[CC1Option]>, 263266630Sdim- HelpText<"Limit debug information produced to reduce size of debug binary">; 264266630Sdim def flimited_precision_EQ : Joined<["-"], "flimited-precision=">, Group<f_Group>; 265266630Sdim def flto : Flag<["-"], "flto">, Group<f_Group>; 266266630Sdim def fno_lto : Flag<["-"], "fno-lto">, Group<f_Group>; 267266630Sdim@@ -645,8 +643,6 @@ def fno_inline : Flag<["-"], "fno-inline">, Group< 268266630Sdim def fno_keep_inline_functions : Flag<["-"], "fno-keep-inline-functions">, Group<clang_ignored_f_Group>; 269266630Sdim def fno_lax_vector_conversions : Flag<["-"], "fno-lax-vector-conversions">, Group<f_Group>, 270266630Sdim HelpText<"Disallow implicit conversions between vectors with a different number of elements or different element types">, Flags<[CC1Option]>; 271266630Sdim-def fno_limit_debug_info : Flag<["-"], "fno-limit-debug-info">, Group<f_Group>, Flags<[CC1Option]>, 272266630Sdim- HelpText<"Do not limit debug information produced to reduce size of debug binary">; 273266630Sdim def fno_merge_all_constants : Flag<["-"], "fno-merge-all-constants">, Group<f_Group>, 274266630Sdim Flags<[CC1Option]>, HelpText<"Disallow merging of constants">; 275266630Sdim def fno_modules : Flag <["-"], "fno-modules">, Group<f_Group>, 276266630Sdim@@ -774,6 +770,12 @@ def fno_signed_char : Flag<["-"], "fno-signed-char 277266630Sdim def fsplit_stack : Flag<["-"], "fsplit-stack">, Group<f_Group>; 278266630Sdim def fstack_protector_all : Flag<["-"], "fstack-protector-all">, Group<f_Group>; 279266630Sdim def fstack_protector : Flag<["-"], "fstack-protector">, Group<f_Group>; 280266630Sdim+def fstandalone_debug : Flag<["-"], "fstandalone-debug">, Group<f_Group>, Flags<[CC1Option]>, 281266630Sdim+ HelpText<"Emit full debug info for all types used by the program">; 282266630Sdim+def fno_standalone_debug : Flag<["-"], "fno-standalone-debug">, Group<f_Group>, Flags<[CC1Option]>, 283266630Sdim+ HelpText<"Limit debug information produced to reduce size of debug binary">; 284266630Sdim+def flimit_debug_info : Flag<["-"], "flimit-debug-info">, Alias<fno_standalone_debug>; 285266630Sdim+def fno_limit_debug_info : Flag<["-"], "fno-limit-debug-info">, Alias<fstandalone_debug>; 286266630Sdim def fstrict_aliasing : Flag<["-"], "fstrict-aliasing">, Group<f_Group>; 287266630Sdim def fstrict_enums : Flag<["-"], "fstrict-enums">, Group<f_Group>, Flags<[CC1Option]>, 288266630Sdim HelpText<"Enable optimizations based on the strict definition of an enum's " 289266630SdimIndex: tools/clang/docs/tools/clang.pod 290266630Sdim=================================================================== 291266630Sdim--- tools/clang/docs/tools/clang.pod 292266630Sdim+++ tools/clang/docs/tools/clang.pod 293266630Sdim@@ -310,9 +310,23 @@ Currently equivalent to B<-O3> 294266630Sdim =item B<-g> 295266630Sdim 296266630Sdim Generate debug information. Note that Clang debug information works best at 297266630Sdim-B<-O0>. At higher optimization levels, only line number information is 298266630Sdim-currently available. 299266630Sdim+B<-O0>. 300266630Sdim 301266630Sdim+=item B<-fstandalone-debug> B<-fno-standalone-debug> 302266630Sdim+ 303266630Sdim+Clang supports a number of optimizations to reduce the size of debug 304266630Sdim+information in the binary. They work based on the assumption that the 305266630Sdim+debug type information can be spread out over multiple compilation 306266630Sdim+units. For instance, Clang will not emit type definitions for types 307266630Sdim+that are not needed by a module and could be replaced with a forward 308266630Sdim+declaration. Further, Clang will only emit type info for a dynamic 309266630Sdim+C++ class in the module that contains the vtable for the class. 310266630Sdim+ 311266630Sdim+The B<-fstandalone-debug> option turns off these optimizations. This 312266630Sdim+is useful when working with 3rd-party libraries that don't come with 313266630Sdim+debug information. Note that Clang will never emit type information 314266630Sdim+for types that are not referenced at all by the program. 315266630Sdim+ 316266630Sdim =item B<-fexceptions> 317266630Sdim 318266630Sdim Enable generation of unwind information, this allows exceptions to be thrown 319