Skip to content

Commit 0eb7a31

Browse files
Merge pull request #7749 from adrian-prantl/117881604-725
[dsymutil] Filter our swiftinterface files from the toolchain. (llvm#71205)
2 parents c88cc4d + f878151 commit 0eb7a31

File tree

3 files changed

+60
-26
lines changed

3 files changed

+60
-26
lines changed

llvm/lib/DWARFLinker/DWARFLinker.cpp

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -177,6 +177,20 @@ static void resolveRelativeObjectPath(SmallVectorImpl<char> &Buf, DWARFDie CU) {
177177
sys::path::append(Buf, dwarf::toString(CU.find(dwarf::DW_AT_comp_dir), ""));
178178
}
179179

180+
/// Make a best effort to guess the
181+
/// Xcode.app/Contents/Developer/Toolchains/ path from an SDK path.
182+
static SmallString<128> guessToolchainBaseDir(StringRef SysRoot) {
183+
SmallString<128> Result;
184+
// Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX.sdk
185+
StringRef Base = sys::path::parent_path(SysRoot);
186+
if (sys::path::filename(Base) != "SDKs")
187+
return Result;
188+
Base = sys::path::parent_path(Base);
189+
Result = Base;
190+
Result += "/Toolchains";
191+
return Result;
192+
}
193+
180194
/// Collect references to parseable Swift interfaces in imported
181195
/// DW_TAG_module blocks.
182196
static void analyzeImportedModule(
@@ -198,6 +212,11 @@ static void analyzeImportedModule(
198212
SysRoot = CU.getSysRoot();
199213
if (!SysRoot.empty() && Path.startswith(SysRoot))
200214
return;
215+
// Don't track interfaces that are part of the toolchain.
216+
// For example: Swift, _Concurrency, ...
217+
SmallString<128> Toolchain = guessToolchainBaseDir(SysRoot);
218+
if (!Toolchain.empty() && Path.startswith(Toolchain))
219+
return;
201220
std::optional<const char *> Name =
202221
dwarf::toString(DIE.find(dwarf::DW_AT_name));
203222
if (!Name)

llvm/test/tools/dsymutil/Inputs/swift-interface.s

Lines changed: 39 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -15,17 +15,19 @@
1515
##; !llvm.dbg.cu = !{!0}
1616
##; !swift.module.flags = !{!14}
1717
##; !llvm.module.flags = !{!20, !21, !24}
18-
##;
19-
##; !0 = distinct !DICompileUnit(language: DW_LANG_Swift, file: !1, isOptimized: false, runtimeVersion: 5, emissionKind: FullDebug, enums: !2, imports: !3, sysroot: "/SDK")
18+
##;
19+
##; !0 = distinct !DICompileUnit(language: DW_LANG_Swift, file: !1, isOptimized: false, runtimeVersion: 5, emissionKind: FullDebug, enums: !2, imports: !3, sysroot: "/Xcode.app/Contents/Developer/SDKs/MacOSX.sdk")
2020
##; !1 = !DIFile(filename: "ParseableInterfaceImports.swift", directory: "/")
2121
##; !2 = !{}
22-
##; !3 = !{!4, !6, !8}
22+
##; !3 = !{!4, !6, !8, !10}
2323
##; !4 = !DIImportedEntity(tag: DW_TAG_imported_module, scope: !1, entity: !5, file: !1)
2424
##; !5 = !DIModule(scope: null, name: "Foo", includePath: "/Foo/x86_64.swiftinterface")
2525
##; !6 = !DIImportedEntity(tag: DW_TAG_imported_module, scope: !1, entity: !7, file: !1)
26-
##; !7 = !DIModule(scope: null, name: "Swift", includePath: "/SDK/Swift.swiftmodule/x86_64.swiftinterface")
27-
##; !8 = !DIImportedEntity(tag: DW_TAG_imported_module, scope: !1, entity: !7, file: !1)
28-
##; !9 = !DIModule(scope: null, name: "Foundation", includePath: "/SDK/Foundation.swiftmodule")
26+
##; !7 = !DIModule(scope: null, name: "Swift", includePath: "/Xcode.app/Contents/Developer/SDKs/MacOSX.sdk/Swift.swiftmodule/x86_64.swiftinterface")
27+
##; !8 = !DIImportedEntity(tag: DW_TAG_imported_module, scope: !1, entity: !9, file: !1)
28+
##; !9 = !DIModule(scope: null, name: "Foundation", includePath: "/Xcode.app/Contents/Developer/SDKs/MacOSX.sdk/Foundation.swiftmodule")
29+
##; !10 = !DIImportedEntity(tag: DW_TAG_imported_module, scope: !1, entity: !11, file: !1)
30+
##; !11 = !DIModule(scope: null, name: "_Concurrency", includePath: "/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/lib/swift/macosx/_Concurrency.swiftmodule/x86_64-apple-macos.swiftinterface")
2931
##; !14 = !{!"standard-library", i1 false}
3032
##; !20 = !{i32 2, !"Dwarf Version", i32 4}
3133
##; !21 = !{i32 2, !"Debug Info Version", i32 3}
@@ -36,6 +38,7 @@
3638
##; !35 = !DILocation(line: 0, scope: !36)
3739
##; !36 = !DILexicalBlockFile(scope: !29, file: !37, discriminator: 0)
3840
##; !37 = !DIFile(filename: "<compiler-generated>", directory: "")
41+
3942
.section __TEXT,__text,regular,pure_instructions
4043
.macosx_version_min 10, 9
4144
.globl _main ## -- Begin function main
@@ -145,56 +148,68 @@ Ldebug_info_start0:
145148
.set Lset1, Lsection_abbrev-Lsection_abbrev ## Offset Into Abbrev. Section
146149
.long Lset1
147150
.byte 8 ## Address Size (in bytes)
148-
.byte 1 ## Abbrev [1] 0xb:0x60 DW_TAG_compile_unit
151+
.byte 1 ## Abbrev [1] 0xb:0x77 DW_TAG_compile_unit
149152
.long 0 ## DW_AT_producer
150153
.short 30 ## DW_AT_language
151154
.long 1 ## DW_AT_name
152155
.long 33 ## DW_AT_LLVM_sysroot
153156
.set Lset2, Lline_table_start0-Lsection_line ## DW_AT_stmt_list
154157
.long Lset2
155-
.long 38 ## DW_AT_comp_dir
158+
.long 79 ## DW_AT_comp_dir
156159
.byte 5 ## DW_AT_APPLE_major_runtime_vers
157160
.quad Lfunc_begin0 ## DW_AT_low_pc
158161
.set Lset3, Lfunc_end0-Lfunc_begin0 ## DW_AT_high_pc
159162
.long Lset3
160163
.byte 2 ## Abbrev [2] 0x2f:0x23 DW_TAG_module
161-
.long 40 ## DW_AT_name
162-
.long 44 ## DW_AT_LLVM_include_path
164+
.long 81 ## DW_AT_name
165+
.long 85 ## DW_AT_LLVM_include_path
163166
.byte 3 ## Abbrev [3] 0x38:0x19 DW_TAG_subprogram
164167
.quad Lfunc_begin0 ## DW_AT_low_pc
165168
.set Lset4, Lfunc_end0-Lfunc_begin0 ## DW_AT_high_pc
166169
.long Lset4
167170
## DW_AT_APPLE_omit_frame_ptr
168171
.byte 1 ## DW_AT_frame_base
169172
.byte 87
170-
.long 122 ## DW_AT_linkage_name
171-
.long 122 ## DW_AT_name
173+
.long 112 ## DW_AT_linkage_name
174+
.long 112 ## DW_AT_name
172175
.byte 1 ## DW_AT_decl_file
173176
.byte 1 ## DW_AT_decl_line
174177
## DW_AT_external
175178
.byte 0 ## End Of Children Mark
176179
.byte 4 ## Abbrev [4] 0x52:0x5 DW_TAG_imported_module
177180
.long 47 ## DW_AT_import
178181
.byte 5 ## Abbrev [5] 0x57:0x9 DW_TAG_module
179-
.long 71 ## DW_AT_name
180-
.long 77 ## DW_AT_LLVM_include_path
182+
.long 117 ## DW_AT_name
183+
.long 123 ## DW_AT_LLVM_include_path
181184
.byte 4 ## Abbrev [4] 0x60:0x5 DW_TAG_imported_module
182185
.long 87 ## DW_AT_import
183-
.byte 4 ## Abbrev [4] 0x65:0x5 DW_TAG_imported_module
184-
.long 87 ## DW_AT_import
186+
.byte 5 ## Abbrev [5] 0x65:0x9 DW_TAG_module
187+
.long 209 ## DW_AT_name
188+
.long 220 ## DW_AT_LLVM_include_path
189+
.byte 4 ## Abbrev [4] 0x6e:0x5 DW_TAG_imported_module
190+
.long 101 ## DW_AT_import
191+
.byte 5 ## Abbrev [5] 0x73:0x9 DW_TAG_module
192+
.long 289 ## DW_AT_name
193+
.long 302 ## DW_AT_LLVM_include_path
194+
.byte 4 ## Abbrev [4] 0x7c:0x5 DW_TAG_imported_module
195+
.long 115 ## DW_AT_import
185196
.byte 0 ## End Of Children Mark
186197
Ldebug_info_end0:
187198
.section __DWARF,__debug_str,regular,debug
188199
Linfo_string:
189200
.byte 0 ## string offset=0
190201
.asciz "ParseableInterfaceImports.swift" ## string offset=1
191-
.asciz "/SDK" ## string offset=33
192-
.asciz "/" ## string offset=38
193-
.asciz "Foo" ## string offset=40
194-
.asciz "/Foo/x86_64.swiftinterface" ## string offset=44
195-
.asciz "Swift" ## string offset=71
196-
.asciz "/SDK/Swift.swiftmodule/x86_64.swiftinterface" ## string offset=77
197-
.asciz "main" ## string offset=122
202+
.asciz "/Xcode.app/Contents/Developer/SDKs/MacOSX.sdk" ## string offset=33
203+
.asciz "/" ## string offset=79
204+
.asciz "Foo" ## string offset=81
205+
.asciz "/Foo/x86_64.swiftinterface" ## string offset=85
206+
.asciz "main" ## string offset=112
207+
.asciz "Swift" ## string offset=117
208+
.asciz "/Xcode.app/Contents/Developer/SDKs/MacOSX.sdk/Swift.swiftmodule/x86_64.swiftinterface" ## string offset=123
209+
.asciz "Foundation" ## string offset=209
210+
.asciz "/Xcode.app/Contents/Developer/SDKs/MacOSX.sdk/Foundation.swiftmodule" ## string offset=220
211+
.asciz "_Concurrency" ## string offset=289
212+
.asciz "/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/lib/swift/macosx/_Concurrency.swiftmodule/x86_64-apple-macos.swiftinterface" ## string offset=302
198213
.section __DWARF,__apple_names,regular,debug
199214
Lnames_begin:
200215
.long 1212240712 ## Header Magic
@@ -212,7 +227,7 @@ Lnames_begin:
212227
.set Lset5, LNames0-Lnames_begin ## Offset in Bucket 0
213228
.long Lset5
214229
LNames0:
215-
.long 122 ## main
230+
.long 112 ## main
216231
.long 1 ## Num DIEs
217232
.long 56
218233
.long 0

llvm/test/tools/dsymutil/X86/swift-interface.test

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,9 +12,9 @@
1212
# RUN: cat %t.dir/swift-interface.dSYM/Contents/Resources/Swift/x86_64/Foo.swiftinterface \
1313
# RUN: | FileCheck %s --check-prefix=INTERFACE
1414

15-
# WARNINGS-NOT: cannot copy parseable Swift interface {{.*}}{{Swift|Foundation}}
15+
# WARNINGS-NOT: cannot copy parseable Swift interface {{.*}}{{Swift|Foundation|_Concurrency}}
1616
# WARNINGS: cannot copy parseable Swift interface {{.*}}Foo
17-
# WARNINGS-NOT: cannot copy parseable Swift interface {{.*}}{{Swift|Foundation}}
17+
# WARNINGS-NOT: cannot copy parseable Swift interface {{.*}}{{Swift|Foundation|_Concurrency}}
1818
# INTERFACE: module Foo
1919

2020
---

0 commit comments

Comments
 (0)