patch-r265477-clang-r198655-standalone-debug.diff revision 269012
1Merge -fstandalone-debug from Clang r198655: 2 3 Implement a new -fstandalone-debug option. rdar://problem/15685848 4 It controls everything that -flimit-debug-info used to, plus the 5 vtable type optimization. The old -fno-limit-debug-info option is now an 6 alias to -fstandalone-debug and vice versa. 7 8 Standalone is the default on Darwin until dtrace is updated to work with 9 non-standalone debug info (rdar://problem/15758808). 10 11 Note: I kept the LimitedDebugInfo name in CodeGenOptions::DebugInfoKind 12 because NoStandaloneDebugInfo sounded even more confusing. 13 14Introduced here: http://svnweb.freebsd.org/changeset/base/265477 15 16Index: tools/clang/lib/CodeGen/CGDebugInfo.cpp 17=================================================================== 18--- tools/clang/lib/CodeGen/CGDebugInfo.cpp 19+++ tools/clang/lib/CodeGen/CGDebugInfo.cpp 20@@ -1456,13 +1456,13 @@ llvm::DIType CGDebugInfo::CreateType(const RecordT 21 // declaration. The completeType, completeRequiredType, and completeClassData 22 // callbacks will handle promoting the declaration to a definition. 23 if (T || 24+ // Under -flimit-debug-info: 25 (DebugKind <= CodeGenOptions::LimitedDebugInfo && 26- // Under -flimit-debug-info, emit only a declaration unless the type is 27- // required to be complete. 28- !RD->isCompleteDefinitionRequired() && CGM.getLangOpts().CPlusPlus) || 29- // If the class is dynamic, only emit a declaration. A definition will be 30- // emitted whenever the vtable is emitted. 31- (CXXDecl && CXXDecl->hasDefinition() && CXXDecl->isDynamicClass()) || T) { 32+ // Emit only a forward declaration unless the type is required. 33+ ((!RD->isCompleteDefinitionRequired() && CGM.getLangOpts().CPlusPlus) || 34+ // If the class is dynamic, only emit a declaration. A definition will be 35+ // emitted whenever the vtable is emitted. 36+ (CXXDecl && CXXDecl->hasDefinition() && CXXDecl->isDynamicClass())))) { 37 llvm::DIDescriptor FDContext = 38 getContextDescriptor(cast<Decl>(RD->getDeclContext())); 39 if (!T) 40Index: tools/clang/lib/Frontend/CompilerInvocation.cpp 41=================================================================== 42--- tools/clang/lib/Frontend/CompilerInvocation.cpp 43+++ tools/clang/lib/Frontend/CompilerInvocation.cpp 44@@ -295,7 +295,8 @@ static void ParseCommentArgs(CommentOptions &Opts, 45 } 46 47 static bool ParseCodeGenArgs(CodeGenOptions &Opts, ArgList &Args, InputKind IK, 48- DiagnosticsEngine &Diags) { 49+ DiagnosticsEngine &Diags, 50+ const TargetOptions &TargetOpts) { 51 using namespace options; 52 bool Success = true; 53 54@@ -322,10 +323,16 @@ static bool ParseCodeGenArgs(CodeGenOptions &Opts, 55 Opts.setDebugInfo(CodeGenOptions::DebugLineTablesOnly); 56 } else if (Args.hasArg(OPT_g_Flag) || Args.hasArg(OPT_gdwarf_2) || 57 Args.hasArg(OPT_gdwarf_3) || Args.hasArg(OPT_gdwarf_4)) { 58- if (Args.hasFlag(OPT_flimit_debug_info, OPT_fno_limit_debug_info, true)) 59+ bool Default = false; 60+ // Until dtrace (via CTF) can deal with distributed debug info, 61+ // Darwin defaults to standalone/full debug info. 62+ if (llvm::Triple(TargetOpts.Triple).isOSDarwin()) 63+ Default = true; 64+ 65+ if (Args.hasFlag(OPT_fstandalone_debug, OPT_fno_standalone_debug, Default)) 66+ Opts.setDebugInfo(CodeGenOptions::FullDebugInfo); 67+ else 68 Opts.setDebugInfo(CodeGenOptions::LimitedDebugInfo); 69- else 70- Opts.setDebugInfo(CodeGenOptions::FullDebugInfo); 71 } 72 Opts.DebugColumnInfo = Args.hasArg(OPT_dwarf_column_info); 73 Opts.SplitDwarfFile = Args.getLastArgValue(OPT_split_dwarf_file); 74@@ -1657,8 +1664,9 @@ bool CompilerInvocation::CreateFromArgs(CompilerIn 75 ParseFileSystemArgs(Res.getFileSystemOpts(), *Args); 76 // FIXME: We shouldn't have to pass the DashX option around here 77 InputKind DashX = ParseFrontendArgs(Res.getFrontendOpts(), *Args, Diags); 78- Success = ParseCodeGenArgs(Res.getCodeGenOpts(), *Args, DashX, Diags) 79- && Success; 80+ ParseTargetArgs(Res.getTargetOpts(), *Args); 81+ Success = ParseCodeGenArgs(Res.getCodeGenOpts(), *Args, DashX, Diags, 82+ Res.getTargetOpts()) && Success; 83 ParseHeaderSearchArgs(Res.getHeaderSearchOpts(), *Args); 84 if (DashX != IK_AST && DashX != IK_LLVM_IR) { 85 ParseLangArgs(*Res.getLangOpts(), *Args, DashX, Diags); 86@@ -1673,8 +1681,6 @@ bool CompilerInvocation::CreateFromArgs(CompilerIn 87 ParsePreprocessorArgs(Res.getPreprocessorOpts(), *Args, FileMgr, Diags); 88 ParsePreprocessorOutputArgs(Res.getPreprocessorOutputOpts(), *Args, 89 Res.getFrontendOpts().ProgramAction); 90- ParseTargetArgs(Res.getTargetOpts(), *Args); 91- 92 return Success; 93 } 94 95Index: tools/clang/lib/Driver/Tools.cpp 96=================================================================== 97--- tools/clang/lib/Driver/Tools.cpp 98+++ tools/clang/lib/Driver/Tools.cpp 99@@ -2995,8 +2995,8 @@ void Clang::ConstructJob(Compilation &C, const Job 100 Args.AddLastArg(CmdArgs, options::OPT_femit_all_decls); 101 Args.AddLastArg(CmdArgs, options::OPT_fformat_extensions); 102 Args.AddLastArg(CmdArgs, options::OPT_fheinous_gnu_extensions); 103- Args.AddLastArg(CmdArgs, options::OPT_flimit_debug_info); 104- Args.AddLastArg(CmdArgs, options::OPT_fno_limit_debug_info); 105+ Args.AddLastArg(CmdArgs, options::OPT_fstandalone_debug); 106+ Args.AddLastArg(CmdArgs, options::OPT_fno_standalone_debug); 107 Args.AddLastArg(CmdArgs, options::OPT_fno_operator_names); 108 // AltiVec language extensions aren't relevant for assembling. 109 if (!isa<PreprocessJobAction>(JA) || 110Index: tools/clang/test/CodeGenCXX/debug-info-template-member.cpp 111=================================================================== 112--- tools/clang/test/CodeGenCXX/debug-info-template-member.cpp 113+++ tools/clang/test/CodeGenCXX/debug-info-template-member.cpp 114@@ -1,4 +1,4 @@ 115-// RUN: %clang_cc1 -emit-llvm -g -triple x86_64-apple-darwin %s -o - | FileCheck %s 116+// RUN: %clang_cc1 -emit-llvm -g -fno-standalone-debug -triple x86_64-apple-darwin %s -o - | FileCheck %s 117 118 struct MyClass { 119 template <int i> int add(int j) { 120Index: tools/clang/test/CodeGenCXX/debug-info-vtable-optzn.cpp 121=================================================================== 122--- tools/clang/test/CodeGenCXX/debug-info-vtable-optzn.cpp 123+++ tools/clang/test/CodeGenCXX/debug-info-vtable-optzn.cpp 124@@ -0,0 +1,21 @@ 125+// RUN: %clang_cc1 -emit-llvm -g -triple x86_64-apple-darwin %s -o - | FileCheck %s 126+// 127+// This tests that the "emit debug info for a C++ class only in the 128+// module that has its vtable" optimization is disabled by default on 129+// Darwin. 130+// 131+// CHECK: [ DW_TAG_member ] [lost] 132+class A 133+{ 134+ virtual bool f() = 0; 135+ int lost; 136+}; 137+ 138+class B : public A 139+{ 140+ B *g(); 141+}; 142+ 143+B *B::g() { 144+ return this; 145+} 146Index: tools/clang/test/CodeGenCXX/debug-info-namespace.cpp 147=================================================================== 148--- tools/clang/test/CodeGenCXX/debug-info-namespace.cpp 149+++ tools/clang/test/CodeGenCXX/debug-info-namespace.cpp 150@@ -1,6 +1,6 @@ 151-// RUN: %clang -g -S -emit-llvm %s -o - | FileCheck %s 152-// RUN: %clang -g -gline-tables-only -S -emit-llvm %s -o - | FileCheck -check-prefix=CHECK-GMLT %s 153-// RUN: %clang -g -fno-limit-debug-info -S -emit-llvm %s -o - | FileCheck -check-prefix=CHECK-NOLIMIT %s 154+// RUN: %clang -g -fno-standalone-debug -S -emit-llvm %s -o - | FileCheck %s 155+// RUN: %clang -g -gline-tables-only -S -emit-llvm %s -o - | FileCheck -check-prefix=CHECK-GMLT %s 156+// RUN: %clang -g -fstandalone-debug -S -emit-llvm %s -o - | FileCheck -check-prefix=CHECK-NOLIMIT %s 157 158 namespace A { 159 #line 1 "foo.cpp" 160Index: tools/clang/test/CodeGenCXX/debug-info-class-limited.cpp 161=================================================================== 162--- tools/clang/test/CodeGenCXX/debug-info-class-limited.cpp 163+++ tools/clang/test/CodeGenCXX/debug-info-class-limited.cpp 164@@ -1,4 +1,4 @@ 165-// RUN: %clang -emit-llvm -g -S %s -o - | FileCheck %s 166+// RUN: %clang -emit-llvm -fno-standalone-debug -g -S %s -o - | FileCheck %s 167 168 namespace PR16214_1 { 169 // CHECK-DAG: [ DW_TAG_structure_type ] [foo] [line [[@LINE+1]], {{.*}} [def] 170Index: tools/clang/test/CodeGenCXX/debug-info-method2.cpp 171=================================================================== 172--- tools/clang/test/CodeGenCXX/debug-info-method2.cpp 173+++ tools/clang/test/CodeGenCXX/debug-info-method2.cpp 174@@ -1,4 +1,4 @@ 175-// RUN: %clang_cc1 -flimit-debug-info -x c++ -g -S -emit-llvm < %s | FileCheck %s 176+// RUN: %clang_cc1 -fno-standalone-debug -x c++ -g -S -emit-llvm < %s | FileCheck %s 177 // rdar://10336845 178 // Preserve type qualifiers in -flimit-debug-info mode. 179 180Index: tools/clang/test/CodeGenCXX/debug-info-dup-fwd-decl.cpp 181=================================================================== 182--- tools/clang/test/CodeGenCXX/debug-info-dup-fwd-decl.cpp 183+++ tools/clang/test/CodeGenCXX/debug-info-dup-fwd-decl.cpp 184@@ -1,4 +1,4 @@ 185-// RUN: %clang_cc1 -emit-llvm -g -triple x86_64-apple-darwin -fno-limit-debug-info %s -o - | FileCheck %s 186+// RUN: %clang_cc1 -emit-llvm -g -triple x86_64-apple-darwin -fstandalone-debug %s -o - | FileCheck %s 187 188 class Test 189 { 190Index: tools/clang/test/CodeGenCXX/debug-info-class-nolimit.cpp 191=================================================================== 192--- tools/clang/test/CodeGenCXX/debug-info-class-nolimit.cpp 193+++ tools/clang/test/CodeGenCXX/debug-info-class-nolimit.cpp 194@@ -1,4 +1,6 @@ 195-// RUN: %clang_cc1 -triple x86_64-unk-unk -fno-limit-debug-info -o - -emit-llvm -g %s | FileCheck %s 196+// RUN: %clang_cc1 -triple x86_64-unk-unk -fstandalone-debug -o - -emit-llvm -g %s | FileCheck %s 197+// On Darwin, this should be the default: 198+// RUN: %clang_cc1 -triple x86_64-apple-darwin -o - -emit-llvm -g %s | FileCheck %s 199 200 namespace rdar14101097_1 { // see also PR16214 201 // Check that we emit debug info for the definition of a struct if the 202Index: tools/clang/test/CodeGenCXX/debug-info-template-limit.cpp 203=================================================================== 204--- tools/clang/test/CodeGenCXX/debug-info-template-limit.cpp 205+++ tools/clang/test/CodeGenCXX/debug-info-template-limit.cpp 206@@ -1,4 +1,4 @@ 207-// RUN: %clang -flimit-debug-info -emit-llvm -g -S %s -o - | FileCheck %s 208+// RUN: %clang -fno-standalone-debug -emit-llvm -g -S %s -o - | FileCheck %s 209 210 // Check that this pointer type is TC<int> 211 // CHECK: ![[LINE:[0-9]+]] = {{.*}}"TC<int>", {{.*}} metadata !"_ZTS2TCIiE"} ; [ DW_TAG_class_type ] 212Index: tools/clang/test/CodeGenCXX/debug-info-pubtypes.cpp 213=================================================================== 214--- tools/clang/test/CodeGenCXX/debug-info-pubtypes.cpp 215+++ tools/clang/test/CodeGenCXX/debug-info-pubtypes.cpp 216@@ -1,5 +1,5 @@ 217 // REQUIRES: x86-64-registered-target 218-// RUN: %clang_cc1 -triple x86_64-apple-darwin10 -g -fno-limit-debug-info -S -mllvm -generate-dwarf-pub-sections=Enable %s -o - | FileCheck %s 219+// RUN: %clang_cc1 -triple x86_64-apple-darwin10 -g -fstandalone-debug -S -mllvm -generate-dwarf-pub-sections=Enable %s -o - | FileCheck %s 220 221 // FIXME: This testcase shouldn't rely on assembly emission. 222 //CHECK: Lpubtypes_begin[[SECNUM:[0-9]:]] 223Index: tools/clang/include/clang/Frontend/CodeGenOptions.h 224=================================================================== 225--- tools/clang/include/clang/Frontend/CodeGenOptions.h 226+++ tools/clang/include/clang/Frontend/CodeGenOptions.h 227@@ -50,12 +50,20 @@ class CodeGenOptions : public CodeGenOptionsBase { 228 }; 229 230 enum DebugInfoKind { 231- NoDebugInfo, // Don't generate debug info. 232- DebugLineTablesOnly, // Emit only debug info necessary for generating 233- // line number tables (-gline-tables-only). 234- LimitedDebugInfo, // Limit generated debug info to reduce size 235- // (-flimit-debug-info). 236- FullDebugInfo // Generate complete debug info. 237+ NoDebugInfo, /// Don't generate debug info. 238+ 239+ DebugLineTablesOnly, /// Emit only debug info necessary for generating 240+ /// line number tables (-gline-tables-only). 241+ 242+ LimitedDebugInfo, /// Limit generated debug info to reduce size 243+ /// (-fno-standalone-debug). This emits 244+ /// forward decls for types that could be 245+ /// replaced with forward decls in the source 246+ /// code. For dynamic C++ classes type info 247+ /// is only emitted int the module that 248+ /// contains the classe's vtable. 249+ 250+ FullDebugInfo /// Generate complete debug info. 251 }; 252 253 enum TLSModel { 254Index: tools/clang/include/clang/Driver/Options.td 255=================================================================== 256--- tools/clang/include/clang/Driver/Options.td 257+++ tools/clang/include/clang/Driver/Options.td 258@@ -549,8 +549,6 @@ def finstrument_functions : Flag<["-"], "finstrume 259 def fkeep_inline_functions : Flag<["-"], "fkeep-inline-functions">, Group<clang_ignored_f_Group>; 260 def flat__namespace : Flag<["-"], "flat_namespace">; 261 def flax_vector_conversions : Flag<["-"], "flax-vector-conversions">, Group<f_Group>; 262-def flimit_debug_info : Flag<["-"], "flimit-debug-info">, Group<f_Group>, Flags<[CC1Option]>, 263- HelpText<"Limit debug information produced to reduce size of debug binary">; 264 def flimited_precision_EQ : Joined<["-"], "flimited-precision=">, Group<f_Group>; 265 def flto : Flag<["-"], "flto">, Group<f_Group>; 266 def fno_lto : Flag<["-"], "fno-lto">, Group<f_Group>; 267@@ -645,8 +643,6 @@ def fno_inline : Flag<["-"], "fno-inline">, Group< 268 def fno_keep_inline_functions : Flag<["-"], "fno-keep-inline-functions">, Group<clang_ignored_f_Group>; 269 def fno_lax_vector_conversions : Flag<["-"], "fno-lax-vector-conversions">, Group<f_Group>, 270 HelpText<"Disallow implicit conversions between vectors with a different number of elements or different element types">, Flags<[CC1Option]>; 271-def fno_limit_debug_info : Flag<["-"], "fno-limit-debug-info">, Group<f_Group>, Flags<[CC1Option]>, 272- HelpText<"Do not limit debug information produced to reduce size of debug binary">; 273 def fno_merge_all_constants : Flag<["-"], "fno-merge-all-constants">, Group<f_Group>, 274 Flags<[CC1Option]>, HelpText<"Disallow merging of constants">; 275 def fno_modules : Flag <["-"], "fno-modules">, Group<f_Group>, 276@@ -774,6 +770,12 @@ def fno_signed_char : Flag<["-"], "fno-signed-char 277 def fsplit_stack : Flag<["-"], "fsplit-stack">, Group<f_Group>; 278 def fstack_protector_all : Flag<["-"], "fstack-protector-all">, Group<f_Group>; 279 def fstack_protector : Flag<["-"], "fstack-protector">, Group<f_Group>; 280+def fstandalone_debug : Flag<["-"], "fstandalone-debug">, Group<f_Group>, Flags<[CC1Option]>, 281+ HelpText<"Emit full debug info for all types used by the program">; 282+def fno_standalone_debug : Flag<["-"], "fno-standalone-debug">, Group<f_Group>, Flags<[CC1Option]>, 283+ HelpText<"Limit debug information produced to reduce size of debug binary">; 284+def flimit_debug_info : Flag<["-"], "flimit-debug-info">, Alias<fno_standalone_debug>; 285+def fno_limit_debug_info : Flag<["-"], "fno-limit-debug-info">, Alias<fstandalone_debug>; 286 def fstrict_aliasing : Flag<["-"], "fstrict-aliasing">, Group<f_Group>; 287 def fstrict_enums : Flag<["-"], "fstrict-enums">, Group<f_Group>, Flags<[CC1Option]>, 288 HelpText<"Enable optimizations based on the strict definition of an enum's " 289Index: tools/clang/docs/tools/clang.pod 290=================================================================== 291--- tools/clang/docs/tools/clang.pod 292+++ tools/clang/docs/tools/clang.pod 293@@ -310,9 +310,23 @@ Currently equivalent to B<-O3> 294 =item B<-g> 295 296 Generate debug information. Note that Clang debug information works best at 297-B<-O0>. At higher optimization levels, only line number information is 298-currently available. 299+B<-O0>. 300 301+=item B<-fstandalone-debug> B<-fno-standalone-debug> 302+ 303+Clang supports a number of optimizations to reduce the size of debug 304+information in the binary. They work based on the assumption that the 305+debug type information can be spread out over multiple compilation 306+units. For instance, Clang will not emit type definitions for types 307+that are not needed by a module and could be replaced with a forward 308+declaration. Further, Clang will only emit type info for a dynamic 309+C++ class in the module that contains the vtable for the class. 310+ 311+The B<-fstandalone-debug> option turns off these optimizations. This 312+is useful when working with 3rd-party libraries that don't come with 313+debug information. Note that Clang will never emit type information 314+for types that are not referenced at all by the program. 315+ 316 =item B<-fexceptions> 317 318 Enable generation of unwind information, this allows exceptions to be thrown 319