llvm.org GIT mirror llvm / 38048cd
Reject alias to undefined symbols in the verifier. On ELF and COFF an alias is just another name for a position in the file. There is no way to refer to a position in another file, so an alias to undefined is meaningless. MachO currently doesn't support aliases. The spec has a N_INDR, which when implemented will have a different set of restrictions. Adding support for it shouldn't be harder than any other IR extension. For now, having the IR represent what is actually possible with current tools makes it easier to fix the design of GlobalAlias. git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@203705 91177308-0d34-0410-b5e6-96231b3b80d8 Rafael Espindola 5 years ago
17 changed file(s) with 166 addition(s) and 63 deletion(s). Raw diff Collapse all Expand all
685685 ``linkonce_odr``, ``weak_odr``, ``external``. Note that some system linkers
686686 might not correctly handle dropping a weak symbol that is aliased by a non-weak
687687 alias.
688
689 Alias that are not ``unnamed_addr`` are guaranteed to have the same address as
690 the aliasee.
691
692 The aliasee must be a definition.
688693
689694 .. _namedmetadatastructure:
690695
927927 MCSymbol *Name = getSymbol(I);
928928
929929 const GlobalValue *GV = I->getAliasedGlobal();
930 if (GV->isDeclaration()) {
931 report_fatal_error(Name->getName() +
932 ": Target doesn't support aliases to declarations");
933 }
934
930 assert(!GV->isDeclaration());
935931 MCSymbol *Target = getSymbol(GV);
936932
937933 if (I->hasExternalLinkage() || !MAI->getWeakRefDirective())
500500 &GA);
501501 }
502502 }
503 Assert1(!GV->isDeclaration(), "Alias must point to a definition", &GA);
503504
504505 const GlobalValue* Resolved = GA.resolveAliasedGlobal(/*stopOnWeak*/ false);
505506 Assert1(Resolved,
66 %struct.pci_device_id = type { i32, i32, i32, i32, i32, i32, i64 }
77 %struct.usb_bus = type { %struct.device* }
88 %struct.usb_hcd = type { %struct.usb_bus, i64, [0 x i64] }
9 @uhci_pci_ids = external constant [1 x %struct.pci_device_id] ; <[1 x %struct.pci_device_id]*> [#uses=1]
9 @uhci_pci_ids = constant [1 x %struct.pci_device_id] zeroinitializer
1010
1111 @__mod_pci_device_table = alias [1 x %struct.pci_device_id]* @uhci_pci_ids
1212 ; <[1 x %struct.pci_device_id]*> [#uses=0]
66 %struct.pci_device_id = type { i32, i32, i32, i32, i32, i32, i64 }
77 %struct.usb_bus = type { %struct.device* }
88 %struct.usb_hcd = type { %struct.usb_bus, [0 x i64] }
9 @pci_ids = external constant [1 x %struct.pci_device_id] ; <[1 x %struct.pci_device_id]*> [#uses=1]
9 @pci_ids = constant [1 x %struct.pci_device_id] zeroinitializer
1010
1111 @__mod_pci_device_table = alias [1 x %struct.pci_device_id]* @pci_ids ; <[1 x %struct.pci_device_id]*> [#uses=0]
1212
55
66
77
8 declare extern_weak i32 @pthread_cancel(i32)
8 define weak i32 @pthread_cancel(i32) {
9 ret i32 0
10 }
55 %struct.locale_data = type { i8*, i8*, i32, i32, { void (%struct.locale_data*)*, %struct.anon }, i32, i32, i32, [0 x %struct.locale_data_value] }
66 %struct.locale_data_value = type { i32* }
77
8 @wcstoll_l = alias i64 (i32*, i32**, i32, %struct.__locale_struct*)* @__wcstoll_l ; [#uses=0]
8 @wcstoll_l = alias i64 (i32*, i32**, i32, %struct.__locale_struct*)* @__wcstoll_l
99
1010 define i64 @____wcstoll_l_internal(i32* %nptr, i32** %endptr, i32 %base, i32 %group, %struct.__locale_struct* %loc) nounwind {
1111 entry:
+0
-5
test/CodeGen/X86/alias-error.ll less more
None ; RUN: not llc -mtriple=i686-pc-linux-gnu %s -o /dev/null 2>&1 | FileCheck %s
1
2 @a = external global i32
3 @b = alias i32* @a
4 ; CHECK: b: Target doesn't support aliases to declarations
33
44 @llvm.used = appending global [1 x i8*] [i8* bitcast (i32* @foo1 to i8*)], section "llvm.metadata"
55
6 @bar = external global i32
6 @bar = global i32 0
77 @foo1 = alias i32* @bar
88 @foo2 = alias i32* @bar
99 @foo3 = alias i32* @foo2
1010
1111 %FunTy = type i32()
1212
13 declare i32 @foo_f()
13 define i32 @foo_f() {
14 ret i32 0
15 }
1416 @bar_f = alias weak %FunTy* @foo_f
1517 @bar_ff = alias i32()* @bar_f
1618
3636 @_ZL33__gthrw_pthread_mutexattr_settypeP19pthread_mutexattr_ti = alias weak i32 (%union.pthread_mutexattr_t*, i32)* @pthread_mutexattr_settype
3737 @_ZL33__gthrw_pthread_mutexattr_destroyP19pthread_mutexattr_t = alias weak i32 (%union.pthread_mutexattr_t*)* @pthread_mutexattr_destroy
3838
39 declare void @_ZN13HexxagonBoardC2ERKS_(%struct.HexxagonBoard*, %struct.HexxagonBoard*) uwtable align 2
39 define void @_ZN13HexxagonBoardC2ERKS_(%struct.HexxagonBoard*, %struct.HexxagonBoard*) uwtable align 2 {
40 ret void
41 }
4042
41 declare extern_weak i32 @pthread_once(i32*, void ()*)
43 define weak i32 @pthread_once(i32*, void ()*) {
44 ret i32 0
45 }
4246
43 declare extern_weak i8* @pthread_getspecific(i32)
47 define weak i8* @pthread_getspecific(i32) {
48 ret i8* null
49 }
4450
45 declare extern_weak i32 @pthread_setspecific(i32, i8*)
51 define weak i32 @pthread_setspecific(i32, i8*) {
52 ret i32 0
53 }
4654
47 declare extern_weak i32 @pthread_create(i64*, %union.pthread_attr_t*, i8* (i8*)*, i8*)
55 define weak i32 @pthread_create(i64*, %union.pthread_attr_t*, i8* (i8*)*, i8*) {
56 ret i32 0
57 }
4858
49 declare extern_weak i32 @pthread_join(i64, i8**)
59 define weak i32 @pthread_join(i64, i8**) {
60 ret i32 0
61 }
5062
51 declare extern_weak i32 @pthread_equal(i64, i64)
63 define weak i32 @pthread_equal(i64, i64) {
64 ret i32 0
65 }
5266
53 declare extern_weak i64 @pthread_self()
67 define weak i64 @pthread_self() {
68 ret i64 0
69 }
5470
55 declare extern_weak i32 @pthread_detach(i64)
71 define weak i32 @pthread_detach(i64) {
72 ret i32 0
73 }
5674
57 declare extern_weak i32 @pthread_cancel(i64)
75 define weak i32 @pthread_cancel(i64) {
76 ret i32 0
77 }
5878
59 declare extern_weak i32 @sched_yield()
79 define weak i32 @sched_yield() {
80 ret i32 0
81 }
6082
61 declare extern_weak i32 @pthread_mutex_lock(%union.pthread_mutex_t*)
83 define weak i32 @pthread_mutex_lock(%union.pthread_mutex_t*) {
84 ret i32 0
85 }
6286
63 declare extern_weak i32 @pthread_mutex_trylock(%union.pthread_mutex_t*)
87 define weak i32 @pthread_mutex_trylock(%union.pthread_mutex_t*) {
88 ret i32 0
89 }
6490
65 declare extern_weak i32 @pthread_mutex_timedlock(%union.pthread_mutex_t*, %struct.timespec*)
91 define weak i32 @pthread_mutex_timedlock(%union.pthread_mutex_t*, %struct.timespec*) {
92 ret i32 0
93 }
6694
67 declare extern_weak i32 @pthread_mutex_unlock(%union.pthread_mutex_t*)
95 define weak i32 @pthread_mutex_unlock(%union.pthread_mutex_t*) {
96 ret i32 0
97 }
6898
69 declare extern_weak i32 @pthread_mutex_init(%union.pthread_mutex_t*, %union.pthread_mutexattr_t*)
99 define weak i32 @pthread_mutex_init(%union.pthread_mutex_t*, %union.pthread_mutexattr_t*) {
100 ret i32 0
101 }
70102
71 declare extern_weak i32 @pthread_mutex_destroy(%union.pthread_mutex_t*)
103 define weak i32 @pthread_mutex_destroy(%union.pthread_mutex_t*) {
104 ret i32 0
105 }
72106
73 declare extern_weak i32 @pthread_cond_broadcast(%union.pthread_cond_t*)
107 define weak i32 @pthread_cond_broadcast(%union.pthread_cond_t*) {
108 ret i32 0
109 }
74110
75 declare extern_weak i32 @pthread_cond_signal(%union.pthread_cond_t*)
111 define weak i32 @pthread_cond_signal(%union.pthread_cond_t*) {
112 ret i32 0
113 }
76114
77 declare extern_weak i32 @pthread_cond_wait(%union.pthread_cond_t*, %union.pthread_mutex_t*)
115 define weak i32 @pthread_cond_wait(%union.pthread_cond_t*, %union.pthread_mutex_t*) {
116 ret i32 0
117 }
78118
79 declare extern_weak i32 @pthread_cond_timedwait(%union.pthread_cond_t*, %union.pthread_mutex_t*, %struct.timespec*)
119 define weak i32 @pthread_cond_timedwait(%union.pthread_cond_t*, %union.pthread_mutex_t*, %struct.timespec*) {
120 ret i32 0
121 }
80122
81 declare extern_weak i32 @pthread_cond_destroy(%union.pthread_cond_t*)
123 define weak i32 @pthread_cond_destroy(%union.pthread_cond_t*) {
124 ret i32 0
125 }
82126
83 declare extern_weak i32 @pthread_key_create(i32*, void (i8*)*)
127 define weak i32 @pthread_key_create(i32*, void (i8*)*) {
128 ret i32 0
129 }
84130
85 declare extern_weak i32 @pthread_key_delete(i32)
131 define weak i32 @pthread_key_delete(i32) {
132 ret i32 0
133 }
86134
87 declare extern_weak i32 @pthread_mutexattr_init(%union.pthread_mutexattr_t*)
135 define weak i32 @pthread_mutexattr_init(%union.pthread_mutexattr_t*) {
136 ret i32 0
137 }
88138
89 declare extern_weak i32 @pthread_mutexattr_settype(%union.pthread_mutexattr_t*, i32)
139 define weak i32 @pthread_mutexattr_settype(%union.pthread_mutexattr_t*, i32) {
140 ret i32 0
141 }
90142
91 declare extern_weak i32 @pthread_mutexattr_destroy(%union.pthread_mutexattr_t*)
143 define weak i32 @pthread_mutexattr_destroy(%union.pthread_mutexattr_t*) {
144 ret i32 0
145 }
5252 unreachable
5353 }
5454
55 declare i32 @pthread_once(i32*, void ()*)
55 define i32 @pthread_once(i32*, void ()*) {
56 ret i32 0
57 }
5658
57 declare i8* @pthread_getspecific(i32)
59 define i8* @pthread_getspecific(i32) {
60 ret i8* null
61 }
5862
59 declare i32 @pthread_setspecific(i32, i8*)
63 define i32 @pthread_setspecific(i32, i8*) {
64 ret i32 0
65 }
6066
61 declare i32 @pthread_create(i32*, %struct.pthread_attr_t*, i8* (i8*)*, i8*)
67 define i32 @pthread_create(i32*, %struct.pthread_attr_t*, i8* (i8*)*, i8*) {
68 ret i32 0
69 }
6270
63 declare i32 @pthread_cancel(i32)
71 define i32 @pthread_cancel(i32) {
72 ret i32 0
73 }
6474
65 declare i32 @pthread_mutex_lock(%struct.pthread_mutex_t*)
75 define i32 @pthread_mutex_lock(%struct.pthread_mutex_t*) {
76 ret i32 0
77 }
6678
67 declare i32 @pthread_mutex_trylock(%struct.pthread_mutex_t*)
79 define i32 @pthread_mutex_trylock(%struct.pthread_mutex_t*) {
80 ret i32 0
81 }
6882
69 declare i32 @pthread_mutex_unlock(%struct.pthread_mutex_t*)
83 define i32 @pthread_mutex_unlock(%struct.pthread_mutex_t*) {
84 ret i32 0
85 }
7086
71 declare i32 @pthread_mutex_init(%struct.pthread_mutex_t*, %struct.__sched_param*)
87 define i32 @pthread_mutex_init(%struct.pthread_mutex_t*, %struct.__sched_param*) {
88 ret i32 0
89 }
7290
73 declare i32 @pthread_key_create(i32*, void (i8*)*)
91 define i32 @pthread_key_create(i32*, void (i8*)*) {
92 ret i32 0
93 }
7494
75 declare i32 @pthread_key_delete(i32)
95 define i32 @pthread_key_delete(i32) {
96 ret i32 0
97 }
7698
77 declare i32 @pthread_mutexattr_init(%struct.__sched_param*)
99 define i32 @pthread_mutexattr_init(%struct.__sched_param*) {
100 ret i32 0
101 }
78102
79 declare i32 @pthread_mutexattr_settype(%struct.__sched_param*, i32)
103 define i32 @pthread_mutexattr_settype(%struct.__sched_param*, i32) {
104 ret i32 0
105 }
80106
81 declare i32 @pthread_mutexattr_destroy(%struct.__sched_param*)
107 define i32 @pthread_mutexattr_destroy(%struct.__sched_param*) {
108 ret i32 0
109 }
0 ; RUN: opt < %s -globalopt
11
2 @g = external global i32
2 @g = global i32 0
33
44 @a = alias bitcast (i32* @g to i8*)
55
88 @bar1 = alias void ()* @bar2
99 ; CHECK: @bar1 = alias void ()* @bar2
1010
11 declare void @bar2()
12 ; CHECK: declare void @bar2()
11 define void @bar2() {
12 ret void
13 }
14 ; CHECK: define void @bar2()
1315
1416 define void @baz() {
1517 entry:
22
33 @__gthrw_pthread_cancel = alias weak i32 (i32)* @pthread_cancel ; [#uses=1]
44 @__gthread_active_ptr.5335 = internal constant i8* bitcast (i32 (i32)* @__gthrw_pthread_cancel to i8*) ; [#uses=1]
5 declare extern_weak i32 @pthread_cancel(i32)
5 define weak i32 @pthread_cancel(i32) {
6 ret i32 0
7 }
68
79 define i1 @__gthread_active_p() {
810 entry:
22
33 @A = alias weak void ()* @B ; [#uses=1]
44
5 declare extern_weak void @B()
5 define weak void @B() {
6 ret void
7 }
68
79 define i32 @active() {
810 entry:
1313
1414 @func_7_xxx = alias weak i32 (...)* @aliased_func_7_xxx
1515
16 declare i32 @aliased_func_7_xxx(...)
16 define i32 @aliased_func_7_xxx(...) {
17 ret i32 0
18 }
1719
1820 define i32 @func_3_xxx() nounwind uwtable ssp {
1921 ret i32 3
0 ; RUN: not llvm-as %s -o /dev/null 2>&1 | FileCheck %s
1
2
3 declare void @f()
4 @fa = alias void ()* @f
5 ; CHECK: Alias must point to a definition
6 ; CHECK-NEXT: @fa
7
8 @g = external global i32
9 @ga = alias i32* @g
10 ; CHECK: Alias must point to a definition
11 ; CHECK-NEXT: @ga