xref: /llvm-project/llvm/test/Object/X86/objdump-disassembly-inline-relocations.test (revision 75cdab6dc2453a508157a9c383b93373a93078d6)
1# RUN: llvm-objdump --no-print-imm-hex -d -r %p/../Inputs/trivial-object-test.coff-i386 \
2# RUN:              | FileCheck %s -check-prefix COFF-i386
3
4# COFF-i386: file format coff-i386
5# COFF-i386: Disassembly of section .text:
6# COFF-i386:        0:       83 ec 0c                                        subl    $12, %esp
7# COFF-i386:        3:       c7 44 24 08 00 00 00 00                         movl    $0, 8(%esp)
8# COFF-i386:        b:       c7 04 24 00 00 00 00                            movl    $0, (%esp)
9# COFF-i386:                              e: IMAGE_REL_I386_DIR32  L_.str
10# COFF-i386:       12:       e8 00 00 00 00                                  calll   0
11# COFF-i386:                             13: IMAGE_REL_I386_REL32  _puts
12# COFF-i386:       17:       e8 00 00 00 00                                  calll   0
13# COFF-i386:                             18: IMAGE_REL_I386_REL32  _SomeOtherFunction
14# COFF-i386:       1c:       8b 44 24 08                                     movl    8(%esp), %eax
15# COFF-i386:       20:       83 c4 0c                                        addl    $12, %esp
16# COFF-i386:       23:       c3                                              ret
17
18# RUN: llvm-objdump --no-print-imm-hex -d -r %p/../Inputs/trivial-object-test.coff-x86-64 \
19# RUN:              | FileCheck %s -check-prefix COFF-x86-64
20
21# COFF-x86-64: file format coff-x86-64
22# COFF-x86-64: Disassembly of section .text:
23# COFF-x86-64:        0:       48 83 ec 28                                     subq    $40, %rsp
24# COFF-x86-64:        4:       c7 44 24 24 00 00 00 00                         movl    $0, 36(%rsp)
25# COFF-x86-64:        c:       48 8d 0d 00 00 00 00                            leaq    (%rip), %rcx
26# COFF-x86-64:                               f: IMAGE_REL_AMD64_REL32 L.str
27# COFF-x86-64:       13:       e8 00 00 00 00                                  callq   0
28# COFF-x86-64:                              14: IMAGE_REL_AMD64_REL32 puts
29# COFF-x86-64:       18:       e8 00 00 00 00                                  callq   0
30# COFF-x86-64:                              19: IMAGE_REL_AMD64_REL32 SomeOtherFunction
31# COFF-x86-64:       1d:       8b 44 24 24                                     movl    36(%rsp), %eax
32# COFF-x86-64:       21:       48 83 c4 28                                     addq    $40, %rsp
33# COFF-x86-64:       25:       c3                                              ret
34
35# RUN: llvm-objdump --no-print-imm-hex -d -r %p/../Inputs/trivial-object-test.macho-i386 \
36# RUN:              | FileCheck %s -check-prefix MACHO-i386
37
38# MACHO-i386: file format mach-o 32-bit i386
39# MACHO-i386: Disassembly of section __TEXT,__text:
40# MACHO-i386: <_main>:
41# MACHO-i386:        0:       83 ec 0c                                        subl    $12, %esp
42# MACHO-i386:        3:       c7 44 24 08 00 00 00 00                         movl    $0, 8(%esp)
43# MACHO-i386:        b:       c7 04 24 24 00 00 00                            movl    $36, (%esp)
44# MACHO-i386:                                e: GENERIC_RELOC_VANILLA __cstring
45# MACHO-i386:       12:       e8 1f 00 00 00                                  calll   0x36
46# MACHO-i386:                               13: GENERIC_RELOC_VANILLA __jump_table
47# MACHO-i386:       17:       e8 15 00 00 00                                  calll   0x31
48# MACHO-i386:                               18: GENERIC_RELOC_VANILLA __jump_table
49# MACHO-i386:       1c:       8b 44 24 08                                     movl    8(%esp), %eax
50# MACHO-i386:       20:       83 c4 0c                                        addl    $12, %esp
51# MACHO-i386:       23:       c3                                              ret
52
53# RUN: llvm-objdump --no-print-imm-hex -d -r %p/../Inputs/trivial-object-test.macho-x86-64 \
54# RUN:              | FileCheck %s -check-prefix MACHO-x86-64
55
56# MACHO-x86-64: file format mach-o 64-bit x86-64
57# MACHO-x86-64: Disassembly of section __TEXT,__text:
58# MACHO-x86-64: <_main>:
59# MACHO-x86-64:        0:       48 83 ec 08                                     subq    $8, %rsp
60# MACHO-x86-64:        4:       c7 44 24 04 00 00 00 00                         movl    $0, 4(%rsp)
61# MACHO-x86-64:        c:       48 8d 3d 00 00 00 00                            leaq    (%rip), %rdi
62# MACHO-x86-64:                                f: X86_64_RELOC_SIGNED   L_.str
63# MACHO-x86-64:       13:       e8 00 00 00 00                                  callq   0
64# MACHO-x86-64:                               14: X86_64_RELOC_BRANCH   _puts
65# MACHO-x86-64:       18:       30 c0                                           xorb    %al, %al
66# MACHO-x86-64:       1a:       e8 00 00 00 00                                  callq   0
67# MACHO-x86-64:                               1b: X86_64_RELOC_BRANCH   _SomeOtherFunction
68# MACHO-x86-64:       1f:       8b 44 24 04                                     movl    4(%rsp), %eax
69# MACHO-x86-64:       23:       48 83 c4 08                                     addq    $8, %rsp
70# MACHO-x86-64:       27:       c3                                              ret
71
72# RUN: yaml2obj --docnum=1 %s -o %t.elf-i386
73# RUN: llvm-objdump --no-print-imm-hex -d -r %t.elf-i386 | FileCheck %s --check-prefix=ELF-i386
74
75# ELF-i386: file format elf32-i386
76# ELF-i386: Disassembly of section .text:
77# ELF-i386: <main>:
78# ELF-i386:        0:     83 ec 0c                                        subl    $12, %esp
79# ELF-i386:        3:     c7 44 24 08 00 00 00 00                         movl    $0, 8(%esp)
80# ELF-i386:        b:     c7 04 24 00 00 00 00                            movl    $0, (%esp)
81# ELF-i386:                              e: R_386_32      .rodata.str1.1
82# ELF-i386:       12:     e8 fc ff ff ff                                  calll   0x13
83# ELF-i386:                             13: R_386_PC32    puts
84# ELF-i386:       17:     e8 fc ff ff ff                                  calll   0x18
85# ELF-i386:                             18: R_386_PC32    SomeOtherFunction
86# ELF-i386:       1c:     8b 44 24 08                                     movl    8(%esp), %eax
87# ELF-i386:       20:     83 c4 0c                                        addl    $12, %esp
88# ELF-i386:       23:     c3                                              ret
89
90--- !ELF
91FileHeader:
92  Class:   ELFCLASS32
93  Data:    ELFDATA2LSB
94  Type:    ET_REL
95  Machine: EM_386
96Sections:
97  - Name:    .text
98    Type:    SHT_PROGBITS
99    Flags:   [ SHF_ALLOC, SHF_EXECINSTR ]
100    Content: 83EC0CC744240800000000C7042400000000E8FCFFFFFFE8FCFFFFFF8B44240883C40CC3
101  - Name:    .rodata.str1.1
102    Type:    SHT_PROGBITS
103  - Name:    .rel.text
104    Type:    SHT_REL
105    Info:    .text
106    Relocations:
107      - Offset: 0x000000000000000E
108        Symbol: .rodata.str1.1
109        Type:   R_386_32
110      - Offset: 0x0000000000000013
111        Symbol: puts
112        Type:   R_386_PC32
113      - Offset: 0x0000000000000018
114        Symbol: SomeOtherFunction
115        Type:   R_386_PC32
116Symbols:
117  - Name:    .rodata.str1.1
118    Type:    STT_SECTION
119    Section: .rodata.str1.1
120  - Name:    main
121    Type:    STT_FUNC
122    Section: .text
123    Binding: STB_GLOBAL
124  - Name:    SomeOtherFunction
125    Binding: STB_GLOBAL
126  - Name:    puts
127    Binding: STB_GLOBAL
128
129# RUN: yaml2obj --docnum=2 %s -o %t.elf-x86-64
130# RUN: llvm-objdump --no-print-imm-hex -d -r %t.elf-x86-64 | FileCheck %s --check-prefix=ELF-x86-64
131
132--- !ELF
133FileHeader:
134  Class:   ELFCLASS64
135  Data:    ELFDATA2LSB
136  Type:    ET_REL
137  Machine: EM_X86_64
138Sections:
139  - Name:    .text
140    Type:    SHT_PROGBITS
141    Flags:   [ SHF_ALLOC, SHF_EXECINSTR ]
142    Content: 4883EC08C744240400000000BF00000000E80000000030C0E8000000008B4424044883C408C3
143  - Name:    .rodata.str1.1
144    Type:    SHT_PROGBITS
145  - Name:    .rela.text
146    Type:    SHT_RELA
147    Info:    .text
148    Relocations:
149      - Offset: 0x000000000000000D
150        Symbol: .rodata.str1.1
151        Type:   R_X86_64_32S
152      - Offset: 0x0000000000000012
153        Symbol: puts
154        Type:   R_X86_64_PC32
155        Addend: -4
156      - Offset: 0x0000000000000019
157        Symbol: SomeOtherFunction
158        Type:   R_X86_64_PC32
159        Addend: -4
160Symbols:
161  - Name:    .rodata.str1.1
162    Type:    STT_SECTION
163    Section: .rodata.str1.1
164  - Name:    main
165    Type:    STT_FUNC
166    Section: .text
167    Binding: STB_GLOBAL
168  - Name:    SomeOtherFunction
169    Binding: STB_GLOBAL
170  - Name:    puts
171    Binding: STB_GLOBAL
172
173# ELF-x86-64: file format elf64-x86-64
174# ELF-x86-64: Disassembly of section .text:
175# ELF-x86-64: <main>:
176# ELF-x86-64:        0:   48 83 ec 08                                     subq    $8, %rsp
177# ELF-x86-64:        4:   c7 44 24 04 00 00 00 00                         movl    $0, 4(%rsp)
178# ELF-x86-64:        c:   bf 00 00 00 00                                  movl    $0, %edi
179# ELF-x86-64:                            d: R_X86_64_32S  .rodata.str1.1
180# ELF-x86-64:       11:   e8 00 00 00 00                                  callq   0
181# ELF-x86-64:                           12: R_X86_64_PC32 puts-0x4
182# ELF-x86-64:       16:   30 c0                                           xorb    %al, %al
183# ELF-x86-64:       18:   e8 00 00 00 00                                  callq   0
184# ELF-x86-64:                           19: R_X86_64_PC32 SomeOtherFunction-0x4
185# ELF-x86-64:       1d:   8b 44 24 04                                     movl    4(%rsp), %eax
186# ELF-x86-64:       21:   48 83 c4 08                                     addq    $8, %rsp
187# ELF-x86-64:       25:   c3                                              ret
188