Skip to content

Commit 4a23512

Browse files
committed
Add an option to disable DWARF skeleton CU breadcrumbs for Clang
module imports. This is useful when building redistributable static archives, since any pointers into the CLang module cache won't be portable. When using this option the Clang type fallback path in LLDB will be less useful since DWARF type information from those modules will not be available unless another object file compiled without the option imported the same modules. rdar://problem/48827784
1 parent b3a2e40 commit 4a23512

File tree

5 files changed

+35
-13
lines changed

5 files changed

+35
-13
lines changed

include/swift/AST/IRGenOptions.h

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -104,14 +104,17 @@ class IRGenOptions {
104104
/// Which sanitizer is turned on.
105105
OptionSet<SanitizerKind> Sanitizers;
106106

107+
/// Path prefixes that should be rewritten in debug info.
108+
PathRemapper DebugPrefixMap;
109+
107110
/// What level of debug info to generate.
108111
IRGenDebugInfoLevel DebugInfoLevel : 2;
109112

110113
/// What type of debug info to generate.
111114
IRGenDebugInfoFormat DebugInfoFormat : 2;
112115

113-
/// Path prefixes that should be rewritten in debug info.
114-
PathRemapper DebugPrefixMap;
116+
/// Whether to leave DWARF breadcrumbs pointing to imported Clang modules.
117+
unsigned DisableClangModuleSkeletonCUs : 1;
115118

116119
/// Whether we're generating IR for the JIT.
117120
unsigned UseJIT : 1;
@@ -227,7 +230,9 @@ class IRGenOptions {
227230
Verify(true), OptMode(OptimizationMode::NotSet),
228231
Sanitizers(OptionSet<SanitizerKind>()),
229232
DebugInfoLevel(IRGenDebugInfoLevel::None),
230-
DebugInfoFormat(IRGenDebugInfoFormat::None), UseJIT(false),
233+
DebugInfoFormat(IRGenDebugInfoFormat::None),
234+
DisableClangModuleSkeletonCUs(false),
235+
UseJIT(false),
231236
IntegratedREPL(false), DisableLLVMOptzns(false),
232237
DisableSwiftSpecificLLVMOptzns(false), DisableLLVMSLPVectorizer(false),
233238
DisableFPElim(true), Playground(false), EmitStackPromotionChecks(false),

include/swift/Option/FrontendOptions.td

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -432,6 +432,10 @@ def disable_playground_transform : Flag<["-"], "disable-playground-transform">,
432432
def pc_macro : Flag<["-"], "pc-macro">,
433433
HelpText<"Apply the 'program counter simulation' macro">;
434434

435+
def no_clang_module_breadcrumbs : Flag<["-"], "no-clang-module-breadcrumbs">,
436+
HelpText<"Don't emit DWARF skeleton CUs for imported Clang modules. "
437+
"Use this when building a redistributable static archive.">;
438+
435439
def use_jit : Flag<["-"], "use-jit">,
436440
HelpText<"Register Objective-C classes as if the JIT were in use">;
437441

lib/Frontend/CompilerInvocation.cpp

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1002,6 +1002,9 @@ static bool ParseIRGenArgs(IRGenOptions &Opts, ArgList &Args,
10021002

10031003
Opts.ModuleName = FrontendOpts.ModuleName;
10041004

1005+
if (Args.hasArg(OPT_no_clang_module_breadcrumbs))
1006+
Opts.DisableClangModuleSkeletonCUs = true;
1007+
10051008
if (Args.hasArg(OPT_use_jit))
10061009
Opts.UseJIT = true;
10071010

lib/IRGen/IRGenDebugInfo.cpp

Lines changed: 13 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -640,16 +640,19 @@ class IRGenDebugInfoImpl : public IRGenDebugInfo {
640640
std::string RemappedIncludePath = DebugPrefixMap.remapPath(IncludePath);
641641

642642
// For Clang modules / PCH, create a Skeleton CU pointing to the PCM/PCH.
643-
bool CreateSkeletonCU = !ASTFile.empty();
644-
bool IsRootModule = !Parent;
645-
if (CreateSkeletonCU && IsRootModule) {
646-
llvm::DIBuilder DIB(M);
647-
DIB.createCompileUnit(IGM.ObjCInterop ? llvm::dwarf::DW_LANG_ObjC
648-
: llvm::dwarf::DW_LANG_C99,
649-
DIB.createFile(Name, RemappedIncludePath),
650-
TheCU->getProducer(), true, StringRef(), 0, ASTFile,
651-
llvm::DICompileUnit::FullDebug, Signature);
652-
DIB.finalize();
643+
if (!Opts.DisableClangModuleSkeletonCUs) {
644+
bool CreateSkeletonCU = !ASTFile.empty();
645+
bool IsRootModule = !Parent;
646+
if (CreateSkeletonCU && IsRootModule) {
647+
llvm::DIBuilder DIB(M);
648+
DIB.createCompileUnit(IGM.ObjCInterop ? llvm::dwarf::DW_LANG_ObjC
649+
: llvm::dwarf::DW_LANG_C99,
650+
DIB.createFile(Name, RemappedIncludePath),
651+
TheCU->getProducer(), true, StringRef(), 0,
652+
ASTFile, llvm::DICompileUnit::FullDebug,
653+
Signature);
654+
DIB.finalize();
655+
}
653656
}
654657

655658
StringRef Sysroot = IGM.Context.SearchPathOpts.SDKPath;

test/DebugInfo/ClangModuleBreadcrumbs.swift

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,9 @@
11
// RUN: %target-swift-frontend -emit-ir %s -g -I %S/Inputs \
22
// RUN: -Xcc -DFOO="foo" -Xcc -UBAR -o - | %FileCheck %s
3+
//
4+
// RUN: %target-swift-frontend -emit-ir %s -g -I %S/Inputs \
5+
// RUN: -Xcc -DFOO="foo" -Xcc -UBAR -o - -no-clang-module-breadcrumbs \
6+
// RUN: | %FileCheck %s --check-prefix=NONE
37
import ClangModule.SubModule
48
import OtherClangModule.SubModule
59

@@ -11,3 +15,6 @@ import OtherClangModule.SubModule
1115
// CHECK: !DICompileUnit(language: DW_LANG_{{ObjC|C99}}, {{.*}} producer: "{{.*}}Swift
1216
// CHECK-SAME: OtherClangModule
1317
// CHECK-SAME: dwoId:
18+
19+
// NONE: DICompileUnit({{.*}}
20+
// NONE-NOT: DICompileUnit({{.*}}ClangModule

0 commit comments

Comments
 (0)