From 54c40cfb7bf3f7ba012269c7061c48bbbccedfdf Mon Sep 17 00:00:00 2001 From: Frederic Riss Date: Fri, 7 Aug 2015 15:14:13 +0000 Subject: [PATCH] [dsymutil] Use the new MCDwarfLineTableParams customization to emit linetables llvm-dsymutil has to be able to process debug info produced by other compilers which use different line table settings. The testcase wasn't generated by another compiler, but by a modified clang. git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@244319 91177308-0d34-0410-b5e6-96231b3b80d8 --- .../basic2-custom-linetable.macho.x86_64.o | Bin 0 -> 3144 bytes test/tools/dsymutil/Inputs/basic2.c | 6 +++ .../tools/dsymutil/X86/custom-line-table.test | 40 ++++++++++++++++++ tools/dsymutil/DwarfLinker.cpp | 27 +++++++----- 4 files changed, 63 insertions(+), 10 deletions(-) create mode 100644 test/tools/dsymutil/Inputs/basic2-custom-linetable.macho.x86_64.o create mode 100644 test/tools/dsymutil/X86/custom-line-table.test diff --git a/test/tools/dsymutil/Inputs/basic2-custom-linetable.macho.x86_64.o b/test/tools/dsymutil/Inputs/basic2-custom-linetable.macho.x86_64.o new file mode 100644 index 0000000000000000000000000000000000000000..07b36a20c1da565e05e356028842f8b686c8d9bc GIT binary patch literal 3144 zcmb7G&2Jk;6rb^WH;(N(P68nXf~^op3$2@mh?caaNlA+XRH{NqbD(T&$4OkAwdIcx zq5>76$W|&foZ!G8&?D-J3n-N;n$fj|`6w*YpZ^eJnc-Av`trww`Gwi^V#t z8_!u+{Z`cD(caY)@=GVnvu3eWP-fs=93DHj6|%~`D=eeP&qej{Sf7oT&81YB8!zZe z;Ojl&C6dWPdO_`9Lw*k43MaK!yo@!Iqap76zU2IVXS`lI9H4MO2>gh4TyG&^&8ATp zH(sG38iSoe+gLl`CGz=f+O!h$1h*^RI*;EgUM_iA6~vw2AYCX>k1fQ{kCIj5>~i6y=ggS`s$mZ>&Bphjk1v{YPu3WZ;pxoGIen5__akE|MECx!G2S8%x`20u z=qiBtXg1_WbqiBKzz!s5C%A%m+InA5h#^R*;sTh6*6A=^zXm`G*aN*2ul^BV{wut4 zih}>7rh4{4eEG-lr8_N=A>sJrD|jH``{=<6em;4RLpPLMIlm!qbHv@{yRxd#xOn8{humtx0bebED@LfLvh+CMPR z|4QG%=z(l@Vg5+XcC7E9NG6JzRDUcbj*MFQa;YfFR=Jp-wjb?`RYJg$$QLpTiBj4m z-S!_9Gr63|SSgVx%nI2mp9{6?S}1Hh6>61j$jLJxw9sh#>EK}CM8Jd6Xgx5z8VH~c zUfbt*^q8PALw+qprqd{x5d&n+)Eguue5Z8b;i%Del(umonZ$2kyPQ6CT7u#jEJQ=9 zwVP|)_r%c|0ZVB#YZbO?^tsc$-bu%)HEY+|=Y7{PdYd)pTcfH$0Z((3oR~vT`lS(N z%gmN1Po8$EW^M9(afJ@LY$sLt$VcSlCnxAjEJMm0e|tDiYoZfNj15slHmNK^Y=TIq z(@j~C?*Dc0#1B)IK-;Zb@oKRWh+M4%E+6{kA*D!@)3Uz;-voaPR;fdl!9hp!g@@h*=wi$(69qu{$}-I z%>(d{gDI9avDD7-y4Il! zLtC2A{c6k`9uH>u1c(6a!e1FB>2!g*&a*rNi6jmWLSpTQUxdV8kW=*klyv?abp2$< z8Q-&{6O3`jD$9>q(mZ6Jhs3QgXg^-nS^1!2;IY%V0S S0?%|x;Ok#|$5}Z_`2PdgEnThv literal 0 HcmV?d00001 diff --git a/test/tools/dsymutil/Inputs/basic2.c b/test/tools/dsymutil/Inputs/basic2.c index 13c6d07c2a0..4524e9bc6cc 100644 --- a/test/tools/dsymutil/Inputs/basic2.c +++ b/test/tools/dsymutil/Inputs/basic2.c @@ -20,3 +20,9 @@ int foo(int arg) { return bar(arg+val) + inc() + baz++; } +/* This file was also used to create basic2-custom-linetable.macho.x86_64.o + with a custom clang that had different settings for the linetable + encoding constants: line_base == -1 and line_range == 4. + + clang -c -g basic2.c -o basic2-custom-linetable.macho.x86_64.o +*/ diff --git a/test/tools/dsymutil/X86/custom-line-table.test b/test/tools/dsymutil/X86/custom-line-table.test new file mode 100644 index 00000000000..86fd7e29468 --- /dev/null +++ b/test/tools/dsymutil/X86/custom-line-table.test @@ -0,0 +1,40 @@ +# RUN: llvm-dsymutil -oso-prepend-path %p/../Inputs -y %s -f -o - | llvm-dwarfdump - -debug-dump=line | FileCheck %s + +# This test runs dsymutil on an object file with non-standard (as far +# as llvm is concerned) line table settings. + +--- +triple: 'x86_64-apple-darwin' +objects: + - filename: basic2-custom-linetable.macho.x86_64.o + symbols: + - { sym: _foo, objAddr: 0x0, binAddr: 0x1000, size: 0x12 } + +# CHECK: 0x0000000000001000 19 0 {{.*}} is_stmt +# CHECK: 0x0000000000001012 20 14 {{.*}} is_stmt prologue_end +# CHECK: 0x0000000000001015 20 18 {{.*}} +# CHECK: 0x0000000000001017 20 17 {{.*}} +# CHECK: 0x0000000000001019 20 10 {{.*}} +# CHECK: 0x000000000000101e 20 25 {{.*}} +# CHECK: 0x0000000000001026 20 23 {{.*}} +# CHECK: 0x000000000000102b 20 36 {{.*}} +# CHECK: 0x000000000000103c 20 31 {{.*}} +# CHECK: 0x000000000000103e 20 3 {{.*}} +# CHECK: 0x0000000000001046 20 3 {{.*}} end_sequence + + - { sym: _inc, objAddr: 0x0, binAddr: 0x2000, size: 0x12 } + +# CHECK: 0x0000000000002000 14 0 {{.*}} is_stmt +# CHECK: 0x0000000000002004 15 10 {{.*}} is_stmt prologue_end +# CHECK: 0x0000000000002013 15 3 {{.*}} +# CHECK: 0x0000000000002015 15 3 {{.*}} end_sequence + + - { sym: _unused1, objAddr: 0x0, binAddr: 0x3000, size: 0x12 } + +# CHECK: 0x0000000000003000 10 0 {{.*}} is_stmt +# CHECK: 0x0000000000003004 11 7 {{.*}} is_stmt prologue_end +# CHECK: 0x000000000000300e 11 3 {{.*}} +# CHECK: 0x0000000000003013 12 1 {{.*}} is_stmt +# CHECK: 0x000000000000301c 12 1 {{.*}} is_stmt end_sequence +... + diff --git a/tools/dsymutil/DwarfLinker.cpp b/tools/dsymutil/DwarfLinker.cpp index 68618bc3371..47d08504786 100644 --- a/tools/dsymutil/DwarfLinker.cpp +++ b/tools/dsymutil/DwarfLinker.cpp @@ -618,7 +618,8 @@ public: /// \brief Emit the line table described in \p Rows into the /// debug_line section. - void emitLineTableForUnit(StringRef PrologueBytes, unsigned MinInstLength, + void emitLineTableForUnit(MCDwarfLineTableParams Params, + StringRef PrologueBytes, unsigned MinInstLength, std::vector &Rows, unsigned AdddressSize); @@ -942,7 +943,8 @@ void DwarfStreamer::emitLocationsForUnit(const CompileUnit &Unit, } } -void DwarfStreamer::emitLineTableForUnit(StringRef PrologueBytes, +void DwarfStreamer::emitLineTableForUnit(MCDwarfLineTableParams Params, + StringRef PrologueBytes, unsigned MinInstLength, std::vector &Rows, unsigned PointerSize) { @@ -965,7 +967,7 @@ void DwarfStreamer::emitLineTableForUnit(StringRef PrologueBytes, if (Rows.empty()) { // We only have the dummy entry, dsymutil emits an entry with a 0 // address in that case. - MCDwarfLineAddr::Encode(*MC, INT64_MAX, 0, EncodingOS); + MCDwarfLineAddr::Encode(*MC, Params, INT64_MAX, 0, EncodingOS); MS->EmitBytes(EncodingOS.str()); LineSectionSize += EncodingBuffer.size(); MS->EmitLabel(LineEndSym); @@ -1047,7 +1049,7 @@ void DwarfStreamer::emitLineTableForUnit(StringRef PrologueBytes, int64_t LineDelta = int64_t(Row.Line) - LastLine; if (!Row.EndSequence) { - MCDwarfLineAddr::Encode(*MC, LineDelta, AddressDelta, EncodingOS); + MCDwarfLineAddr::Encode(*MC, Params, LineDelta, AddressDelta, EncodingOS); MS->EmitBytes(EncodingOS.str()); LineSectionSize += EncodingBuffer.size(); EncodingBuffer.resize(0); @@ -1066,7 +1068,7 @@ void DwarfStreamer::emitLineTableForUnit(StringRef PrologueBytes, MS->EmitULEB128IntValue(AddressDelta); LineSectionSize += 1 + getULEB128Size(AddressDelta); } - MCDwarfLineAddr::Encode(*MC, INT64_MAX, 0, EncodingOS); + MCDwarfLineAddr::Encode(*MC, Params, INT64_MAX, 0, EncodingOS); MS->EmitBytes(EncodingOS.str()); LineSectionSize += EncodingBuffer.size(); EncodingBuffer.resize(0); @@ -1078,7 +1080,7 @@ void DwarfStreamer::emitLineTableForUnit(StringRef PrologueBytes, } if (RowsSinceLastSequence) { - MCDwarfLineAddr::Encode(*MC, INT64_MAX, 0, EncodingOS); + MCDwarfLineAddr::Encode(*MC, Params, INT64_MAX, 0, EncodingOS); MS->EmitBytes(EncodingOS.str()); LineSectionSize += EncodingBuffer.size(); EncodingBuffer.resize(0); @@ -2915,13 +2917,18 @@ void DwarfLinker::patchLineTableForUnit(CompileUnit &Unit, // table emitter. if (LineTable.Prologue.Version != 2 || LineTable.Prologue.DefaultIsStmt != DWARF2_LINE_DEFAULT_IS_STMT || - LineTable.Prologue.LineBase != -5 || LineTable.Prologue.LineRange != 14 || - LineTable.Prologue.OpcodeBase != 13) + LineTable.Prologue.OpcodeBase > 13) reportWarning("line table paramters mismatch. Cannot emit."); - else - Streamer->emitLineTableForUnit(LineData.slice(StmtList + 4, PrologueEnd), + else { + MCDwarfLineTableParams Params; + Params.DWARF2LineOpcodeBase = LineTable.Prologue.OpcodeBase; + Params.DWARF2LineBase = LineTable.Prologue.LineBase; + Params.DWARF2LineRange = LineTable.Prologue.LineRange; + Streamer->emitLineTableForUnit(Params, + LineData.slice(StmtList + 4, PrologueEnd), LineTable.Prologue.MinInstLength, NewRows, Unit.getOrigUnit().getAddressByteSize()); + } } void DwarfLinker::emitAcceleratorEntriesForUnit(CompileUnit &Unit) { -- 2.34.1