3 ;; NOTE: We deviate significantly from ld64's behavior here. We treat common
4 ;; bitcode symbols like regular common symbols, but ld64 gives them different
5 ;; (and IMO very strange) precedence. This test documents the differences.
7 ; RUN: rm -rf %t; split-file %s %t
8 ; RUN: opt -module-summary %t/common.ll -o %t/common.o
9 ; RUN: opt -module-summary %t/defined.ll -o %t/defined.o
10 ; RUN: opt -module-summary %t/weak-defined.ll -o %t/weak-defined.o
11 ; RUN: opt -module-summary %t/libfoo.ll -o %t/libfoo.o
12 ; RUN: opt -module-summary %t/refs-foo.ll -o %t/refs-foo.o
13 ; RUN: llvm-mc -filetype=obj -triple=x86_64-apple-darwin %t/weak-defined.s -o %t/weak-defined-asm.o
15 ; RUN: %lld -dylib -dylib %t/libfoo.o -o %t/libfoo.dylib
17 ; RUN: llvm-ar rcs %t/defined.a %t/defined.o
18 ; RUN: llvm-ar rcs %t/defined-and-common.a %t/defined.o %t/common.o
19 ; RUN: llvm-ar rcs %t/common-and-defined.a %t/common.o %t/defined.o
20 ; RUN: llvm-ar rcs %t/weak-defined-and-common.a %t/weak-defined.o %t/common.o
21 ; RUN: llvm-ar rcs %t/common-and-weak-defined.a %t/common.o %t/weak-defined.o
23 ;; Defined symbols take precedence over common bitcode symbols.
24 ; RUN: %lld -dylib %t/defined.o %t/common.o -o %t/test
25 ; RUN: llvm-objdump --syms %t/test | FileCheck %s --check-prefix=DEFINED
26 ; RUN: %lld -dylib %t/common.o %t/defined.o -o %t/test
27 ; RUN: llvm-objdump --syms %t/test | FileCheck %s --check-prefix=DEFINED
29 ;; Defined symbols have the same precedence as common bitcode symbols within
31 ; RUN: %lld -dylib %t/defined-and-common.a %t/refs-foo.o -o %t/refs-foo
32 ; RUN: llvm-objdump --syms %t/refs-foo | FileCheck %s --check-prefix=DEFINED
33 ; RUN: %lld -dylib %t/common-and-defined.a %t/refs-foo.o -o %t/refs-foo
34 ; RUN: llvm-objdump --syms %t/refs-foo | FileCheck %s --check-prefix=COMMON
36 ;; ld64: Weak bitcode symbols have the same precedence as common bitcode symbols.
37 ;; lld: Weak bitcode symbols take precedence over common bitcode symbols.
38 ; RUN: %lld -dylib %t/weak-defined.o %t/common.o -o %t/test
39 ; RUN: llvm-objdump --syms %t/test | FileCheck %s --check-prefix=WEAK-DEFINED
40 ; RUN: %lld -dylib %t/common.o %t/weak-defined.o -o %t/test
41 ; RUN: llvm-objdump --syms %t/test | FileCheck %s --check-prefix=WEAK-DEFINED
43 ;; Weak non-bitcode symbols take precedence over common bitcode symbols.
44 ; RUN: %lld -dylib %t/weak-defined-asm.o %t/common.o -o %t/test
45 ; RUN: llvm-objdump --syms %t/test | FileCheck %s --check-prefix=WEAK-DEFINED
46 ; RUN: %lld -dylib %t/common.o %t/weak-defined-asm.o -o %t/test
47 ; RUN: llvm-objdump --syms %t/test | FileCheck %s --check-prefix=WEAK-DEFINED
49 ;; ld64: Archive symbols take precedence over common bitcode symbols.
50 ;; lld: Common bitcode symbols take precedence over archive symbols.
51 ; RUN: %lld -dylib %t/defined.a %t/common.o -o %t/test
52 ; RUN: llvm-objdump --syms %t/test | FileCheck %s --check-prefix=COMMON
53 ; COM (ld64): llvm-objdump --syms %t/test | FileCheck %s --check-prefix=DEFINED
54 ; RUN: %lld -dylib %t/common.o %t/defined.a -o %t/test
55 ; RUN: llvm-objdump --syms %t/test | FileCheck %s --check-prefix=COMMON
56 ; COM (ld64): llvm-objdump --syms %t/test | FileCheck %s --check-prefix=DEFINED
58 ;; ld64: Dylib symbols take precedence over common bitcode symbols.
59 ;; lld: Common bitcode symbols take precedence over dylib symbols.
60 ; RUN: %lld -dylib %t/libfoo.dylib %t/common.o %t/refs-foo.o -o %t/test
61 ; RUN: llvm-objdump --syms %t/test | FileCheck %s --check-prefix=COMMON
62 ; COM (ld64): llvm-objdump --syms %t/test | FileCheck %s --check-prefix=DYLIB
63 ; RUN: %lld -dylib %t/common.o %t/libfoo.dylib %t/refs-foo.o -o %t/test
64 ; RUN: llvm-objdump --syms %t/test | FileCheck %s --check-prefix=COMMON
65 ; COM (ld64): llvm-objdump --syms %t/test | FileCheck %s --check-prefix=DYLIB
67 ; COMMON: g O __DATA,__common _foo
68 ; DEFINED: g O __DATA,__data _foo
69 ; WEAK-DEFINED: w O __DATA,__data _foo
73 target datalayout = "e-m:o-p270:32:32-p271:32:32-p272:64:64-i64:64-f80:128-n8:16:32:64-S128"
74 target triple = "x86_64-apple-macosx10.15.0"
76 @foo = common global i8 0
79 target datalayout = "e-m:o-p270:32:32-p271:32:32-p272:64:64-i64:64-f80:128-n8:16:32:64-S128"
80 target triple = "x86_64-apple-macosx10.15.0"
85 target datalayout = "e-m:o-p270:32:32-p271:32:32-p272:64:64-i64:64-f80:128-n8:16:32:64-S128"
86 target triple = "x86_64-apple-macosx10.15.0"
88 @foo = weak global i8 12
97 target datalayout = "e-m:o-p270:32:32-p271:32:32-p272:64:64-i64:64-f80:128-n8:16:32:64-S128"
98 target triple = "x86_64-apple-macosx10.15.0"
100 @foo = common global i8 0
103 target datalayout = "e-m:o-p270:32:32-p271:32:32-p272:64:64-i64:64-f80:128-n8:16:32:64-S128"
104 target triple = "x86_64-apple-macosx10.15.0"
106 @foo = external global i8
109 %1 = load i8, ptr @foo