@@ -74,19 +74,25 @@ std::string lld::toString(const coff::InputFile *file) {
74
74
// / If Source is Undefined and has no weak alias set, makes it a weak
75
75
// / alias to Target.
76
76
static void checkAndSetWeakAlias (COFFLinkerContext &ctx, InputFile *f,
77
- Symbol *source, Symbol *target) {
77
+ Symbol *source, Symbol *target,
78
+ bool isAntiDep) {
78
79
if (auto *u = dyn_cast<Undefined>(source)) {
79
80
if (u->weakAlias && u->weakAlias != target) {
80
- // Weak aliases as produced by GCC are named in the form
81
- // .weak.<weaksymbol>.<othersymbol>, where <othersymbol> is the name
82
- // of another symbol emitted near the weak symbol.
83
- // Just use the definition from the first object file that defined
84
- // this weak symbol.
85
- if (ctx.config .allowDuplicateWeak )
81
+ // Ignore duplicated anti-dependency symbols.
82
+ if (isAntiDep)
86
83
return ;
87
- ctx.symtab .reportDuplicate (source, f);
84
+ if (!u->isAntiDep ) {
85
+ // Weak aliases as produced by GCC are named in the form
86
+ // .weak.<weaksymbol>.<othersymbol>, where <othersymbol> is the name
87
+ // of another symbol emitted near the weak symbol.
88
+ // Just use the definition from the first object file that defined
89
+ // this weak symbol.
90
+ if (ctx.config .allowDuplicateWeak )
91
+ return ;
92
+ ctx.symtab .reportDuplicate (source, f);
93
+ }
88
94
}
89
- u->weakAlias = target;
95
+ u->setWeakAlias ( target, isAntiDep) ;
90
96
}
91
97
}
92
98
@@ -436,7 +442,8 @@ void ObjFile::initializeSymbols() {
436
442
uint32_t numSymbols = coffObj->getNumberOfSymbols ();
437
443
symbols.resize (numSymbols);
438
444
439
- SmallVector<std::pair<Symbol *, uint32_t >, 8 > weakAliases;
445
+ SmallVector<std::pair<Symbol *, const coff_aux_weak_external *>, 8 >
446
+ weakAliases;
440
447
std::vector<uint32_t > pendingIndexes;
441
448
pendingIndexes.reserve (numSymbols);
442
449
@@ -451,8 +458,8 @@ void ObjFile::initializeSymbols() {
451
458
symbols[i] = createUndefined (coffSym);
452
459
} else if (coffSym.isWeakExternal ()) {
453
460
symbols[i] = createUndefined (coffSym);
454
- uint32_t tagIndex = coffSym. getAux <coff_aux_weak_external>()-> TagIndex ;
455
- weakAliases. emplace_back (symbols[i], tagIndex );
461
+ weakAliases. emplace_back (symbols[i],
462
+ coffSym. getAux <coff_aux_weak_external>() );
456
463
} else if (std::optional<Symbol *> optSym =
457
464
createDefined (coffSym, comdatDefs, prevailingComdat)) {
458
465
symbols[i] = *optSym;
@@ -491,8 +498,10 @@ void ObjFile::initializeSymbols() {
491
498
492
499
for (auto &kv : weakAliases) {
493
500
Symbol *sym = kv.first ;
494
- uint32_t idx = kv.second ;
495
- checkAndSetWeakAlias (ctx, this , sym, symbols[idx]);
501
+ const coff_aux_weak_external *aux = kv.second ;
502
+ checkAndSetWeakAlias (ctx, this , sym, symbols[aux->TagIndex ],
503
+ aux->Characteristics ==
504
+ IMAGE_WEAK_EXTERN_ANTI_DEPENDENCY);
496
505
}
497
506
498
507
// Free the memory used by sparseChunks now that symbol loading is finished.
@@ -1202,7 +1211,7 @@ void BitcodeFile::parse() {
1202
1211
sym = ctx.symtab .addUndefined (symName, this , true );
1203
1212
std::string fallback = std::string (objSym.getCOFFWeakExternalFallback ());
1204
1213
Symbol *alias = ctx.symtab .addUndefined (saver.save (fallback));
1205
- checkAndSetWeakAlias (ctx, this , sym, alias);
1214
+ checkAndSetWeakAlias (ctx, this , sym, alias, false );
1206
1215
} else if (comdatIndex != -1 ) {
1207
1216
if (symName == obj->getComdatTable ()[comdatIndex].first ) {
1208
1217
sym = comdat[comdatIndex].first ;
0 commit comments