xref: /llvm-project/llvm/test/tools/llvm-objcopy/MachO/install-name-tool-rpath.test (revision c0da287c30c9f511ccb07fdd42c997be2caea9ec)
1b925ca37SAlexander Shaposhnikov## This test checks updating a LC_RPATH load command in a MachO binary.
2b925ca37SAlexander Shaposhnikov
3b925ca37SAlexander Shaposhnikov# RUN: yaml2obj %s -o %t
4b925ca37SAlexander Shaposhnikov
5b925ca37SAlexander Shaposhnikov## Updating a single RPath entry:
6b925ca37SAlexander Shaposhnikov# RUN: llvm-install-name-tool -rpath @executable_a/. @executable_A/. %t
7b925ca37SAlexander Shaposhnikov# RUN: llvm-objdump -p %t | \
8b925ca37SAlexander Shaposhnikov# RUN:   FileCheck %s --check-prefix=RPATHS --implicit-check-not=@executable
9b925ca37SAlexander Shaposhnikov
10b925ca37SAlexander Shaposhnikov# RPATHS: @executable_A/.
11b925ca37SAlexander Shaposhnikov# RPATHS: @executable_short_test
12b925ca37SAlexander Shaposhnikov# RPATHS: @executable_long_test/.
13b925ca37SAlexander Shaposhnikov# RPATHS: @executable_d/.
14b925ca37SAlexander Shaposhnikov
15b925ca37SAlexander Shaposhnikov## Updating multiple RPath entries:
16b925ca37SAlexander Shaposhnikov# RUN: llvm-install-name-tool -rpath @executable_short_test/. @executable_test/. \
17b925ca37SAlexander Shaposhnikov# RUN:                        -rpath @executable_long_test/. @executable_long_long_test/. %t
18b925ca37SAlexander Shaposhnikov# RUN: llvm-objdump -p %t | \
19b925ca37SAlexander Shaposhnikov# RUN:   FileCheck %s --check-prefix=RPATHS-MULTIPLE --implicit-check-not=@executable
20b925ca37SAlexander Shaposhnikov
21b925ca37SAlexander Shaposhnikov# RPATHS-MULTIPLE: @executable_A/.
22b925ca37SAlexander Shaposhnikov# RPATHS-MULTIPLE: @executable_test/.
23b925ca37SAlexander Shaposhnikov# RPATHS-MULTIPLE: @executable_long_long_test/.
24b925ca37SAlexander Shaposhnikov# RPATHS-MULTIPLE: @executable_d/.
25b925ca37SAlexander Shaposhnikov
26b925ca37SAlexander Shaposhnikov## Check that cmdsize accounts for NULL terminator:
27b925ca37SAlexander Shaposhnikov# RUN: llvm-install-name-tool -rpath @executable_A/. ABCD %t
28b925ca37SAlexander Shaposhnikov# RUN: llvm-objdump -p %t | FileCheck %s --check-prefix=RPATH-SIZE
29b925ca37SAlexander Shaposhnikov
30b925ca37SAlexander Shaposhnikov# RPATH-SIZE:      cmd LC_RPATH
31b925ca37SAlexander Shaposhnikov# RPATH-SIZE-NEXT: cmdsize 24
32b925ca37SAlexander Shaposhnikov# RPATH-SIZE-NEXT: path ABCD
33b925ca37SAlexander Shaposhnikov
34b925ca37SAlexander Shaposhnikov## Updating and adding different RPaths:
35b925ca37SAlexander Shaposhnikov# RUN: llvm-install-name-tool -rpath @executable_d/. @executable_D/. \
36b925ca37SAlexander Shaposhnikov# RUN:                        -add_rpath @executable_e/. %t
37b925ca37SAlexander Shaposhnikov# RUN: llvm-objdump -p %t | FileCheck %s --check-prefix=RPATHS-ADD --implicit-check-not=@executable
38b925ca37SAlexander Shaposhnikov
39b925ca37SAlexander Shaposhnikov# RPATHS-ADD: ABCD
40b925ca37SAlexander Shaposhnikov# RPATHS-ADD: @executable_test/.
41b925ca37SAlexander Shaposhnikov# RPATHS-ADD: @executable_long_long_test/.
42b925ca37SAlexander Shaposhnikov# RPATHS-ADD: @executable_D/.
43b925ca37SAlexander Shaposhnikov# RPATHS-ADD: @executable_e/.
44b925ca37SAlexander Shaposhnikov
45b925ca37SAlexander Shaposhnikov## Updating and deleting different RPaths:
46b925ca37SAlexander Shaposhnikov# RUN: llvm-install-name-tool -rpath @executable_D/. @executable_d/. \
47b925ca37SAlexander Shaposhnikov# RUN:                        -delete_rpath @executable_e/. %t
48b925ca37SAlexander Shaposhnikov# RUN: llvm-objdump -p %t | FileCheck %s --check-prefix=RPATHS-DELETE --implicit-check-not=@executable
49b925ca37SAlexander Shaposhnikov
50b925ca37SAlexander Shaposhnikov# RPATHS-DELETE: ABCD
51b925ca37SAlexander Shaposhnikov# RPATHS-DELETE: @executable_test/.
52b925ca37SAlexander Shaposhnikov# RPATHS-DELETE: @executable_long_long_test/.
53b925ca37SAlexander Shaposhnikov# RPATHS-DELETE: @executable_d/.
54b925ca37SAlexander Shaposhnikov
55b925ca37SAlexander Shaposhnikov# RUN: cp %t %t1
56b925ca37SAlexander Shaposhnikov
57b925ca37SAlexander Shaposhnikov## Updating multiple RPath entries where one exists and the other doesn't:
58b925ca37SAlexander Shaposhnikov# RUN: not llvm-install-name-tool -rpath @executable_test/. @executable/. \
59b925ca37SAlexander Shaposhnikov# RUN:                            -rpath @executable_long_test/. @executable_long_longest/. %t 2>&1 | \
60b925ca37SAlexander Shaposhnikov# RUN:   FileCheck %s --check-prefix=RPATHS-FAIL
61b925ca37SAlexander Shaposhnikov# RUN: cmp %t %t1
62b925ca37SAlexander Shaposhnikov
63b925ca37SAlexander Shaposhnikov# RPATHS-FAIL: no LC_RPATH load command with path: @executable_long_test/.
64b925ca37SAlexander Shaposhnikov
65b925ca37SAlexander Shaposhnikov## Updating a nonexistent RPath:
66b925ca37SAlexander Shaposhnikov# RUN: not llvm-install-name-tool -rpath @executable_a/. @executable_AA/. %t 2>&1 | \
67b925ca37SAlexander Shaposhnikov# RUN:   FileCheck %s --check-prefix=ABSENT-RPATH
68b925ca37SAlexander Shaposhnikov# RUN: cmp %t %t1
69b925ca37SAlexander Shaposhnikov
70b925ca37SAlexander Shaposhnikov# ABSENT-RPATH: no LC_RPATH load command with path: @executable_a/.
71b925ca37SAlexander Shaposhnikov
72b925ca37SAlexander Shaposhnikov## Updating to an existing RPath:
73b925ca37SAlexander Shaposhnikov# RUN: not llvm-install-name-tool -rpath @executable_d/. ABCD %t 2>&1 | \
74b925ca37SAlexander Shaposhnikov# RUN:   FileCheck %s --check-prefix=EXISTING
75b925ca37SAlexander Shaposhnikov# RUN: cmp %t %t1
76b925ca37SAlexander Shaposhnikov
7751f8d464SKeith Smiley# EXISTING: rpath 'ABCD' would create a duplicate load command
78b925ca37SAlexander Shaposhnikov
79b925ca37SAlexander Shaposhnikov## Duplicate RPath entries:
80b925ca37SAlexander Shaposhnikov# RUN: not llvm-install-name-tool -rpath DDD1/. @exec_d/. \
81b925ca37SAlexander Shaposhnikov# RUN:                            -rpath @exec_d/. DDD2/. %t 2>&1 | \
82b925ca37SAlexander Shaposhnikov# RUN:   FileCheck %s --check-prefix=DUPLICATE
83b925ca37SAlexander Shaposhnikov# RUN: cmp %t %t1
84b925ca37SAlexander Shaposhnikov
8551f8d464SKeith Smiley# DUPLICATE: cannot specify both -rpath 'DDD1/.' '@exec_d/.' and -rpath '@exec_d/.' 'DDD2/.'
86b925ca37SAlexander Shaposhnikov
87b925ca37SAlexander Shaposhnikov## Updating and deleting RPath at the same time:
88b925ca37SAlexander Shaposhnikov# RUN: not llvm-install-name-tool -rpath @executable_d/. DD/. \
89b925ca37SAlexander Shaposhnikov# RUN:                            -delete_rpath @executable_d/. %t 2>&1 | \
90b925ca37SAlexander Shaposhnikov# RUN:   FileCheck %s --check-prefix=COMBINED-DELETE
91b925ca37SAlexander Shaposhnikov# RUN: cmp %t %t1
92b925ca37SAlexander Shaposhnikov
9351f8d464SKeith Smiley# COMBINED-DELETE: cannot specify both -delete_rpath '@executable_d/.' and -rpath '@executable_d/.' 'DD/.'
94b925ca37SAlexander Shaposhnikov
95b925ca37SAlexander Shaposhnikov## Updating and adding RPath at the same time:
96b925ca37SAlexander Shaposhnikov# RUN: not llvm-install-name-tool -rpath @executable_e/. EE/. \
97b925ca37SAlexander Shaposhnikov# RUN:                            -add_rpath @executable_e/. %t 2>&1 | \
98b925ca37SAlexander Shaposhnikov# RUN:   FileCheck %s --check-prefix=COMBINED-ADD
99b925ca37SAlexander Shaposhnikov# RUN: cmp %t %t1
100b925ca37SAlexander Shaposhnikov
10151f8d464SKeith Smiley# COMBINED-ADD: cannot specify both -add_rpath '@executable_e/.' and -rpath '@executable_e/.' 'EE/.'
102b925ca37SAlexander Shaposhnikov
103b925ca37SAlexander Shaposhnikov## Missing an RPath argument:
104b925ca37SAlexander Shaposhnikov# RUN: not llvm-install-name-tool %t -rpath @executable_e/. 2>&1 | \
105b925ca37SAlexander Shaposhnikov# RUN:   FileCheck %s --check-prefix=MISSING
106b925ca37SAlexander Shaposhnikov# RUN: cmp %t %t1
107b925ca37SAlexander Shaposhnikov
108b925ca37SAlexander Shaposhnikov## Missing both RPath arguments:
109b925ca37SAlexander Shaposhnikov# RUN: not llvm-install-name-tool %t -rpath 2>&1 | \
110b925ca37SAlexander Shaposhnikov# RUN:   FileCheck %s --check-prefix=MISSING
111b925ca37SAlexander Shaposhnikov# RUN: cmp %t %t1
112b925ca37SAlexander Shaposhnikov
113b925ca37SAlexander Shaposhnikov# MISSING: missing argument to -rpath option
114b925ca37SAlexander Shaposhnikov
115b925ca37SAlexander Shaposhnikov
116b925ca37SAlexander Shaposhnikov--- !mach-o
117b925ca37SAlexander ShaposhnikovFileHeader:
118b925ca37SAlexander Shaposhnikov  magic:           0xFEEDFACF
119b925ca37SAlexander Shaposhnikov  cputype:         0x01000007
120b925ca37SAlexander Shaposhnikov  cpusubtype:      0x00000003
121b925ca37SAlexander Shaposhnikov  filetype:        0x00000001
122b925ca37SAlexander Shaposhnikov  ncmds:           4
123b925ca37SAlexander Shaposhnikov  sizeofcmds:      144
124b925ca37SAlexander Shaposhnikov  flags:           0x00002000
125b925ca37SAlexander Shaposhnikov  reserved:        0x00000000
126b925ca37SAlexander ShaposhnikovLoadCommands:
127b925ca37SAlexander Shaposhnikov  - cmd:             LC_RPATH
128b925ca37SAlexander Shaposhnikov    cmdsize:         32
129b925ca37SAlexander Shaposhnikov    path:            12
130*c0da287cSFangrui Song    Content:         '@executable_a/.'
131b925ca37SAlexander Shaposhnikov  - cmd:             LC_RPATH
132b925ca37SAlexander Shaposhnikov    cmdsize:         40
133b925ca37SAlexander Shaposhnikov    path:            12
134*c0da287cSFangrui Song    Content:         '@executable_short_test/.'
135b925ca37SAlexander Shaposhnikov  - cmd:             LC_RPATH
136b925ca37SAlexander Shaposhnikov    cmdsize:         40
137b925ca37SAlexander Shaposhnikov    path:            12
138*c0da287cSFangrui Song    Content:         '@executable_long_test/.'
139b925ca37SAlexander Shaposhnikov  - cmd:             LC_RPATH
140b925ca37SAlexander Shaposhnikov    cmdsize:         32
141b925ca37SAlexander Shaposhnikov    path:            12
142*c0da287cSFangrui Song    Content:         '@executable_d/.'
143