[llvm] [DWARFLinker] Allow emission of repeated identical discriminators (PR #98255)

David Tellenbach via llvm-commits llvm-commits at lists.llvm.org
Tue Jul 9 17:31:23 PDT 2024


https://github.com/dtellenbach created https://github.com/llvm/llvm-project/pull/98255

Zero discriminator for each row in the line-table to correctly emit repeated but identical discriminators.

Without this patch line-tables like

    0x0000000100003bac     12     20      0   0            65       0
    0x0000000100003bb4     12     30      0   0            65       0
    0x0000000100003bbc     12     28      0   0            65       0
    0x0000000100003bcc     12     17      0   0            65       0

get falsely linked as

    0x0000000100003bac     12     20      0   0            65       0
    0x0000000100003bb4     12     30      0   0             0       0
    0x0000000100003bbc     12     28      0   0             0       0
    0x0000000100003bcc     12     17      0   0             0       0

>From 44f90471acef9664df6f83198ebe372ad1c3522b Mon Sep 17 00:00:00 2001
From: David Tellenbach <dtellenbach at apple.com>
Date: Tue, 9 Jul 2024 16:13:21 -0700
Subject: [PATCH] [DWARFLinker] Allow emission of repeated identical
 discriminators

Zero discriminator for each row in the line-table to correctly emit
repeated but identical discriminators.

Without this patch line-tables like

    0x0000000100003bac     12     20      0   0            65       0
    0x0000000100003bb4     12     30      0   0            65       0
    0x0000000100003bbc     12     28      0   0            65       0
    0x0000000100003bcc     12     17      0   0            65       0

get falsely linked as

    0x0000000100003bac     12     20      0   0            65       0
    0x0000000100003bb4     12     30      0   0             0       0
    0x0000000100003bbc     12     28      0   0             0       0
    0x0000000100003bcc     12     17      0   0             0       0
---
 .../lib/DWARFLinker/Classic/DWARFStreamer.cpp |   1 +
 .../Parallel/DebugLineSectionEmitter.h        |   1 +
 .../tools/dsymutil/ARM/discriminator.test     |  16 +++---
 .../dsymutil/ARM/discriminator_repeated.test  |  51 ++++++++++++++++++
 .../Inputs/discriminator_repeated.arm64.dylib | Bin 0 -> 17072 bytes
 .../Inputs/discriminator_repeated.arm64.o     | Bin 0 -> 2800 bytes
 6 files changed, 60 insertions(+), 9 deletions(-)
 create mode 100644 llvm/test/tools/dsymutil/ARM/discriminator_repeated.test
 create mode 100755 llvm/test/tools/dsymutil/Inputs/discriminator_repeated.arm64.dylib
 create mode 100644 llvm/test/tools/dsymutil/Inputs/discriminator_repeated.arm64.o

diff --git a/llvm/lib/DWARFLinker/Classic/DWARFStreamer.cpp b/llvm/lib/DWARFLinker/Classic/DWARFStreamer.cpp
index cc4ee2a1b4aec..74df2eb9d68ae 100644
--- a/llvm/lib/DWARFLinker/Classic/DWARFStreamer.cpp
+++ b/llvm/lib/DWARFLinker/Classic/DWARFStreamer.cpp
@@ -1110,6 +1110,7 @@ void DwarfStreamer::emitLineTableRows(
       LineSectionSize += /* extended op */ 1 + getULEB128Size(Size + 1) +
                          /* discriminator */ 1 + Size;
     }
+    Discriminator = 0;
 
     if (Isa != Row.Isa) {
       Isa = Row.Isa;
diff --git a/llvm/lib/DWARFLinker/Parallel/DebugLineSectionEmitter.h b/llvm/lib/DWARFLinker/Parallel/DebugLineSectionEmitter.h
index 0c4395589248a..38357c7f97314 100644
--- a/llvm/lib/DWARFLinker/Parallel/DebugLineSectionEmitter.h
+++ b/llvm/lib/DWARFLinker/Parallel/DebugLineSectionEmitter.h
@@ -359,6 +359,7 @@ class DebugLineSectionEmitter {
         Section.emitIntVal(dwarf::DW_LNE_set_discriminator, 1);
         encodeULEB128(Discriminator, Section.OS);
       }
+      Discriminator = 0;
 
       if (Isa != Row.Isa) {
         Isa = Row.Isa;
diff --git a/llvm/test/tools/dsymutil/ARM/discriminator.test b/llvm/test/tools/dsymutil/ARM/discriminator.test
index d89d9af95d281..5d258786889cc 100644
--- a/llvm/test/tools/dsymutil/ARM/discriminator.test
+++ b/llvm/test/tools/dsymutil/ARM/discriminator.test
@@ -6,18 +6,16 @@
 ;
 ; with -g -fdebug-info-for-profiling -O2.
 
-RUN: dsymutil --flat --linker=classic -oso-prepend-path %p -o - \
-RUN:  --oso-prepend-path %p/../Inputs --verify-dwarf=none \
-RUN:  %p/../Inputs/discriminator.arm64.dylib | llvm-dwarfdump -debug-line - \
-RUN:  | FileCheck %s
+RUN: dsymutil --flat --linker=classic -o - --oso-prepend-path %p/../Inputs \
+RUN:  --verify-dwarf=none %p/../Inputs/discriminator.arm64.dylib \
+RUN:  | llvm-dwarfdump -debug-line - | FileCheck %s
 
-RUN: dsymutil --flat --linker=parallel -oso-prepend-path %p -o - \
-RUN:  --oso-prepend-path %p/../Inputs --verify-dwarf=none \
-RUN:  %p/../Inputs/discriminator.arm64.dylib | llvm-dwarfdump -debug-line - \
-RUN:  | FileCheck %s
+RUN: dsymutil --flat --linker=parallel -o - --oso-prepend-path %p/../Inputs \
+RUN:  --verify-dwarf=none %p/../Inputs/discriminator.arm64.dylib \
+RUN:  | llvm-dwarfdump -debug-line - | FileCheck %s
 
 CHECK:          Address            Line   Column File   ISA Discriminator OpIndex Flags
 CHECK-NEXT:     ------------------ ------ ------ ------ --- ------------- ------- -------------
 CHECK-NEXT:     0x0000000000003f98      2     10      0   0             0       0  is_stmt prologue_end
 CHECK-NEXT:     0x0000000000003fa4      2      3      0   0             6       0
-CHECK-NEXT:     0x0000000000003fa8      2      3      0   0             0       0  end_sequence
\ No newline at end of file
+CHECK-NEXT:     0x0000000000003fa8      2      3      0   0             6       0  end_sequence
\ No newline at end of file
diff --git a/llvm/test/tools/dsymutil/ARM/discriminator_repeated.test b/llvm/test/tools/dsymutil/ARM/discriminator_repeated.test
new file mode 100644
index 0000000000000..1c4dfc133abde
--- /dev/null
+++ b/llvm/test/tools/dsymutil/ARM/discriminator_repeated.test
@@ -0,0 +1,51 @@
+; The input at Inputs/discriminator_repeated.arm64.* were
+; produced by compiling
+;
+;    void loop(int X, int Y, unsigned int **A, unsigned int **B, unsigned int **C) {
+;      for (int i = 0; i < X; i++)
+;        for (int j = 0; j < Y; j++)
+;          C[i][j] += A[i][j] + B[i][j];
+;    }
+;
+; with -g -fdebug-info-for-profiling -O2.
+
+RUN: dsymutil --flat --linker=classic -o - --oso-prepend-path %p/../Inputs \
+RUN:  --verify-dwarf=none %p/../Inputs/discriminator_repeated.arm64.dylib \
+RUN:  | llvm-dwarfdump -debug-line - | FileCheck %s
+
+RUN: dsymutil --flat --linker=parallel -o - --oso-prepend-path %p/../Inputs \
+RUN:  --verify-dwarf=none %p/../Inputs/discriminator_repeated.arm64.dylib \
+RUN:  | llvm-dwarfdump -debug-line - | FileCheck %s
+
+CHECK:      Address            Line   Column File   ISA Discriminator OpIndex Flags
+CHECK-NEXT: ------------------ ------ ------ ------ --- ------------- ------- -------------
+CHECK-NEXT: 0x0000000000003e8c      2      3      0   0             2       0  is_stmt prologue_end
+CHECK-NEXT: 0x0000000000003e94      0      3      0   0             0       0
+CHECK-NEXT: 0x0000000000003e98      2     21      0   0             2       0
+CHECK-NEXT: 0x0000000000003ea0      2      3      0   0             2       0
+CHECK-NEXT: 0x0000000000003eac      2     27      0   0             4       0
+CHECK-NEXT: 0x0000000000003eb0      2      3      0   0             2       0
+CHECK-NEXT: 0x0000000000003eb8      3      5      0   0             2       0  is_stmt
+CHECK-NEXT: 0x0000000000003ec0      0      5      0   0             0       0
+CHECK-NEXT: 0x0000000000003ecc      3      5      0   0             2       0
+CHECK-NEXT: 0x0000000000003ed4      0      5      0   0             0       0
+CHECK-NEXT: 0x0000000000003ed8      3      5      0   0             0       0
+CHECK-NEXT: 0x0000000000003eec      4     18      0   0             0       0  is_stmt
+CHECK-NEXT: 0x0000000000003ef0      4     28      0   0             0       0
+CHECK-NEXT: 0x0000000000003ef4      4     15      0   0             0       0
+CHECK-NEXT: 0x0000000000003ef8      4     26      0   0             0       0
+CHECK-NEXT: 0x0000000000003efc      4     15      0   0             0       0
+CHECK-NEXT: 0x0000000000003f04      3     23      0   0             2       0  is_stmt
+CHECK-NEXT: 0x0000000000003f08      3      5      0   0             2       0
+CHECK-NEXT: 0x0000000000003f10      0      5      0   0             0       0
+CHECK-NEXT: 0x0000000000003f14      3      5      0   0             2       0
+CHECK-NEXT: 0x0000000000003f3c      3      5      0   0             0       0
+CHECK-NEXT: 0x0000000000003f4c      4     18      0   0            65       0  is_stmt
+CHECK-NEXT: 0x0000000000003f54      4     28      0   0            65       0
+CHECK-NEXT: 0x0000000000003f5c      4     26      0   0            65       0
+CHECK-NEXT: 0x0000000000003f6c      4     15      0   0            65       0
+CHECK-NEXT: 0x0000000000003f8c      3     29      0   0          4100       0  is_stmt
+CHECK-NEXT: 0x0000000000003f94      0     29      0   0             0       0
+CHECK-NEXT: 0x0000000000003f98      3      5      0   0          4098       0
+CHECK-NEXT: 0x0000000000003fa4      5      1      0   0             0       0  is_stmt
+CHECK-NEXT: 0x0000000000003fa8      5      1      0   0             0       0  is_stmt end_sequence
\ No newline at end of file
diff --git a/llvm/test/tools/dsymutil/Inputs/discriminator_repeated.arm64.dylib b/llvm/test/tools/dsymutil/Inputs/discriminator_repeated.arm64.dylib
new file mode 100755
index 0000000000000000000000000000000000000000..62b7a42499a65f3c1068ee4530432192c2420a87
GIT binary patch
literal 17072
zcmeI4Uu;u#6vxl)pKZ{}+5`n*vMx-BbLpQ^#}*AOlkQI(*Cmvs(Zp-lc2e!1(H0nU
zu+DTrGl;<#AADe_6O=XsW5Re)XA^xPZW$OgVrD>>Feb`g$TG!x&h4$KjhTt@@tow_
z^E>DKe!u(seR^NdonF5EhaNxxv at +Bh)L9k4Fc>HW529|OB+2daxG7U&&VP=zm?q&?
zvPn`R(3emGbfx<p-;u9X$tMAzxUg2PXds!Nk^hyX1Cc|)h+hgudZL&r-S4a;KhL8q
zqWEw7Dfxn<d$yw_sk1|T%C)Pba95`?qr{(AHlyPzN0ukvhrcv+J*qhG55|45U^p1@
zCZaJZ7U&Il69K>38w)qu&HlroU^gy6vjZe$@=kyzjJGLq6UMYBJ(j!&<JIVw(7%da
zhw4I+tx`nKr#b({HsT_B&d)=aFZ8wA`iGty{`T?Ni_Hy~GokW#tHe>IJXTY#{8>#M
z`uv-N12lZM<a-p(4$y|Lg#eZV at t6f~P1<ufo(P1^EyWzR;5yo;%L!0{{t+dndy_qc
zqIz;CfHi*@O0zKmCcp%k025#WOn?b60Vco%m;e)C0!)AjFaajO1egF5U;<2l2`~XB
zzyz286JP>NfC(@GCcp%k025#WOn?b60Vco%m;e)C0!)AjFaajO1egF5U;<2l2`~XB
z at IMi#*1-OA72vLb<du0f)ZJ1Gb&n1lz1kTZctZoQwn7UhtA$ky$#QTzaPCMh=ic47
zZz+O$9p!ie_E)IDZNT-$yGO77Di}wmP#IL0V7Pq2<(!yA%?Zv+MlkAZDy?qO1rvrc
zSggUlZsv09Xzi$=8<|1n1mnUS`mD{hytwt$hEE0U!VQ~qdGo!T+jy^h`<)>;IfEKS
z&8hVtfMzhG(r44P4-96uY|5sSsZsHC>a>_my)FKjdPme?zHE~-1F3h#n$(!sl6p_{
zrOt>@=E$hlypkSs!s2z@`ws4PN?5&+T*|qp at Jy3x>1%3nu2MJ`d+G<LUU?^aQlami
z#>Gbc*?R1|HYlCj7}8SNO!#Y6M2X^d>c1vYq1Xf|6pi)*^}B-_jvrBKg#qp1FWQKD
zxc$l;axEpX7vmm$a_g5TdZ<oI&G=LJE&!dQwkW20EvoRn0E)$udhzpVePvPI1o`t@
z_QnITxW%6cghGKxx7WANV#ZE=ZvqDm)&{$EyR})e*`;lblC{y?`C?ns?nBLw+1o6z
zVn at FZEGyROlLfLZ&*~@fwiXQN3S?_BhsPB*f(qYymHa=wjCqe-l|QSnGig%Et at TQ3
zB_|YKmz7VP{{}&9b9Q1}+HwDIxFfrM?DO&IU*2zDcU=g#&YC~@-E{Ez%wYOMPxOoV
zo=MF&Gczx#p7v;S10N0a4}bUZNc(H`Xa22z?5**wH|EdR*YE19N+&~ieZPHwZFcJR
wXV<zf9TZKyj$`R78+6mpy!pf47cRQ>Pu6|af9qlQiKTN#_S9Iby}F;^PgT8K at c;k-

literal 0
HcmV?d00001

diff --git a/llvm/test/tools/dsymutil/Inputs/discriminator_repeated.arm64.o b/llvm/test/tools/dsymutil/Inputs/discriminator_repeated.arm64.o
new file mode 100644
index 0000000000000000000000000000000000000000..ebfac06d592d8d9d0ed22e7d0a25033a7dad939d
G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