3 ; RUN: rm -rf %t; split-file %s %t
5 ; RUN: opt -module-summary %t/defined.ll -o %t/defined.o
6 ; RUN: opt -module-summary %t/weak-defined.ll -o %t/weak-defined.o
7 ; RUN: opt -module-summary %t/archive.ll -o %t/archive.o
8 ; RUN: opt -module-summary %t/calls-foo.ll -o %t/calls-foo.o
9 ; RUN: llvm-mc -filetype=obj -triple=x86_64-apple-darwin %t/weak-defined.s -o %t/weak-defined-asm.o
11 ; RUN: %lld -lSystem -dylib %t/defined.o -o %t/libfoo.dylib
12 ; RUN: %lld -lSystem -dylib %t/weak-defined.o -o %t/libweakfoo.dylib
14 ; RUN: llvm-ar rcs %t/archive.a %t/archive.o
16 ;; Regular defined symbols take precedence over weak ones.
17 ; RUN: %lld -lSystem %t/defined.o %t/weak-defined.o %t/calls-foo.o -o %t/test
18 ; RUN: llvm-objdump --syms %t/test | FileCheck %s --check-prefix=DEFINED
19 ; RUN: %lld -lSystem %t/weak-defined.o %t/defined.o %t/calls-foo.o -o %t/test
20 ; RUN: llvm-objdump --syms %t/test | FileCheck %s --check-prefix=DEFINED
22 ;; Regular defined symbols take precedence over weak non-bitcode ones.
23 ; RUN: %lld -lSystem %t/defined.o %t/weak-defined-asm.o %t/calls-foo.o -o %t/test
24 ; RUN: llvm-objdump --syms %t/test | FileCheck %s --check-prefix=DEFINED
25 ; RUN: %lld -lSystem %t/weak-defined-asm.o %t/defined.o %t/calls-foo.o -o %t/test
26 ; RUN: llvm-objdump --syms %t/test | FileCheck %s --check-prefix=DEFINED
28 ;; NOTE: we are deviating from ld64's behavior here.
29 ;; ld64: Weak non-bitcode symbols take precedence over weak bitcode ones.
30 ;; lld: Weak non-bitcode symbols have the same precedence as weak bitcode ones.
31 ; RUN: %lld -lSystem %t/weak-defined.o %t/weak-defined-asm.o %t/calls-foo.o -o %t/test
32 ; RUN: llvm-objdump --syms %t/test | FileCheck %s --check-prefix=WEAK-DEFINED
33 ; COM (ld64): llvm-objdump --syms %t/test | FileCheck %s --check-prefix=WEAK-DEFINED-ASM
34 ; RUN: %lld -lSystem %t/weak-defined-asm.o %t/weak-defined.o %t/calls-foo.o -o %t/test
35 ; RUN: llvm-objdump --syms %t/test | FileCheck %s --check-prefix=WEAK-DEFINED-ASM
37 ;; Weak defined symbols take precedence over dylib symbols.
38 ; RUN: %lld -lSystem %t/weak-defined.o %t/libfoo.dylib %t/calls-foo.o -o %t/test
39 ; RUN: llvm-objdump --syms %t/test | FileCheck %s --check-prefix=WEAK-DEFINED
40 ; RUN: %lld -lSystem %t/libfoo.dylib %t/weak-defined.o %t/calls-foo.o -o %t/test
41 ; RUN: llvm-objdump --syms %t/test | FileCheck %s --check-prefix=WEAK-DEFINED
43 ;; Weak defined symbols take precedence over archive symbols.
44 ; RUN: %lld -lSystem %t/archive.a %t/weak-defined.o %t/calls-foo.o -o %t/test
45 ; RUN: llvm-objdump --syms %t/test | FileCheck %s --check-prefix=WEAK-DEFINED
46 ; RUN: %lld -lSystem %t/weak-defined.o %t/archive.a %t/calls-foo.o -o %t/test
47 ; RUN: llvm-objdump --syms %t/test | FileCheck %s --check-prefix=WEAK-DEFINED
49 ;; Archive symbols have the same precedence as dylib symbols.
50 ; RUN: %lld -lSystem %t/archive.a %t/libfoo.dylib %t/calls-foo.o -o %t/test
51 ; RUN: llvm-objdump --syms %t/test | FileCheck %s --check-prefix=ARCHIVE
52 ; RUN: %lld -lSystem %t/libfoo.dylib %t/archive.a %t/calls-foo.o -o %t/test
53 ; RUN: llvm-objdump --syms %t/test | FileCheck %s --check-prefix=DYLIB
55 ;; Archive symbols take precedence over weak dylib symbols.
56 ; RUN: %lld -lSystem %t/archive.a %t/libweakfoo.dylib %t/calls-foo.o -o %t/test
57 ; RUN: llvm-objdump --syms %t/test | FileCheck %s --check-prefix=ARCHIVE
58 ; RUN: %lld -lSystem %t/libweakfoo.dylib %t/archive.a %t/calls-foo.o -o %t/test
59 ; RUN: llvm-objdump --syms %t/test | FileCheck %s --check-prefix=ARCHIVE
61 ; DEFINED: g O __TEXT,defined _foo
62 ; WEAK-DEFINED: w O __TEXT,weak_defined _foo
63 ; WEAK-DEFINED-ASM: w O __TEXT,weak_defined_asm _foo
64 ; ARCHIVE: g O __TEXT,archive _foo
68 target datalayout = "e-m:o-p270:32:32-p271:32:32-p272:64:64-i64:64-f80:128-n8:16:32:64-S128"
69 target triple = "x86_64-apple-macosx10.15.0"
71 define void @foo() section "__TEXT,defined" {
76 target datalayout = "e-m:o-p270:32:32-p271:32:32-p272:64:64-i64:64-f80:128-n8:16:32:64-S128"
77 target triple = "x86_64-apple-macosx10.15.0"
79 define weak void @foo() section "__TEXT,weak_defined" {
86 .section __TEXT,weak_defined_asm
90 target datalayout = "e-m:o-p270:32:32-p271:32:32-p272:64:64-i64:64-f80:128-n8:16:32:64-S128"
91 target triple = "x86_64-apple-macosx10.15.0"
93 define void @foo() section "__TEXT,archive" {
98 target datalayout = "e-m:o-p270:32:32-p271:32:32-p272:64:64-i64:64-f80:128-n8:16:32:64-S128"
99 target triple = "x86_64-apple-macosx10.15.0"
103 define void @main() {