[llvm] [llvm-objdump][AVR] Detect AVR architecture from ELF flags for disassembling (PR #174731)

Ruoyu Qiu via llvm-commits llvm-commits at lists.llvm.org
Wed Jan 28 02:36:33 PST 2026


================

----------------
cabbaken wrote:

How about this?
```diff
diff --git a/llvm/tools/llvm-objdump/llvm-objdump.cpp b/llvm/tools/llvm-objdump/llvm-objdump
.cpp
index 68b76c9ed542..62dfa19d3388 100644
--- a/llvm/tools/llvm-objdump/llvm-objdump.cpp
+++ b/llvm/tools/llvm-objdump/llvm-objdump.cpp
@@ -2691,19 +2691,17 @@ static void disassembleObject(ObjectFile *Obj, bool InlineRelocs,
   } else if (MCPU.empty() && Obj->makeTriple().isAArch64()) {
     Features.AddFeature("+all");
   } else if (MCPU.empty() && Obj->makeTriple().isAVR()) {
-    // Assign attributes based on the AVR architecture version, default to
-    // "avr0". Report "<unknown>" for unsupported AVR instructions to avoid
-    // silent failures.
     if (const auto *Elf = dyn_cast<ELFObjectFileBase>(Obj)) {
       unsigned AVRVersion = Elf->getPlatformFlags() & ELF::EF_AVR_ARCH_MASK;
       if (Expected<std::string> VersionOrErr =
               AVR::getFeatureSetFromEFlag(AVRVersion)) {
         Features.AddFeature('+' + *VersionOrErr);
       } else {
-        reportWarning("unknown AVR EFlags value: 0x" +
-                          Twine::utohexstr(AVRVersion) + ", defaulting to avr0",
+        // If the architecture version cannot be determined from ELF flags,
+        // fall back to the baseline "avr0" ISA. The AVR disassembler
+        // requires a valid feature specification to function correctly.
+        reportWarning(toString(VersionOrErr.takeError()) +
+                          ": defaulting to avr0",
                       Obj->getFileName());
-        consumeError(VersionOrErr.takeError());
         Features.AddFeature("+avr0");
       }
     }
```
I've moved the comment to the error handling section to explain why we fall back to "avr0". Would you like to add more detailed information here?

https://github.com/llvm/llvm-project/pull/174731


More information about the llvm-commits mailing list