@@ -74,19 +74,25 @@ std::string lld::toString(const coff::InputFile *file) {
7474// / If Source is Undefined and has no weak alias set, makes it a weak
7575// / alias to Target.
7676static void checkAndSetWeakAlias (COFFLinkerContext &ctx, InputFile *f,
77- Symbol *source, Symbol *target) {
77+ Symbol *source, Symbol *target,
78+ bool isAntiDep) {
7879 if (auto *u = dyn_cast<Undefined>(source)) {
7980 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)
8683 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+ }
8894 }
89- u->weakAlias = target;
95+ u->setWeakAlias ( target, isAntiDep) ;
9096 }
9197}
9298
@@ -436,7 +442,8 @@ void ObjFile::initializeSymbols() {
436442 uint32_t numSymbols = coffObj->getNumberOfSymbols ();
437443 symbols.resize (numSymbols);
438444
439- SmallVector<std::pair<Symbol *, uint32_t >, 8 > weakAliases;
445+ SmallVector<std::pair<Symbol *, const coff_aux_weak_external *>, 8 >
446+ weakAliases;
440447 std::vector<uint32_t > pendingIndexes;
441448 pendingIndexes.reserve (numSymbols);
442449
@@ -451,8 +458,8 @@ void ObjFile::initializeSymbols() {
451458 symbols[i] = createUndefined (coffSym);
452459 } else if (coffSym.isWeakExternal ()) {
453460 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>() );
456463 } else if (std::optional<Symbol *> optSym =
457464 createDefined (coffSym, comdatDefs, prevailingComdat)) {
458465 symbols[i] = *optSym;
@@ -491,8 +498,10 @@ void ObjFile::initializeSymbols() {
491498
492499 for (auto &kv : weakAliases) {
493500 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);
496505 }
497506
498507 // Free the memory used by sparseChunks now that symbol loading is finished.
@@ -1202,7 +1211,7 @@ void BitcodeFile::parse() {
12021211 sym = ctx.symtab .addUndefined (symName, this , true );
12031212 std::string fallback = std::string (objSym.getCOFFWeakExternalFallback ());
12041213 Symbol *alias = ctx.symtab .addUndefined (saver.save (fallback));
1205- checkAndSetWeakAlias (ctx, this , sym, alias);
1214+ checkAndSetWeakAlias (ctx, this , sym, alias, false );
12061215 } else if (comdatIndex != -1 ) {
12071216 if (symName == obj->getComdatTable ()[comdatIndex].first ) {
12081217 sym = comdat[comdatIndex].first ;
0 commit comments