mirror of
https://github.com/c64scene-ar/llvm-6502.git
synced 2024-12-28 19:31:58 +00:00
[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
This commit is contained in:
parent
8e617cceb1
commit
848edb1bfa
@ -45,6 +45,7 @@ LLVM_YAML_STRONG_TYPEDEF(uint8_t, ELF_REL)
|
|||||||
LLVM_YAML_STRONG_TYPEDEF(uint64_t, ELF_SHF)
|
LLVM_YAML_STRONG_TYPEDEF(uint64_t, ELF_SHF)
|
||||||
LLVM_YAML_STRONG_TYPEDEF(uint8_t, ELF_STT)
|
LLVM_YAML_STRONG_TYPEDEF(uint8_t, ELF_STT)
|
||||||
LLVM_YAML_STRONG_TYPEDEF(uint8_t, ELF_STV)
|
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
|
// For now, hardcode 64 bits everywhere that 32 or 64 would be needed
|
||||||
// since 64-bit can hold 32-bit values too.
|
// since 64-bit can hold 32-bit values too.
|
||||||
@ -63,7 +64,7 @@ struct Symbol {
|
|||||||
StringRef Section;
|
StringRef Section;
|
||||||
llvm::yaml::Hex64 Value;
|
llvm::yaml::Hex64 Value;
|
||||||
llvm::yaml::Hex64 Size;
|
llvm::yaml::Hex64 Size;
|
||||||
ELF_STV Visibility;
|
uint8_t Other;
|
||||||
};
|
};
|
||||||
struct LocalGlobalWeakSymbols {
|
struct LocalGlobalWeakSymbols {
|
||||||
std::vector<Symbol> Local;
|
std::vector<Symbol> Local;
|
||||||
@ -174,6 +175,11 @@ struct ScalarEnumerationTraits<ELFYAML::ELF_STV> {
|
|||||||
static void enumeration(IO &IO, ELFYAML::ELF_STV &Value);
|
static void enumeration(IO &IO, ELFYAML::ELF_STV &Value);
|
||||||
};
|
};
|
||||||
|
|
||||||
|
template <>
|
||||||
|
struct ScalarBitSetTraits<ELFYAML::ELF_STO> {
|
||||||
|
static void bitset(IO &IO, ELFYAML::ELF_STO &Value);
|
||||||
|
};
|
||||||
|
|
||||||
template <>
|
template <>
|
||||||
struct ScalarEnumerationTraits<ELFYAML::ELF_REL> {
|
struct ScalarEnumerationTraits<ELFYAML::ELF_REL> {
|
||||||
static void enumeration(IO &IO, ELFYAML::ELF_REL &Value);
|
static void enumeration(IO &IO, ELFYAML::ELF_REL &Value);
|
||||||
|
@ -395,6 +395,25 @@ void ScalarEnumerationTraits<ELFYAML::ELF_STV>::enumeration(
|
|||||||
#undef ECase
|
#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(
|
void ScalarEnumerationTraits<ELFYAML::ELF_REL>::enumeration(
|
||||||
IO &IO, ELFYAML::ELF_REL &Value) {
|
IO &IO, ELFYAML::ELF_REL &Value) {
|
||||||
const auto *Object = static_cast<ELFYAML::Object *>(IO.getContext());
|
const auto *Object = static_cast<ELFYAML::Object *>(IO.getContext());
|
||||||
@ -670,13 +689,30 @@ void MappingTraits<ELFYAML::FileHeader>::mapping(IO &IO,
|
|||||||
IO.mapOptional("Entry", FileHdr.Entry, Hex64(0));
|
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) {
|
void MappingTraits<ELFYAML::Symbol>::mapping(IO &IO, ELFYAML::Symbol &Symbol) {
|
||||||
IO.mapOptional("Name", Symbol.Name, StringRef());
|
IO.mapOptional("Name", Symbol.Name, StringRef());
|
||||||
IO.mapOptional("Type", Symbol.Type, ELFYAML::ELF_STT(0));
|
IO.mapOptional("Type", Symbol.Type, ELFYAML::ELF_STT(0));
|
||||||
IO.mapOptional("Section", Symbol.Section, StringRef());
|
IO.mapOptional("Section", Symbol.Section, StringRef());
|
||||||
IO.mapOptional("Value", Symbol.Value, Hex64(0));
|
IO.mapOptional("Value", Symbol.Value, Hex64(0));
|
||||||
IO.mapOptional("Size", Symbol.Size, 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(
|
void MappingTraits<ELFYAML::LocalGlobalWeakSymbols>::mapping(
|
||||||
|
@ -44,7 +44,7 @@
|
|||||||
# OBJ-NEXT: Size: 4
|
# OBJ-NEXT: Size: 4
|
||||||
# OBJ-NEXT: Binding: Global (0x1)
|
# OBJ-NEXT: Binding: Global (0x1)
|
||||||
# OBJ-NEXT: Type: Object (0x1)
|
# OBJ-NEXT: Type: Object (0x1)
|
||||||
# OBJ-NEXT: Other: 3
|
# OBJ-NEXT: Other: 163
|
||||||
# OBJ-NEXT: Section: .data (0x1)
|
# OBJ-NEXT: Section: .data (0x1)
|
||||||
# OBJ-NEXT: }
|
# OBJ-NEXT: }
|
||||||
|
|
||||||
@ -77,6 +77,7 @@
|
|||||||
# YAML-NEXT: Value: 0x0000000000000010
|
# YAML-NEXT: Value: 0x0000000000000010
|
||||||
# YAML-NEXT: Size: 0x0000000000000004
|
# YAML-NEXT: Size: 0x0000000000000004
|
||||||
# YAML-NEXT: Visibility: STV_PROTECTED
|
# YAML-NEXT: Visibility: STV_PROTECTED
|
||||||
|
# YAML-NEXT: Other: [ STO_MIPS_PIC, STO_MIPS_MICROMIPS ]
|
||||||
|
|
||||||
---
|
---
|
||||||
FileHeader:
|
FileHeader:
|
||||||
@ -121,6 +122,7 @@ Symbols:
|
|||||||
- Name: protected
|
- Name: protected
|
||||||
Type: STT_OBJECT
|
Type: STT_OBJECT
|
||||||
Visibility: STV_PROTECTED
|
Visibility: STV_PROTECTED
|
||||||
|
Other: [ STO_MIPS_MICROMIPS, STO_MIPS_PIC ]
|
||||||
Section: .data
|
Section: .data
|
||||||
Value: 0x10
|
Value: 0x10
|
||||||
Size: 0x04
|
Size: 0x04
|
||||||
|
@ -133,7 +133,7 @@ std::error_code ELFDumper<ELFT>::dumpSymbol(Elf_Sym_Iter Sym,
|
|||||||
S.Type = Sym->getType();
|
S.Type = Sym->getType();
|
||||||
S.Value = Sym->st_value;
|
S.Value = Sym->st_value;
|
||||||
S.Size = Sym->st_size;
|
S.Size = Sym->st_size;
|
||||||
S.Visibility = Sym->getVisibility();
|
S.Other = Sym->st_other;
|
||||||
|
|
||||||
ErrorOr<StringRef> NameOrErr = Obj.getSymbolName(Sym);
|
ErrorOr<StringRef> NameOrErr = Obj.getSymbolName(Sym);
|
||||||
if (std::error_code EC = NameOrErr.getError())
|
if (std::error_code EC = NameOrErr.getError())
|
||||||
|
@ -304,7 +304,7 @@ void ELFState<ELFT>::addSymbols(const std::vector<ELFYAML::Symbol> &Symbols,
|
|||||||
Symbol.st_shndx = Index;
|
Symbol.st_shndx = Index;
|
||||||
} // else Symbol.st_shndex == SHN_UNDEF (== 0), since it was zero'd earlier.
|
} // else Symbol.st_shndex == SHN_UNDEF (== 0), since it was zero'd earlier.
|
||||||
Symbol.st_value = Sym.Value;
|
Symbol.st_value = Sym.Value;
|
||||||
Symbol.st_other = Sym.Visibility;
|
Symbol.st_other = Sym.Other;
|
||||||
Symbol.st_size = Sym.Size;
|
Symbol.st_size = Sym.Size;
|
||||||
Syms.push_back(Symbol);
|
Syms.push_back(Symbol);
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user