Skip to content

Commit aec1737

Browse files
authored
[MLIR][mlir-link] Fix conflict resolutions, and add fallback for missing ctors/dtor global symbols (#74)
1 parent 53112a5 commit aec1737

File tree

2 files changed

+24
-1
lines changed

2 files changed

+24
-1
lines changed

mlir/include/mlir/Linker/LLVMLinkerMixin.h

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -374,6 +374,12 @@ class LLVMLinkerMixin {
374374
if (srcComdat == mlir::LLVM::comdat::Comdat::NoDeduplicate) {
375375
return ConflictResolution::Failure;
376376
}
377+
if (srcComdat == mlir::LLVM::comdat::Comdat::ExactMatch) {
378+
return ConflictResolution::LinkFromDst;
379+
}
380+
if (srcComdat == mlir::LLVM::comdat::Comdat::SameSize) {
381+
return ConflictResolution::LinkFromDst;
382+
}
377383
llvm_unreachable("unimplemented comdat kind");
378384
}
379385

@@ -384,6 +390,20 @@ class LLVMLinkerMixin {
384390
return ConflictResolution::Failure;
385391
}
386392

393+
if (!srcIsDeclaration && !dstIsDeclaration)
394+
return ConflictResolution::Failure;
395+
396+
if (!srcIsDeclaration && dstIsDeclaration)
397+
return ConflictResolution::LinkFromSrc;
398+
399+
if (srcIsDeclaration && !dstIsDeclaration)
400+
return ConflictResolution::LinkFromDst;
401+
402+
// For same-type linkages not handled above, prefer dst to maintain
403+
// stability
404+
if (srcLinkage == dstLinkage)
405+
return ConflictResolution::LinkFromDst;
406+
387407
llvm_unreachable("unimplemented conflict resolution");
388408
}
389409
};

mlir/lib/Dialect/LLVMIR/IR/LLVMLinkerInterface.cpp

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -535,8 +535,11 @@ Operation *LLVM::LLVMSymbolLinkerInterface::appendGlobals(llvm::StringRef glob,
535535
return appendGlobalStructors<LLVM::GlobalDtorsOp>(state);
536536

537537
const auto &globs = append.lookup(glob);
538-
if (globs.empty())
538+
if (globs.empty()) {
539+
if (auto found = summary.find(glob); found != summary.end())
540+
return state.clone(found->second);
539541
return nullptr;
542+
}
540543
if (auto lastGV = dyn_cast<LLVM::GlobalOp>(globs.back()))
541544
return appendGlobalOps(globs, lastGV, state);
542545
if (auto comdat = dyn_cast<LLVM::ComdatOp>(globs.back()))

0 commit comments

Comments
 (0)