From 5b003bb869bb79cbec59f76c2ffe6461c8a8efea Mon Sep 17 00:00:00 2001 From: Tim Northover Date: Fri, 4 Jul 2014 10:57:56 +0000 Subject: [PATCH] llvm-readobj: fix MachO relocatoin printing a bit. There were two issues here: 1. At the very least, scattered relocations cannot use the same code to determine the corresponding symbol being referred to. For some reason we pretend there is no symbol, even when one actually exists in the symtab, so to match this behaviour getRelocationSymbol should simply return symbols_end for scattered relocations. 2. Printing "-" when we can't get a symbol (including the scattered case, but not exclusively), isn't that helpful. In both cases there *is* interesting information in that field, so we should print it. As hex will do. Small part of rdar://problem/17553104 git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@212332 91177308-0d34-0410-b5e6-96231b3b80d8 --- lib/Object/MachOObjectFile.cpp | 3 ++ test/CodeGen/PowerPC/hello-reloc.s | 18 +++---- test/MC/AArch64/arm64-leaf-compact-unwind.s | 8 ++-- test/MC/MachO/eh-frame-reloc.s | 4 +- test/tools/llvm-readobj/relocations.test | 52 ++++++++++----------- test/tools/llvm-readobj/sections-ext.test | 52 ++++++++++----------- tools/llvm-readobj/MachODumper.cpp | 24 +++++++--- 7 files changed, 88 insertions(+), 73 deletions(-) diff --git a/lib/Object/MachOObjectFile.cpp b/lib/Object/MachOObjectFile.cpp index 50e7f63a930..4919114d234 100644 --- a/lib/Object/MachOObjectFile.cpp +++ b/lib/Object/MachOObjectFile.cpp @@ -868,6 +868,9 @@ std::error_code MachOObjectFile::getRelocationOffset(DataRefImpl Rel, symbol_iterator MachOObjectFile::getRelocationSymbol(DataRefImpl Rel) const { MachO::any_relocation_info RE = getRelocation(Rel); + if (isRelocationScattered(RE)) + return symbol_end(); + uint32_t SymbolIdx = getPlainRelocationSymbolNum(RE); bool isExtern = getPlainRelocationExternal(RE); if (!isExtern) diff --git a/test/CodeGen/PowerPC/hello-reloc.s b/test/CodeGen/PowerPC/hello-reloc.s index 1e3fb8fb0e7..97dfbb5362f 100644 --- a/test/CodeGen/PowerPC/hello-reloc.s +++ b/test/CodeGen/PowerPC/hello-reloc.s @@ -62,17 +62,17 @@ L_.str: ; @.str ; DARWIN-G4-DUMP:AddressSize: 32bit ; DARWIN-G4-DUMP:Relocations [ ; DARWIN-G4-DUMP: Section __text { -; DARWIN-G4-DUMP: 0x34 1 2 0 PPC_RELOC_BR24 0 - -; DARWIN-G4-DUMP: 0x30 0 2 n/a PPC_RELOC_LO16_SECTDIFF 1 _main -; DARWIN-G4-DUMP: 0x0 0 2 n/a PPC_RELOC_PAIR 1 _main -; DARWIN-G4-DUMP: 0x2C 0 2 n/a PPC_RELOC_HA16_SECTDIFF 1 _main -; DARWIN-G4-DUMP: 0x60 0 2 n/a PPC_RELOC_PAIR 1 _main +; DARWIN-G4-DUMP: 0x34 1 2 0 PPC_RELOC_BR24 0 0x3 +; DARWIN-G4-DUMP: 0x30 0 2 n/a PPC_RELOC_LO16_SECTDIFF 1 0x74 +; DARWIN-G4-DUMP: 0x0 0 2 n/a PPC_RELOC_PAIR 1 0x14 +; DARWIN-G4-DUMP: 0x2C 0 2 n/a PPC_RELOC_HA16_SECTDIFF 1 0x74 +; DARWIN-G4-DUMP: 0x60 0 2 n/a PPC_RELOC_PAIR 1 0x14 ; DARWIN-G4-DUMP: } ; DARWIN-G4-DUMP: Section __picsymbolstub1 { -; DARWIN-G4-DUMP: 0x14 0 2 n/a PPC_RELOC_LO16_SECTDIFF 1 _main -; DARWIN-G4-DUMP: 0x0 0 2 n/a PPC_RELOC_PAIR 1 _main -; DARWIN-G4-DUMP: 0xC 0 2 n/a PPC_RELOC_HA16_SECTDIFF 1 _main -; DARWIN-G4-DUMP: 0x18 0 2 n/a PPC_RELOC_PAIR 1 _main +; DARWIN-G4-DUMP: 0x14 0 2 n/a PPC_RELOC_LO16_SECTDIFF 1 0x70 +; DARWIN-G4-DUMP: 0x0 0 2 n/a PPC_RELOC_PAIR 1 0x58 +; DARWIN-G4-DUMP: 0xC 0 2 n/a PPC_RELOC_HA16_SECTDIFF 1 0x70 +; DARWIN-G4-DUMP: 0x18 0 2 n/a PPC_RELOC_PAIR 1 0x58 ; DARWIN-G4-DUMP: } ; DARWIN-G4-DUMP: Section __la_symbol_ptr { ; DARWIN-G4-DUMP: 0x0 0 2 1 PPC_RELOC_VANILLA 0 dyld_stub_binding_helper diff --git a/test/MC/AArch64/arm64-leaf-compact-unwind.s b/test/MC/AArch64/arm64-leaf-compact-unwind.s index d6998134d04..27d3d51c293 100644 --- a/test/MC/AArch64/arm64-leaf-compact-unwind.s +++ b/test/MC/AArch64/arm64-leaf-compact-unwind.s @@ -23,10 +23,10 @@ // CHECK-NEXT: Reserved1: // CHECK-NEXT: Reserved2: // CHECK-NEXT: Relocations [ -// CHECK-NEXT: 0x60 0 3 0 ARM64_RELOC_UNSIGNED 0 - -// CHECK-NEXT: 0x40 0 3 0 ARM64_RELOC_UNSIGNED 0 - -// CHECK-NEXT: 0x20 0 3 0 ARM64_RELOC_UNSIGNED 0 - -// CHECK-NEXT: 0x0 0 3 0 ARM64_RELOC_UNSIGNED 0 - +// CHECK-NEXT: 0x60 0 3 0 ARM64_RELOC_UNSIGNED 0 0x1 +// CHECK-NEXT: 0x40 0 3 0 ARM64_RELOC_UNSIGNED 0 0x1 +// CHECK-NEXT: 0x20 0 3 0 ARM64_RELOC_UNSIGNED 0 0x1 +// CHECK-NEXT: 0x0 0 3 0 ARM64_RELOC_UNSIGNED 0 0x1 // CHECK-NEXT: ] // CHECK-NEXT: SectionData ( // CHECK-NEXT: 0000: 00000000 00000000 08000000 00000002 diff --git a/test/MC/MachO/eh-frame-reloc.s b/test/MC/MachO/eh-frame-reloc.s index 4b2822404de..e14825b92f8 100644 --- a/test/MC/MachO/eh-frame-reloc.s +++ b/test/MC/MachO/eh-frame-reloc.s @@ -17,8 +17,8 @@ _bar: // OLD32: Relocations [ // OLD32-NEXT: Section __eh_frame { -// OLD32-NEXT: 0x20 0 2 n/a GENERIC_RELOC_LOCAL_SECTDIFF 1 - -// OLD32-NEXT: 0x0 0 2 n/a GENERIC_RELOC_PAIR 1 - +// OLD32-NEXT: 0x20 0 2 n/a GENERIC_RELOC_LOCAL_SECTDIFF 1 0x0 +// OLD32-NEXT: 0x0 0 2 n/a GENERIC_RELOC_PAIR 1 0x20 // OLD32-NEXT: } // OLD32-NEXT: ] diff --git a/test/tools/llvm-readobj/relocations.test b/test/tools/llvm-readobj/relocations.test index 3a87ff548e3..864ded35a4e 100644 --- a/test/tools/llvm-readobj/relocations.test +++ b/test/tools/llvm-readobj/relocations.test @@ -34,8 +34,8 @@ MACHO-I386: Relocations [ MACHO-I386-NEXT: Section __text { MACHO-I386-NEXT: 0x18 1 2 1 GENERIC_RELOC_VANILLA 0 _SomeOtherFunction MACHO-I386-NEXT: 0x13 1 2 1 GENERIC_RELOC_VANILLA 0 _puts -MACHO-I386-NEXT: 0xB 0 2 n/a GENERIC_RELOC_LOCAL_SECTDIFF 1 - -MACHO-I386-NEXT: 0x0 0 2 n/a GENERIC_RELOC_PAIR 1 - +MACHO-I386-NEXT: 0xB 0 2 n/a GENERIC_RELOC_LOCAL_SECTDIFF 1 0x22 +MACHO-I386-NEXT: 0x0 0 2 n/a GENERIC_RELOC_PAIR 1 0x8 MACHO-I386-NEXT: } MACHO-I386-NEXT: ] @@ -49,17 +49,17 @@ MACHO-X86-64-NEXT:] MACHO-PPC: Relocations [ MACHO-PPC-NEXT: Section __text { -MACHO-PPC-NEXT: 0x24 0 2 n/a PPC_RELOC_LO16_SECTDIFF 1 - -MACHO-PPC-NEXT: 0x0 0 2 n/a PPC_RELOC_PAIR 1 - -MACHO-PPC-NEXT: 0x1C 0 2 n/a PPC_RELOC_HA16_SECTDIFF 1 - -MACHO-PPC-NEXT: 0x58 0 2 n/a PPC_RELOC_PAIR 1 - -MACHO-PPC-NEXT: 0x18 1 2 0 PPC_RELOC_BR24 0 - +MACHO-PPC-NEXT: 0x24 0 2 n/a PPC_RELOC_LO16_SECTDIFF 1 0x64 +MACHO-PPC-NEXT: 0x0 0 2 n/a PPC_RELOC_PAIR 1 0xC +MACHO-PPC-NEXT: 0x1C 0 2 n/a PPC_RELOC_HA16_SECTDIFF 1 0x64 +MACHO-PPC-NEXT: 0x58 0 2 n/a PPC_RELOC_PAIR 1 0xC +MACHO-PPC-NEXT: 0x18 1 2 0 PPC_RELOC_BR24 0 0x2 MACHO-PPC-NEXT: } MACHO-PPC-NEXT: Section __picsymbolstub1 { -MACHO-PPC-NEXT: 0x14 0 2 n/a PPC_RELOC_LO16_SECTDIFF 1 - -MACHO-PPC-NEXT: 0x0 0 2 n/a PPC_RELOC_PAIR 1 - -MACHO-PPC-NEXT: 0xC 0 2 n/a PPC_RELOC_HA16_SECTDIFF 1 - -MACHO-PPC-NEXT: 0x20 0 2 n/a PPC_RELOC_PAIR 1 - +MACHO-PPC-NEXT: 0x14 0 2 n/a PPC_RELOC_LO16_SECTDIFF 1 0x68 +MACHO-PPC-NEXT: 0x0 0 2 n/a PPC_RELOC_PAIR 1 0x48 +MACHO-PPC-NEXT: 0xC 0 2 n/a PPC_RELOC_HA16_SECTDIFF 1 0x68 +MACHO-PPC-NEXT: 0x20 0 2 n/a PPC_RELOC_PAIR 1 0x48 MACHO-PPC-NEXT: } MACHO-PPC-NEXT: Section __la_symbol_ptr { MACHO-PPC-NEXT: 0x0 0 2 1 PPC_RELOC_VANILLA 0 dyld_stub_binding_helper @@ -68,17 +68,17 @@ MACHO-PPC-NEXT: ] MACHO-PPC64: Relocations [ MACHO-PPC64-NEXT: Section __text { -MACHO-PPC64-NEXT: 0x24 0 2 n/a 1 - -MACHO-PPC64-NEXT: 0x0 0 2 n/a 1 - -MACHO-PPC64-NEXT: 0x1C 0 2 n/a 1 - -MACHO-PPC64-NEXT: 0x58 0 2 n/a 1 - -MACHO-PPC64-NEXT: 0x18 1 2 0 0 - +MACHO-PPC64-NEXT: 0x24 0 2 n/a 1 0x64 +MACHO-PPC64-NEXT: 0x0 0 2 n/a 1 0xC +MACHO-PPC64-NEXT: 0x1C 0 2 n/a 1 0x64 +MACHO-PPC64-NEXT: 0x58 0 2 n/a 1 0xC +MACHO-PPC64-NEXT: 0x18 1 2 0 0 0x2 MACHO-PPC64-NEXT: } MACHO-PPC64-NEXT: Section __picsymbolstub1 { -MACHO-PPC64-NEXT: 0x14 0 2 n/a 1 - -MACHO-PPC64-NEXT: 0x0 0 2 n/a 1 - -MACHO-PPC64-NEXT: 0xC 0 2 n/a 1 - -MACHO-PPC64-NEXT: 0x24 0 2 n/a 1 - +MACHO-PPC64-NEXT: 0x14 0 2 n/a 1 0x6C +MACHO-PPC64-NEXT: 0x0 0 2 n/a 1 0x48 +MACHO-PPC64-NEXT: 0xC 0 2 n/a 1 0x6C +MACHO-PPC64-NEXT: 0x24 0 2 n/a 1 0x48 MACHO-PPC64-NEXT: } MACHO-PPC64-NEXT: Section __la_symbol_ptr { MACHO-PPC64-NEXT: 0x0 0 3 1 0 dyld_stub_binding_helper @@ -94,7 +94,7 @@ MACHO-ARM-NEXT: PCRel: 0 MACHO-ARM-NEXT: Length: 2 MACHO-ARM-NEXT: Extern: N/A MACHO-ARM-NEXT: Type: ARM_RELOC_SECTDIFF (2) -MACHO-ARM-NEXT: Symbol: - +MACHO-ARM-NEXT: Symbol: 0x40 MACHO-ARM-NEXT: Scattered: 1 MACHO-ARM-NEXT: } MACHO-ARM-NEXT: Relocation { @@ -103,7 +103,7 @@ MACHO-ARM-NEXT: PCRel: 0 MACHO-ARM-NEXT: Length: 2 MACHO-ARM-NEXT: Extern: N/A MACHO-ARM-NEXT: Type: ARM_RELOC_PAIR (1) -MACHO-ARM-NEXT: Symbol: - +MACHO-ARM-NEXT: Symbol: 0x28 MACHO-ARM-NEXT: Scattered: 1 MACHO-ARM-NEXT: } MACHO-ARM-NEXT: Relocation { @@ -130,7 +130,7 @@ MACHO-ARM-NEXT: PCRel: 0 MACHO-ARM-NEXT: Length: 1 MACHO-ARM-NEXT: Extern: 0 MACHO-ARM-NEXT: Type: ARM_RELOC_PAIR (1) -MACHO-ARM-NEXT: Symbol: - +MACHO-ARM-NEXT: Symbol: 0xFFFFFF MACHO-ARM-NEXT: Scattered: 0 MACHO-ARM-NEXT: } MACHO-ARM-NEXT: Relocation { @@ -148,7 +148,7 @@ MACHO-ARM-NEXT: PCRel: 0 MACHO-ARM-NEXT: Length: 0 MACHO-ARM-NEXT: Extern: 0 MACHO-ARM-NEXT: Type: ARM_RELOC_PAIR (1) -MACHO-ARM-NEXT: Symbol: - +MACHO-ARM-NEXT: Symbol: 0xFFFFFF MACHO-ARM-NEXT: Scattered: 0 MACHO-ARM-NEXT: } MACHO-ARM-NEXT: Relocation { @@ -157,7 +157,7 @@ MACHO-ARM-NEXT: PCRel: 0 MACHO-ARM-NEXT: Length: 2 MACHO-ARM-NEXT: Extern: N/A MACHO-ARM-NEXT: Type: ARM_RELOC_SECTDIFF (2) -MACHO-ARM-NEXT: Symbol: - +MACHO-ARM-NEXT: Symbol: 0x44 MACHO-ARM-NEXT: Scattered: 1 MACHO-ARM-NEXT: } MACHO-ARM-NEXT: Relocation { @@ -166,7 +166,7 @@ MACHO-ARM-NEXT: PCRel: 0 MACHO-ARM-NEXT: Length: 2 MACHO-ARM-NEXT: Extern: N/A MACHO-ARM-NEXT: Type: ARM_RELOC_PAIR (1) -MACHO-ARM-NEXT: Symbol: - +MACHO-ARM-NEXT: Symbol: 0x4 MACHO-ARM-NEXT: Scattered: 1 MACHO-ARM-NEXT: } MACHO-ARM-NEXT: } diff --git a/test/tools/llvm-readobj/sections-ext.test b/test/tools/llvm-readobj/sections-ext.test index 0f7ce26b613..972d8e6f4ef 100644 --- a/test/tools/llvm-readobj/sections-ext.test +++ b/test/tools/llvm-readobj/sections-ext.test @@ -183,8 +183,8 @@ MACHO-I386-NEXT: Reserved2: 0x0 MACHO-I386-NEXT: Relocations [ MACHO-I386-NEXT: 0x18 1 2 1 GENERIC_RELOC_VANILLA 0 _SomeOtherFunction MACHO-I386-NEXT: 0x13 1 2 1 GENERIC_RELOC_VANILLA 0 _puts -MACHO-I386-NEXT: 0xB 0 2 n/a GENERIC_RELOC_LOCAL_SECTDIFF 1 - -MACHO-I386-NEXT: 0x0 0 2 n/a GENERIC_RELOC_PAIR 1 - +MACHO-I386-NEXT: 0xB 0 2 n/a GENERIC_RELOC_LOCAL_SECTDIFF 1 0x22 +MACHO-I386-NEXT: 0x0 0 2 n/a GENERIC_RELOC_PAIR 1 0x8 MACHO-I386-NEXT: ] MACHO-I386-NEXT: Symbols [ MACHO-I386-NEXT: Symbol { @@ -299,11 +299,11 @@ MACHO-PPC-NEXT: ] MACHO-PPC-NEXT: Reserved1: 0x0 MACHO-PPC-NEXT: Reserved2: 0x0 MACHO-PPC-NEXT: Relocations [ -MACHO-PPC-NEXT: 0x24 0 2 n/a PPC_RELOC_LO16_SECTDIFF 1 - -MACHO-PPC-NEXT: 0x0 0 2 n/a PPC_RELOC_PAIR 1 - -MACHO-PPC-NEXT: 0x1C 0 2 n/a PPC_RELOC_HA16_SECTDIFF 1 - -MACHO-PPC-NEXT: 0x58 0 2 n/a PPC_RELOC_PAIR 1 - -MACHO-PPC-NEXT: 0x18 1 2 0 PPC_RELOC_BR24 0 - +MACHO-PPC-NEXT: 0x24 0 2 n/a PPC_RELOC_LO16_SECTDIFF 1 0x64 +MACHO-PPC-NEXT: 0x0 0 2 n/a PPC_RELOC_PAIR 1 0xC +MACHO-PPC-NEXT: 0x1C 0 2 n/a PPC_RELOC_HA16_SECTDIFF 1 0x64 +MACHO-PPC-NEXT: 0x58 0 2 n/a PPC_RELOC_PAIR 1 0xC +MACHO-PPC-NEXT: 0x18 1 2 0 PPC_RELOC_BR24 0 0x2 MACHO-PPC-NEXT: ] MACHO-PPC-NEXT: Symbols [ MACHO-PPC-NEXT: Symbol { @@ -342,10 +342,10 @@ MACHO-PPC-NEXT: ] MACHO-PPC-NEXT: Reserved1: 0x0 MACHO-PPC-NEXT: Reserved2: 0x20 MACHO-PPC-NEXT: Relocations [ -MACHO-PPC-NEXT: 0x14 0 2 n/a PPC_RELOC_LO16_SECTDIFF 1 - -MACHO-PPC-NEXT: 0x0 0 2 n/a PPC_RELOC_PAIR 1 - -MACHO-PPC-NEXT: 0xC 0 2 n/a PPC_RELOC_HA16_SECTDIFF 1 - -MACHO-PPC-NEXT: 0x20 0 2 n/a PPC_RELOC_PAIR 1 - +MACHO-PPC-NEXT: 0x14 0 2 n/a PPC_RELOC_LO16_SECTDIFF 1 0x68 +MACHO-PPC-NEXT: 0x0 0 2 n/a PPC_RELOC_PAIR 1 0x48 +MACHO-PPC-NEXT: 0xC 0 2 n/a PPC_RELOC_HA16_SECTDIFF 1 0x68 +MACHO-PPC-NEXT: 0x20 0 2 n/a PPC_RELOC_PAIR 1 0x48 MACHO-PPC-NEXT: ] MACHO-PPC-NEXT: Symbols [ MACHO-PPC-NEXT: ] @@ -456,11 +456,11 @@ MACHO-PPC64-NEXT: ] MACHO-PPC64-NEXT: Reserved1: 0x0 MACHO-PPC64-NEXT: Reserved2: 0x0 MACHO-PPC64-NEXT: Relocations [ -MACHO-PPC64-NEXT: 0x24 0 2 n/a 1 - -MACHO-PPC64-NEXT: 0x0 0 2 n/a 1 - -MACHO-PPC64-NEXT: 0x1C 0 2 n/a 1 - -MACHO-PPC64-NEXT: 0x58 0 2 n/a 1 - -MACHO-PPC64-NEXT: 0x18 1 2 0 0 - +MACHO-PPC64-NEXT: 0x24 0 2 n/a 1 0x64 +MACHO-PPC64-NEXT: 0x0 0 2 n/a 1 0xC +MACHO-PPC64-NEXT: 0x1C 0 2 n/a 1 0x64 +MACHO-PPC64-NEXT: 0x58 0 2 n/a 1 0xC +MACHO-PPC64-NEXT: 0x18 1 2 0 0 0x2 MACHO-PPC64-NEXT: ] MACHO-PPC64-NEXT: Symbols [ MACHO-PPC64-NEXT: Symbol { @@ -499,10 +499,10 @@ MACHO-PPC64-NEXT: ] MACHO-PPC64-NEXT: Reserved1: 0x0 MACHO-PPC64-NEXT: Reserved2: 0x20 MACHO-PPC64-NEXT: Relocations [ -MACHO-PPC64-NEXT: 0x14 0 2 n/a 1 - -MACHO-PPC64-NEXT: 0x0 0 2 n/a 1 - -MACHO-PPC64-NEXT: 0xC 0 2 n/a 1 - -MACHO-PPC64-NEXT: 0x24 0 2 n/a 1 - +MACHO-PPC64-NEXT: 0x14 0 2 n/a 1 0x6C +MACHO-PPC64-NEXT: 0x0 0 2 n/a 1 0x48 +MACHO-PPC64-NEXT: 0xC 0 2 n/a 1 0x6C +MACHO-PPC64-NEXT: 0x24 0 2 n/a 1 0x48 MACHO-PPC64-NEXT: ] MACHO-PPC64-NEXT: Symbols [ MACHO-PPC64-NEXT: ] @@ -618,7 +618,7 @@ MACHO-ARM-NEXT: PCRel: 0 MACHO-ARM-NEXT: Length: 2 MACHO-ARM-NEXT: Extern: N/A MACHO-ARM-NEXT: Type: ARM_RELOC_SECTDIFF (2) -MACHO-ARM-NEXT: Symbol: - +MACHO-ARM-NEXT: Symbol: 0x40 MACHO-ARM-NEXT: Scattered: 1 MACHO-ARM-NEXT: } MACHO-ARM-NEXT: Relocation { @@ -627,7 +627,7 @@ MACHO-ARM-NEXT: PCRel: 0 MACHO-ARM-NEXT: Length: 2 MACHO-ARM-NEXT: Extern: N/A MACHO-ARM-NEXT: Type: ARM_RELOC_PAIR (1) -MACHO-ARM-NEXT: Symbol: - +MACHO-ARM-NEXT: Symbol: 0x28 MACHO-ARM-NEXT: Scattered: 1 MACHO-ARM-NEXT: } MACHO-ARM-NEXT: Relocation { @@ -654,7 +654,7 @@ MACHO-ARM-NEXT: PCRel: 0 MACHO-ARM-NEXT: Length: 1 MACHO-ARM-NEXT: Extern: 0 MACHO-ARM-NEXT: Type: ARM_RELOC_PAIR (1) -MACHO-ARM-NEXT: Symbol: - +MACHO-ARM-NEXT: Symbol: 0xFFFFFF MACHO-ARM-NEXT: Scattered: 0 MACHO-ARM-NEXT: } MACHO-ARM-NEXT: Relocation { @@ -672,7 +672,7 @@ MACHO-ARM-NEXT: PCRel: 0 MACHO-ARM-NEXT: Length: 0 MACHO-ARM-NEXT: Extern: 0 MACHO-ARM-NEXT: Type: ARM_RELOC_PAIR (1) -MACHO-ARM-NEXT: Symbol: - +MACHO-ARM-NEXT: Symbol: 0xFFFFFF MACHO-ARM-NEXT: Scattered: 0 MACHO-ARM-NEXT: } MACHO-ARM-NEXT: Relocation { @@ -681,7 +681,7 @@ MACHO-ARM-NEXT: PCRel: 0 MACHO-ARM-NEXT: Length: 2 MACHO-ARM-NEXT: Extern: N/A MACHO-ARM-NEXT: Type: ARM_RELOC_SECTDIFF (2) -MACHO-ARM-NEXT: Symbol: - +MACHO-ARM-NEXT: Symbol: 0x44 MACHO-ARM-NEXT: Scattered: 1 MACHO-ARM-NEXT: } MACHO-ARM-NEXT: Relocation { @@ -690,7 +690,7 @@ MACHO-ARM-NEXT: PCRel: 0 MACHO-ARM-NEXT: Length: 2 MACHO-ARM-NEXT: Extern: N/A MACHO-ARM-NEXT: Type: ARM_RELOC_PAIR (1) -MACHO-ARM-NEXT: Symbol: - +MACHO-ARM-NEXT: Symbol: 0x4 MACHO-ARM-NEXT: Scattered: 1 MACHO-ARM-NEXT: } MACHO-ARM-NEXT: ] diff --git a/tools/llvm-readobj/MachODumper.cpp b/tools/llvm-readobj/MachODumper.cpp index d168030a270..a5e5cf850a3 100644 --- a/tools/llvm-readobj/MachODumper.cpp +++ b/tools/llvm-readobj/MachODumper.cpp @@ -16,6 +16,7 @@ #include "ObjDumper.h" #include "StreamWriter.h" #include "llvm/ADT/SmallString.h" +#include "llvm/ADT/StringExtras.h" #include "llvm/Object/MachO.h" #include "llvm/Support/Casting.h" @@ -309,18 +310,29 @@ void MachODumper::printRelocation(const MachOObjectFile *Obj, const RelocationRef &Reloc) { uint64_t Offset; SmallString<32> RelocName; - StringRef SymbolName; if (error(Reloc.getOffset(Offset))) return; if (error(Reloc.getTypeName(RelocName))) return; - symbol_iterator Symbol = Reloc.getSymbol(); - if (Symbol != Obj->symbol_end() && error(Symbol->getName(SymbolName))) - return; DataRefImpl DR = Reloc.getRawDataRefImpl(); MachO::any_relocation_info RE = Obj->getRelocation(DR); bool IsScattered = Obj->isRelocationScattered(RE); + SmallString<32> SymbolNameOrOffset("0x"); + if (IsScattered) { + // Scattered relocations don't really have an associated symbol + // for some reason, even if one exists in the symtab at the correct address. + SymbolNameOrOffset += utohexstr(Obj->getScatteredRelocationValue(RE)); + } else { + symbol_iterator Symbol = Reloc.getSymbol(); + if (Symbol != Obj->symbol_end()) { + StringRef SymbolName; + if (error(Symbol->getName(SymbolName))) + return; + SymbolNameOrOffset = SymbolName; + } else + SymbolNameOrOffset += utohexstr(Obj->getPlainRelocationSymbolNum(RE)); + } if (opts::ExpandRelocs) { DictScope Group(W, "Relocation"); @@ -332,7 +344,7 @@ void MachODumper::printRelocation(const MachOObjectFile *Obj, else W.printNumber("Extern", Obj->getPlainRelocationExternal(RE)); W.printNumber("Type", RelocName, Obj->getAnyRelocationType(RE)); - W.printString("Symbol", SymbolName.size() > 0 ? SymbolName : "-"); + W.printString("Symbol", SymbolNameOrOffset); W.printNumber("Scattered", IsScattered); } else { raw_ostream& OS = W.startLine(); @@ -345,7 +357,7 @@ void MachODumper::printRelocation(const MachOObjectFile *Obj, OS << " " << Obj->getPlainRelocationExternal(RE); OS << " " << RelocName << " " << IsScattered - << " " << (SymbolName.size() > 0 ? SymbolName : "-") + << " " << SymbolNameOrOffset << "\n"; } }