File tree Expand file tree Collapse file tree 4 files changed +45
-13
lines changed Expand file tree Collapse file tree 4 files changed +45
-13
lines changed Original file line number Diff line number Diff line change @@ -494,20 +494,8 @@ void SymbolTable::resolveRemainingUndefines() {
494
494
StringRef name = undef->getName ();
495
495
496
496
// A weak alias may have been resolved, so check for that.
497
- if (Defined *d = undef->getWeakAlias ()) {
498
- // We want to replace Sym with D. However, we can't just blindly
499
- // copy sizeof(SymbolUnion) bytes from D to Sym because D may be an
500
- // internal symbol, and internal symbols are stored as "unparented"
501
- // Symbols. For that reason we need to check which type of symbol we
502
- // are dealing with and copy the correct number of bytes.
503
- if (isa<DefinedRegular>(d))
504
- memcpy (sym, d, sizeof (DefinedRegular));
505
- else if (isa<DefinedAbsolute>(d))
506
- memcpy (sym, d, sizeof (DefinedAbsolute));
507
- else
508
- memcpy (sym, d, sizeof (SymbolUnion));
497
+ if (undef->resolveWeakAlias ())
509
498
continue ;
510
- }
511
499
512
500
// If we can resolve a symbol by removing __imp_ prefix, do that.
513
501
// This odd rule is for compatibility with MSVC linker.
Original file line number Diff line number Diff line change @@ -136,6 +136,29 @@ Defined *Undefined::getWeakAlias() {
136
136
return nullptr ;
137
137
}
138
138
139
+ bool Undefined::resolveWeakAlias () {
140
+ Defined *d = getWeakAlias ();
141
+ if (!d)
142
+ return false ;
143
+
144
+ // We want to replace Sym with D. However, we can't just blindly
145
+ // copy sizeof(SymbolUnion) bytes from D to Sym because D may be an
146
+ // internal symbol, and internal symbols are stored as "unparented"
147
+ // Symbols. For that reason we need to check which type of symbol we
148
+ // are dealing with and copy the correct number of bytes.
149
+ StringRef name = getName ();
150
+ if (isa<DefinedRegular>(d))
151
+ memcpy (this , d, sizeof (DefinedRegular));
152
+ else if (isa<DefinedAbsolute>(d))
153
+ memcpy (this , d, sizeof (DefinedAbsolute));
154
+ else
155
+ memcpy (this , d, sizeof (SymbolUnion));
156
+
157
+ nameData = name.data ();
158
+ nameSize = name.size ();
159
+ return true ;
160
+ }
161
+
139
162
MemoryBufferRef LazyArchive::getMemberBuffer () {
140
163
Archive::Child c =
141
164
CHECK (sym.getMember (), " could not get the member for symbol " +
Original file line number Diff line number Diff line change @@ -341,6 +341,9 @@ class Undefined : public Symbol {
341
341
// symbol by searching the chain of fallback symbols. Returns the symbol if
342
342
// successful, otherwise returns null.
343
343
Defined *getWeakAlias ();
344
+
345
+ // If this symbol is external weak, replace this object with aliased symbol.
346
+ bool resolveWeakAlias ();
344
347
};
345
348
346
349
// Windows-specific classes.
Original file line number Diff line number Diff line change 86
86
# CHECK-NEXT: StorageClass: External (0x2)
87
87
# CHECK-NEXT: AuxSymbolCount: 0
88
88
# CHECK-NEXT: }
89
+ # CHECK-NEXT: Symbol {
90
+ # CHECK-NEXT: Name: weak_main
91
+ # CHECK-NEXT: Value: 0
92
+ # CHECK-NEXT: Section: .text (1)
93
+ # CHECK-NEXT: BaseType: Null (0x0)
94
+ # CHECK-NEXT: ComplexType: Null (0x0)
95
+ # CHECK-NEXT: StorageClass: External (0x2)
96
+ # CHECK-NEXT: AuxSymbolCount: 0
97
+ # CHECK-NEXT: }
89
98
# CHECK-NEXT: ]
90
99
91
100
# NO: Symbols [
@@ -237,4 +246,13 @@ symbols:
237
246
SimpleType: IMAGE_SYM_TYPE_NULL
238
247
ComplexType: IMAGE_SYM_DTYPE_NULL
239
248
StorageClass: IMAGE_SYM_CLASS_LABEL
249
+ - Name: weak_main
250
+ Value: 0
251
+ SectionNumber: 0
252
+ SimpleType: IMAGE_SYM_TYPE_NULL
253
+ ComplexType: IMAGE_SYM_DTYPE_NULL
254
+ StorageClass: IMAGE_SYM_CLASS_WEAK_EXTERNAL
255
+ WeakExternal:
256
+ TagIndex: 10
257
+ Characteristics: IMAGE_WEAK_EXTERN_SEARCH_ALIAS
240
258
...
You can’t perform that action at this time.
0 commit comments