1; REQUIRES: x86 2 3; RUN: rm -rf %t; split-file %s %t 4 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 10 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 13 14; RUN: llvm-ar rcs %t/archive.a %t/archive.o 15 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 21 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 27 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 36 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 42 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 48 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 54 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 60 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 65; DYLIB: *UND* _foo 66 67;--- defined.ll 68target datalayout = "e-m:o-p270:32:32-p271:32:32-p272:64:64-i64:64-f80:128-n8:16:32:64-S128" 69target triple = "x86_64-apple-macosx10.15.0" 70 71define void @foo() section "__TEXT,defined" { 72 ret void 73} 74 75;--- weak-defined.ll 76target datalayout = "e-m:o-p270:32:32-p271:32:32-p272:64:64-i64:64-f80:128-n8:16:32:64-S128" 77target triple = "x86_64-apple-macosx10.15.0" 78 79define weak void @foo() section "__TEXT,weak_defined" { 80 ret void 81} 82 83;--- weak-defined.s 84.globl _foo 85.weak_definition _foo 86.section __TEXT,weak_defined_asm 87_foo: 88 89;--- archive.ll 90target datalayout = "e-m:o-p270:32:32-p271:32:32-p272:64:64-i64:64-f80:128-n8:16:32:64-S128" 91target triple = "x86_64-apple-macosx10.15.0" 92 93define void @foo() section "__TEXT,archive" { 94 ret void 95} 96 97;--- calls-foo.ll 98target datalayout = "e-m:o-p270:32:32-p271:32:32-p272:64:64-i64:64-f80:128-n8:16:32:64-S128" 99target triple = "x86_64-apple-macosx10.15.0" 100 101declare void @foo() 102 103define void @main() { 104 call void @foo() 105 ret void 106} 107