llvm.org GIT mirror llvm / ebb9f17
Object: Fix Mach-O relocation printing. There were two problems that made llvm-objdump -r crash: - for non-scattered relocations, the symbol/section index is actually in the (aptly named) symbolnum field. - sections are 1-indexed. git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@181843 91177308-0d34-0410-b5e6-96231b3b80d8 Ahmed Bougacha 7 years ago
2 changed file(s) with 38 addition(s) and 2 deletion(s). Raw diff Collapse all Expand all
338338
339339 StringRef S;
340340 bool isExtern = O->getPlainRelocationExternal(RE);
341 uint64_t Val = O->getAnyRelocationAddress(RE);
341 uint64_t Val = O->getPlainRelocationSymbolNum(RE);
342342
343343 if (isExtern) {
344344 symbol_iterator SI = O->begin_symbols();
346346 SI->getName(S);
347347 } else {
348348 section_iterator SI = O->begin_sections();
349 advanceTo(SI, Val);
349 // Adjust for the fact that sections are 1-indexed.
350 advanceTo(SI, Val - 1);
350351 SI->getName(S);
351352 }
352353
11 RUN: | FileCheck %s -check-prefix COFF-i386
22 RUN: llvm-objdump -d -r %p/../Inputs/trivial-object-test.coff-x86-64 \
33 RUN: | FileCheck %s -check-prefix COFF-x86-64
4 RUN: llvm-objdump -d -r %p/../Inputs/trivial-object-test.macho-i386 \
5 RUN: | FileCheck %s -check-prefix MACHO-i386
6 RUN: llvm-objdump -d -r %p/../Inputs/trivial-object-test.macho-x86-64 \
7 RUN: | FileCheck %s -check-prefix MACHO-x86-64
48
59 COFF-i386: file format COFF-i386
610 COFF-i386: Disassembly of section .text:
2933 COFF-x86-64: 1d: 8b 44 24 24 movl 36(%rsp), %eax
3034 COFF-x86-64: 21: 48 83 c4 28 addq $40, %rsp
3135 COFF-x86-64: 25: c3 ret
36
37 MACHO-i386: file format Mach-O 32-bit i386
38 MACHO-i386: Disassembly of section __TEXT,__text:
39 MACHO-i386: _main:
40 MACHO-i386: 0: 83 ec 0c subl $12, %esp
41 MACHO-i386: 3: c7 44 24 08 00 00 00 00 movl $0, 8(%esp)
42 MACHO-i386: b: c7 04 24 24 00 00 00 movl $36, (%esp)
43 MACHO-i386: e: GENERIC_RELOC_VANILLA __cstring
44 MACHO-i386: 12: e8 1f 00 00 00 calll 31
45 MACHO-i386: 13: GENERIC_RELOC_VANILLA __jump_table
46 MACHO-i386: 17: e8 15 00 00 00 calll 21
47 MACHO-i386: 18: GENERIC_RELOC_VANILLA __jump_table
48 MACHO-i386: 1c: 8b 44 24 08 movl 8(%esp), %eax
49 MACHO-i386: 20: 83 c4 0c addl $12, %esp
50 MACHO-i386: 23: c3 ret
51
52 MACHO-x86-64: file format Mach-O 64-bit x86-64
53 MACHO-x86-64: Disassembly of section __TEXT,__text:
54 MACHO-x86-64: _main:
55 MACHO-x86-64: 0: 48 83 ec 08 subq $8, %rsp
56 MACHO-x86-64: 4: c7 44 24 04 00 00 00 00 movl $0, 4(%rsp)
57 MACHO-x86-64: c: 48 8d 3d 00 00 00 00 leaq (%rip), %rdi
58 MACHO-x86-64: f: X86_64_RELOC_SIGNED L_.str
59 MACHO-x86-64: 13: e8 00 00 00 00 callq 0
60 MACHO-x86-64: 14: X86_64_RELOC_BRANCH _puts
61 MACHO-x86-64: 18: 30 c0 xorb %al, %al
62 MACHO-x86-64: 1a: e8 00 00 00 00 callq 0
63 MACHO-x86-64: 1b: X86_64_RELOC_BRANCH _SomeOtherFunction
64 MACHO-x86-64: 1f: 8b 44 24 04 movl 4(%rsp), %eax
65 MACHO-x86-64: 23: 48 83 c4 08 addq $8, %rsp
66 MACHO-x86-64: 27: c3 ret