llvm-project

Форк
0
/
local-alias-to-weak.s 
149 строк · 5.8 Кб
1
# REQUIRES: x86
2
## This test checks that when we coalesce weak definitions, their local symbol
3
## aliases defs don't cause the coalesced data to be retained. This was
4
## motivated by MC's aarch64 backend which automatically creates `ltmp<N>`
5
## symbols at the start of each .text section. These symbols are frequently
6
## aliases of other symbols created by clang or other inputs to MC. I've chosen
7
## to explicitly create them here since we can then reference those symbols for
8
## a more complete test.
9
##
10
## Not retaining the data matters for more than just size -- we have a use case
11
## that depends on proper data coalescing to emit a valid file format. We also
12
## need this behavior to properly deduplicate the __objc_protolist section;
13
## failure to do this can result in dyld crashing on iOS 13.
14
##
15
## Finally, ld64 does all this regardless of whether .subsections_via_symbols is
16
## specified. We don't. But again, given how rare the lack of that directive is
17
## (I've only seen it from hand-written assembly inputs), I don't think we need
18
## to worry about it.
19

20
# RUN: rm -rf %t; split-file %s %t
21
# RUN: llvm-mc -filetype=obj -triple=x86_64-apple-darwin %t/weak-then-local.s -o %t/weak-then-local.o
22
# RUN: llvm-mc -filetype=obj -triple=x86_64-apple-darwin %t/local-then-weak.s -o %t/local-then-weak.o
23
# RUN: llvm-mc -filetype=obj -triple=x86_64-apple-darwin %t/no-subsections.s -o %t/no-subsections.o
24
# RUN: llvm-mc -filetype=obj -triple=x86_64-apple-darwin %t/no-dead-strip.s -o %t/no-dead-strip.o
25

26
# RUN: %lld -lSystem -dylib %t/weak-then-local.o %t/local-then-weak.o -o %t/test1
27
# RUN: llvm-objdump --macho --syms --section="__DATA,__data" --weak-bind %t/test1 | FileCheck %s
28
# RUN: %lld -lSystem -dylib %t/local-then-weak.o %t/weak-then-local.o -o %t/test2
29
# RUN: llvm-objdump --macho --syms --section="__DATA,__data" --weak-bind %t/test2 | FileCheck %s
30

31
## Check that we only have one copy of 0x123 in the data, not two.
32
# CHECK:       Contents of (__DATA,__data) section
33
# CHECK-NEXT:  0000000000001000  23 01 00 00 00 00 00 00 00 10 00 00 00 00 00 00 {{$}}
34
# CHECK-NEXT:  0000000000001010  00 10 00 00 00 00 00 00 {{$}}
35
# CHECK-EMPTY:
36
# CHECK-NEXT:  SYMBOL TABLE:
37
# CHECK-NEXT:  0000000000001000 l     O __DATA,__data _alias
38
# CHECK-NEXT:  0000000000001008 l     O __DATA,__data _ref
39
# CHECK-NEXT:  0000000000001000 l     O __DATA,__data _alias
40
# CHECK-NEXT:  0000000000001010 l     O __DATA,__data _ref
41
# CHECK-NEXT:  0000000000001000  w    O __DATA,__data _weak
42
# CHECK-NEXT:  0000000000000000         *UND* dyld_stub_binder
43
# CHECK-EMPTY:
44
## Even though the references were to the non-weak `_alias` symbols, ld64 still
45
## emits weak binds as if they were the `_weak` symbol itself. We do not. I
46
## don't know of any programs that rely on this behavior, so I'm just
47
## documenting it here.
48
# CHECK-NEXT:  Weak bind table:
49
# CHECK-NEXT:  segment  section            address     type       addend   symbol
50
# CHECK-EMPTY:
51

52
# RUN: %lld -lSystem -dylib %t/local-then-weak.o %t/no-subsections.o -o %t/sub-nosub
53
# RUN: llvm-objdump --macho --syms --section="__DATA,__data" %t/sub-nosub | FileCheck %s --check-prefix SUB-NOSUB
54

55
## This test case demonstrates a shortcoming of LLD: If .subsections_via_symbols
56
## isn't enabled, we don't elide the contents of coalesced weak symbols if they
57
## are part of a section that has other non-coalesced symbols. In contrast, LD64
58
## does elide the contents.
59
# SUB-NOSUB:       Contents of (__DATA,__data) section
60
# SUB-NOSUB-NEXT:  0000000000001000    23 01 00 00 00 00 00 00 00 10 00 00 00 00 00 00
61
# SUB-NOSUB-NEXT:  0000000000001010    00 00 00 00 00 00 00 00 23 01 00 00 00 00 00 00
62
# SUB-NOSUB-EMPTY:
63
# SUB-NOSUB-NEXT:  SYMBOL TABLE:
64
# SUB-NOSUB-NEXT:  0000000000001000 l     O __DATA,__data _alias
65
# SUB-NOSUB-NEXT:  0000000000001008 l     O __DATA,__data _ref
66
# SUB-NOSUB-NEXT:  0000000000001010 l     O __DATA,__data _zeros
67
# SUB-NOSUB-NEXT:  0000000000001000 l     O __DATA,__data _alias
68
# SUB-NOSUB-NEXT:  0000000000001000  w    O __DATA,__data _weak
69
# SUB-NOSUB-NEXT:  0000000000000000         *UND* dyld_stub_binder
70

71
# RUN: %lld -lSystem -dylib %t/no-subsections.o %t/local-then-weak.o -o %t/nosub-sub
72
# RUN: llvm-objdump --macho --syms --section="__DATA,__data" %t/nosub-sub | FileCheck %s --check-prefix NOSUB-SUB
73

74
# NOSUB-SUB:       Contents of (__DATA,__data) section
75
# NOSUB-SUB-NEXT:  0000000000001000    00 00 00 00 00 00 00 00 23 01 00 00 00 00 00 00
76
# NOSUB-SUB-NEXT:  0000000000001010    08 10 00 00 00 00 00 00 {{$}}
77
# NOSUB-SUB-EMPTY:
78
# NOSUB-SUB-NEXT:  SYMBOL TABLE:
79
# NOSUB-SUB-NEXT:  0000000000001000 l     O __DATA,__data _zeros
80
# NOSUB-SUB-NEXT:  0000000000001008 l     O __DATA,__data _alias
81
# NOSUB-SUB-NEXT:  0000000000001008 l     O __DATA,__data _alias
82
# NOSUB-SUB-NEXT:  0000000000001010 l     O __DATA,__data _ref
83
# NOSUB-SUB-NEXT:  0000000000001008  w    O __DATA,__data _weak
84
# NOSUB-SUB-NEXT:  0000000000000000         *UND* dyld_stub_binder
85

86
## Verify that we don't drop any flags that the aliases have (such as
87
## .no_dead_strip). This is a regression test. We previously had subsections
88
## that were mistakenly stripped.
89

90
# RUN: %lld -lSystem -dead_strip %t/no-dead-strip.o -o %t/no-dead-strip
91
# RUN: llvm-objdump --macho --section-headers %t/no-dead-strip | FileCheck %s \
92
# RUN:   --check-prefix=NO-DEAD-STRIP
93
# NO-DEAD-STRIP: __data        00000010
94

95
#--- weak-then-local.s
96
.globl _weak
97
.weak_definition _weak
98
.data
99
_weak:
100
_alias:
101
  .quad 0x123
102

103
_ref:
104
  .quad _alias
105

106
.subsections_via_symbols
107

108
#--- local-then-weak.s
109
.globl _weak
110
.weak_definition _weak
111
.data
112
_alias:
113
_weak:
114
  .quad 0x123
115

116
_ref:
117
  .quad _alias
118

119
.subsections_via_symbols
120

121
#--- no-subsections.s
122
.globl _weak
123
.weak_definition _weak
124
.data
125
_zeros:
126
.space 8
127

128
_weak:
129
_alias:
130
  .quad 0x123
131

132
#--- no-dead-strip.s
133
.globl _main
134

135
_main:
136
  ret
137

138
.data
139
.no_dead_strip l_foo, l_bar
140

141
_foo:
142
l_foo:
143
  .quad 0x123
144

145
l_bar:
146
_bar:
147
  .quad 0x123
148

149
.subsections_via_symbols
150

Использование cookies

Мы используем файлы cookie в соответствии с Политикой конфиденциальности и Политикой использования cookies.

Нажимая кнопку «Принимаю», Вы даете АО «СберТех» согласие на обработку Ваших персональных данных в целях совершенствования нашего веб-сайта и Сервиса GitVerse, а также повышения удобства их использования.

Запретить использование cookies Вы можете самостоятельно в настройках Вашего браузера.