From 28b2d0c96f2277b87f50dde6e3e9d6273617b1e6 Mon Sep 17 00:00:00 2001 From: Jonas Devlieghere Date: Thu, 21 Sep 2017 10:28:33 +0000 Subject: [PATCH] [dsymutil] Don't resolve DIE reference to NULL DIE. This patch prevents dsymutil from resolving a reference to a NULL DIE when a bogus reference happens to be coincidentally referencing a NULL DIE. Now this is detected as an invalid reference and a warning is printed. Fixes: https://bugs.llvm.org/show_bug.cgi?id=33873 Differential revision: https://reviews.llvm.org/D38078 git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@313872 91177308-0d34-0410-b5e6-96231b3b80d8 --- test/tools/dsymutil/Inputs/null_die.o | Bin 0 -> 2216 bytes test/tools/dsymutil/null-die.test | 41 ++++++++++++++++++++++++++ tools/dsymutil/DwarfLinker.cpp | 8 +++-- 3 files changed, 47 insertions(+), 2 deletions(-) create mode 100644 test/tools/dsymutil/Inputs/null_die.o create mode 100644 test/tools/dsymutil/null-die.test diff --git a/test/tools/dsymutil/Inputs/null_die.o b/test/tools/dsymutil/Inputs/null_die.o new file mode 100644 index 0000000000000000000000000000000000000000..1abde8676a3d2062f1cf9fc08fc1ad8d449cc406 GIT binary patch literal 2216 zcmb7F%}*0S6o1op+e$wuq7mZx{%GrDu}^P;}*TjDwWY^E)v+In9JJb7hK(&a+Bh5aJ7R%AGS zO*5vnR1Qx=+8giN50Sm>gkc5o#8u{=0Kk+8aY6eWAuUwHZJOSIJcZwj`QF$ zaye1F9J@TWm40>b(buunRJ6A70Z%1+jkK}V+Qv9Q(T;r>TTPmHJJdNNmru`FYHze7 z+M%}CxmoMB+7;{S>5R3iEv7k_X)pP@I$FV+HBD_IZA6pMp3SA_blYgRGuifu{CvhX z@;0Pmkm`htp0*%u*}&>pbGTk{ha-FTh3nW(JX%*2Na=5IhmQwN1p4sVbW2yP9$&90 z$cTztq(l*;lzyR}CU_4(te)H>fl##VuVKK<|l_LVX?#zj-DH&x|pJ(Bnlz3#7!ENhd6o{acDv&qGn@W@Fh_ySjga& zfk7%no~(T3$;ZG8>qw~bYF^$Mh3We*?!7`8M;~?Y1TrrTX>-KBP@}ux5Czz; za0o}{RDy|RO@(oQ9mSJjO0edl0`C=f%_W76Dlm)Mpu!3+7b5WFQbp|U5U@goMS?#6 zG6w0(`;pgv(;ly{7oU}ZaAeVSCM0djiz9y)d35res^pm%cqj6x4LDWgH9Ow6-9pkk vj^%iH8=>qM_7Ncu3K*|IY!M7D~Olg6)`hWAdx>j!@UA?x)q literal 0 HcmV?d00001 diff --git a/test/tools/dsymutil/null-die.test b/test/tools/dsymutil/null-die.test new file mode 100644 index 00000000000..253c23c6058 --- /dev/null +++ b/test/tools/dsymutil/null-die.test @@ -0,0 +1,41 @@ +#RUN: llvm-dsymutil -f -oso-prepend-path=%p/Inputs/ -y %s -no-output 2>&1 \ +#RUN: | FileCheck %s + +# CHECK: warning: could not find referenced DIE + +# We've modified the DW_AT_abstract_origin offset to reference a NULL DIE. +# +# Source: +# +# void f1() {} +# __attribute__((always_inline)) void f2() { +# f1(); +# } +# int main() { +# f2(); +# } +# +# Compile with: +# +# $ clang -g null_die.c -O0 -S -o null_die.s +# +# Manually patch the DW_AT_abstract_origin to point to a NULL DIE. +# +# $ llvm-mc -triple x86_64-apple-darwin -filetype=obj -o null_die.o null_die.s +# +# To generate the debug map: +# +# $ ld -arch x86_64 -macosx_version_min 10.13.0 -lSystem null_die.o -o null_die +# $ llvm-dsymutil -dump-debug-map null_die + +--- +triple: 'x86_64-apple-darwin' +binary-path: null_die +objects: + - filename: /null_die.o + timestamp: 1505928022 + symbols: + - { sym: _main, objAddr: 0x0000000000000020, binAddr: 0x0000000100000F10, size: 0x0000000D } + - { sym: _f1, objAddr: 0x0000000000000000, binAddr: 0x0000000100000EF0, size: 0x00000010 } + - { sym: _f2, objAddr: 0x0000000000000010, binAddr: 0x0000000100000F00, size: 0x00000010 } +... diff --git a/tools/dsymutil/DwarfLinker.cpp b/tools/dsymutil/DwarfLinker.cpp index 3ab3c7f5720..69adf379ca0 100644 --- a/tools/dsymutil/DwarfLinker.cpp +++ b/tools/dsymutil/DwarfLinker.cpp @@ -1495,8 +1495,12 @@ static DWARFDie resolveDIEReference( uint64_t RefOffset = *RefValue.getAsReference(); if ((RefCU = getUnitForOffset(Units, RefOffset))) - if (const auto RefDie = RefCU->getOrigUnit().getDIEForOffset(RefOffset)) - return RefDie; + if (const auto RefDie = RefCU->getOrigUnit().getDIEForOffset(RefOffset)) { + // In a file with broken references, an attribute might point to a NULL + // DIE. + if(!RefDie.isNULL()) + return RefDie; + } Linker.reportWarning("could not find referenced DIE", &DIE); return DWARFDie(); -- 2.40.0