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/test.ll -o %t/test.o
9 ; RUN: opt -module-summary %t/same-size.ll -o %t/same-size.o
10 ; RUN: opt -module-summary %t/smaller-size.ll -o %t/smaller-size.o
11 ; RUN: llvm-mc -filetype=obj -triple=x86_64-apple-darwin %t/same-size.s -o %t/same-size-asm.o
12 ; RUN: llvm-mc -filetype=obj -triple=x86_64-apple-darwin %t/smaller-size.s -o %t/smaller-size-asm.o
14 ;; ld64: Common bitcode symbols all have equal precedence, regardless of size or
16 ;; lld: We pick the symbol with the larger size, regardless of alignment.
17 ; RUN: %lld -dylib %t/test.o %t/smaller-size.o -order_file %t/order -o %t/test
18 ; RUN: llvm-objdump --section-headers --syms %t/test | FileCheck %s -D#SIZE=2 -D#ALIGN=8
19 ; RUN: %lld -dylib %t/smaller-size.o %t/test.o -order_file %t/order -o %t/test
20 ; RUN: llvm-objdump --section-headers --syms %t/test | FileCheck %s -D#SIZE=2 -D#ALIGN=8
21 ; COM (ld64): llvm-objdump --section-headers --syms %t/test | FileCheck %s -D#SIZE=1 -D#ALIGN=16
23 ;; ld64: Common bitcode symbols all have equal precedence, regardless of size or
25 ;; lld: When the sizes are equal, we pick the symbol whose file occurs later in
26 ;; the command-line argument list.
27 ; RUN: %lld -dylib %t/test.o %t/same-size.o -order_file %t/order -o %t/test
28 ; RUN: llvm-objdump --section-headers --syms %t/test | FileCheck %s -D#SIZE=2 -D#ALIGN=16
29 ; COM (ld64): llvm-objdump --section-headers --syms %t/test | FileCheck %s -D#SIZE=2 -D#ALIGN=8
30 ; RUN: %lld -dylib %t/same-size.o %t/test.o -order_file %t/order -o %t/test
31 ; RUN: llvm-objdump --section-headers --syms %t/test | FileCheck %s -D#SIZE=2 -D#ALIGN=8
33 ;; ld64: Non-bitcode common symbols take precedence.
34 ;; lld: We pick the symbol with the larger size, regardless of alignment.
35 ; RUN: %lld -dylib %t/test.o %t/smaller-size-asm.o -order_file %t/order -o %t/test
36 ; RUN: llvm-objdump --section-headers --syms %t/test | FileCheck %s -D#SIZE=2 -D#ALIGN=8
37 ; COM (ld64): llvm-objdump --section-headers --syms %t/test | FileCheck %s -D#SIZE=1 -D#ALIGN=16
38 ; RUN: %lld -dylib %t/smaller-size-asm.o %t/test.o -order_file %t/order -o %t/test
39 ; RUN: llvm-objdump --section-headers --syms %t/test | FileCheck %s -D#SIZE=2 -D#ALIGN=8
40 ; COM (ld64): llvm-objdump --section-headers --syms %t/test | FileCheck %s -D#SIZE=1 -D#ALIGN=16
42 ; RUN: %lld -dylib %t/test.o %t/same-size-asm.o -order_file %t/order -o %t/test
43 ; RUN: llvm-objdump --section-headers --syms %t/test | FileCheck %s -D#SIZE=2 -D#ALIGN=16
44 ; RUN: %lld -dylib %t/same-size-asm.o %t/test.o -order_file %t/order -o %t/test
45 ; RUN: llvm-objdump --section-headers --syms %t/test | FileCheck %s -D#SIZE=2 -D#ALIGN=8
46 ; COM (ld64): llvm-objdump --section-headers --syms %t/test | FileCheck %s -D#SIZE=2 -D#ALIGN=16
48 ; CHECK-LABEL: Sections:
49 ; CHECK: __common {{[0-9a-f]+}} [[#%x, COMMON_START:]] BSS
51 ; CHECK-LABEL: SYMBOL TABLE:
52 ; CHECK-DAG: [[#%.16x, COMMON_START]] g O __DATA,__common _check_size
53 ; CHECK-DAG: [[#%.16x, COMMON_START + SIZE]] g O __DATA,__common _end_marker
54 ; CHECK-DAG: [[#%.16x, COMMON_START + ALIGN]] g O __DATA,__common _check_alignment
57 ;; Order is important as we determine the size of a given symbol via the
58 ;; address of the next symbol.
64 target datalayout = "e-m:o-p270:32:32-p271:32:32-p272:64:64-i64:64-f80:128-n8:16:32:64-S128"
65 target triple = "x86_64-apple-macosx10.15.0"
67 @check_size = common global i8 0, align 1
68 @check_alignment = common global i8 0, align 16
71 target datalayout = "e-m:o-p270:32:32-p271:32:32-p272:64:64-i64:64-f80:128-n8:16:32:64-S128"
72 target triple = "x86_64-apple-macosx10.15.0"
74 @check_size = common global i16 0, align 1
75 @check_alignment = common global i16 0, align 16
78 .comm _check_size, 1, 1
79 .comm _check_alignment, 1, 4
82 .comm _check_size, 2, 1
83 .comm _check_alignment, 2, 4
86 target datalayout = "e-m:o-p270:32:32-p271:32:32-p272:64:64-i64:64-f80:128-n8:16:32:64-S128"
87 target triple = "x86_64-apple-macosx10.15.0"
88 @check_size = common global i16 0, align 1
89 @end_marker = common global i8 0
90 @check_alignment = common global i16 0, align 8