2018-02-17 05:16:57 +08:00
|
|
|
# RUN: ld64.lld -arch i386 -r -print_atoms %s -o %t | FileCheck %s \
|
|
|
|
# RUN: && ld64.lld -arch i386 -r -print_atoms %t -o %t2 | FileCheck %s
|
2014-07-03 07:52:22 +08:00
|
|
|
#
|
2014-07-18 07:16:21 +08:00
|
|
|
# Test parsing and writing of x86 relocations.
|
2014-07-03 07:52:22 +08:00
|
|
|
#
|
2014-07-18 07:16:21 +08:00
|
|
|
# The first step tests if the supplied mach-o file is parsed into the correct
|
|
|
|
# set of references. The second step verifies relocations can be round-tripped
|
|
|
|
# by writing to a new .o file, then parsing that file which should result in
|
|
|
|
# the same references.
|
2014-07-03 07:52:22 +08:00
|
|
|
#
|
2014-07-18 07:16:21 +08:00
|
|
|
# .text
|
2014-07-03 07:52:22 +08:00
|
|
|
#_test:
|
|
|
|
# call _undef
|
|
|
|
# call _undef+2
|
2014-07-18 08:37:52 +08:00
|
|
|
# call _foo
|
|
|
|
# call _foo+2
|
2014-07-03 07:52:22 +08:00
|
|
|
# callw _undef
|
2014-07-18 08:37:52 +08:00
|
|
|
# callw _foo
|
|
|
|
# callw _foo+2
|
2014-07-03 07:52:22 +08:00
|
|
|
#L1:
|
|
|
|
# movl _undef, %eax
|
|
|
|
# movl _x, %eax
|
2014-07-18 09:05:35 +08:00
|
|
|
# movl _x+4, %eax
|
2014-07-03 07:52:22 +08:00
|
|
|
# movl _x-L1(%eax), %eax
|
|
|
|
# movl _x+4-L1(%eax), %eax
|
|
|
|
#
|
2014-07-18 08:37:52 +08:00
|
|
|
#_foo:
|
|
|
|
# ret
|
|
|
|
#
|
2014-07-03 07:52:22 +08:00
|
|
|
# .data
|
2015-04-28 01:18:04 +08:00
|
|
|
#_x:
|
2014-07-03 07:52:22 +08:00
|
|
|
# .long _undef
|
2014-07-18 09:05:35 +08:00
|
|
|
# .long _undef+7
|
2014-07-18 08:37:52 +08:00
|
|
|
# .long _foo
|
2014-07-18 09:05:35 +08:00
|
|
|
# .long _foo+3
|
2014-07-03 07:52:22 +08:00
|
|
|
# .long _test - .
|
|
|
|
# .long _test+3 - .
|
|
|
|
#
|
|
|
|
|
|
|
|
--- !mach-o
|
|
|
|
arch: x86
|
|
|
|
file-type: MH_OBJECT
|
2014-07-18 08:37:52 +08:00
|
|
|
flags: [ MH_SUBSECTIONS_VIA_SYMBOLS ]
|
2014-07-03 07:52:22 +08:00
|
|
|
OS: unknown
|
2015-04-28 01:18:04 +08:00
|
|
|
sections:
|
2014-07-03 07:52:22 +08:00
|
|
|
- segment: __TEXT
|
|
|
|
section: __text
|
|
|
|
type: S_REGULAR
|
|
|
|
attributes: [ S_ATTR_PURE_INSTRUCTIONS, S_ATTR_SOME_INSTRUCTIONS ]
|
|
|
|
address: 0x0000000000000000
|
2015-04-28 01:18:04 +08:00
|
|
|
content: [ 0xE8, 0xFB, 0xFF, 0xFF, 0xFF, 0xE8, 0xF8, 0xFF,
|
|
|
|
0xFF, 0xFF, 0xE8, 0x2C, 0x00, 0x00, 0x00, 0xE8,
|
|
|
|
0x29, 0x00, 0x00, 0x00, 0x66, 0xE8, 0xE8, 0xFF,
|
|
|
|
0x66, 0xE8, 0x1F, 0x00, 0x66, 0xE8, 0x1D, 0x00,
|
|
|
|
0xA1, 0x00, 0x00, 0x00, 0x00, 0xA1, 0x3C, 0x00,
|
|
|
|
0x00, 0x00, 0xA1, 0x40, 0x00, 0x00, 0x00, 0x8B,
|
|
|
|
0x80, 0x1C, 0x00, 0x00, 0x00, 0x8B, 0x80, 0x20,
|
2014-07-18 09:05:35 +08:00
|
|
|
0x00, 0x00, 0x00, 0xC3 ]
|
2015-04-28 01:18:04 +08:00
|
|
|
relocations:
|
2014-07-18 09:05:35 +08:00
|
|
|
- offset: 0x00000037
|
2014-07-03 07:52:22 +08:00
|
|
|
scattered: true
|
|
|
|
type: GENERIC_RELOC_LOCAL_SECTDIFF
|
|
|
|
length: 2
|
|
|
|
pc-rel: false
|
2014-07-18 09:05:35 +08:00
|
|
|
value: 0x0000003C
|
2014-07-03 07:52:22 +08:00
|
|
|
- offset: 0x00000000
|
|
|
|
scattered: true
|
|
|
|
type: GENERIC_RELOC_PAIR
|
|
|
|
length: 2
|
|
|
|
pc-rel: false
|
2014-07-18 08:37:52 +08:00
|
|
|
value: 0x00000020
|
2014-07-18 09:05:35 +08:00
|
|
|
- offset: 0x00000031
|
2014-07-03 07:52:22 +08:00
|
|
|
scattered: true
|
|
|
|
type: GENERIC_RELOC_LOCAL_SECTDIFF
|
|
|
|
length: 2
|
|
|
|
pc-rel: false
|
2014-07-18 09:05:35 +08:00
|
|
|
value: 0x0000003C
|
2014-07-03 07:52:22 +08:00
|
|
|
- offset: 0x00000000
|
|
|
|
scattered: true
|
|
|
|
type: GENERIC_RELOC_PAIR
|
|
|
|
length: 2
|
|
|
|
pc-rel: false
|
2014-07-18 08:37:52 +08:00
|
|
|
value: 0x00000020
|
2014-07-18 09:05:35 +08:00
|
|
|
- offset: 0x0000002B
|
|
|
|
scattered: true
|
|
|
|
type: GENERIC_RELOC_VANILLA
|
|
|
|
length: 2
|
|
|
|
pc-rel: false
|
|
|
|
value: 0x0000003C
|
2014-07-18 08:37:52 +08:00
|
|
|
- offset: 0x00000026
|
2014-07-03 07:52:22 +08:00
|
|
|
type: GENERIC_RELOC_VANILLA
|
|
|
|
length: 2
|
|
|
|
pc-rel: false
|
|
|
|
extern: false
|
|
|
|
symbol: 2
|
2014-07-18 08:37:52 +08:00
|
|
|
- offset: 0x00000021
|
2014-07-03 07:52:22 +08:00
|
|
|
type: GENERIC_RELOC_VANILLA
|
|
|
|
length: 2
|
|
|
|
pc-rel: false
|
|
|
|
extern: true
|
2014-07-18 08:37:52 +08:00
|
|
|
symbol: 3
|
|
|
|
- offset: 0x0000001E
|
|
|
|
scattered: true
|
|
|
|
type: GENERIC_RELOC_VANILLA
|
|
|
|
length: 1
|
|
|
|
pc-rel: true
|
2014-07-18 09:05:35 +08:00
|
|
|
value: 0x0000003B
|
2014-07-18 08:37:52 +08:00
|
|
|
- offset: 0x0000001A
|
|
|
|
type: GENERIC_RELOC_VANILLA
|
|
|
|
length: 1
|
|
|
|
pc-rel: true
|
|
|
|
extern: false
|
|
|
|
symbol: 1
|
|
|
|
- offset: 0x00000016
|
2014-07-03 07:52:22 +08:00
|
|
|
type: GENERIC_RELOC_VANILLA
|
|
|
|
length: 1
|
|
|
|
pc-rel: true
|
|
|
|
extern: true
|
2014-07-18 08:37:52 +08:00
|
|
|
symbol: 3
|
|
|
|
- offset: 0x00000010
|
|
|
|
scattered: true
|
|
|
|
type: GENERIC_RELOC_VANILLA
|
|
|
|
length: 2
|
|
|
|
pc-rel: true
|
2014-07-18 09:05:35 +08:00
|
|
|
value: 0x0000003B
|
2014-07-18 08:37:52 +08:00
|
|
|
- offset: 0x0000000B
|
|
|
|
type: GENERIC_RELOC_VANILLA
|
|
|
|
length: 2
|
|
|
|
pc-rel: true
|
|
|
|
extern: false
|
|
|
|
symbol: 1
|
2014-07-03 07:52:22 +08:00
|
|
|
- offset: 0x00000006
|
|
|
|
type: GENERIC_RELOC_VANILLA
|
|
|
|
length: 2
|
|
|
|
pc-rel: true
|
|
|
|
extern: true
|
2014-07-18 08:37:52 +08:00
|
|
|
symbol: 3
|
2014-07-03 07:52:22 +08:00
|
|
|
- offset: 0x00000001
|
|
|
|
type: GENERIC_RELOC_VANILLA
|
|
|
|
length: 2
|
|
|
|
pc-rel: true
|
|
|
|
extern: true
|
2014-07-18 08:37:52 +08:00
|
|
|
symbol: 3
|
2014-07-03 07:52:22 +08:00
|
|
|
- segment: __DATA
|
|
|
|
section: __data
|
|
|
|
type: S_REGULAR
|
|
|
|
attributes: [ ]
|
2014-07-18 09:05:35 +08:00
|
|
|
address: 0x000000000000003C
|
2015-04-28 01:18:04 +08:00
|
|
|
content: [ 0x00, 0x00, 0x00, 0x00, 0x07, 0x00, 0x00, 0x00,
|
|
|
|
0x3B, 0x00, 0x00, 0x00, 0x3E, 0x00, 0x00, 0x00,
|
2014-07-18 09:05:35 +08:00
|
|
|
0xB4, 0xFF, 0xFF, 0xFF, 0xB3, 0xFF, 0xFF, 0xFF ]
|
2015-04-28 01:18:04 +08:00
|
|
|
relocations:
|
2014-07-18 09:05:35 +08:00
|
|
|
- offset: 0x00000014
|
2014-07-03 07:52:22 +08:00
|
|
|
scattered: true
|
|
|
|
type: GENERIC_RELOC_LOCAL_SECTDIFF
|
|
|
|
length: 2
|
|
|
|
pc-rel: false
|
|
|
|
value: 0x00000000
|
|
|
|
- offset: 0x00000000
|
|
|
|
scattered: true
|
|
|
|
type: GENERIC_RELOC_PAIR
|
|
|
|
length: 2
|
|
|
|
pc-rel: false
|
2014-07-18 09:05:35 +08:00
|
|
|
value: 0x00000050
|
|
|
|
- offset: 0x00000010
|
2014-07-03 07:52:22 +08:00
|
|
|
scattered: true
|
|
|
|
type: GENERIC_RELOC_LOCAL_SECTDIFF
|
|
|
|
length: 2
|
|
|
|
pc-rel: false
|
|
|
|
value: 0x00000000
|
|
|
|
- offset: 0x00000000
|
|
|
|
scattered: true
|
|
|
|
type: GENERIC_RELOC_PAIR
|
|
|
|
length: 2
|
|
|
|
pc-rel: false
|
2014-07-18 09:05:35 +08:00
|
|
|
value: 0x0000004C
|
|
|
|
- offset: 0x0000000C
|
|
|
|
scattered: true
|
|
|
|
type: GENERIC_RELOC_VANILLA
|
|
|
|
length: 2
|
|
|
|
pc-rel: false
|
|
|
|
value: 0x0000003B
|
|
|
|
- offset: 0x00000008
|
2014-07-18 08:37:52 +08:00
|
|
|
type: GENERIC_RELOC_VANILLA
|
|
|
|
length: 2
|
|
|
|
pc-rel: false
|
|
|
|
extern: false
|
|
|
|
symbol: 1
|
2014-07-18 09:05:35 +08:00
|
|
|
- offset: 0x00000004
|
|
|
|
type: GENERIC_RELOC_VANILLA
|
|
|
|
length: 2
|
|
|
|
pc-rel: false
|
|
|
|
extern: true
|
|
|
|
symbol: 3
|
2014-07-03 07:52:22 +08:00
|
|
|
- offset: 0x00000000
|
|
|
|
type: GENERIC_RELOC_VANILLA
|
|
|
|
length: 2
|
|
|
|
pc-rel: false
|
|
|
|
extern: true
|
2014-07-18 08:37:52 +08:00
|
|
|
symbol: 3
|
2015-04-28 01:18:04 +08:00
|
|
|
local-symbols:
|
2014-07-03 07:52:22 +08:00
|
|
|
- name: _test
|
|
|
|
type: N_SECT
|
|
|
|
sect: 1
|
|
|
|
value: 0x0000000000000000
|
2014-07-18 08:37:52 +08:00
|
|
|
- name: _foo
|
|
|
|
type: N_SECT
|
|
|
|
sect: 1
|
2014-07-18 09:05:35 +08:00
|
|
|
value: 0x000000000000003B
|
2014-07-03 07:52:22 +08:00
|
|
|
- name: _x
|
|
|
|
type: N_SECT
|
|
|
|
sect: 2
|
2014-07-18 09:05:35 +08:00
|
|
|
value: 0x000000000000003C
|
2015-04-28 01:18:04 +08:00
|
|
|
undefined-symbols:
|
2014-07-03 07:52:22 +08:00
|
|
|
- name: _undef
|
|
|
|
type: N_UNDF
|
|
|
|
scope: [ N_EXT ]
|
|
|
|
value: 0x0000000000000000
|
|
|
|
...
|
|
|
|
|
|
|
|
# CHECK: defined-atoms:
|
|
|
|
# CHECK: - name: _x
|
|
|
|
# CHECK: type: data
|
|
|
|
# CHECK: references:
|
|
|
|
# CHECK: - kind: pointer32
|
|
|
|
# CHECK: offset: 0
|
|
|
|
# CHECK: target: _undef
|
2014-07-18 09:05:35 +08:00
|
|
|
# CHECK-NOT: addend:
|
2014-07-18 08:37:52 +08:00
|
|
|
# CHECK: - kind: pointer32
|
2014-07-03 07:52:22 +08:00
|
|
|
# CHECK: offset: 4
|
2014-07-18 09:05:35 +08:00
|
|
|
# CHECK: target: _undef
|
|
|
|
# CHECK: addend: 7
|
|
|
|
# CHECK: - kind: pointer32
|
|
|
|
# CHECK: offset: 8
|
2014-07-18 08:37:52 +08:00
|
|
|
# CHECK: target: _foo
|
2014-07-18 09:05:35 +08:00
|
|
|
# CHECK-NOT: addend:
|
|
|
|
# CHECK: - kind: pointer32
|
|
|
|
# CHECK: offset: 12
|
|
|
|
# CHECK: target: _foo
|
|
|
|
# CHECK: addend: 3
|
2014-07-03 07:52:22 +08:00
|
|
|
# CHECK: - kind: delta32
|
2014-07-18 09:05:35 +08:00
|
|
|
# CHECK: offset: 16
|
2014-07-03 07:52:22 +08:00
|
|
|
# CHECK: target: _test
|
2014-07-18 08:37:52 +08:00
|
|
|
# CHECK: - kind: delta32
|
2014-07-18 09:05:35 +08:00
|
|
|
# CHECK: offset: 20
|
2014-07-18 08:37:52 +08:00
|
|
|
# CHECK: target: _test
|
2014-07-03 07:52:22 +08:00
|
|
|
# CHECK: addend: 3
|
|
|
|
# CHECK: - name: _test
|
|
|
|
# CHECK: references:
|
|
|
|
# CHECK: - kind: branch32
|
|
|
|
# CHECK: offset: 1
|
|
|
|
# CHECK: target: _undef
|
|
|
|
# CHECK-NOT: addend:
|
|
|
|
# CHECK: - kind: branch32
|
|
|
|
# CHECK: offset: 6
|
|
|
|
# CHECK: target: _undef
|
|
|
|
# CHECK: addend: 2
|
2014-07-18 08:37:52 +08:00
|
|
|
# CHECK: - kind: branch32
|
|
|
|
# CHECK: offset: 11
|
|
|
|
# CHECK: target: _foo
|
|
|
|
# CHECK-NOT: addend:
|
|
|
|
# CHECK: - kind: branch32
|
|
|
|
# CHECK: offset: 16
|
|
|
|
# CHECK: target: _foo
|
|
|
|
# CHECK: addend: 2
|
2014-07-03 07:52:22 +08:00
|
|
|
# CHECK: - kind: branch16
|
2014-07-18 08:37:52 +08:00
|
|
|
# CHECK: offset: 22
|
2014-07-03 07:52:22 +08:00
|
|
|
# CHECK: target: _undef
|
2014-07-18 08:37:52 +08:00
|
|
|
# CHECK-NOT: addend:
|
|
|
|
# CHECK: - kind: branch16
|
|
|
|
# CHECK: offset: 26
|
|
|
|
# CHECK: target: _foo
|
|
|
|
# CHECK-NOT: addend:
|
|
|
|
# CHECK: - kind: branch16
|
|
|
|
# CHECK: offset: 30
|
|
|
|
# CHECK: target: _foo
|
|
|
|
# CHECK: addend: 2
|
2014-07-03 07:52:22 +08:00
|
|
|
# CHECK: - kind: abs32
|
2014-07-18 08:37:52 +08:00
|
|
|
# CHECK: offset: 33
|
2014-07-03 07:52:22 +08:00
|
|
|
# CHECK: target: _undef
|
|
|
|
# CHECK: - kind: abs32
|
2014-07-18 08:37:52 +08:00
|
|
|
# CHECK: offset: 38
|
2014-07-03 07:52:22 +08:00
|
|
|
# CHECK: target: _x
|
2014-07-18 09:05:35 +08:00
|
|
|
# CHECK: - kind: abs32
|
|
|
|
# CHECK: offset: 43
|
|
|
|
# CHECK: target: _x
|
|
|
|
# CHECK: addend: 4
|
2014-07-03 07:52:22 +08:00
|
|
|
# CHECK: - kind: funcRel32
|
2014-07-18 09:05:35 +08:00
|
|
|
# CHECK: offset: 49
|
2014-07-03 07:52:22 +08:00
|
|
|
# CHECK: target: _x
|
2014-07-18 08:37:52 +08:00
|
|
|
# CHECK: addend: -32
|
2014-07-03 07:52:22 +08:00
|
|
|
# CHECK: - kind: funcRel32
|
2014-07-18 09:05:35 +08:00
|
|
|
# CHECK: offset: 55
|
2014-07-03 07:52:22 +08:00
|
|
|
# CHECK: target: _x
|
2014-07-18 08:37:52 +08:00
|
|
|
# CHECK: addend: -28
|
2014-07-03 07:52:22 +08:00
|
|
|
|