[llvm-branch-commits] [RISCV][lld] Support merging RISC-V Atomics ABI attributes (PR #97347)
Fangrui Song via llvm-branch-commits
llvm-branch-commits at lists.llvm.org
Mon Jul 1 20:13:01 PDT 2024
================
@@ -1084,10 +1084,76 @@ static void mergeArch(RISCVISAUtils::OrderedExtensionMap &mergedExts,
}
}
+static void mergeAtomic(DenseMap<unsigned, unsigned>::iterator it,
+ const InputSectionBase *oldSection,
+ const InputSectionBase *newSection,
+ RISCVAttrs::RISCVAtomicAbiTag oldTag,
+ RISCVAttrs::RISCVAtomicAbiTag newTag) {
+ using RISCVAttrs::RISCVAtomicAbiTag;
+ // Same tags stay the same, and UNKNOWN is compatible with anything
+ if (oldTag == newTag || newTag == RISCVAtomicAbiTag::UNKNOWN)
+ return;
+
+ auto reportAbiError = [&]() {
+ errorOrWarn("atomic abi mismatch for " + oldSection->name + "\n>>> " +
+ toString(oldSection) +
+ ": atomic_abi=" + Twine(static_cast<unsigned>(oldTag)) +
+ "\n>>> " + toString(newSection) +
+ ": atomic_abi=" + Twine(static_cast<unsigned>(newTag)));
+ };
+
+ switch (static_cast<RISCVAtomicAbiTag>(oldTag)) {
+ case RISCVAtomicAbiTag::UNKNOWN:
+ it->getSecond() = static_cast<unsigned>(newTag);
+ return;
+ case RISCVAtomicAbiTag::A6C:
+ switch (newTag) {
+ case RISCVAtomicAbiTag::A6S:
+ it->getSecond() = static_cast<unsigned>(RISCVAtomicAbiTag::A6C);
+ return;
+ case RISCVAtomicAbiTag::A7:
+ reportAbiError();
+ return;
+ case RISCVAttrs::RISCVAtomicAbiTag::UNKNOWN:
+ case RISCVAttrs::RISCVAtomicAbiTag::A6C:
+ return;
+ };
+
+ case RISCVAtomicAbiTag::A6S:
+ switch (newTag) {
+ case RISCVAtomicAbiTag::A6C:
+ it->getSecond() = static_cast<unsigned>(RISCVAtomicAbiTag::A6C);
+ return;
+ case RISCVAtomicAbiTag::A7:
+ it->getSecond() = static_cast<unsigned>(RISCVAtomicAbiTag::A7);
+ return;
+ case RISCVAttrs::RISCVAtomicAbiTag::UNKNOWN:
+ case RISCVAttrs::RISCVAtomicAbiTag::A6S:
+ return;
+ };
+
+ case RISCVAtomicAbiTag::A7:
+ switch (newTag) {
+ case RISCVAtomicAbiTag::A6S:
+ it->getSecond() = static_cast<unsigned>(RISCVAtomicAbiTag::A7);
+ return;
+ case RISCVAtomicAbiTag::A6C:
+ reportAbiError();
+ return;
+ case RISCVAttrs::RISCVAtomicAbiTag::UNKNOWN:
+ case RISCVAttrs::RISCVAtomicAbiTag::A7:
+ return;
+ };
+ };
+ llvm_unreachable("unknown AtomicABI");
----------------
MaskRay wrote:
If a potentially-corrupted object file may contain an unknown tag, it's inappropriate to use unreachable.
https://github.com/llvm/llvm-project/pull/97347
More information about the llvm-branch-commits
mailing list