From 09e26a42d2ad562eafe4fdb35dd4dd090e726f5d Mon Sep 17 00:00:00 2001 From: Frederic Riss Date: Fri, 31 Jul 2015 20:22:50 +0000 Subject: [PATCH] [dwarfdump] Ignore scattered relocations for mach-o. When encountering a scattered relocation, the code would assert trying to access an unexisting section. I couldn't find a way to expose the result of the processing of a scattered reloc, and I'm really unsure what the right thing to do is. This patch just skips them during the processing in DwarfContext and adds a mach-o file to the tests that exposed the asserting behavior. (This is a new failure that is being exposed by Rafael's recent work on the libObject interfaces. I think the wrong behavior has always happened, but now it's asserting) git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@243778 91177308-0d34-0410-b5e6-96231b3b80d8 --- lib/DebugInfo/DWARF/DWARFContext.cpp | 12 +++++++++--- test/DebugInfo/Inputs/dwarfdump-test.cc | 2 ++ .../DebugInfo/Inputs/dwarfdump-test.macho-i386.o | Bin 0 -> 3620 bytes test/DebugInfo/dwarfdump-dump-flags.test | 3 +++ 4 files changed, 14 insertions(+), 3 deletions(-) create mode 100644 test/DebugInfo/Inputs/dwarfdump-test.macho-i386.o diff --git a/lib/DebugInfo/DWARF/DWARFContext.cpp b/lib/DebugInfo/DWARF/DWARFContext.cpp index 4858f3633d0..408214339a8 100644 --- a/lib/DebugInfo/DWARF/DWARFContext.cpp +++ b/lib/DebugInfo/DWARF/DWARFContext.cpp @@ -689,9 +689,15 @@ DWARFContextInMemory::DWARFContextInMemory(const object::ObjectFile &Obj, } else if (auto *MObj = dyn_cast(&Obj)) { // MachO also has relocations that point to sections and // scattered relocations. - // FIXME: We are not handling scattered relocations, do we have to? - RSec = MObj->getRelocationSection(Reloc.getRawDataRefImpl()); - SymAddr = RSec->getAddress(); + auto RelocInfo = MObj->getRelocation(Reloc.getRawDataRefImpl()); + if (MObj->isRelocationScattered(RelocInfo)) { + // FIXME: it's not clear how to correctly handle scattered + // relocations. + continue; + } else { + RSec = MObj->getRelocationSection(Reloc.getRawDataRefImpl()); + SymAddr = RSec->getAddress(); + } } // If we are given load addresses for the sections, we need to adjust: diff --git a/test/DebugInfo/Inputs/dwarfdump-test.cc b/test/DebugInfo/Inputs/dwarfdump-test.cc index 14295d3cffa..815c33dd3ac 100644 --- a/test/DebugInfo/Inputs/dwarfdump-test.cc +++ b/test/DebugInfo/Inputs/dwarfdump-test.cc @@ -27,3 +27,5 @@ int main() { // $ cp output2.dwz // $ dwz -m output.dwz -r output1.dwz output2.dwz // $ rm output2.dwz + +// The mach-o version was generated using clang-3.6.2. diff --git a/test/DebugInfo/Inputs/dwarfdump-test.macho-i386.o b/test/DebugInfo/Inputs/dwarfdump-test.macho-i386.o new file mode 100644 index 0000000000000000000000000000000000000000..b53c8a6959e30f8fc8502cfe96dd32392a9b6ffe GIT binary patch literal 3620 zcmb7HZERCj7(Tb{EqDD|ai~NTmRN8zp<@FV0*mWp70^xRJ_1hh(yiTA(spI-VBnM? zB(4F%Fwq!(fF%13#26#`Ln0(I{y-A_WAukVAi?;Ng@`VI*5^6*cDuAS;>q6op7-lH z?|IL;@9nPK{`K!gLI^uZ0XaZJd{i6qEDdGGQ3M@^A35VmKGRRvv$3)4LXfU^hqrex z$eir~F`i5LJ;wSFCLqe8>(N->=%5}?4GdGE>#f^bI-fO+crreNgl`i7qXrl*V`?)P zV+@Q)U*AX!0mT?UA^s+ulg>iKJTJjW#8WX^i!r{3=X=z%02pJ)!wfFL$Ye*PPcg=B z)c67{w@eJ_WIReR62tvvF`hK*a8|QK{|m-QBsCbzl({7(B3R2xLlM0)zL;eb3oO(&8+`i&|?05RLlOJRh|X9O*wvis6y_p%IkYXHlhHZeN9 zMqQw?t0iA?7#L9~G`A6y1_n~&uwcZ7^nnpn)G!pE%MD;m z!;~;F3@@AuUiZSB^^$dV8_5!UDd>H3y>G!gAR|U{u=&A!%$(+R_dDsyT|e~8(j#Hd zk#_A^&up&!ZZ14`Bz!lwB#>(jIBxuq&*zVYXOFbc?;1~KH5o>;!Q|7{2If!{`!?|1 zAjM{TTsWvzpjOl|&YZM}MX%w(mqJm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