xref: /llvm-project/lld/test/MachO/weak-definition-indirect-fetch.s (revision a1a2a8e8acef1061215d1baa442755b472cc1448)
131d58858SJez Ng# REQUIRES: x86
2a817594dSJez Ng# RUN: rm -rf %t; split-file %s %t
331d58858SJez Ng
431d58858SJez Ng## This tests examines the effect of .weak_definition on symbols in an archive
531d58858SJez Ng## that are not referenced directly, but which are still loaded due to some
631d58858SJez Ng## other symbol in the archive member being referenced.
731d58858SJez Ng##
831d58858SJez Ng## In this particular test, _foo isn't referenced directly, but both archives
931d58858SJez Ng## will be fetched when linking against the main test file due to its references
1031d58858SJez Ng## to _bar and _baz.
1131d58858SJez Ng
12a817594dSJez Ng# RUN: llvm-mc -filetype=obj -triple=x86_64-apple-darwin %t/test.s -o %t/test.o
13a817594dSJez Ng# RUN: llvm-mc -filetype=obj -triple=x86_64-apple-darwin %t/foo.s -o %t/foo.o
14a817594dSJez Ng# RUN: llvm-mc -filetype=obj -triple=x86_64-apple-darwin %t/weakfoo.s -o %t/weakfoo.o
1531d58858SJez Ng
1631d58858SJez Ng# RUN: llvm-ar --format=darwin rcs %t/foo.a %t/foo.o
1731d58858SJez Ng# RUN: llvm-ar --format=darwin rcs %t/weakfoo.a %t/weakfoo.o
1831d58858SJez Ng
1931d58858SJez Ng# PREFER-NONWEAK-OBJECT: O __TEXT,nonweak _foo
2031d58858SJez Ng
21*a1a2a8e8SNico Weber# RUN: %lld -lSystem -o %t/weak-nonweak-archives %t/weakfoo.a %t/foo.a %t/test.o
2231d58858SJez Ng# RUN: llvm-objdump --syms %t/weak-nonweak-archives | FileCheck %s --check-prefix=PREFER-NONWEAK-OBJECT
23*a1a2a8e8SNico Weber# RUN: %lld -lSystem -o %t/nonweak-weak-archives %t/foo.a %t/weakfoo.a %t/test.o
2431d58858SJez Ng# RUN: llvm-objdump --syms %t/nonweak-weak-archives | FileCheck %s --check-prefix=PREFER-NONWEAK-OBJECT
2531d58858SJez Ng
26*a1a2a8e8SNico Weber# RUN: %lld -lSystem -o %t/weak-nonweak-objs %t/weakfoo.o %t/foo.o %t/test.o
2731d58858SJez Ng# RUN: llvm-objdump --syms %t/weak-nonweak-objs | FileCheck %s --check-prefix=PREFER-NONWEAK-OBJECT
28*a1a2a8e8SNico Weber# RUN: %lld -lSystem -o %t/nonweak-weak-objs %t/foo.o %t/weakfoo.o %t/test.o
2931d58858SJez Ng# RUN: llvm-objdump --syms %t/nonweak-weak-objs | FileCheck %s --check-prefix=PREFER-NONWEAK-OBJECT
3031d58858SJez Ng
31*a1a2a8e8SNico Weber# RUN: %lld -lSystem -o %t/weak-obj-nonweak-ar %t/weakfoo.o %t/foo.a %t/test.o
3231d58858SJez Ng# RUN: llvm-objdump --syms %t/weak-obj-nonweak-ar | FileCheck %s --check-prefix=PREFER-NONWEAK-OBJECT
33*a1a2a8e8SNico Weber# RUN: %lld -lSystem -o %t/nonweak-ar-weak-obj %t/foo.a %t/weakfoo.o %t/test.o
3431d58858SJez Ng# RUN: llvm-objdump --syms %t/nonweak-ar-weak-obj | FileCheck %s --check-prefix=PREFER-NONWEAK-OBJECT
3531d58858SJez Ng
36a817594dSJez Ng#--- foo.s
37a817594dSJez Ng.globl _foo, _bar
38a817594dSJez Ng.section __TEXT,nonweak
39a817594dSJez Ng_bar:
40a817594dSJez Ng_foo:
41a817594dSJez Ng
42a817594dSJez Ng#--- weakfoo.s
43a817594dSJez Ng.globl _foo, _baz
44a817594dSJez Ng.weak_definition _foo
45a817594dSJez Ng.section __TEXT,weak
46a817594dSJez Ng_baz:
47a817594dSJez Ng_foo:
48a817594dSJez Ng
49a817594dSJez Ng#--- test.s
5031d58858SJez Ng.globl _main
5131d58858SJez Ng_main:
5231d58858SJez Ng  callq _bar
5331d58858SJez Ng  callq _baz
5431d58858SJez Ng  ret
55