-bool ModuleLinker::linkAliasProto(GlobalAlias *SGA) {
- GlobalValue *DGV = getLinkedToGlobal(SGA);
- llvm::Optional<GlobalValue::VisibilityTypes> NewVisibility;
- bool HasUnnamedAddr = SGA->hasUnnamedAddr();
-
- bool LinkFromSrc = false;
- Comdat *DC = nullptr;
- if (const Comdat *SC = SGA->getComdat()) {
- Comdat::SelectionKind SK;
- std::tie(SK, LinkFromSrc) = ComdatsChosen[SC];
- DC = DstM->getOrInsertComdat(SC->getName());
- DC->setSelectionKind(SK);
- }
-
- if (DGV) {
- if (!DC) {
- GlobalValue::LinkageTypes NewLinkage = GlobalValue::InternalLinkage;
- GlobalValue::VisibilityTypes NV;
- if (getLinkageResult(DGV, SGA, NewLinkage, NV, LinkFromSrc))
- return true;
- NewVisibility = NV;
- HasUnnamedAddr = HasUnnamedAddr && DGV->hasUnnamedAddr();
-
- if (!LinkFromSrc) {
- // Set calculated linkage.
- DGV->setLinkage(NewLinkage);
- DGV->setVisibility(*NewVisibility);
- DGV->setUnnamedAddr(HasUnnamedAddr);
- }
- }
-
- if (!LinkFromSrc) {
- // Make sure to remember this mapping.
- ValueMap[SGA] = ConstantExpr::getBitCast(DGV,TypeMap.get(SGA->getType()));
-
- // Track the alias from the source module so we don't attempt to remap it.
- DoNotLinkFromSource.insert(SGA);
-
- return false;
- }
- }
-
- // If the Comdat this alias was inside of wasn't selected, skip it.
- if (DC && !DGV && !LinkFromSrc) {
- DoNotLinkFromSource.insert(SGA);
- return false;
- }