[yaml2obj][ELF] Support st_info through `Binding` and `Type` YAML keys.

llvm-svn: 184263
This commit is contained in:
Sean Silva 2013-06-19 00:11:59 +00:00
parent 08a1bb8199
commit bba8559767
4 changed files with 44 additions and 0 deletions

View File

@ -39,6 +39,8 @@ LLVM_YAML_STRONG_TYPEDEF(uint8_t, ELF_ELFDATA)
LLVM_YAML_STRONG_TYPEDEF(uint32_t, ELF_SHT)
// Just use 64, since it can hold 32-bit values too.
LLVM_YAML_STRONG_TYPEDEF(uint64_t, ELF_SHF)
LLVM_YAML_STRONG_TYPEDEF(uint8_t, ELF_STB)
LLVM_YAML_STRONG_TYPEDEF(uint8_t, ELF_STT)
// For now, hardcode 64 bits everywhere that 32 or 64 would be needed
// since 64-bit can hold 32-bit values too.
@ -51,6 +53,8 @@ struct FileHeader {
};
struct Symbol {
StringRef Name;
ELF_STB Binding;
ELF_STT Type;
};
struct Section {
StringRef Name;
@ -107,6 +111,16 @@ struct ScalarBitSetTraits<ELFYAML::ELF_SHF> {
static void bitset(IO &IO, ELFYAML::ELF_SHF &Value);
};
template <>
struct ScalarEnumerationTraits<ELFYAML::ELF_STB> {
static void enumeration(IO &IO, ELFYAML::ELF_STB &Value);
};
template <>
struct ScalarEnumerationTraits<ELFYAML::ELF_STT> {
static void enumeration(IO &IO, ELFYAML::ELF_STT &Value);
};
template <>
struct MappingTraits<ELFYAML::FileHeader> {
static void mapping(IO &IO, ELFYAML::FileHeader &FileHdr);

View File

@ -251,6 +251,29 @@ void ScalarBitSetTraits<ELFYAML::ELF_SHF>::bitset(IO &IO,
#undef BCase
}
void ScalarEnumerationTraits<ELFYAML::ELF_STB>::enumeration(
IO &IO, ELFYAML::ELF_STB &Value) {
#define ECase(X) IO.enumCase(Value, #X, ELF::X);
ECase(STB_LOCAL)
ECase(STB_GLOBAL)
ECase(STB_WEAK)
#undef ECase
}
void ScalarEnumerationTraits<ELFYAML::ELF_STT>::enumeration(
IO &IO, ELFYAML::ELF_STT &Value) {
#define ECase(X) IO.enumCase(Value, #X, ELF::X);
ECase(STT_NOTYPE)
ECase(STT_OBJECT)
ECase(STT_FUNC)
ECase(STT_SECTION)
ECase(STT_FILE)
ECase(STT_COMMON)
ECase(STT_TLS)
ECase(STT_GNU_IFUNC)
#undef ECase
}
void MappingTraits<ELFYAML::FileHeader>::mapping(IO &IO,
ELFYAML::FileHeader &FileHdr) {
IO.mapRequired("Class", FileHdr.Class);
@ -262,6 +285,8 @@ void MappingTraits<ELFYAML::FileHeader>::mapping(IO &IO,
void MappingTraits<ELFYAML::Symbol>::mapping(IO &IO, ELFYAML::Symbol &Symbol) {
IO.mapOptional("Name", Symbol.Name, StringRef());
IO.mapOptional("Binding", Symbol.Binding, ELFYAML::ELF_STB(0));
IO.mapOptional("Type", Symbol.Type, ELFYAML::ELF_STT(0));
}
void MappingTraits<ELFYAML::Section>::mapping(IO &IO,

View File

@ -13,9 +13,13 @@ Sections:
Type: SHT_SYMTAB
Symbols:
- Name: main
Binding: STB_GLOBAL
Type: STT_FUNC
# CHECK: Symbols [
# CHECK-NEXT: Symbol {
# CHECK-NEXT: Name: (0)
# CHECK: Symbol {
# CHECK-NEXT: Name: main
# CHECK: Binding: Global
# CHECK-NEXT: Type: Function

View File

@ -166,6 +166,7 @@ static void handleSymtabSectionHeader(
zero(Symbol);
if (!Sym.Name.empty())
Symbol.st_name = StrTab.addString(Sym.Name);
Symbol.setBindingAndType(Sym.Binding, Sym.Type);
Syms.push_back(Symbol);
}