From d2681e88129a763fc16f9d0c1977670d0370fee4 Mon Sep 17 00:00:00 2001 From: Frederic Riss Date: Sun, 23 Aug 2015 04:44:21 +0000 Subject: [PATCH] [dwarfdump] Do not apply relocations in mach-o files if there is no LoadedObjectInfo. Not only do we not need to do anything to read correct values from the object files, but the current logic actually wrongly applies twice the section base address when there is no LoadedObjectInfo passed to the DWARFContext creation (as the added test shows). Simply do not apply any relocations on the mach-o debug info if there is no load offset to apply. git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@245807 91177308-0d34-0410-b5e6-96231b3b80d8 --- lib/DebugInfo/DWARF/DWARFContext.cpp | 8 ++++++ .../dwarfdump-macho-relocs.macho.x86_64.o | Bin 0 -> 2364 bytes test/DebugInfo/dwarfdump-macho-relocs.test | 27 ++++++++++++++++++ 3 files changed, 35 insertions(+) create mode 100644 test/DebugInfo/Inputs/dwarfdump-macho-relocs.macho.x86_64.o create mode 100644 test/DebugInfo/dwarfdump-macho-relocs.test diff --git a/lib/DebugInfo/DWARF/DWARFContext.cpp b/lib/DebugInfo/DWARF/DWARFContext.cpp index 2e7bcaf96c0..aecd991ff0d 100644 --- a/lib/DebugInfo/DWARF/DWARFContext.cpp +++ b/lib/DebugInfo/DWARF/DWARFContext.cpp @@ -637,6 +637,14 @@ DWARFContextInMemory::DWARFContextInMemory(const object::ObjectFile &Obj, if (L && L->getLoadedSectionContents(*RelocatedSection,RelSecData)) continue; + // In Mach-o files, the relocations do not need to be applied if + // there is no load offset to apply. The value read at the + // relocation point already factors in the section address + // (actually applying the relocations will produce wrong results + // as the section address will be added twice). + if (!L && dyn_cast(&Obj)) + continue; + RelSecName = RelSecName.substr( RelSecName.find_first_not_of("._")); // Skip . and _ prefixes. diff --git a/test/DebugInfo/Inputs/dwarfdump-macho-relocs.macho.x86_64.o b/test/DebugInfo/Inputs/dwarfdump-macho-relocs.macho.x86_64.o new file mode 100644 index 0000000000000000000000000000000000000000..a5f8476df5e759c0c01891bdff22b5756cd3a5ed GIT binary patch literal 2364 zcmb7E&1(}u6rag9v1w}DS`U69izrm3HM9k*g0_A}^q^L&2W8x(8=IPJ!e(1P5EKN_ zThAUndGsh=6+GI%z?}_fB*7poeZRqr@wT!9J}mp9Tjxcc zhXw;D;j_nQRi)SSEq|~%mn!Bl5VGu!-I&o#<;;9(Ek3Em=E#7Yo z5F*v)Q+}GS)+k5eB;P_inEb^x^0}o_;LT(IEAumaqs+TjzN%koU`mqjE%W$nyE58& zN%z4=*Kxmr>)-TRtNDiUxJU}xh=BPP|H$Vyn>A1QZXI;1@+&dlRpxuneB6ae zrP=60lKXwle7l(7`x^P8{F-h#$@d|_w*$qnQaa`r-fec=Z;H{Und8_$`O1wtw)hN4hh zA5}kMOrGC2<}>eajPi;k+c`hnn+-s&CxT)6W>TB+1+u*uCOuEuF2M3~?cp`~my1t7 z79V}K-<|vc{3kTUM{n)xZ{P`m@mG7vx&EeHquOxhy`WWX_|C}C*igY42!lEQmNPs$ zI()FO#~G;A=Ii^HV+RU*#Pn@9s7%k*n}cTLQebf~=EotI#EDw{PRRwRqws018aJ!Udl!YgV@tbt zUH1Z^u*!DQ=1=TvX-Vfpfr-5RICXrzK1YqiM=`*-_*N1){bq&zW^5B2I6EQ>ySm<^ryIglq_&GCN_}ckc9xa0YM`Q<))%~`whgi@0b7p literal 0 HcmV?d00001 diff --git a/test/DebugInfo/dwarfdump-macho-relocs.test b/test/DebugInfo/dwarfdump-macho-relocs.test new file mode 100644 index 00000000000..95798a841ca --- /dev/null +++ b/test/DebugInfo/dwarfdump-macho-relocs.test @@ -0,0 +1,27 @@ +// RUN: llvm-dwarfdump -debug-dump=info %p/Inputs/dwarfdump-macho-relocs.macho.x86_64.o | FileCheck %s + +// The dumped file has 2 functions in different sections of the __TEXT segment. +// Check that the addresses are are dumped correctly + +// Compiled with: clang -x c -g -c -o dwarfdump-macho-relocs.macho.x86_64.o dwarfdump-macho-relocs.test + +__attribute__((section("__TEXT,__blah"))) +int foo() { + return 42; +} + +// CHECK: DW_TAG_subprogram +// CHECK-NEXT: DW_AT_low_pc{{.*}}0x0000000000000020 +// CHECK-NEXT: DW_AT_high_pc{{.*}}0x000000000000002b +// CHECK-NEXT: DW_AT_frame_base +// CHECK-NEXT: DW_AT_name{{.*}}"foo" + +int main() { + return foo(); +} + +// CHECK: DW_TAG_subprogram +// CHECK-NEXT: DW_AT_low_pc{{.*}}0x0000000000000000 +// CHECK-NEXT: DW_AT_high_pc{{.*}}0x000000000000001a +// CHECK-NEXT: DW_AT_frame_base +// CHECK-NEXT: DW_AT_name{{.*}}"main" -- 2.34.1