[llvm] r200450 - tools: add support for decoding ARM attributes

Saleem Abdulrasool compnerd at compnerd.org
Wed Jan 29 20:46:33 PST 2014


Author: compnerd
Date: Wed Jan 29 22:46:33 2014
New Revision: 200450

URL: http://llvm.org/viewvc/llvm-project?rev=200450&view=rev
Log:
tools: add support for decoding ARM attributes

Enhance the ARM specific parsing support in llvm-readobj to support attributes.
This allows for simpler tests to validate encoding of the build attributes as
specified in the ARM ELF specification.

Added:
    llvm/trunk/test/tools/llvm-readobj/ARM/attributes.s
    llvm/trunk/tools/llvm-readobj/ARMAttributeParser.cpp
    llvm/trunk/tools/llvm-readobj/ARMAttributeParser.h
Modified:
    llvm/trunk/tools/llvm-readobj/CMakeLists.txt
    llvm/trunk/tools/llvm-readobj/ELFDumper.cpp
    llvm/trunk/tools/llvm-readobj/ObjDumper.h
    llvm/trunk/tools/llvm-readobj/StreamWriter.h
    llvm/trunk/tools/llvm-readobj/llvm-readobj.cpp
    llvm/trunk/tools/llvm-readobj/llvm-readobj.h

Added: llvm/trunk/test/tools/llvm-readobj/ARM/attributes.s
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/test/tools/llvm-readobj/ARM/attributes.s?rev=200450&view=auto
==============================================================================
--- llvm/trunk/test/tools/llvm-readobj/ARM/attributes.s (added)
+++ llvm/trunk/test/tools/llvm-readobj/ARM/attributes.s Wed Jan 29 22:46:33 2014
@@ -0,0 +1,287 @@
+@ RUN: llvm-mc -triple armv7-eabi -filetype obj -o - %s \
+@ RUN:   | llvm-readobj -arm-attributes - | FileCheck %s
+
+	.syntax unified
+
+	.cpu cortex-a8
+	.fpu neon
+
+	.eabi_attribute Tag_CPU_raw_name, "Cortex-A9"
+	.eabi_attribute Tag_CPU_name, "cortex-a9"
+	.eabi_attribute Tag_CPU_arch, 10
+	.eabi_attribute Tag_CPU_arch_profile, 'A'
+	.eabi_attribute Tag_ARM_ISA_use, 0
+	.eabi_attribute Tag_THUMB_ISA_use, 2
+	.eabi_attribute Tag_FP_arch, 3
+	.eabi_attribute Tag_WMMX_arch, 0
+	.eabi_attribute Tag_Advanced_SIMD_arch, 1
+	.eabi_attribute Tag_PCS_config, 2
+	.eabi_attribute Tag_ABI_PCS_R9_use, 0
+	.eabi_attribute Tag_ABI_PCS_RW_data, 0
+	.eabi_attribute Tag_ABI_PCS_RO_data, 0
+	.eabi_attribute Tag_ABI_PCS_GOT_use, 0
+	.eabi_attribute Tag_ABI_PCS_wchar_t, 4
+	.eabi_attribute Tag_ABI_FP_rounding, 1
+	.eabi_attribute Tag_ABI_FP_denormal, 2
+	.eabi_attribute Tag_ABI_FP_exceptions, 1
+	.eabi_attribute Tag_ABI_FP_user_exceptions, 1
+	.eabi_attribute Tag_ABI_FP_number_model, 3
+	.eabi_attribute Tag_ABI_align_needed, 1
+	.eabi_attribute Tag_ABI_align_preserved, 2
+	.eabi_attribute Tag_ABI_enum_size, 3
+	.eabi_attribute Tag_ABI_HardFP_use, 0
+	.eabi_attribute Tag_ABI_VFP_args, 1
+	.eabi_attribute Tag_ABI_WMMX_args, 0
+	.eabi_attribute Tag_ABI_optimization_goals, 2
+	.eabi_attribute Tag_ABI_FP_optimization_goals, 2
+	.eabi_attribute Tag_compatibility, 1
+	.eabi_attribute Tag_compatibility, 1, "aeabi"
+	.eabi_attribute Tag_CPU_unaligned_access, 0
+	.eabi_attribute Tag_FP_HP_extension, 0
+	.eabi_attribute Tag_ABI_FP_16bit_format, 0
+	.eabi_attribute Tag_MPextension_use, 0
+	.eabi_attribute Tag_DIV_use, 0
+	.eabi_attribute Tag_nodefaults, 0
+	.eabi_attribute Tag_also_compatible_with, "gnu"
+	.eabi_attribute Tag_T2EE_use, 0
+	.eabi_attribute Tag_conformance, "2.09"
+	.eabi_attribute Tag_Virtualization_use, 0
+
+@ CHECK: BuildAttributes {
+@ CHECK:   Section 1 {
+@ CHECK:     Tag: Tag_File (0x1)
+@ CHECK:     FileAttributes {
+@ CHECK:       Attribute {
+@ CHECK:         Tag: 4
+@ CHECK:         TagName: CPU_raw_name
+@ CHECK:         Value: CORTEX-A9
+@ CHECK:       }
+@ CHECK:       Attribute {
+@ CHECK:         Tag: 5
+@ CHECK:         TagName: CPU_name
+@ CHECK:         Value: CORTEX-A9
+@ CHECK:       }
+@ CHECK:       Attribute {
+@ CHECK:         Tag: 6
+@ CHECK:         Value: 10
+@ CHECK:         TagName: CPU_arch
+@ CHECK:         Description: ARM v7
+@ CHECK:       }
+@ CHECK:       Attribute {
+@ CHECK:         Tag: 7
+@ CHECK:         Value: 65
+@ CHECK:         TagName: CPU_arch_profile
+@ CHECK:         Description: Application
+@ CHECK:       }
+@ CHECK:       Attribute {
+@ CHECK:         Tag: 8
+@ CHECK:         Value: 0
+@ CHECK:         TagName: ARM_ISA_use
+@ CHECK:         Description: Not Permitted
+@ CHECK:       }
+@ CHECK:       Attribute {
+@ CHECK:         Tag: 9
+@ CHECK:         Value: 2
+@ CHECK:         TagName: THUMB_ISA_use
+@ CHECK:         Description: Thumb-2
+@ CHECK:       }
+@ CHECK:       Attribute {
+@ CHECK:         Tag: 10
+@ CHECK:         Value: 3
+@ CHECK:         TagName: FP_arch
+@ CHECK:         Description: VFPv3
+@ CHECK:       }
+@ CHECK:       Attribute {
+@ CHECK:         Tag: 11
+@ CHECK:         Value: 0
+@ CHECK:         TagName: WMMX_arch
+@ CHECK:         Description: Not Permitted
+@ CHECK:       }
+@ CHECK:       Attribute {
+@ CHECK:         Tag: 12
+@ CHECK:         Value: 1
+@ CHECK:         TagName: Advanced_SIMD_arch
+@ CHECK:         Description: NEONv1
+@ CHECK:       }
+@ CHECK:       Attribute {
+@ CHECK:         Tag: 13
+@ CHECK:         Value: 2
+@ CHECK:         TagName: PCS_config
+@ CHECK:         Description: Linux Application
+@ CHECK:       }
+@ CHECK:       Attribute {
+@ CHECK:         Tag: 14
+@ CHECK:         Value: 0
+@ CHECK:         TagName: ABI_PCS_R9_use
+@ CHECK:         Description: v6
+@ CHECK:       }
+@ CHECK:       Attribute {
+@ CHECK:         Tag: 15
+@ CHECK:         Value: 0
+@ CHECK:         TagName: ABI_PCS_RW_data
+@ CHECK:         Description: Absolute
+@ CHECK:       }
+@ CHECK:       Attribute {
+@ CHECK:         Tag: 16
+@ CHECK:         Value: 0
+@ CHECK:         TagName: ABI_PCS_RO_data
+@ CHECK:         Description: Absolute
+@ CHECK:       }
+@ CHECK:       Attribute {
+@ CHECK:         Tag: 17
+@ CHECK:         Value: 0
+@ CHECK:         TagName: ABI_PCS_GOT_use
+@ CHECK:         Description: Not Permitted
+@ CHECK:       }
+@ CHECK:       Attribute {
+@ CHECK:         Tag: 18
+@ CHECK:         Value: 4
+@ CHECK:         TagName: ABI_PCS_wchar_t
+@ CHECK:         Description: 4-byte
+@ CHECK:       }
+@ CHECK:       Attribute {
+@ CHECK:         Tag: 19
+@ CHECK:         Value: 1
+@ CHECK:         TagName: ABI_FP_rounding
+@ CHECK:         Description: Runtime
+@ CHECK:       }
+@ CHECK:       Attribute {
+@ CHECK:         Tag: 20
+@ CHECK:         Value: 2
+@ CHECK:         TagName: ABI_FP_denormal
+@ CHECK:         Description: Sign Only
+@ CHECK:       }
+@ CHECK:       Attribute {
+@ CHECK:         Tag: 21
+@ CHECK:         Value: 1
+@ CHECK:         TagName: ABI_FP_exceptions
+@ CHECK:         Description: IEEE-754
+@ CHECK:       }
+@ CHECK:       Attribute {
+@ CHECK:         Tag: 22
+@ CHECK:         Value: 1
+@ CHECK:         TagName: ABI_FP_user_exceptions
+@ CHECK:         Description: IEEE-754
+@ CHECK:       }
+@ CHECK:       Attribute {
+@ CHECK:         Tag: 23
+@ CHECK:         Value: 3
+@ CHECK:         TagName: ABI_FP_number_model
+@ CHECK:         Description: IEEE-754
+@ CHECK:       }
+@ CHECK:       Attribute {
+@ CHECK:         Tag: 24
+@ CHECK:         Value: 1
+@ CHECK:         TagName: ABI_align_needed
+@ CHECK:         Description: 8-byte alignment
+@ CHECK:       }
+@ CHECK:       Attribute {
+@ CHECK:         Tag: 25
+@ CHECK:         Value: 2
+@ CHECK:         TagName: ABI_align_preserved
+@ CHECK:         Description: 8-byte data and code alignment
+@ CHECK:       }
+@ CHECK:       Attribute {
+@ CHECK:         Tag: 26
+@ CHECK:         Value: 3
+@ CHECK:         TagName: ABI_enum_size
+@ CHECK:         Description: External Int32
+@ CHECK:       }
+@ CHECK:       Attribute {
+@ CHECK:         Tag: 27
+@ CHECK:         Value: 0
+@ CHECK:         TagName: ABI_HardFP_use
+@ CHECK:         Description: Tag_FP_arch
+@ CHECK:       }
+@ CHECK:       Attribute {
+@ CHECK:         Tag: 28
+@ CHECK:         Value: 1
+@ CHECK:         TagName: ABI_VFP_args
+@ CHECK:         Description: AAPCS VFP
+@ CHECK:       }
+@ CHECK:       Attribute {
+@ CHECK:         Tag: 29
+@ CHECK:         Value: 0
+@ CHECK:         TagName: ABI_WMMX_args
+@ CHECK:         Description: AAPCS
+@ CHECK:       }
+@ CHECK:       Attribute {
+@ CHECK:         Tag: 30
+@ CHECK:         Value: 2
+@ CHECK:         TagName: ABI_optimization_goals
+@ CHECK:         Description: Aggressive Speed
+@ CHECK:       }
+@ CHECK:       Attribute {
+@ CHECK:         Tag: 31
+@ CHECK:         Value: 2
+@ CHECK:         TagName: ABI_FP_optimization_goals
+@ CHECK:         Description: Aggressive Speed
+@ CHECK:       }
+@ CHECK:       Attribute {
+@ CHECK:         Tag: 32
+@ CHECK:         Value: 1, AEABI
+@ CHECK:         TagName: compatibility
+@ CHECK:         Description: AEABI Conformant
+@ CHECK:       }
+@ CHECK:       Attribute {
+@ CHECK:         Tag: 34
+@ CHECK:         Value: 0
+@ CHECK:         TagName: CPU_unaligned_access
+@ CHECK:         Description: Not Permitted
+@ CHECK:       }
+@ CHECK:       Attribute {
+@ CHECK:         Tag: 36
+@ CHECK:         Value: 0
+@ CHECK:         TagName: FP_HP_extension
+@ CHECK:         Description: If Available
+@ CHECK:       }
+@ CHECK:       Attribute {
+@ CHECK:         Tag: 38
+@ CHECK:         Value: 0
+@ CHECK:         TagName: ABI_FP_16bit_format
+@ CHECK:         Description: Not Permitted
+@ CHECK:       }
+@ CHECK:       Attribute {
+@ CHECK:         Tag: 42
+@ CHECK:         Value: 0
+@ CHECK:         TagName: MPextension_use
+@ CHECK:         Description: Not Permitted
+@ CHECK:       }
+@ CHECK:       Attribute {
+@ CHECK:         Tag: 44
+@ CHECK:         Value: 0
+@ CHECK:         TagName: DIV_use
+@ CHECK:         Description: If Available
+@ CHECK:       }
+@ CHECK:       Attribute {
+@ CHECK:         Tag: 64
+@ CHECK:         Value: 0
+@ CHECK:         TagName: nodefaults
+@ CHECK:         Description: Unspecified Tags UNDEFINED
+@ CHECK:       }
+@ CHECK:       Attribute {
+@ CHECK:         Tag: 65
+@ CHECK:         TagName: also_compatible_with
+@ CHECK:         Value: GNU
+@ CHECK:       }
+@ CHECK:       Attribute {
+@ CHECK:         Tag: 66
+@ CHECK:         Value: 0
+@ CHECK:         TagName: T2EE_use
+@ CHECK:         Description: Not Permitted
+@ CHECK:       }
+@ CHECK:       Attribute {
+@ CHECK:         Tag: 67
+@ CHECK:         TagName: conformance
+@ CHECK:         Value: 2.09
+@ CHECK:       }
+@ CHECK:       Attribute {
+@ CHECK:         Tag: 68
+@ CHECK:         Value: 0
+@ CHECK:         TagName: Virtualization_use
+@ CHECK:         Description: Not Permitted
+@ CHECK:       }
+@ CHECK:     }
+@ CHECK:   }
+@ CHECK: }
+

Added: llvm/trunk/tools/llvm-readobj/ARMAttributeParser.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/tools/llvm-readobj/ARMAttributeParser.cpp?rev=200450&view=auto
==============================================================================
--- llvm/trunk/tools/llvm-readobj/ARMAttributeParser.cpp (added)
+++ llvm/trunk/tools/llvm-readobj/ARMAttributeParser.cpp Wed Jan 29 22:46:33 2014
@@ -0,0 +1,639 @@
+//===--- ARMAttributeParser.cpp - ARM Attribute Information Printer -------===//
+//
+//                     The LLVM Compiler Infrastructure
+//
+// This file is distributed under the University of Illinois Open Source
+// License. See LICENSE.TXT for details.
+//
+//===----------------------------------------------------------------------===//
+
+#include "ARMAttributeParser.h"
+#include "StreamWriter.h"
+#include "llvm/ADT/StringExtras.h"
+#include "llvm/Support/LEB128.h"
+
+using namespace llvm;
+using namespace llvm::ARMBuildAttrs;
+
+
+static const EnumEntry<unsigned> TagNames[] = {
+  { "Tag_File", ARMBuildAttrs::File },
+  { "Tag_Section", ARMBuildAttrs::Section },
+  { "Tag_Symbol", ARMBuildAttrs::Symbol },
+};
+
+template <typename type_, size_t size_>
+size_t countof(const type_ (&)[size_]) {
+  return size_;
+}
+
+namespace llvm {
+#define ATTRIBUTE_HANDLER(Attr_)                                                \
+  { ARMBuildAttrs::Attr_, &ARMAttributeParser::Attr_ }
+
+const ARMAttributeParser::DisplayHandler
+ARMAttributeParser::DisplayRoutines[] = {
+  { ARMBuildAttrs::CPU_raw_name, &ARMAttributeParser::StringAttribute, },
+  { ARMBuildAttrs::CPU_name, &ARMAttributeParser::StringAttribute },
+  ATTRIBUTE_HANDLER(CPU_arch),
+  ATTRIBUTE_HANDLER(CPU_arch_profile),
+  ATTRIBUTE_HANDLER(ARM_ISA_use),
+  ATTRIBUTE_HANDLER(THUMB_ISA_use),
+  ATTRIBUTE_HANDLER(FP_arch),
+  ATTRIBUTE_HANDLER(WMMX_arch),
+  ATTRIBUTE_HANDLER(Advanced_SIMD_arch),
+  ATTRIBUTE_HANDLER(PCS_config),
+  ATTRIBUTE_HANDLER(ABI_PCS_R9_use),
+  ATTRIBUTE_HANDLER(ABI_PCS_RW_data),
+  ATTRIBUTE_HANDLER(ABI_PCS_RO_data),
+  ATTRIBUTE_HANDLER(ABI_PCS_GOT_use),
+  ATTRIBUTE_HANDLER(ABI_PCS_wchar_t),
+  ATTRIBUTE_HANDLER(ABI_FP_rounding),
+  ATTRIBUTE_HANDLER(ABI_FP_denormal),
+  ATTRIBUTE_HANDLER(ABI_FP_exceptions),
+  ATTRIBUTE_HANDLER(ABI_FP_user_exceptions),
+  ATTRIBUTE_HANDLER(ABI_FP_number_model),
+  ATTRIBUTE_HANDLER(ABI_align_needed),
+  ATTRIBUTE_HANDLER(ABI_align_preserved),
+  ATTRIBUTE_HANDLER(ABI_enum_size),
+  ATTRIBUTE_HANDLER(ABI_HardFP_use),
+  ATTRIBUTE_HANDLER(ABI_VFP_args),
+  ATTRIBUTE_HANDLER(ABI_WMMX_args),
+  ATTRIBUTE_HANDLER(ABI_optimization_goals),
+  ATTRIBUTE_HANDLER(ABI_FP_optimization_goals),
+  ATTRIBUTE_HANDLER(compatibility),
+  ATTRIBUTE_HANDLER(CPU_unaligned_access),
+  ATTRIBUTE_HANDLER(FP_HP_extension),
+  ATTRIBUTE_HANDLER(ABI_FP_16bit_format),
+  ATTRIBUTE_HANDLER(MPextension_use),
+  ATTRIBUTE_HANDLER(DIV_use),
+  ATTRIBUTE_HANDLER(T2EE_use),
+  ATTRIBUTE_HANDLER(Virtualization_use),
+  ATTRIBUTE_HANDLER(nodefaults)
+};
+
+#undef ATTRIBUTE_HANDLER
+
+uint64_t ARMAttributeParser::ParseInteger(const uint8_t *Data,
+                                          uint32_t &Offset) {
+  unsigned Length;
+  uint64_t Value = decodeULEB128(Data + Offset, &Length);
+  Offset = Offset + Length;
+  return Value;
+}
+
+StringRef ARMAttributeParser::ParseString(const uint8_t *Data,
+                                          uint32_t &Offset) {
+  const char *String = reinterpret_cast<const char*>(Data + Offset);
+  size_t Length = std::strlen(String);
+  Offset = Offset + Length + 1;
+  return StringRef(String, Length);
+}
+
+void ARMAttributeParser::IntegerAttribute(AttrType Tag, const uint8_t *Data,
+                                          uint32_t &Offset) {
+  SW.printNumber(ARMBuildAttrs::AttrTypeAsString(Tag),
+                 ParseInteger(Data, Offset));
+}
+
+void ARMAttributeParser::StringAttribute(AttrType Tag, const uint8_t *Data,
+                                         uint32_t &Offset) {
+  StringRef TagName = ARMBuildAttrs::AttrTypeAsString(Tag, /*TagPrefix*/false);
+
+  DictScope AS(SW, "Attribute");
+  SW.printNumber("Tag", Tag);
+  if (!TagName.empty())
+    SW.printString("TagName", TagName);
+  SW.printString("Value", ParseString(Data, Offset));
+}
+
+void ARMAttributeParser::PrintAttribute(unsigned Tag, unsigned Value,
+                                        StringRef ValueDesc) {
+  StringRef TagName = ARMBuildAttrs::AttrTypeAsString(Tag, /*TagPrefix*/false);
+
+  DictScope AS(SW, "Attribute");
+  SW.printNumber("Tag", Tag);
+  SW.printNumber("Value", Value);
+  if (!TagName.empty())
+    SW.printString("TagName", TagName);
+  if (!ValueDesc.empty())
+    SW.printString("Description", ValueDesc);
+}
+
+void ARMAttributeParser::CPU_arch(AttrType Tag, const uint8_t *Data,
+                                  uint32_t &Offset) {
+  static const char *Strings[] = {
+    "Pre-v4", "ARM v4", "ARM v4T", "ARM v5T", "ARM v5TE", "ARM v5TEJ", "ARM v6",
+    "ARM v6KZ", "ARM v6T2", "ARM v6K", "ARM v7", "ARM v6-M", "ARM v6S-M",
+    "ARM v7E-M", "ARM v8"
+  };
+
+  uint64_t Value = ParseInteger(Data, Offset);
+  StringRef ValueDesc = (Value < countof(Strings)) ? Strings[Value] : NULL;
+  PrintAttribute(Tag, Value, ValueDesc);
+}
+
+void ARMAttributeParser::CPU_arch_profile(AttrType Tag, const uint8_t *Data,
+                                          uint32_t &Offset) {
+  uint64_t Encoded = ParseInteger(Data, Offset);
+
+  StringRef Profile;
+  switch (Encoded) {
+  default:  Profile = "Unknown"; break;
+  case 'A': Profile = "Application"; break;
+  case 'R': Profile = "Real-time"; break;
+  case 'M': Profile = "Microcontroller"; break;
+  case 'S': Profile = "Classic"; break;
+  case '0': Profile = "None"; break;
+  }
+
+  PrintAttribute(Tag, Encoded, Profile);
+}
+
+void ARMAttributeParser::ARM_ISA_use(AttrType Tag, const uint8_t *Data,
+                                     uint32_t &Offset) {
+  static const char *Strings[] = { "Not Permitted", "Permitted" };
+
+  uint64_t Value = ParseInteger(Data, Offset);
+  StringRef ValueDesc = (Value < countof(Strings)) ? Strings[Value] : NULL;
+  PrintAttribute(Tag, Value, ValueDesc);
+}
+
+void ARMAttributeParser::THUMB_ISA_use(AttrType Tag, const uint8_t *Data,
+                                       uint32_t &Offset) {
+  static const char *Strings[] = { "Not Permitted", "Thumb-1", "Thumb-2" };
+
+  uint64_t Value = ParseInteger(Data, Offset);
+  StringRef ValueDesc = (Value < countof(Strings)) ? Strings[Value] : NULL;
+  PrintAttribute(Tag, Value, ValueDesc);
+}
+
+void ARMAttributeParser::FP_arch(AttrType Tag, const uint8_t *Data,
+                                 uint32_t &Offset) {
+  static const char *Strings[] = {
+    "Not Permitted", "VFPv1", "VFPv2", "VFPv3", "VFPv3-D16", "VFPv4",
+    "VFPv4-D16", "ARMv8-a FP", "ARMv8-a FP-D16"
+  };
+
+  uint64_t Value = ParseInteger(Data, Offset);
+  StringRef ValueDesc = (Value < countof(Strings)) ? Strings[Value] : NULL;
+  PrintAttribute(Tag, Value, ValueDesc);
+}
+
+void ARMAttributeParser::WMMX_arch(AttrType Tag, const uint8_t *Data,
+                                   uint32_t &Offset) {
+  static const char *Strings[] = { "Not Permitted", "WMMXv1", "WMMXv2" };
+
+  uint64_t Value = ParseInteger(Data, Offset);
+  StringRef ValueDesc = (Value < countof(Strings)) ? Strings[Value] : NULL;
+  PrintAttribute(Tag, Value, ValueDesc);
+}
+
+void ARMAttributeParser::Advanced_SIMD_arch(AttrType Tag, const uint8_t *Data,
+                                            uint32_t &Offset) {
+  static const char *Strings[] = {
+    "Not Permitted", "NEONv1", "NEONv2+FMA", "ARMv8-a NEON"
+  };
+
+  uint64_t Value = ParseInteger(Data, Offset);
+  StringRef ValueDesc = (Value < countof(Strings)) ? Strings[Value] : NULL;
+  PrintAttribute(Tag, Value, ValueDesc);
+}
+
+void ARMAttributeParser::PCS_config(AttrType Tag, const uint8_t *Data,
+                                    uint32_t &Offset) {
+  static const char *Strings[] = {
+    "None", "Bare Platform", "Linux Application", "Linux DSO", "Palm OS 2004",
+    "Reserved (Palm OS)", "Symbian OS 2004", "Reserved (Symbian OS)"
+  };
+
+  uint64_t Value = ParseInteger(Data, Offset);
+  StringRef ValueDesc = (Value < countof(Strings)) ? Strings[Value] : NULL;
+  PrintAttribute(Tag, Value, ValueDesc);
+}
+
+void ARMAttributeParser::ABI_PCS_R9_use(AttrType Tag, const uint8_t *Data,
+                                        uint32_t &Offset) {
+  static const char *Strings[] = { "v6", "Static Base", "TLS", "Unused" };
+
+  uint64_t Value = ParseInteger(Data, Offset);
+  StringRef ValueDesc = (Value < countof(Strings)) ? Strings[Value] : NULL;
+  PrintAttribute(Tag, Value, ValueDesc);
+}
+
+void ARMAttributeParser::ABI_PCS_RW_data(AttrType Tag, const uint8_t *Data,
+                                         uint32_t &Offset) {
+  static const char *Strings[] = {
+    "Absolute", "PC-relative", "SB-relative", "Not Permitted"
+  };
+
+  uint64_t Value = ParseInteger(Data, Offset);
+  StringRef ValueDesc = (Value < countof(Strings)) ? Strings[Value] : NULL;
+  PrintAttribute(Tag, Value, ValueDesc);
+}
+
+void ARMAttributeParser::ABI_PCS_RO_data(AttrType Tag, const uint8_t *Data,
+                                         uint32_t &Offset) {
+  static const char *Strings[] = { "Absolute", "PC-relative", "Not Permitted" };
+
+  uint64_t Value = ParseInteger(Data, Offset);
+  StringRef ValueDesc = (Value < countof(Strings)) ? Strings[Value] : NULL;
+  PrintAttribute(Tag, Value, ValueDesc);
+}
+
+void ARMAttributeParser::ABI_PCS_GOT_use(AttrType Tag, const uint8_t *Data,
+                                         uint32_t &Offset) {
+  static const char *Strings[] = { "Not Permitted", "Direct", "GOT-Indirect" };
+
+  uint64_t Value = ParseInteger(Data, Offset);
+  StringRef ValueDesc = (Value < countof(Strings)) ? Strings[Value] : NULL;
+  PrintAttribute(Tag, Value, ValueDesc);
+}
+
+void ARMAttributeParser::ABI_PCS_wchar_t(AttrType Tag, const uint8_t *Data,
+                                         uint32_t &Offset) {
+  static const char *Strings[] = {
+    "Not Permitted", "Unknown", "2-byte", "Unknown", "4-byte"
+  };
+
+  uint64_t Value = ParseInteger(Data, Offset);
+  StringRef ValueDesc = (Value < countof(Strings)) ? Strings[Value] : NULL;
+  PrintAttribute(Tag, Value, ValueDesc);
+}
+
+void ARMAttributeParser::ABI_FP_rounding(AttrType Tag, const uint8_t *Data,
+                                         uint32_t &Offset) {
+  static const char *Strings[] = { "IEEE-754", "Runtime" };
+
+  uint64_t Value = ParseInteger(Data, Offset);
+  StringRef ValueDesc = (Value < countof(Strings)) ? Strings[Value] : NULL;
+  PrintAttribute(Tag, Value, ValueDesc);
+}
+
+void ARMAttributeParser::ABI_FP_denormal(AttrType Tag, const uint8_t *Data,
+                                         uint32_t &Offset) {
+  static const char *Strings[] = { "Unsupported", "IEEE-754", "Sign Only" };
+
+  uint64_t Value = ParseInteger(Data, Offset);
+  StringRef ValueDesc = (Value < countof(Strings)) ? Strings[Value] : NULL;
+  PrintAttribute(Tag, Value, ValueDesc);
+}
+
+void ARMAttributeParser::ABI_FP_exceptions(AttrType Tag, const uint8_t *Data,
+                                           uint32_t &Offset) {
+  static const char *Strings[] = { "Not Permitted", "IEEE-754" };
+
+  uint64_t Value = ParseInteger(Data, Offset);
+  StringRef ValueDesc = (Value < countof(Strings)) ? Strings[Value] : NULL;
+  PrintAttribute(Tag, Value, ValueDesc);
+}
+
+void ARMAttributeParser::ABI_FP_user_exceptions(AttrType Tag,
+                                                const uint8_t *Data,
+                                                uint32_t &Offset) {
+  static const char *Strings[] = { "Not Permitted", "IEEE-754" };
+
+  uint64_t Value = ParseInteger(Data, Offset);
+  StringRef ValueDesc = (Value < countof(Strings)) ? Strings[Value] : NULL;
+  PrintAttribute(Tag, Value, ValueDesc);
+}
+
+void ARMAttributeParser::ABI_FP_number_model(AttrType Tag, const uint8_t *Data,
+                                             uint32_t &Offset) {
+  static const char *Strings[] = {
+    "Not Permitted", "Finite Only", "RTABI", "IEEE-754"
+  };
+
+  uint64_t Value = ParseInteger(Data, Offset);
+  StringRef ValueDesc = (Value < countof(Strings)) ? Strings[Value] : NULL;
+  PrintAttribute(Tag, Value, ValueDesc);
+}
+
+void ARMAttributeParser::ABI_align_needed(AttrType Tag, const uint8_t *Data,
+                                          uint32_t &Offset) {
+  static const char *Strings[] = {
+    "Not Permitted", "8-byte alignment", "4-byte alignment", "Reserved"
+  };
+
+  uint64_t Value = ParseInteger(Data, Offset);
+
+  Twine Description;
+  if (Value < countof(Strings))
+    Description = StringRef(Strings[Value]);
+  else if (Value <= 12)
+    Description = Twine("8-byte alignment, ") + utostr(exp2(Value))
+                + Twine("-byte extended alignment");
+  else
+    Description = "Invalid";
+
+  PrintAttribute(Tag, Value, Description.str());
+}
+
+void ARMAttributeParser::ABI_align_preserved(AttrType Tag, const uint8_t *Data,
+                                             uint32_t &Offset) {
+  static const char *Strings[] = {
+    "Not Required", "8-byte data alignment", "8-byte data and code alignment",
+    "Reserved"
+  };
+
+  uint64_t Value = ParseInteger(Data, Offset);
+
+  Twine Description;
+  if (Value < countof(Strings))
+    Description = StringRef(Strings[Value]);
+  else if (Value <= 12)
+    Description = Twine("8-byte stack alignment, ") + utostr(exp2(Value))
+                + Twine("-byte data alignment");
+  else
+    Description = "Invalid";
+
+  PrintAttribute(Tag, Value, Description.str());
+}
+
+void ARMAttributeParser::ABI_enum_size(AttrType Tag, const uint8_t *Data,
+                                       uint32_t &Offset) {
+  static const char *Strings[] = {
+    "Not Permitted", "Packed", "Int32", "External Int32"
+  };
+
+  uint64_t Value = ParseInteger(Data, Offset);
+  StringRef ValueDesc = (Value < countof(Strings)) ? Strings[Value] : NULL;
+  PrintAttribute(Tag, Value, ValueDesc);
+}
+
+void ARMAttributeParser::ABI_HardFP_use(AttrType Tag, const uint8_t *Data,
+                                        uint32_t &Offset) {
+  static const char *Strings[] = {
+    "Tag_FP_arch", "Single-Precision", "Reserved", "Tag_FP_arch (deprecated)"
+  };
+
+  uint64_t Value = ParseInteger(Data, Offset);
+  StringRef ValueDesc = (Value < countof(Strings)) ? Strings[Value] : NULL;
+  PrintAttribute(Tag, Value, ValueDesc);
+}
+
+void ARMAttributeParser::ABI_VFP_args(AttrType Tag, const uint8_t *Data,
+                                      uint32_t &Offset) {
+  static const char *Strings[] = {
+    "AAPCS", "AAPCS VFP", "Custom", "Not Permitted"
+  };
+
+  uint64_t Value = ParseInteger(Data, Offset);
+  StringRef ValueDesc = (Value < countof(Strings)) ? Strings[Value] : NULL;
+  PrintAttribute(Tag, Value, ValueDesc);
+}
+
+void ARMAttributeParser::ABI_WMMX_args(AttrType Tag, const uint8_t *Data,
+                                       uint32_t &Offset) {
+  static const char *Strings[] = { "AAPCS", "iWMMX", "Custom" };
+
+  uint64_t Value = ParseInteger(Data, Offset);
+  StringRef ValueDesc = (Value < countof(Strings)) ? Strings[Value] : NULL;
+  PrintAttribute(Tag, Value, ValueDesc);
+}
+
+void ARMAttributeParser::ABI_optimization_goals(AttrType Tag,
+                                                const uint8_t *Data,
+                                                uint32_t &Offset) {
+  static const char *Strings[] = {
+    "None", "Speed", "Aggressive Speed", "Size", "Aggressive Size", "Debugging",
+    "Best Debugging"
+  };
+
+  uint64_t Value = ParseInteger(Data, Offset);
+  StringRef ValueDesc = (Value < countof(Strings)) ? Strings[Value] : NULL;
+  PrintAttribute(Tag, Value, ValueDesc);
+}
+
+void ARMAttributeParser::ABI_FP_optimization_goals(AttrType Tag,
+                                                   const uint8_t *Data,
+                                                   uint32_t &Offset) {
+  static const char *Strings[] = {
+    "None", "Speed", "Aggressive Speed", "Size", "Aggressive Size", "Accuracy",
+    "Best Accuracy"
+  };
+
+  uint64_t Value = ParseInteger(Data, Offset);
+  StringRef ValueDesc = (Value < countof(Strings)) ? Strings[Value] : NULL;
+  PrintAttribute(Tag, Value, ValueDesc);
+}
+
+void ARMAttributeParser::compatibility(AttrType Tag, const uint8_t *Data,
+                                       uint32_t &Offset) {
+  uint64_t Integer = ParseInteger(Data, Offset);
+  StringRef String = ParseString(Data, Offset);
+
+  DictScope AS(SW, "Attribute");
+  SW.printNumber("Tag", Tag);
+  SW.startLine() << "Value: " << Integer << ", " << String << '\n';
+  SW.printString("TagName", AttrTypeAsString(Tag, /*TagPrefix*/false));
+  switch (Integer) {
+  case 0:
+    SW.printString("Description", StringRef("No Specific Requirements"));
+    break;
+  case 1:
+    SW.printString("Description", StringRef("AEABI Conformant"));
+    break;
+  default:
+    SW.printString("Description", StringRef("AEABI Non-Conformant"));
+    break;
+  }
+}
+
+void ARMAttributeParser::CPU_unaligned_access(AttrType Tag, const uint8_t *Data,
+                                              uint32_t &Offset) {
+  static const char *Strings[] = { "Not Permitted", "v6-style" };
+
+  uint64_t Value = ParseInteger(Data, Offset);
+  StringRef ValueDesc = (Value < countof(Strings)) ? Strings[Value] : NULL;
+  PrintAttribute(Tag, Value, ValueDesc);
+}
+
+void ARMAttributeParser::FP_HP_extension(AttrType Tag, const uint8_t *Data,
+                                         uint32_t &Offset) {
+  static const char *Strings[] = { "If Available", "Permitted" };
+
+  uint64_t Value = ParseInteger(Data, Offset);
+  StringRef ValueDesc = (Value < countof(Strings)) ? Strings[Value] : NULL;
+  PrintAttribute(Tag, Value, ValueDesc);
+}
+
+void ARMAttributeParser::ABI_FP_16bit_format(AttrType Tag, const uint8_t *Data,
+                                             uint32_t &Offset) {
+  static const char *Strings[] = { "Not Permitted", "IEEE-754", "VFPv3" };
+
+  uint64_t Value = ParseInteger(Data, Offset);
+  StringRef ValueDesc = (Value < countof(Strings)) ? Strings[Value] : NULL;
+  PrintAttribute(Tag, Value, ValueDesc);
+}
+
+void ARMAttributeParser::MPextension_use(AttrType Tag, const uint8_t *Data,
+                                         uint32_t &Offset) {
+  static const char *Strings[] = { "Not Permitted", "Permitted" };
+
+  uint64_t Value = ParseInteger(Data, Offset);
+  StringRef ValueDesc = (Value < countof(Strings)) ? Strings[Value] : NULL;
+  PrintAttribute(Tag, Value, ValueDesc);
+}
+
+void ARMAttributeParser::DIV_use(AttrType Tag, const uint8_t *Data,
+                                 uint32_t &Offset) {
+  static const char *Strings[] = {
+    "If Available", "Not Permitted", "Permitted"
+  };
+
+  uint64_t Value = ParseInteger(Data, Offset);
+  StringRef ValueDesc = (Value < countof(Strings)) ? Strings[Value] : NULL;
+  PrintAttribute(Tag, Value, ValueDesc);
+}
+
+void ARMAttributeParser::T2EE_use(AttrType Tag, const uint8_t *Data,
+                                  uint32_t &Offset) {
+  static const char *Strings[] = { "Not Permitted", "Permitted" };
+
+  uint64_t Value = ParseInteger(Data, Offset);
+  StringRef ValueDesc = (Value < countof(Strings)) ? Strings[Value] : NULL;
+  PrintAttribute(Tag, Value, ValueDesc);
+}
+
+void ARMAttributeParser::Virtualization_use(AttrType Tag, const uint8_t *Data,
+                                            uint32_t &Offset) {
+  static const char *Strings[] = {
+    "Not Permitted", "TrustZone", "Virtualization Extensions",
+    "TrustZone + Virtualization Extensions"
+  };
+
+  uint64_t Value = ParseInteger(Data, Offset);
+  StringRef ValueDesc = (Value < countof(Strings)) ? Strings[Value] : NULL;
+  PrintAttribute(Tag, Value, ValueDesc);
+}
+
+void ARMAttributeParser::nodefaults(AttrType Tag, const uint8_t *Data,
+                                    uint32_t &Offset) {
+  uint64_t Value = ParseInteger(Data, Offset);
+  PrintAttribute(Tag, Value, "Unspecified Tags UNDEFINED");
+}
+
+void ARMAttributeParser::ParseIndexList(const uint8_t *Data, uint32_t &Offset,
+                                        SmallVectorImpl<uint8_t> &IndexList) {
+  for (;;) {
+    unsigned Length;
+    uint64_t Value = decodeULEB128(Data + Offset, &Length);
+    Offset = Offset + Length;
+    if (Value == 0)
+      break;
+    IndexList.push_back(Value);
+  }
+}
+
+void ARMAttributeParser::ParseAttributeList(const uint8_t *Data,
+                                            uint32_t &Offset, uint32_t Length) {
+  while (Offset < Length) {
+    unsigned Length;
+    uint64_t Tag = decodeULEB128(Data + Offset, &Length);
+    Offset += Length;
+
+    bool Handled = false;
+    for (unsigned AHI = 0, AHE = countof(DisplayRoutines);
+         AHI != AHE && !Handled; ++AHI) {
+      if (DisplayRoutines[AHI].Attribute == Tag) {
+        (this->*DisplayRoutines[AHI].Routine)(ARMBuildAttrs::AttrType(Tag),
+                                              Data, Offset);
+        Handled = true;
+        break;
+      }
+    }
+    if (!Handled) {
+      if (Tag < 32) {
+        errs() << "unhandled AEABI Tag " << Tag
+               << " (" << ARMBuildAttrs::AttrTypeAsString(Tag) << ")\n";
+        continue;
+      }
+
+      if (Tag % 2 == 0)
+        IntegerAttribute(ARMBuildAttrs::AttrType(Tag), Data, Offset);
+      else
+        StringAttribute(ARMBuildAttrs::AttrType(Tag), Data, Offset);
+    }
+  }
+}
+
+void ARMAttributeParser::ParseSubsection(const uint8_t *Data, uint32_t Length) {
+  uint32_t Offset = sizeof(uint32_t); /* SectionLength */
+
+  SW.printNumber("SectionLength", Length);
+
+  const char *VendorName = reinterpret_cast<const char*>(Data + Offset);
+  size_t VendorNameLength = std::strlen(VendorName);
+  SW.printString("Vendor", StringRef(VendorName, VendorNameLength));
+  Offset = Offset + VendorNameLength + 1;
+
+  if (StringRef(VendorName, VendorNameLength).lower() != "aeabi")
+    return;
+
+  while (Offset < Length) {
+    /// Tag_File | Tag_Section | Tag_Symbol   uleb128:byte-size
+    uint8_t Tag = Data[Offset];
+    SW.printEnum("Tag", Tag, makeArrayRef(TagNames));
+    Offset = Offset + sizeof(Tag);
+
+    uint32_t Size =
+      *reinterpret_cast<const support::ulittle32_t*>(Data + Offset);
+    SW.printNumber("Size", Size);
+    Offset = Offset + sizeof(Size);
+
+    if (Size > Length) {
+      errs() << "subsection length greater than section length\n";
+      return;
+    }
+
+    StringRef ScopeName, IndexName;
+    SmallVector<uint8_t, 8> Indicies;
+    switch (Tag) {
+    case ARMBuildAttrs::File:
+      ScopeName = "FileAttributes";
+      break;
+    case ARMBuildAttrs::Section:
+      ScopeName = "SectionAttributes";
+      IndexName = "Sections";
+      ParseIndexList(Data, Offset, Indicies);
+      break;
+    case ARMBuildAttrs::Symbol:
+      ScopeName = "SymbolAttributes";
+      IndexName = "Symbols";
+      ParseIndexList(Data, Offset, Indicies);
+      break;
+    default:
+      errs() << "unrecognised tag: 0x" << utohexstr(Tag) << '\n';
+      return;
+    }
+
+    DictScope ASS(SW, ScopeName);
+
+    if (!Indicies.empty())
+      SW.printList(IndexName, Indicies);
+
+    ParseAttributeList(Data, Offset, Length);
+  }
+}
+
+void ARMAttributeParser::Parse(ArrayRef<uint8_t> Section) {
+  size_t Offset = 1;
+  unsigned SectionNumber = 0;
+
+  while (Offset < Section.size()) {
+    uint32_t SectionLength =
+      *reinterpret_cast<const support::ulittle32_t*>(Section.data() + Offset);
+
+    SW.startLine() << "Section " << ++SectionNumber << " {\n";
+    SW.indent();
+
+    ParseSubsection(Section.data() + Offset, SectionLength);
+    Offset = Offset + SectionLength;
+
+    SW.unindent();
+    SW.startLine() << "}\n";
+  }
+}
+}
+

Added: llvm/trunk/tools/llvm-readobj/ARMAttributeParser.h
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/tools/llvm-readobj/ARMAttributeParser.h?rev=200450&view=auto
==============================================================================
--- llvm/trunk/tools/llvm-readobj/ARMAttributeParser.h (added)
+++ llvm/trunk/tools/llvm-readobj/ARMAttributeParser.h Wed Jan 29 22:46:33 2014
@@ -0,0 +1,124 @@
+//===--- ARMAttributeParser.h - ARM Attribute Information Printer ---------===//
+//
+//                     The LLVM Compiler Infrastructure
+//
+// This file is distributed under the University of Illinois Open Source
+// License. See LICENSE.TXT for details.
+//
+//===----------------------------------------------------------------------===//
+
+#ifndef LLVM_READOBJ_ARMATTRIBUTE_PARSER_H
+#define LLVM_READOBJ_ARMATTRIBUTE_PARSER_H
+
+#include "StreamWriter.h"
+#include "llvm/Support/ARMBuildAttributes.h"
+
+namespace llvm {
+class StringRef;
+
+class ARMAttributeParser {
+  StreamWriter &SW;
+
+  struct DisplayHandler {
+    ARMBuildAttrs::AttrType Attribute;
+    void (ARMAttributeParser::*Routine)(ARMBuildAttrs::AttrType,
+                                        const uint8_t *, uint32_t &);
+  };
+  static const DisplayHandler DisplayRoutines[];
+
+  uint64_t ParseInteger(const uint8_t *Data, uint32_t &Offset);
+  StringRef ParseString(const uint8_t *Data, uint32_t &Offset);
+
+  void IntegerAttribute(ARMBuildAttrs::AttrType Tag, const uint8_t *Data,
+                        uint32_t &Offset);
+  void StringAttribute(ARMBuildAttrs::AttrType Tag, const uint8_t *Data,
+                       uint32_t &Offset);
+
+  void PrintAttribute(unsigned Tag, unsigned Value, StringRef ValueDesc);
+
+  void CPU_arch(ARMBuildAttrs::AttrType Tag, const uint8_t *Data,
+                uint32_t &Offset);
+  void CPU_arch_profile(ARMBuildAttrs::AttrType Tag, const uint8_t *Data,
+                        uint32_t &Offset);
+  void ARM_ISA_use(ARMBuildAttrs::AttrType Tag, const uint8_t *Data,
+                   uint32_t &Offset);
+  void THUMB_ISA_use(ARMBuildAttrs::AttrType Tag, const uint8_t *Data,
+                     uint32_t &Offset);
+  void FP_arch(ARMBuildAttrs::AttrType Tag, const uint8_t *Data,
+               uint32_t &Offset);
+  void WMMX_arch(ARMBuildAttrs::AttrType Tag, const uint8_t *Data,
+                 uint32_t &Offset);
+  void Advanced_SIMD_arch(ARMBuildAttrs::AttrType Tag, const uint8_t *Data,
+                          uint32_t &Offset);
+  void PCS_config(ARMBuildAttrs::AttrType Tag, const uint8_t *Data,
+                  uint32_t &Offset);
+  void ABI_PCS_R9_use(ARMBuildAttrs::AttrType Tag, const uint8_t *Data,
+                      uint32_t &Offset);
+  void ABI_PCS_RW_data(ARMBuildAttrs::AttrType Tag, const uint8_t *Data,
+                       uint32_t &Offset);
+  void ABI_PCS_RO_data(ARMBuildAttrs::AttrType Tag, const uint8_t *Data,
+                       uint32_t &Offset);
+  void ABI_PCS_GOT_use(ARMBuildAttrs::AttrType Tag, const uint8_t *Data,
+                       uint32_t &Offset);
+  void ABI_PCS_wchar_t(ARMBuildAttrs::AttrType Tag, const uint8_t *Data,
+                       uint32_t &Offset);
+  void ABI_FP_rounding(ARMBuildAttrs::AttrType Tag, const uint8_t *Data,
+                       uint32_t &Offset);
+  void ABI_FP_denormal(ARMBuildAttrs::AttrType Tag, const uint8_t *Data,
+                       uint32_t &Offset);
+  void ABI_FP_exceptions(ARMBuildAttrs::AttrType Tag, const uint8_t *Data,
+                         uint32_t &Offset);
+  void ABI_FP_user_exceptions(ARMBuildAttrs::AttrType Tag, const uint8_t *Data,
+                              uint32_t &Offset);
+  void ABI_FP_number_model(ARMBuildAttrs::AttrType Tag, const uint8_t *Data,
+                           uint32_t &Offset);
+  void ABI_align_needed(ARMBuildAttrs::AttrType Tag, const uint8_t *Data,
+                        uint32_t &Offset);
+  void ABI_align_preserved(ARMBuildAttrs::AttrType Tag, const uint8_t *Data,
+                           uint32_t &Offset);
+  void ABI_enum_size(ARMBuildAttrs::AttrType Tag, const uint8_t *Data,
+                     uint32_t &Offset);
+  void ABI_HardFP_use(ARMBuildAttrs::AttrType Tag, const uint8_t *Data,
+                      uint32_t &Offset);
+  void ABI_VFP_args(ARMBuildAttrs::AttrType Tag, const uint8_t *Data,
+                    uint32_t &Offset);
+  void ABI_WMMX_args(ARMBuildAttrs::AttrType Tag, const uint8_t *Data,
+                     uint32_t &Offset);
+  void ABI_optimization_goals(ARMBuildAttrs::AttrType Tag, const uint8_t *Data,
+                              uint32_t &Offset);
+  void ABI_FP_optimization_goals(ARMBuildAttrs::AttrType Tag,
+                                 const uint8_t *Data, uint32_t &Offset);
+  void compatibility(ARMBuildAttrs::AttrType Tag, const uint8_t *Data,
+                     uint32_t &Offset);
+  void CPU_unaligned_access(ARMBuildAttrs::AttrType Tag, const uint8_t *Data,
+                            uint32_t &Offset);
+  void FP_HP_extension(ARMBuildAttrs::AttrType Tag, const uint8_t *Data,
+                       uint32_t &Offset);
+  void ABI_FP_16bit_format(ARMBuildAttrs::AttrType Tag, const uint8_t *Data,
+                           uint32_t &Offset);
+  void MPextension_use(ARMBuildAttrs::AttrType Tag, const uint8_t *Data,
+                       uint32_t &Offset);
+  void DIV_use(ARMBuildAttrs::AttrType Tag, const uint8_t *Data,
+               uint32_t &Offset);
+  void T2EE_use(ARMBuildAttrs::AttrType Tag, const uint8_t *Data,
+                uint32_t &Offset);
+  void Virtualization_use(ARMBuildAttrs::AttrType Tag, const uint8_t *Data,
+                          uint32_t &Offset);
+  void nodefaults(ARMBuildAttrs::AttrType Tag, const uint8_t *Data,
+                  uint32_t &Offset);
+
+  void ParseAttributeList(const uint8_t *Data, uint32_t &Offset,
+                          uint32_t Length);
+  void ParseIndexList(const uint8_t *Data, uint32_t &Offset,
+                      SmallVectorImpl<uint8_t> &IndexList);
+  void ParseSubsection(const uint8_t *Data, uint32_t Length);
+public:
+  ARMAttributeParser(StreamWriter &SW) : SW(SW) {}
+
+  void Parse(ArrayRef<uint8_t> Section);
+};
+
+}
+
+#endif
+

Modified: llvm/trunk/tools/llvm-readobj/CMakeLists.txt
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/tools/llvm-readobj/CMakeLists.txt?rev=200450&r1=200449&r2=200450&view=diff
==============================================================================
--- llvm/trunk/tools/llvm-readobj/CMakeLists.txt (original)
+++ llvm/trunk/tools/llvm-readobj/CMakeLists.txt Wed Jan 29 22:46:33 2014
@@ -12,4 +12,5 @@ add_llvm_tool(llvm-readobj
   MachODumper.cpp
   Error.cpp
   StreamWriter.cpp
+  ARMAttributeParser.cpp
   )

Modified: llvm/trunk/tools/llvm-readobj/ELFDumper.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/tools/llvm-readobj/ELFDumper.cpp?rev=200450&r1=200449&r2=200450&view=diff
==============================================================================
--- llvm/trunk/tools/llvm-readobj/ELFDumper.cpp (original)
+++ llvm/trunk/tools/llvm-readobj/ELFDumper.cpp Wed Jan 29 22:46:33 2014
@@ -13,12 +13,15 @@
 //===----------------------------------------------------------------------===//
 
 #include "llvm-readobj.h"
+#include "ARMAttributeParser.h"
 #include "ARMEHABIPrinter.h"
 #include "Error.h"
 #include "ObjDumper.h"
 #include "StreamWriter.h"
 #include "llvm/ADT/SmallString.h"
+#include "llvm/ADT/StringExtras.h"
 #include "llvm/Object/ELFObjectFile.h"
+#include "llvm/Support/ARMBuildAttributes.h"
 #include "llvm/Support/Compiler.h"
 #include "llvm/Support/Format.h"
 #include "llvm/Support/MathExtras.h"
@@ -50,6 +53,8 @@ public:
   virtual void printNeededLibraries() LLVM_OVERRIDE;
   virtual void printProgramHeaders() LLVM_OVERRIDE;
 
+  virtual void printAttributes() LLVM_OVERRIDE;
+
 private:
   typedef ELFFile<ELFT> ELFO;
   typedef typename ELFO::Elf_Shdr Elf_Shdr;
@@ -855,3 +860,42 @@ void ELFDumper<ELFT>::printProgramHeader
     W.printNumber("Alignment", PI->p_align);
   }
 }
+
+template <class ELFT>
+void ELFDumper<ELFT>::printAttributes() {
+  W.startLine() << "Attributes not implemented.\n";
+}
+
+namespace {
+template <>
+void ELFDumper<ELFType<support::little, 2, false> >::printAttributes() {
+  if (Obj->getHeader()->e_machine != EM_ARM) {
+    W.startLine() << "Attributes not implemented.\n";
+    return;
+  }
+
+  DictScope BA(W, "BuildAttributes");
+  for (typename ELFO::Elf_Shdr_Iter SI = Obj->begin_sections(),
+                                    SE = Obj->end_sections(); SI != SE; ++SI) {
+    if (SI->sh_type != ELF::SHT_ARM_ATTRIBUTES)
+      continue;
+
+    ErrorOr<ArrayRef<uint8_t> > Contents = Obj->getSectionContents(&(*SI));
+    if (!Contents)
+      continue;
+
+    if ((*Contents)[0] != ARMBuildAttrs::Format_Version) {
+      errs() << "unrecognised FormatVersion: 0x" << utohexstr((*Contents)[0])
+             << '\n';
+      continue;
+    }
+
+    W.printHex("FormatVersion", (*Contents)[0]);
+    if (Contents->size() == 1)
+      continue;
+
+    ARMAttributeParser(W).Parse(*Contents);
+  }
+}
+}
+

Modified: llvm/trunk/tools/llvm-readobj/ObjDumper.h
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/tools/llvm-readobj/ObjDumper.h?rev=200450&r1=200449&r2=200450&view=diff
==============================================================================
--- llvm/trunk/tools/llvm-readobj/ObjDumper.h (original)
+++ llvm/trunk/tools/llvm-readobj/ObjDumper.h Wed Jan 29 22:46:33 2014
@@ -40,6 +40,9 @@ public:
   virtual void printNeededLibraries() { }
   virtual void printProgramHeaders() { }
 
+  // Only implemented for ARM ELF at this time.
+  virtual void printAttributes() { }
+
 protected:
   StreamWriter& W;
 };

Modified: llvm/trunk/tools/llvm-readobj/StreamWriter.h
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/tools/llvm-readobj/StreamWriter.h?rev=200450&r1=200449&r2=200450&view=diff
==============================================================================
--- llvm/trunk/tools/llvm-readobj/StreamWriter.h (original)
+++ llvm/trunk/tools/llvm-readobj/StreamWriter.h Wed Jan 29 22:46:33 2014
@@ -172,6 +172,19 @@ public:
     startLine() << Label << ": " << int(Value) << "\n";
   }
 
+  template <typename T_>
+  void printList(StringRef Label, const SmallVectorImpl<T_> &List) {
+    startLine() << Label << ": [";
+    bool Comma = false;
+    for (unsigned LI = 0, LE = List.size(); LI != LE; ++LI) {
+      if (Comma)
+        OS << ", ";
+      OS << List[LI];
+      Comma = true;
+    }
+    OS << "]\n";
+  }
+
   template<typename T>
   void printHex(StringRef Label, T Value) {
     startLine() << Label << ": " << hex(Value) << "\n";

Modified: llvm/trunk/tools/llvm-readobj/llvm-readobj.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/tools/llvm-readobj/llvm-readobj.cpp?rev=200450&r1=200449&r2=200450&view=diff
==============================================================================
--- llvm/trunk/tools/llvm-readobj/llvm-readobj.cpp (original)
+++ llvm/trunk/tools/llvm-readobj/llvm-readobj.cpp Wed Jan 29 22:46:33 2014
@@ -129,6 +129,12 @@ namespace opts {
   // -codeview-linetables
   cl::opt<bool> CodeViewLineTables("codeview-linetables",
     cl::desc("Display CodeView line table information"));
+
+  // -arm-attributes, -a
+  cl::opt<bool> ARMAttributes("arm-attributes",
+                              cl::desc("Display the ARM attributes section"));
+  cl::alias ARMAttributesShort("-a", cl::desc("Alias for --arm-attributes"),
+                               cl::aliasopt(ARMAttributes));
 } // namespace opts
 
 static int ReturnValue = EXIT_SUCCESS;
@@ -227,6 +233,9 @@ static void dumpObject(const ObjectFile
     Dumper->printNeededLibraries();
   if (opts::ProgramHeaders)
     Dumper->printProgramHeaders();
+  if (Obj->getArch() == llvm::Triple::arm && Obj->isELF())
+    if (opts::ARMAttributes)
+      Dumper->printAttributes();
 }
 
 

Modified: llvm/trunk/tools/llvm-readobj/llvm-readobj.h
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/tools/llvm-readobj/llvm-readobj.h?rev=200450&r1=200449&r2=200450&view=diff
==============================================================================
--- llvm/trunk/tools/llvm-readobj/llvm-readobj.h (original)
+++ llvm/trunk/tools/llvm-readobj/llvm-readobj.h Wed Jan 29 22:46:33 2014
@@ -39,6 +39,7 @@ namespace opts {
   extern llvm::cl::opt<bool> UnwindInfo;
   extern llvm::cl::opt<bool> ExpandRelocs;
   extern llvm::cl::opt<bool> CodeViewLineTables;
+  extern llvm::cl::opt<bool> ARMAttributes;
 } // namespace opts
 
 #define LLVM_READOBJ_ENUM_ENT(ns, enum) \





More information about the llvm-commits mailing list