[llvm] r221491 - [ELF][yaml2obj] Handle additional MIPS specific st_other field flags
Simon Atanasyan
simon at atanasyan.com
Thu Nov 6 14:46:24 PST 2014
Author: atanasyan
Date: Thu Nov 6 16:46:24 2014
New Revision: 221491
URL: http://llvm.org/viewvc/llvm-project?rev=221491&view=rev
Log:
[ELF][yaml2obj] Handle additional MIPS specific st_other field flags
The ELF symbol `st_other` field might contain additional flags besides
visibility ones. This patch implements support for some MIPS specific
flags.
Modified:
llvm/trunk/include/llvm/Object/ELFYAML.h
llvm/trunk/lib/Object/ELFYAML.cpp
llvm/trunk/test/Object/yaml2obj-elf-symbol-visibility.yaml
llvm/trunk/tools/obj2yaml/elf2yaml.cpp
llvm/trunk/tools/yaml2obj/yaml2elf.cpp
Modified: llvm/trunk/include/llvm/Object/ELFYAML.h
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/include/llvm/Object/ELFYAML.h?rev=221491&r1=221490&r2=221491&view=diff
==============================================================================
--- llvm/trunk/include/llvm/Object/ELFYAML.h (original)
+++ llvm/trunk/include/llvm/Object/ELFYAML.h Thu Nov 6 16:46:24 2014
@@ -45,6 +45,7 @@ LLVM_YAML_STRONG_TYPEDEF(uint8_t, ELF_RE
LLVM_YAML_STRONG_TYPEDEF(uint64_t, ELF_SHF)
LLVM_YAML_STRONG_TYPEDEF(uint8_t, ELF_STT)
LLVM_YAML_STRONG_TYPEDEF(uint8_t, ELF_STV)
+LLVM_YAML_STRONG_TYPEDEF(uint8_t, ELF_STO)
// For now, hardcode 64 bits everywhere that 32 or 64 would be needed
// since 64-bit can hold 32-bit values too.
@@ -63,7 +64,7 @@ struct Symbol {
StringRef Section;
llvm::yaml::Hex64 Value;
llvm::yaml::Hex64 Size;
- ELF_STV Visibility;
+ uint8_t Other;
};
struct LocalGlobalWeakSymbols {
std::vector<Symbol> Local;
@@ -175,6 +176,11 @@ struct ScalarEnumerationTraits<ELFYAML::
};
template <>
+struct ScalarBitSetTraits<ELFYAML::ELF_STO> {
+ static void bitset(IO &IO, ELFYAML::ELF_STO &Value);
+};
+
+template <>
struct ScalarEnumerationTraits<ELFYAML::ELF_REL> {
static void enumeration(IO &IO, ELFYAML::ELF_REL &Value);
};
Modified: llvm/trunk/lib/Object/ELFYAML.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/Object/ELFYAML.cpp?rev=221491&r1=221490&r2=221491&view=diff
==============================================================================
--- llvm/trunk/lib/Object/ELFYAML.cpp (original)
+++ llvm/trunk/lib/Object/ELFYAML.cpp Thu Nov 6 16:46:24 2014
@@ -395,6 +395,25 @@ void ScalarEnumerationTraits<ELFYAML::EL
#undef ECase
}
+void ScalarBitSetTraits<ELFYAML::ELF_STO>::bitset(IO &IO,
+ ELFYAML::ELF_STO &Value) {
+ const auto *Object = static_cast<ELFYAML::Object *>(IO.getContext());
+ assert(Object && "The IO context is not initialized");
+#define BCase(X) IO.bitSetCase(Value, #X, ELF::X);
+ switch (Object->Header.Machine) {
+ case ELF::EM_MIPS:
+ BCase(STO_MIPS_OPTIONAL)
+ BCase(STO_MIPS_PLT)
+ BCase(STO_MIPS_PIC)
+ BCase(STO_MIPS_MICROMIPS)
+ break;
+ default:
+ break; // Nothing to do
+ }
+#undef BCase
+#undef BCaseMask
+}
+
void ScalarEnumerationTraits<ELFYAML::ELF_REL>::enumeration(
IO &IO, ELFYAML::ELF_REL &Value) {
const auto *Object = static_cast<ELFYAML::Object *>(IO.getContext());
@@ -670,13 +689,30 @@ void MappingTraits<ELFYAML::FileHeader>:
IO.mapOptional("Entry", FileHdr.Entry, Hex64(0));
}
+namespace {
+struct NormalizedOther {
+ NormalizedOther(IO &)
+ : Visibility(ELFYAML::ELF_STV(0)), Other(ELFYAML::ELF_STO(0)) {}
+ NormalizedOther(IO &, uint8_t Original)
+ : Visibility(Original & 0x3), Other(Original & ~0x3) {}
+
+ uint8_t denormalize(IO &) { return Visibility | Other; }
+
+ ELFYAML::ELF_STV Visibility;
+ ELFYAML::ELF_STO Other;
+};
+}
+
void MappingTraits<ELFYAML::Symbol>::mapping(IO &IO, ELFYAML::Symbol &Symbol) {
IO.mapOptional("Name", Symbol.Name, StringRef());
IO.mapOptional("Type", Symbol.Type, ELFYAML::ELF_STT(0));
IO.mapOptional("Section", Symbol.Section, StringRef());
IO.mapOptional("Value", Symbol.Value, Hex64(0));
IO.mapOptional("Size", Symbol.Size, Hex64(0));
- IO.mapOptional("Visibility", Symbol.Visibility, ELFYAML::ELF_STV(0));
+
+ MappingNormalization<NormalizedOther, uint8_t> Keys(IO, Symbol.Other);
+ IO.mapOptional("Visibility", Keys->Visibility, ELFYAML::ELF_STV(0));
+ IO.mapOptional("Other", Keys->Other, ELFYAML::ELF_STO(0));
}
void MappingTraits<ELFYAML::LocalGlobalWeakSymbols>::mapping(
Modified: llvm/trunk/test/Object/yaml2obj-elf-symbol-visibility.yaml
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/test/Object/yaml2obj-elf-symbol-visibility.yaml?rev=221491&r1=221490&r2=221491&view=diff
==============================================================================
--- llvm/trunk/test/Object/yaml2obj-elf-symbol-visibility.yaml (original)
+++ llvm/trunk/test/Object/yaml2obj-elf-symbol-visibility.yaml Thu Nov 6 16:46:24 2014
@@ -44,7 +44,7 @@
# OBJ-NEXT: Size: 4
# OBJ-NEXT: Binding: Global (0x1)
# OBJ-NEXT: Type: Object (0x1)
-# OBJ-NEXT: Other: 3
+# OBJ-NEXT: Other: 163
# OBJ-NEXT: Section: .data (0x1)
# OBJ-NEXT: }
@@ -77,6 +77,7 @@
# YAML-NEXT: Value: 0x0000000000000010
# YAML-NEXT: Size: 0x0000000000000004
# YAML-NEXT: Visibility: STV_PROTECTED
+# YAML-NEXT: Other: [ STO_MIPS_PIC, STO_MIPS_MICROMIPS ]
---
FileHeader:
@@ -121,6 +122,7 @@ Symbols:
- Name: protected
Type: STT_OBJECT
Visibility: STV_PROTECTED
+ Other: [ STO_MIPS_MICROMIPS, STO_MIPS_PIC ]
Section: .data
Value: 0x10
Size: 0x04
Modified: llvm/trunk/tools/obj2yaml/elf2yaml.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/tools/obj2yaml/elf2yaml.cpp?rev=221491&r1=221490&r2=221491&view=diff
==============================================================================
--- llvm/trunk/tools/obj2yaml/elf2yaml.cpp (original)
+++ llvm/trunk/tools/obj2yaml/elf2yaml.cpp Thu Nov 6 16:46:24 2014
@@ -133,7 +133,7 @@ std::error_code ELFDumper<ELFT>::dumpSym
S.Type = Sym->getType();
S.Value = Sym->st_value;
S.Size = Sym->st_size;
- S.Visibility = Sym->getVisibility();
+ S.Other = Sym->st_other;
ErrorOr<StringRef> NameOrErr = Obj.getSymbolName(Sym);
if (std::error_code EC = NameOrErr.getError())
Modified: llvm/trunk/tools/yaml2obj/yaml2elf.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/tools/yaml2obj/yaml2elf.cpp?rev=221491&r1=221490&r2=221491&view=diff
==============================================================================
--- llvm/trunk/tools/yaml2obj/yaml2elf.cpp (original)
+++ llvm/trunk/tools/yaml2obj/yaml2elf.cpp Thu Nov 6 16:46:24 2014
@@ -304,7 +304,7 @@ void ELFState<ELFT>::addSymbols(const st
Symbol.st_shndx = Index;
} // else Symbol.st_shndex == SHN_UNDEF (== 0), since it was zero'd earlier.
Symbol.st_value = Sym.Value;
- Symbol.st_other = Sym.Visibility;
+ Symbol.st_other = Sym.Other;
Symbol.st_size = Sym.Size;
Syms.push_back(Symbol);
}
More information about the llvm-commits
mailing list