llvm-project
74 строки · 3.6 Кб
1# REQUIRES: x86
2# RUN: rm -rf %t; split-file %s %t
3# RUN: llvm-mc -filetype=obj -triple=x86_64-apple-darwin %t/dylib.s -o %t/dylib.o
4# RUN: %lld -lSystem -dylib %t/dylib.o -o %t/libdylib.dylib
5
6## FileCheck does not like wrapping arithmetic, so we specify all 3 check variables manually:
7## ADDEND := inline/outline addend, unsigned
8## OUTLINE := outline addend, signed
9## REBASE := target of rebase; 0x1000 + ADDEND, unsigned
10
11## We can use the DYLD_CHAINED_IMPORT import format if 0 <= ADDEND <= 255 bytes.
12# RUN: llvm-mc -filetype=obj -triple=x86_64-apple-darwin %t/main.s -o %t/main.o --defsym ADDEND=0
13# RUN: %lld -lSystem -dylib %t/main.o -L%t -ldylib -fixup_chains -o %t/out
14# RUN: llvm-objdump --macho --chained-fixups --dyld-info %t/out | \
15# RUN: FileCheck %s -D#OUTLINE=0 -D#ADDEND=0 -D#%x,REBASE=0x1000 --check-prefixes=IMPORT,COMMON
16# RUN: llvm-mc -filetype=obj -triple=x86_64-apple-darwin %t/main.s -o %t/main.o --defsym ADDEND=255
17# RUN: %lld -lSystem -dylib %t/main.o -L%t -ldylib -fixup_chains -o %t/out
18# RUN: llvm-objdump --macho --chained-fixups --dyld-info %t/out | \
19# RUN: FileCheck %s -D#OUTLINE=0 -D#ADDEND=255 -D#%x,REBASE=0x10FF --check-prefixes=IMPORT,COMMON
20
21## DYLD_CHAINED_IMPORT_ADDEND is used if the addend fits in a 32-bit signed integer.
22# RUN: llvm-mc -filetype=obj -triple=x86_64-apple-darwin %t/main.s -o %t/main.o --defsym ADDEND=-1
23# RUN: %lld -lSystem -dylib %t/main.o -L%t -ldylib -fixup_chains -o %t/out
24# RUN: llvm-objdump --macho --chained-fixups --dyld-info %t/out | \
25# RUN: FileCheck %s -D#%d,OUTLINE=-1 -D#%x,ADDEND=0xFFFFFFFFFFFFFFFF -D#%x,REBASE=0xFFF \
26# RUN: --check-prefixes=IMPORT-ADDEND,COMMON
27# RUN: llvm-mc -filetype=obj -triple=x86_64-apple-darwin %t/main.s -o %t/main.o --defsym ADDEND=256
28# RUN: %lld -lSystem -dylib %t/main.o -L%t -ldylib -fixup_chains -o %t/out
29# RUN: llvm-objdump --macho --chained-fixups --dyld-info %t/out | \
30# RUN: FileCheck %s -D#OUTLINE=256 -D#ADDEND=256 -D#%x,REBASE=0x1100 \
31# RUN: --check-prefixes=IMPORT-ADDEND,COMMON
32
33## Otherwise, DYLD_CHAINED_IMPORT_ADDEND64 is used.
34# RUN: llvm-mc -filetype=obj -triple=x86_64-apple-darwin %t/main.s -o %t/main.o --defsym ADDEND=0x100000000
35# RUN: %lld -lSystem -dylib %t/main.o -L%t -ldylib -fixup_chains -o %t/out
36# RUN: llvm-objdump --macho --chained-fixups --dyld-info %t/out | \
37# RUN: FileCheck %s -D#%x,OUTLINE=0x100000000 -D#%x,ADDEND=0x100000000 \
38# RUN: -D#%x,REBASE=0x100001000 --check-prefixes=IMPORT-ADDEND64,COMMON
39
40# COMMON: dyld information:
41# COMMON-NEXT: segment section address pointer type addend dylib symbol/vm address
42# COMMON-NEXT: __DATA __data {{.*}} bind 0x[[#%X, ADDEND]] libdylib _dysym
43# COMMON-NEXT: __DATA __data {{.*}} rebase 0x[[#%X, REBASE]]
44
45# COMMON: chained fixups header (LC_DYLD_CHAINED_FIXUPS)
46# IMPORT: imports_format = 1 (DYLD_CHAINED_IMPORT)
47# IMPORT-ADDEND: imports_format = 2 (DYLD_CHAINED_IMPORT_ADDEND)
48# IMPORT-ADDEND64: imports_format = 3 (DYLD_CHAINED_IMPORT_ADDEND64)
49
50# IMPORT: dyld chained import[0]
51# IMPORT-ADDEND: dyld chained import addend[0]
52# IMPORT-ADDEND64: dyld chained import addend64[0]
53# COMMON-NEXT: lib_ordinal = 2 (libdylib)
54# COMMON-NEXT: weak_import = 0
55# COMMON-NEXT: name_offset = 0 (_dysym)
56# IMPORT-ADDEND-NEXT: addend = [[#%d, OUTLINE]]
57# IMPORT-ADDEND64-NEXT: addend = [[#%d, OUTLINE]]
58
59#--- dylib.s
60.globl _dysym
61
62_dysym:
63ret
64
65#--- main.s
66.globl _dysym, _local
67
68.data
69_local:
70.skip 128
71
72.p2align 3
73.quad _dysym + ADDEND
74.quad _local + ADDEND
75