xref: /llvm-project/lld/test/MachO/reloc-subtractor.s (revision b1dadab3d9e32206a751dee3247228be79b2f831)
1# REQUIRES: x86, aarch64
2# RUN: rm -rf %t; split-file %s %t
3# RUN: llvm-mc -filetype=obj -triple=x86_64-apple-darwin %t/test.s -o %t/x86_64.o
4# RUN: llvm-mc -filetype=obj -triple=arm64-apple-darwin %t/test.s -o %t/arm64.o
5# RUN: %lld -lSystem %t/x86_64.o -o %t/x86_64 -order_file %t/order-file
6# RUN: llvm-objdump --syms --full-contents --rebase %t/x86_64 | FileCheck %s
7# RUN: %lld -arch arm64 -lSystem %t/arm64.o -o %t/arm64 -order_file %t/order-file
8# RUN: llvm-objdump --syms --full-contents --rebase %t/arm64 | FileCheck %s
9
10# CHECK-LABEL: SYMBOL TABLE:
11# CHECK:       {{0*}}[[#%x, SUB1ADDR:]] l {{.*}} __DATA,bar _sub1
12# CHECK:       {{0*}}[[#%x, SUB2ADDR:]] l {{.*}} __DATA,bar _sub2
13# CHECK:       {{0*}}[[#%x, SUB3ADDR:]] l {{.*}} __DATA,bar _sub3
14# CHECK:       {{0*}}[[#%x, SUB4ADDR:]] l {{.*}} __DATA,bar _sub4
15# CHECK:       {{0*}}[[#%x, SUB5ADDR:]] l {{.*}} __DATA,bar _sub5
16# CHECK-LABEL: Contents of section __DATA,bar:
17# CHECK:       [[#SUB1ADDR]] 10000000
18# CHECK-NEXT:  [[#SUB2ADDR]] f2ffffff
19# CHECK-NEXT:  [[#SUB3ADDR]] 14000000 00000000
20# CHECK-NEXT:  [[#SUB4ADDR]] f6ffffff ffffffff
21# CHECK-NEXT:  [[#SUB5ADDR]] f1ffffff ffffffff
22# CHECK:       Rebase table:
23# CHECK-NEXT:  segment  section            address     type
24# CHECK-EMPTY:
25
26#--- test.s
27
28.globl _main, _subtrahend_1, _subtrahend_2, _minuend1, _minuend2
29
30.section __DATA,foo
31  .space 16
32L_.minuend:
33  .space 16
34
35.section __DATA,bar
36_sub1:
37  .long _minuend_1 - _subtrahend_1
38  .space 12
39_sub2:
40  .long _minuend_2 - _subtrahend_2 + 2
41  .space 12
42_sub3:
43  .quad _minuend_1 - _subtrahend_1 + 4
44  .space 8
45_sub4:
46  .quad _minuend_2 - _subtrahend_2 + 6
47  .space 8
48_sub5:
49  .quad L_.minuend - _subtrahend_1 + 1
50  .space 8
51
52_minuend_1:
53  .space 16
54_minuend_2:
55  .space 16
56_subtrahend_1:
57  .space 16
58_subtrahend_2:
59  .space 16
60
61.text
62.p2align 2
63_main:
64  ret
65
66.subsections_via_symbols
67
68#--- order-file
69## Reorder the symbols to make sure that the addends are being associated with
70## the minuend (and not the subtrahend) relocation.
71_subtrahend_1
72_minuend_1
73_minuend_2
74_subtrahend_2
75