[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
Sun Jan 18 03:11:31 PST 2026


================
@@ -0,0 +1,45 @@
+//===-- AVRTargetParser - Parser for AVR target features --------*- C++ -*-===//
+//
+// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
+// See https://llvm.org/LICENSE.txt for license information.
+// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
+//
+//===----------------------------------------------------------------------===//
+//
+// This file implements a target parser to recognise AVR hardware features
+//
+//===----------------------------------------------------------------------===//
+#include "llvm/TargetParser/AVRTargetParser.h"
+#include "llvm/BinaryFormat/ELF.h"
+#include <map>
+
+using namespace llvm;
+
+std::string AVR::getFeatureSetForEFlag(unsigned EFlag) {
+  static std::map<unsigned, StringRef> EFlagToFeatureSet = {
+      {ELF::EF_AVR_ARCH_AVR1, "avr1"},
+      {ELF::EF_AVR_ARCH_AVR2, "avr2"},
+      {ELF::EF_AVR_ARCH_AVR25, "avr25"},
+      {ELF::EF_AVR_ARCH_AVR3, "avr3"},
+      {ELF::EF_AVR_ARCH_AVR31, "avr31"},
+      {ELF::EF_AVR_ARCH_AVR35, "avr35"},
+      {ELF::EF_AVR_ARCH_AVR4, "avr4"},
+      {ELF::EF_AVR_ARCH_AVR5, "avr5"},
+      {ELF::EF_AVR_ARCH_AVR51, "avr51"},
+      {ELF::EF_AVR_ARCH_AVR6, "avr6"},
+      {ELF::EF_AVR_ARCH_AVRTINY, "avrtiny"},
+      {ELF::EF_AVR_ARCH_XMEGA1, "xmega1"},
+      {ELF::EF_AVR_ARCH_XMEGA2, "xmega2"},
+      {ELF::EF_AVR_ARCH_XMEGA3, "xmega3"},
+      {ELF::EF_AVR_ARCH_XMEGA4, "xmega4"},
+      {ELF::EF_AVR_ARCH_XMEGA5, "xmegau"},
+      {ELF::EF_AVR_ARCH_XMEGA6, "xmegau"},
+      {ELF::EF_AVR_ARCH_XMEGA7, "xmegau"},
+  };
+
+  auto It = EFlagToFeatureSet.find(EFlag);
+  if (It != EFlagToFeatureSet.end())
+    return It->second.str();
+
+  return "special";
----------------
cabbaken wrote:

When we are unable to infer Feature from a malformed ELF, we cannot retrieve the desired architecture from the map. We return "special" in this circumstance currently, we can default to "avr0" instead if you prefer.

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


More information about the llvm-commits mailing list