File: lto-common-symbol-resolution.ll

package info (click to toggle)
swiftlang 6.0.3-2
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 2,519,992 kB
  • sloc: cpp: 9,107,863; ansic: 2,040,022; asm: 1,135,751; python: 296,500; objc: 82,456; f90: 60,502; lisp: 34,951; pascal: 19,946; sh: 18,133; perl: 7,482; ml: 4,937; javascript: 4,117; makefile: 3,840; awk: 3,535; xml: 914; fortran: 619; cs: 573; ruby: 573
file content (111 lines) | stat: -rw-r--r-- 4,899 bytes parent folder | download | duplicates (14)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
; REQUIRES: x86

;; NOTE: We deviate significantly from ld64's behavior here. We treat common
;; bitcode symbols like regular common symbols, but ld64 gives them different
;; (and IMO very strange) precedence. This test documents the differences.

; RUN: rm -rf %t; split-file %s %t
; RUN: opt -module-summary %t/common.ll -o %t/common.o
; RUN: opt -module-summary %t/defined.ll -o %t/defined.o
; RUN: opt -module-summary %t/weak-defined.ll -o %t/weak-defined.o
; RUN: opt -module-summary %t/libfoo.ll -o %t/libfoo.o
; RUN: opt -module-summary %t/refs-foo.ll -o %t/refs-foo.o
; RUN: llvm-mc -filetype=obj -triple=x86_64-apple-darwin %t/weak-defined.s -o %t/weak-defined-asm.o

; RUN: %lld -dylib -dylib %t/libfoo.o -o %t/libfoo.dylib

; RUN: llvm-ar rcs %t/defined.a %t/defined.o
; RUN: llvm-ar rcs %t/defined-and-common.a %t/defined.o %t/common.o
; RUN: llvm-ar rcs %t/common-and-defined.a %t/common.o %t/defined.o
; RUN: llvm-ar rcs %t/weak-defined-and-common.a %t/weak-defined.o %t/common.o
; RUN: llvm-ar rcs %t/common-and-weak-defined.a %t/common.o %t/weak-defined.o

;; Defined symbols take precedence over common bitcode symbols.
; RUN: %lld -dylib %t/defined.o %t/common.o -o %t/test
; RUN: llvm-objdump --syms %t/test | FileCheck %s --check-prefix=DEFINED
; RUN: %lld -dylib %t/common.o %t/defined.o -o %t/test
; RUN: llvm-objdump --syms %t/test | FileCheck %s --check-prefix=DEFINED

;; Defined symbols have the same precedence as common bitcode symbols within
;; an archive.
; RUN: %lld -dylib %t/defined-and-common.a %t/refs-foo.o -o %t/refs-foo
; RUN: llvm-objdump --syms %t/refs-foo | FileCheck %s --check-prefix=DEFINED
; RUN: %lld -dylib %t/common-and-defined.a %t/refs-foo.o -o %t/refs-foo
; RUN: llvm-objdump --syms %t/refs-foo | FileCheck %s --check-prefix=COMMON

;; ld64: Weak bitcode symbols have the same precedence as common bitcode symbols.
;; lld: Weak bitcode symbols take precedence over common bitcode symbols.
; RUN: %lld -dylib %t/weak-defined.o %t/common.o -o %t/test
; RUN: llvm-objdump --syms %t/test | FileCheck %s --check-prefix=WEAK-DEFINED
; RUN: %lld -dylib %t/common.o %t/weak-defined.o -o %t/test
; RUN: llvm-objdump --syms %t/test | FileCheck %s --check-prefix=WEAK-DEFINED

;; Weak non-bitcode symbols take precedence over common bitcode symbols.
; RUN: %lld -dylib %t/weak-defined-asm.o %t/common.o -o %t/test
; RUN: llvm-objdump --syms %t/test | FileCheck %s --check-prefix=WEAK-DEFINED
; RUN: %lld -dylib %t/common.o %t/weak-defined-asm.o -o %t/test
; RUN: llvm-objdump --syms %t/test | FileCheck %s --check-prefix=WEAK-DEFINED

;; ld64: Archive symbols take precedence over common bitcode symbols.
;; lld: Common bitcode symbols take precedence over archive symbols.
; RUN: %lld -dylib %t/defined.a %t/common.o -o %t/test
; RUN: llvm-objdump --syms %t/test | FileCheck %s --check-prefix=COMMON
; COM (ld64): llvm-objdump --syms %t/test | FileCheck %s --check-prefix=DEFINED
; RUN: %lld -dylib %t/common.o %t/defined.a -o %t/test
; RUN: llvm-objdump --syms %t/test | FileCheck %s --check-prefix=COMMON
; COM (ld64): llvm-objdump --syms %t/test | FileCheck %s --check-prefix=DEFINED

;; ld64: Dylib symbols take precedence over common bitcode symbols.
;; lld: Common bitcode symbols take precedence over dylib symbols.
; RUN: %lld -dylib %t/libfoo.dylib %t/common.o %t/refs-foo.o -o %t/test
; RUN: llvm-objdump --syms %t/test | FileCheck %s --check-prefix=COMMON
; COM (ld64): llvm-objdump --syms %t/test | FileCheck %s --check-prefix=DYLIB
; RUN: %lld -dylib %t/common.o %t/libfoo.dylib %t/refs-foo.o -o %t/test
; RUN: llvm-objdump --syms %t/test | FileCheck %s --check-prefix=COMMON
; COM (ld64): llvm-objdump --syms %t/test | FileCheck %s --check-prefix=DYLIB

; COMMON:       g     O __DATA,__common _foo
; DEFINED:      g     O __DATA,__data _foo
; WEAK-DEFINED: w     O __DATA,__data _foo
; DYLIB:        *UND* _foo

;--- common.ll
target datalayout = "e-m:o-p270:32:32-p271:32:32-p272:64:64-i64:64-f80:128-n8:16:32:64-S128"
target triple = "x86_64-apple-macosx10.15.0"

@foo = common global i8 0

;--- defined.ll
target datalayout = "e-m:o-p270:32:32-p271:32:32-p272:64:64-i64:64-f80:128-n8:16:32:64-S128"
target triple = "x86_64-apple-macosx10.15.0"

@foo = global i8 12

;--- weak-defined.ll
target datalayout = "e-m:o-p270:32:32-p271:32:32-p272:64:64-i64:64-f80:128-n8:16:32:64-S128"
target triple = "x86_64-apple-macosx10.15.0"

@foo = weak global i8 12

;--- weak-defined.s
.globl _foo
.weak_definition _foo
.data
_foo:

;--- libfoo.ll
target datalayout = "e-m:o-p270:32:32-p271:32:32-p272:64:64-i64:64-f80:128-n8:16:32:64-S128"
target triple = "x86_64-apple-macosx10.15.0"

@foo = common global i8 0

;--- refs-foo.ll
target datalayout = "e-m:o-p270:32:32-p271:32:32-p272:64:64-i64:64-f80:128-n8:16:32:64-S128"
target triple = "x86_64-apple-macosx10.15.0"

@foo = external global i8

define void @f() {
  %1 = load i8, ptr @foo
  ret void
}