File: common-symbol-resolution.s

package info (click to toggle)
llvm-toolchain-20 1%3A20.1.8-1
  • links: PTS, VCS
  • area: main
  • in suites: experimental
  • size: 2,111,696 kB
  • sloc: cpp: 7,438,781; ansic: 1,393,871; asm: 1,012,926; python: 241,771; f90: 86,635; objc: 75,411; lisp: 42,144; pascal: 17,286; sh: 8,596; ml: 5,082; perl: 4,730; makefile: 3,591; awk: 3,523; javascript: 2,251; xml: 892; fortran: 672
file content (109 lines) | stat: -rw-r--r-- 4,462 bytes parent folder | download | duplicates (22)
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
# REQUIRES: x86
# RUN: rm -rf %t; split-file %s %t

# RUN: llvm-mc -filetype=obj -triple=x86_64-apple-darwin %t/common.s -o %t/common.o
# RUN: llvm-mc -filetype=obj -triple=x86_64-apple-darwin %t/weak-common.s -o %t/weak-common.o
# RUN: llvm-mc -filetype=obj -triple=x86_64-apple-darwin %t/defined.s -o %t/defined.o
# RUN: llvm-mc -filetype=obj -triple=x86_64-apple-darwin %t/weak-defined.s -o %t/weak-defined.o
# RUN: llvm-mc -filetype=obj -triple=x86_64-apple-darwin %t/libfoo.s -o %t/libfoo.o
# RUN: llvm-mc -filetype=obj -triple=x86_64-apple-darwin %t/test.s -o %t/test.o
# RUN: llvm-mc -filetype=obj -triple=x86_64-apple-darwin %t/calls-foo.s -o %t/calls-foo.o

# RUN: %lld -lSystem -order_file %t/order -dylib %t/libfoo.o -o %t/libfoo.dylib

# RUN: llvm-ar rcs %t/defined.a %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

## The weak attribute appears to have no effect on common symbols. Given two
## common symbols of the same name, we always pick the one with the larger size,
## regardless of whether it is weak. Moreover, the resolved symbol in the output
## file will always be non-weak, even if the winning input symbol definition was
## weak.
# RUN: %lld -lSystem -order_file %t/order %t/common.o %t/weak-common.o %t/test.o -o %t/test
# RUN: llvm-objdump --syms %t/test | FileCheck %s --check-prefix=LARGER-COMMON
# RUN: %lld -lSystem -order_file %t/order %t/weak-common.o %t/common.o %t/test.o -o %t/test
# RUN: llvm-objdump --syms %t/test | FileCheck %s --check-prefix=LARGER-COMMON

## Defined symbols are the only ones that take precedence over common symbols.
# RUN: %lld -lSystem -order_file %t/order %t/defined.o %t/common.o %t/test.o -o %t/test
# RUN: llvm-objdump --syms %t/test | FileCheck %s --check-prefix=DEFINED
# RUN: %lld -lSystem -order_file %t/order %t/common.o %t/defined.o %t/test.o -o %t/test
# RUN: llvm-objdump --syms %t/test | FileCheck %s --check-prefix=DEFINED

# RUN: %lld -lSystem -order_file %t/order %t/weak-defined.o %t/common.o %t/test.o -o %t/test
# RUN: llvm-objdump --syms %t/test | FileCheck %s --check-prefix=WEAK-DEFINED
# RUN: %lld -lSystem -order_file %t/order %t/common.o %t/weak-defined.o %t/test.o -o %t/test
# RUN: llvm-objdump --syms %t/test | FileCheck %s --check-prefix=WEAK-DEFINED

## Common symbols take precedence over archive symbols.
# RUN: %lld -lSystem -order_file %t/order %t/defined.a %t/weak-common.o %t/test.o -o %t/test
# RUN: llvm-objdump --syms %t/test | FileCheck %s --check-prefix=LARGER-COMMON
# RUN: %lld -lSystem -order_file %t/order %t/weak-common.o %t/defined.a %t/test.o -o %t/test
# RUN: llvm-objdump --syms %t/test | FileCheck %s --check-prefix=LARGER-COMMON

## Defined symbols have the same precedence as common symbols within an archive.
# RUN: %lld -lSystem -order_file %t/order %t/weak-defined-and-common.a %t/calls-foo.o -o %t/calls-foo
# RUN: llvm-objdump --syms %t/calls-foo | FileCheck %s --check-prefix=WEAK-DEFINED
# RUN: %lld -lSystem -order_file %t/order %t/calls-foo.o %t/common-and-weak-defined.a -o %t/calls-foo
# RUN: llvm-objdump --syms %t/calls-foo | FileCheck %s --check-prefix=COMMON

## Common symbols take precedence over dylib symbols.
# RUN: %lld -lSystem -order_file %t/order %t/libfoo.dylib %t/weak-common.o %t/test.o -o %t/test
# RUN: llvm-objdump --syms %t/test | FileCheck %s --check-prefix=LARGER-COMMON
# RUN: %lld -lSystem -order_file %t/order %t/weak-common.o %t/libfoo.dylib %t/test.o -o %t/test
# RUN: llvm-objdump --syms %t/test | FileCheck %s --check-prefix=LARGER-COMMON

# LARGER-COMMON-DAG:   [[#%x, FOO_ADDR:]] g     O __DATA,__common _foo
# LARGER-COMMON-DAG:   [[#FOO_ADDR + 2]]  g     O __DATA,__common _foo_end

# COMMON:              g     O __DATA,__common _foo
# DEFINED:             g     F __TEXT,__text _foo
# WEAK-DEFINED:        w     F __TEXT,__text _foo

#--- order
## %t/order is important as we determine the size of a given symbol via the
## address of the next symbol.
_foo
_foo_end

#--- common.s
.comm _foo, 1

.globl _bar
_bar:

#--- weak-common.s
.weak_definition _foo
.comm _foo, 2

#--- defined.s
.globl _foo
_foo:
  .quad 0x1234

#--- weak-defined.s
.globl _foo
.weak_definition _foo
_foo:
  .quad 0x1234

#--- libfoo.s
.globl _foo
_foo:
  .quad 0x1234

#--- test.s
.comm _foo_end, 1

.globl _main
_main:
  ret

#--- calls-foo.s
.comm _foo_end, 1

.globl _main
_main:
  callq _foo
  ret