llvm.org GIT mirror llvm / 5ba1225
[yaml2obj][ELF] Support st_info through `Binding` and `Type` YAML keys. git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@184263 91177308-0d34-0410-b5e6-96231b3b80d8 Sean Silva 7 years ago
4 changed file(s) with 44 addition(s) and 0 deletion(s). Raw diff Collapse all Expand all
3838 LLVM_YAML_STRONG_TYPEDEF(uint32_t, ELF_SHT)
3939 // Just use 64, since it can hold 32-bit values too.
4040 LLVM_YAML_STRONG_TYPEDEF(uint64_t, ELF_SHF)
41 LLVM_YAML_STRONG_TYPEDEF(uint8_t, ELF_STB)
42 LLVM_YAML_STRONG_TYPEDEF(uint8_t, ELF_STT)
4143
4244 // For now, hardcode 64 bits everywhere that 32 or 64 would be needed
4345 // since 64-bit can hold 32-bit values too.
5052 };
5153 struct Symbol {
5254 StringRef Name;
55 ELF_STB Binding;
56 ELF_STT Type;
5357 };
5458 struct Section {
5559 StringRef Name;
107111 };
108112
109113 template <>
114 struct ScalarEnumerationTraits {
115 static void enumeration(IO &IO, ELFYAML::ELF_STB &Value);
116 };
117
118 template <>
119 struct ScalarEnumerationTraits {
120 static void enumeration(IO &IO, ELFYAML::ELF_STT &Value);
121 };
122
123 template <>
110124 struct MappingTraits {
111125 static void mapping(IO &IO, ELFYAML::FileHeader &FileHdr);
112126 };
250250 #undef BCase
251251 }
252252
253 void ScalarEnumerationTraits::enumeration(
254 IO &IO, ELFYAML::ELF_STB &Value) {
255 #define ECase(X) IO.enumCase(Value, #X, ELF::X);
256 ECase(STB_LOCAL)
257 ECase(STB_GLOBAL)
258 ECase(STB_WEAK)
259 #undef ECase
260 }
261
262 void ScalarEnumerationTraits::enumeration(
263 IO &IO, ELFYAML::ELF_STT &Value) {
264 #define ECase(X) IO.enumCase(Value, #X, ELF::X);
265 ECase(STT_NOTYPE)
266 ECase(STT_OBJECT)
267 ECase(STT_FUNC)
268 ECase(STT_SECTION)
269 ECase(STT_FILE)
270 ECase(STT_COMMON)
271 ECase(STT_TLS)
272 ECase(STT_GNU_IFUNC)
273 #undef ECase
274 }
275
253276 void MappingTraits::mapping(IO &IO,
254277 ELFYAML::FileHeader &FileHdr) {
255278 IO.mapRequired("Class", FileHdr.Class);
261284
262285 void MappingTraits::mapping(IO &IO, ELFYAML::Symbol &Symbol) {
263286 IO.mapOptional("Name", Symbol.Name, StringRef());
287 IO.mapOptional("Binding", Symbol.Binding, ELFYAML::ELF_STB(0));
288 IO.mapOptional("Type", Symbol.Type, ELFYAML::ELF_STT(0));
264289 }
265290
266291 void MappingTraits::mapping(IO &IO,
1212 Type: SHT_SYMTAB
1313 Symbols:
1414 - Name: main
15 Binding: STB_GLOBAL
16 Type: STT_FUNC
1517
1618 # CHECK: Symbols [
1719 # CHECK-NEXT: Symbol {
1820 # CHECK-NEXT: Name: (0)
1921 # CHECK: Symbol {
2022 # CHECK-NEXT: Name: main
23 # CHECK: Binding: Global
24 # CHECK-NEXT: Type: Function
165165 zero(Symbol);
166166 if (!Sym.Name.empty())
167167 Symbol.st_name = StrTab.addString(Sym.Name);
168 Symbol.setBindingAndType(Sym.Binding, Sym.Type);
168169 Syms.push_back(Symbol);
169170 }
170171