xref: /llvm-project/lld/test/MachO/reroot-path.s (revision 595fc59f742aeee398eb35ff69182a413a882317)
1# REQUIRES: x86
2# UNSUPPORTED: system-windows
3## FIXME: In principle this test should pass on Windows
4# RUN: rm -rf %t; split-file %s %t
5
6## This test verifies that we attempt to re-root absolute paths if -syslibroot
7## is specified. Therefore we would like to be able to specify an absolute path
8## without worrying that it may match an actual file on the system outside the
9## syslibroot. `chroot` would do the job but isn't cross-platform, so I've used
10## this %t/%:t hack instead.
11# RUN: mkdir -p %t/%:t
12
13# RUN: llvm-mc -filetype=obj -triple=x86_64-apple-darwin %t/foo.s -o %t/foo.o
14# RUN: llvm-mc -filetype=obj -triple=x86_64-apple-darwin %t/bar.s -o %t/bar.o
15# RUN: llvm-mc -filetype=obj -triple=x86_64-apple-darwin %t/test.s -o %t/test.o
16
17## bar.a is under %t/%:t, and so verifies that rerooting happens. foo.a isn't,
18## and therefore verifies that we still fall back to the original path if no
19## file exists at the rerooted path.
20# RUN: llvm-ar rcs %t/foo.a %t/foo.o
21# RUN: %lld -dylib %t/foo.o -o %t/libfoo.dylib
22# RUN: llvm-ar rcs %t/%:t/bar.a %t/bar.o
23# RUN: %lld -dylib %t/bar.o -o %t/%:t/libbar.dylib
24
25## Test our various file-loading flags to make sure all bases are covered.
26# RUN: %lld --reproduce %t/repro1.tar -lSystem -syslibroot %t %t/foo.a %t/bar.a %t/test.o -o /dev/null -t | FileCheck %s -DDIR="%t/%:t"
27# RUN: tar xf %t/repro1.tar -C %t
28# RUN: cd %t/repro1; %no-arg-lld @response.txt | FileCheck %s -DDIR="%:t/%:t"
29
30# RUN: %lld --reproduce %t/repro2.tar -lSystem -syslibroot %t -force_load %t/foo.a -force_load %t/bar.a %t/test.o -o /dev/null -t | FileCheck %s -DDIR="%t/%:t"
31# RUN: tar xf %t/repro2.tar -C %t
32# RUN: cd %t/repro2; %no-arg-lld @response.txt | FileCheck %s -DDIR="%:t/%:t"
33
34# RUN: %lld --reproduce %t/repro3.tar -lSystem -syslibroot %t %t/libfoo.dylib %t/libbar.dylib %t/test.o -o /dev/null -t | FileCheck %s -DDIR="%t/%:t"
35# RUN: tar xf %t/repro3.tar -C %t
36# RUN: cd %t/repro3; %no-arg-lld @response.txt | FileCheck %s -DDIR="%:t/%:t"
37
38# RUN: %lld --reproduce %t/repro4.tar -lSystem -syslibroot %t -weak_library %t/libfoo.dylib -weak_library %t/libbar.dylib %t/test.o -o /dev/null -t | FileCheck %s -DDIR="%t/%:t"
39# RUN: tar xf %t/repro4.tar -C %t
40# RUN: cd %t/repro4; %no-arg-lld @response.txt | FileCheck %s -DDIR="%:t/%:t"
41
42# RUN: %lld --reproduce %t/repro7.tar -lSystem -syslibroot %t -force_load %t/foo.a -force_load %t/bar.a %t/test.o -o /dev/null -t | FileCheck %s -DDIR="%t/%:t"
43# RUN: tar xf %t/repro7.tar -C %t
44# RUN: cd %t/repro7; %no-arg-lld @response.txt | FileCheck %s -DDIR="%:t/%:t"
45
46# RUN: echo "%t/libfoo.dylib" > %t/filelist
47# RUN: echo "%t/libbar.dylib" >> %t/filelist
48# RUN: %lld --reproduce %t/repro5.tar -lSystem -syslibroot %t -filelist %t/filelist %t/test.o -o /dev/null -t | FileCheck %s -DDIR="%t/%:t"
49# RUN: tar xf %t/repro5.tar -C %t
50# RUN: cd %t/repro5; %no-arg-lld @response.txt | FileCheck %s -DDIR="%:t/%:t"
51
52## The {{^}} ensures that we only match relative paths if DIR is relative.
53# CHECK: {{^}}[[DIR]]/{{(lib)?}}bar
54
55## Paths to object files don't get rerooted.
56# RUN: mv %t/bar.o %t/%:t/bar.o
57# RUN: not %lld -lSystem -syslibroot %t %t/foo.o %t/bar.o %t/test.o -o \
58# RUN:   /dev/null 2>&1 | FileCheck %s --check-prefix=OBJ
59# OBJ: error: cannot open {{.*[\\/]}}bar.o: {{[Nn]}}o such file or directory
60
61## Now create a "decoy" libfoo.dylib under %t/%:t to demonstrate that the
62## rerooted path takes precedence over the original path. We will get an
63## undefined symbol error since we aren't loading %t/libfoo.dylib.
64# RUN: cp %t/%:t/libbar.dylib %t/%:t/libfoo.dylib
65# RUN: not %lld --reproduce %t/repro6.tar -lSystem -syslibroot %t %t/libfoo.dylib %t/libbar.dylib %t/test.o \
66# RUN:   -o /dev/null -t 2> %t/error | FileCheck %s -DDIR="%t/%:t" --check-prefix=FOO
67# RUN: FileCheck %s --check-prefix=UNDEF < %t/error
68
69# RUN: tar xf %t/repro6.tar -C %t
70# RUN: cd %t/repro6; not %no-arg-lld @response.txt 2> %t/error | FileCheck %s -DDIR="%:t/%:t" --check-prefix=FOO
71# RUN: FileCheck %s --check-prefix=UNDEF < %t/error
72
73# FOO: [[DIR]]/libfoo.dylib
74# UNDEF: error: undefined symbol: _foo
75
76#--- foo.s
77.globl _foo
78_foo:
79
80#--- bar.s
81.globl _bar
82_bar:
83
84#--- test.s
85.text
86.globl _main
87
88_main:
89  callq _foo
90  callq _bar
91  ret
92