llvm.org GIT mirror llvm / 848edb1
[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. git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@221491 91177308-0d34-0410-b5e6-96231b3b80d8 Simon Atanasyan 4 years ago
5 changed file(s) with 49 addition(s) and 5 deletion(s). Raw diff Collapse all Expand all
4444 LLVM_YAML_STRONG_TYPEDEF(uint64_t, ELF_SHF)
4545 LLVM_YAML_STRONG_TYPEDEF(uint8_t, ELF_STT)
4646 LLVM_YAML_STRONG_TYPEDEF(uint8_t, ELF_STV)
47 LLVM_YAML_STRONG_TYPEDEF(uint8_t, ELF_STO)
4748
4849 // For now, hardcode 64 bits everywhere that 32 or 64 would be needed
4950 // since 64-bit can hold 32-bit values too.
6263 StringRef Section;
6364 llvm::yaml::Hex64 Value;
6465 llvm::yaml::Hex64 Size;
65 ELF_STV Visibility;
66 uint8_t Other;
6667 };
6768 struct LocalGlobalWeakSymbols {
6869 std::vector Local;
174175 };
175176
176177 template <>
178 struct ScalarBitSetTraits {
179 static void bitset(IO &IO, ELFYAML::ELF_STO &Value);
180 };
181
182 template <>
177183 struct ScalarEnumerationTraits {
178184 static void enumeration(IO &IO, ELFYAML::ELF_REL &Value);
179185 };
394394 #undef ECase
395395 }
396396
397 void ScalarBitSetTraits::bitset(IO &IO,
398 ELFYAML::ELF_STO &Value) {
399 const auto *Object = static_cast(IO.getContext());
400 assert(Object && "The IO context is not initialized");
401 #define BCase(X) IO.bitSetCase(Value, #X, ELF::X);
402 switch (Object->Header.Machine) {
403 case ELF::EM_MIPS:
404 BCase(STO_MIPS_OPTIONAL)
405 BCase(STO_MIPS_PLT)
406 BCase(STO_MIPS_PIC)
407 BCase(STO_MIPS_MICROMIPS)
408 break;
409 default:
410 break; // Nothing to do
411 }
412 #undef BCase
413 #undef BCaseMask
414 }
415
397416 void ScalarEnumerationTraits::enumeration(
398417 IO &IO, ELFYAML::ELF_REL &Value) {
399418 const auto *Object = static_cast(IO.getContext());
669688 IO.mapOptional("Entry", FileHdr.Entry, Hex64(0));
670689 }
671690
691 namespace {
692 struct NormalizedOther {
693 NormalizedOther(IO &)
694 : Visibility(ELFYAML::ELF_STV(0)), Other(ELFYAML::ELF_STO(0)) {}
695 NormalizedOther(IO &, uint8_t Original)
696 : Visibility(Original & 0x3), Other(Original & ~0x3) {}
697
698 uint8_t denormalize(IO &) { return Visibility | Other; }
699
700 ELFYAML::ELF_STV Visibility;
701 ELFYAML::ELF_STO Other;
702 };
703 }
704
672705 void MappingTraits::mapping(IO &IO, ELFYAML::Symbol &Symbol) {
673706 IO.mapOptional("Name", Symbol.Name, StringRef());
674707 IO.mapOptional("Type", Symbol.Type, ELFYAML::ELF_STT(0));
675708 IO.mapOptional("Section", Symbol.Section, StringRef());
676709 IO.mapOptional("Value", Symbol.Value, Hex64(0));
677710 IO.mapOptional("Size", Symbol.Size, Hex64(0));
678 IO.mapOptional("Visibility", Symbol.Visibility, ELFYAML::ELF_STV(0));
711
712 MappingNormalization Keys(IO, Symbol.Other);
713 IO.mapOptional("Visibility", Keys->Visibility, ELFYAML::ELF_STV(0));
714 IO.mapOptional("Other", Keys->Other, ELFYAML::ELF_STO(0));
679715 }
680716
681717 void MappingTraits::mapping(
4343 # OBJ-NEXT: Size: 4
4444 # OBJ-NEXT: Binding: Global (0x1)
4545 # OBJ-NEXT: Type: Object (0x1)
46 # OBJ-NEXT: Other: 3
46 # OBJ-NEXT: Other: 163
4747 # OBJ-NEXT: Section: .data (0x1)
4848 # OBJ-NEXT: }
4949
7676 # YAML-NEXT: Value: 0x0000000000000010
7777 # YAML-NEXT: Size: 0x0000000000000004
7878 # YAML-NEXT: Visibility: STV_PROTECTED
79 # YAML-NEXT: Other: [ STO_MIPS_PIC, STO_MIPS_MICROMIPS ]
7980
8081 ---
8182 FileHeader:
120121 - Name: protected
121122 Type: STT_OBJECT
122123 Visibility: STV_PROTECTED
124 Other: [ STO_MIPS_MICROMIPS, STO_MIPS_PIC ]
123125 Section: .data
124126 Value: 0x10
125127 Size: 0x04
132132 S.Type = Sym->getType();
133133 S.Value = Sym->st_value;
134134 S.Size = Sym->st_size;
135 S.Visibility = Sym->getVisibility();
135 S.Other = Sym->st_other;
136136
137137 ErrorOr NameOrErr = Obj.getSymbolName(Sym);
138138 if (std::error_code EC = NameOrErr.getError())
303303 Symbol.st_shndx = Index;
304304 } // else Symbol.st_shndex == SHN_UNDEF (== 0), since it was zero'd earlier.
305305 Symbol.st_value = Sym.Value;
306 Symbol.st_other = Sym.Visibility;
306 Symbol.st_other = Sym.Other;
307307 Symbol.st_size = Sym.Size;
308308 Syms.push_back(Symbol);
309309 }