From 87b0f4a33cafe87763b4f046bf2fae41adc7f877 Mon Sep 17 00:00:00 2001 From: Francis Ricci Date: Mon, 9 Oct 2017 17:27:47 +0000 Subject: [PATCH] [dsymutil] Emit valid debug locations when no symbol flags are set Summary: swiftc emits symbols without flags set, which led dsymutil to ignore them when searching for global symbols, causing dwarf location data to be omitted. Xcode's dsymutil handles this case correctly, and emits valid location data. Add this functionality to llvm-dsymutil by allowing parsing of symbols with no flags set. Reviewers: aprantl, friss, JDevlieghere Subscribers: llvm-commits Differential Revision: https://reviews.llvm.org/D38587 git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@315218 91177308-0d34-0410-b5e6-96231b3b80d8 --- .../dsymutil/Inputs/swift-dwarf-loc.macho.x86_64 | Bin 0 -> 4320 bytes .../dsymutil/Inputs/swift-dwarf-loc.macho.x86_64.o | Bin 0 -> 1704 bytes test/tools/dsymutil/X86/swift-dwarf-loc.test | 37 +++++++++++++++++++++ tools/dsymutil/MachODebugMapParser.cpp | 4 ++- 4 files changed, 40 insertions(+), 1 deletion(-) create mode 100755 test/tools/dsymutil/Inputs/swift-dwarf-loc.macho.x86_64 create mode 100644 test/tools/dsymutil/Inputs/swift-dwarf-loc.macho.x86_64.o create mode 100644 test/tools/dsymutil/X86/swift-dwarf-loc.test diff --git a/test/tools/dsymutil/Inputs/swift-dwarf-loc.macho.x86_64 b/test/tools/dsymutil/Inputs/swift-dwarf-loc.macho.x86_64 new file mode 100755 index 0000000000000000000000000000000000000000..b232e50944243d16ab3441ef4ce9230c08fc4090 GIT binary patch literal 4320 zcmeHKPfHs?6n|0MsT@WoK5COA*BH z;0Gvp@_Tp_LA>Gffv9e zj3b(aM)Vpu2BfU4eW|c#K)Pvtr?F9!o&W_Cky86D-B0_Y-aqQ}PK?k&PlwX)YjwG@ zoQq_2vOO1KmHXni_WN?=e+%DQlATB*NLibBX(MgC0Uxs1&}vH2OqoYqt+p0ac`q|2lw8>-oXAG z*aBGie`2uko_}A*`G{o(IegFY&cc;iD%~8uJZqd>Ui^3qAFd=C8z-6=rw^IUKF9>H z2=H0%b!h2oggX$aN<)#|zc)6&(~4!lGGH073|Iy% z1C{~HfMvikU>W!y7?{E%yxc=x4cH5?>%#>){rT%Fr|kemR*dj$=j8^xZ?I>1@G^4~ qs|fcpiiDxdlS-#GSqqw;pO7Qyp*huwNjx~nB0A_)f^~xc literal 0 HcmV?d00001 diff --git a/test/tools/dsymutil/Inputs/swift-dwarf-loc.macho.x86_64.o b/test/tools/dsymutil/Inputs/swift-dwarf-loc.macho.x86_64.o new file mode 100644 index 0000000000000000000000000000000000000000..2e34ce3de5b3a4a9616adbb9c33511eeb1b14f3a GIT binary patch literal 1704 zcmb7_-D(p-6vxl(CNZ+QRwCFUMlV!~kQ6c2Vucd?XbQa$4cNPNv)#0j><7u(Mkus* zdRg!VdYcYz6x9FOow0GVC2`<<&7A$^%$eEE!H;jhP7n#5pdf6+9Mok9 z#tfv$@o_^-7WQS%cZOhq8Oy0SBC@Q=9YivKv8?8UwdPTr_7rbues9Rf^G@J-fv@H) z>wdjiR}s;ntfP1|74J=ja#@Aot-Gxk8&*H+#dF|2tv`PFcU?JmrIS&g>_n2Fcy_DR zbGLZE|MC>)p5%QT?Qtfr4Q-*Ee*yaUNm#*#c0 zAII}-CoVBvpW>;$kLTH8*mW)6_PD%}{eF^#tV#Q9Y<&qYXgzoMk#v2tvalXPZ@6%gY zezy#Wx^r;j!Dxw>Gn1SCcBdUV6r0NWw%u!2x`9*0wb~4-gN1o(zE%yWN}k>EX+Z5D zpcOwNYs>DDI4iE2rMzxVoxfmy*+pquS?DG{YBkc$mD1A89b?hZrhQE1cx7(~UcQ7y z!}!Yivu+`z;5Q)r8=Rx=BlCx2#pO93S=|54Vb-~rmi!M0Tr!>V zXb884XzK8lQG?~paW40u1i@H@Xmkr&h@a+ZXu%l}G43pphH(Re{uKDBOK? + +@_var = hidden global %TSi zeroinitializer, align 8, !dbg !0 + +!llvm.dbg.cu = !{!8} +!llvm.module.flags = !{!11, !12} + +!0 = !DIGlobalVariableExpression(var: !1, expr: !DIExpression()) +!1 = distinct !DIGlobalVariable(name: "x", linkageName: "_var", scope: !2, file: !3, line: 1, type: !4, isLocal: false, isDefinition: true) +!2 = !DIModule(scope: null, name: "main") +!3 = !DIFile(filename: "", directory: "") +!4 = !DICompositeType(tag: DW_TAG_structure_type, name: "Int", scope: !6, file: !5, size: 64, elements: !7, runtimeLang: DW_LANG_Swift, identifier: "_T0SiD") +!5 = !DIFile(filename: "foo", directory: "/tmp") +!6 = !DIModule(scope: null, name: "foo", includePath: "") +!7 = !{} +!8 = distinct !DICompileUnit(language: DW_LANG_Swift, file: !9, producer: "swiftc", isOptimized: false, flags: "", runtimeVersion: 4, emissionKind: FullDebug, enums: !7, globals: !10, imports: null) +!9 = !DIFile(filename: "/tmp", directory: "") +!10 = !{!0} +!11 = !{i32 2, !"Dwarf Version", i32 4} +!12 = !{i32 2, !"Debug Info Version", i32 3} + +Compiled with: llc -filetype=obj %p/../Inputs/swift-dwarf-loc.ll -mtriple x86_64-apple-darwin +Linked with: ld -dylib %T/swift-dwarf-loc.o -arch x86_64 -lSystem -macosx_version_min 10.9.0 + +CHECK: __var, +CHECK-NOT: __var,{{.*}}binAddr: 0x0000000000000000 +CHECK-NOT: __var{{.*}} => 0000000000000000 diff --git a/tools/dsymutil/MachODebugMapParser.cpp b/tools/dsymutil/MachODebugMapParser.cpp index 79b19137119..0cd6a89cc01 100644 --- a/tools/dsymutil/MachODebugMapParser.cpp +++ b/tools/dsymutil/MachODebugMapParser.cpp @@ -482,7 +482,9 @@ void MachODebugMapParser::loadMainBinarySymbols( // are the only ones that need to be queried because the address // of common data won't be described in the debug map. All other // addresses should be fetched for the debug map. - if (!(Sym.getFlags() & SymbolRef::SF_Global)) + uint8_t SymType = + MainBinary.getSymbolTableEntry(Sym.getRawDataRefImpl()).n_type; + if (!(SymType & (MachO::N_EXT | MachO::N_PEXT))) continue; Expected SectionOrErr = Sym.getSection(); if (!SectionOrErr) { -- 2.11.0