<div dir="ltr"><br><br><div class="gmail_quote"><div dir="ltr">On Wed, Sep 13, 2017 at 10:52 PM Dean Michael Berris via Phabricator <<a href="mailto:reviews@reviews.llvm.org">reviews@reviews.llvm.org</a>> wrote:<br></div><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">dberris updated this revision to Diff 115167.<br>
dberris edited the summary of this revision.<br>
dberris added reviewers: dblaikie, echristo.<br>
dberris added a comment.<br>
Herald added a subscriber: JDevlieghere.<br>
<br>
Reworded description, added a test.<br>
<br>
<br>
<a href="https://reviews.llvm.org/D37791" rel="noreferrer" target="_blank">https://reviews.llvm.org/D37791</a><br>
<br>
Files:<br>
  lib/CodeGen/AsmPrinter/AsmPrinter.cpp<br>
  test/DebugInfo/X86/xray-split-dwarf-interaction.ll<br>
<br>
<br>
Index: test/DebugInfo/X86/xray-split-dwarf-interaction.ll<br>
===================================================================<br>
--- /dev/null<br>
+++ test/DebugInfo/X86/xray-split-dwarf-interaction.ll<br>
@@ -0,0 +1,76 @@<br>
+; RUN: %llc_dwarf -split-dwarf-file=input.dwo -O3 -function-sections -data-sections \<br>
+; RUN:     -relocation-model=pic -filetype=obj -generate-type-units -debug-compile -o %t %s<br></blockquote><div><br>Have you tried this without fission/split-dwarf? I imagine it still reproduces (I think it's only type units that are important?)<br> </div><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">
+; RUN: llvm-readelf -sections %t | FileCheck %s<br>
+; Created from:<br>
+; input.cc:<br>
+;<br>
+; class a {<br>
+;   int b();<br>
+; };<br>
+; int a::b() {<br>
+;   for (;;)<br>
+;     ;<br>
+; }<br></blockquote><div><br>Does this function need the for loop inside, or the int return type (rather than void)? I can try to minimize this a bit further if you like.<br><br>It might be good to understand exactly under what conditions the switch to debug_types happens (I can see how it could happen in endFunction for inlined functions - not entirely sure where it happens for this example, though - perhaps you could break on switchSection so you can see/tell me, or I can do it?)<br><br>If a member function is what triggers this (what about a non-member function that takes a struct/class as a parameter?) what about a static function (wilnl lead to simpler IR, no dbg.values, etc)<br> </div><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">
+;<br>
+; ModuleID = 'input.cc'<br>
+source_filename = "input.cc"<br>
+target datalayout = "e-m:e-i64:64-f80:128-n8:16:32:64-S128"<br>
+target triple = "x86_64-pc-linux"<br></blockquote><div><br>I usually strip out these lines ^ I think... <br> </div><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">
+<br>
+%class.a = type { i8 }<br>
+<br>
+; Function Attrs: nounwind readnone uwtable<br>
+define i32 @_ZN1a1bEv(%class.a* nocapture readnone) local_unnamed_addr #0 align 2 !dbg !8 {<br>
+  tail call void @llvm.dbg.value(metadata %class.a* %0, metadata !17, metadata !DIExpression()), !dbg !19 </blockquote><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">
+  br label %2, !dbg !20<br>
+<br>
+; <label>:2:                                      ; preds = %2, %1<br>
+  br label %2, !dbg !21, !llvm.loop !25<br>
+}<br>
+<br>
+; In this test we want to make sure that the xray_instr_map section for `a::b()` is actually<br>
+; associated with the per-function section defined for the function instead of associating with<br>
+; the .debug_types.dwo section.<br>
+;<br>
+; CHECK-DAG: [[FSECT:[0-9]+]]] .text._ZN1a1bEv PROGBITS<br>
+; CHECK-DAG: [{{.*}}] .debug_types.dwo PROGBITS<br>
+; CHECK-DAG: [{{.*}}] xray_instr_map PROGBITS {{.*}} {{.*}} {{.*}} {{.*}} WAL [[FSECT]]<br></blockquote><div><br>Generally I'd put the CHECKs above all the IR, so they're quicker/easier to spot.<br> </div><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">
+<br>
+; Function Attrs: nounwind readnone speculatable<br>
+declare void @llvm.dbg.value(metadata, metadata, metadata) #1<br>
+<br>
+attributes #0 = { nounwind readnone uwtable "correctly-rounded-divide-sqrt-fp-math"="false" "disable-tail-calls"="false" "less-precise-fpmad"="false" "no-frame-pointer-elim"="false" "no-frame-pointer-elim-non-leaf" "no-infs-fp-math"="false" "no-jump-tables"="false" "no-nans-fp-math"="false" "no-signed-zeros-fp-math"="false" "no-trapping-math"="false" "stack-protector-buffer-size"="8" "target-cpu"="x86-64" "target-features"="+fxsr,+mmx,+sse,+sse2,+sse3,+sse4.1,+ssse3,+x87" "unsafe-fp-math"="false" "use-soft-float"="false" "xray-instruction-threshold"="200" }<br>
+attributes #1 = { nounwind readnone speculatable }<br></blockquote><div><br>Usually the attributes are stripped out to simplify the test.<br> </div><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">
+<br>
+!<a href="http://llvm.dbg.cu" rel="noreferrer" target="_blank">llvm.dbg.cu</a> = !{!0}<br>
+!llvm.module.flags = !{!3, !4, !5, !6}<br>
+!llvm.ident = !{!7}<br>
+<br>
+!0 = distinct !DICompileUnit(language: DW_LANG_C_plus_plus, file: !1, producer: "clang version trunk (trunk r312634)", isOptimized: true, runtimeVersion: 0, emissionKind: FullDebug, enums: !2, splitDebugInlining: false, debugInfoForProfiling: true)<br>
+!1 = !DIFile(filename: "input.cc", directory: "/usr/local/google/home/dberris/tmp")<br>
+!2 = !{}<br>
+!3 = !{i32 2, !"Debug Info Version", i32 3}<br>
+!4 = !{i32 1, !"wchar_size", i32 4}<br>
+!5 = !{i32 7, !"PIC Level", i32 2}<br>
+!6 = !{i32 7, !"PIE Level", i32 2}<br>
+!7 = !{!"clang version trunk (trunk r312634)"}<br>
+!8 = distinct !DISubprogram(name: "b", linkageName: "_ZN1a1bEv", scope: !9, file: !1, line: 4, type: !12, isLocal: false, isDefinition: true, scopeLine: 4, flags: DIFlagPrototyped, isOptimized: true, unit: !0, declaration: !11, variables: !16)<br>
+!9 = distinct !DICompositeType(tag: DW_TAG_class_type, name: "a", file: !1, line: 1, size: 8, elements: !10, identifier: "_ZTS1a")<br>
+!10 = !{!11}<br>
+!11 = !DISubprogram(name: "b", linkageName: "_ZN1a1bEv", scope: !9, file: !1, line: 2, type: !12, isLocal: false, isDefinition: false, scopeLine: 2, flags: DIFlagPrototyped, isOptimized: true)<br>
+!12 = !DISubroutineType(types: !13)<br>
+!13 = !{!14, !15}<br>
+!14 = !DIBasicType(name: "int", size: 32, encoding: DW_ATE_signed)<br>
+!15 = !DIDerivedType(tag: DW_TAG_pointer_type, baseType: !9, size: 64, flags: DIFlagArtificial | DIFlagObjectPointer)<br>
+!16 = !{!17}<br>
+!17 = !DILocalVariable(name: "this", arg: 1, scope: !8, type: !18, flags: DIFlagArtificial | DIFlagObjectPointer)<br>
+!18 = !DIDerivedType(tag: DW_TAG_pointer_type, baseType: !9, size: 64)<br>
+!19 = !DILocation(line: 0, scope: !8)<br>
+!20 = !DILocation(line: 5, column: 3, scope: !8)<br>
+!21 = !DILocation(line: 5, column: 3, scope: !22)<br>
+!22 = !DILexicalBlockFile(scope: !23, file: !1, discriminator: 2)<br>
+!23 = distinct !DILexicalBlock(scope: !24, file: !1, line: 5, column: 3)<br>
+!24 = distinct !DILexicalBlock(scope: !8, file: !1, line: 5, column: 3)<br>
+!25 = distinct !{!25, !26, !27}<br>
+!26 = !DILocation(line: 5, column: 3, scope: !24)<br>
+!27 = !DILocation(line: 6, column: 5, scope: !24)<br>
Index: lib/CodeGen/AsmPrinter/AsmPrinter.cpp<br>
===================================================================<br>
--- lib/CodeGen/AsmPrinter/AsmPrinter.cpp<br>
+++ lib/CodeGen/AsmPrinter/AsmPrinter.cpp<br>
@@ -2785,7 +2785,7 @@<br>
   MCSection *InstMap = nullptr;<br>
   MCSection *FnSledIndex = nullptr;<br>
   if (MF->getSubtarget().getTargetTriple().isOSBinFormatELF()) {<br>
-    auto Associated = dyn_cast<MCSymbolELF>(PrevSection->getBeginSymbol());<br>
+    auto Associated = dyn_cast<MCSymbolELF>(CurrentFnSym);<br>
     assert(Associated != nullptr);<br>
     auto Flags = ELF::SHF_WRITE | ELF::SHF_ALLOC | ELF::SHF_LINK_ORDER;<br>
     std::string GroupName;<br>
<br>
<br>
</blockquote></div></div>