mirror of
https://github.com/c64scene-ar/llvm-6502.git
synced 2024-11-01 15:11:24 +00:00
[yaml2obj][obj2yaml] Support ELF symbol's visibility flags (default/hidden/protected).
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@210316 91177308-0d34-0410-b5e6-96231b3b80d8
This commit is contained in:
parent
2c3e3b491e
commit
3c9a2ee891
@ -44,6 +44,7 @@ LLVM_YAML_STRONG_TYPEDEF(uint8_t, ELF_REL)
|
||||
// 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_STT)
|
||||
LLVM_YAML_STRONG_TYPEDEF(uint8_t, ELF_STV)
|
||||
|
||||
// For now, hardcode 64 bits everywhere that 32 or 64 would be needed
|
||||
// since 64-bit can hold 32-bit values too.
|
||||
@ -62,6 +63,7 @@ struct Symbol {
|
||||
StringRef Section;
|
||||
llvm::yaml::Hex64 Value;
|
||||
llvm::yaml::Hex64 Size;
|
||||
ELF_STV Visibility;
|
||||
};
|
||||
struct LocalGlobalWeakSymbols {
|
||||
std::vector<Symbol> Local;
|
||||
@ -167,6 +169,11 @@ struct ScalarEnumerationTraits<ELFYAML::ELF_STT> {
|
||||
static void enumeration(IO &IO, ELFYAML::ELF_STT &Value);
|
||||
};
|
||||
|
||||
template <>
|
||||
struct ScalarEnumerationTraits<ELFYAML::ELF_STV> {
|
||||
static void enumeration(IO &IO, ELFYAML::ELF_STV &Value);
|
||||
};
|
||||
|
||||
template <>
|
||||
struct ScalarEnumerationTraits<ELFYAML::ELF_REL> {
|
||||
static void enumeration(IO &IO, ELFYAML::ELF_REL &Value);
|
||||
|
@ -368,6 +368,16 @@ void ScalarEnumerationTraits<ELFYAML::ELF_STT>::enumeration(
|
||||
#undef ECase
|
||||
}
|
||||
|
||||
void ScalarEnumerationTraits<ELFYAML::ELF_STV>::enumeration(
|
||||
IO &IO, ELFYAML::ELF_STV &Value) {
|
||||
#define ECase(X) IO.enumCase(Value, #X, ELF::X);
|
||||
ECase(STV_DEFAULT)
|
||||
ECase(STV_INTERNAL)
|
||||
ECase(STV_HIDDEN)
|
||||
ECase(STV_PROTECTED)
|
||||
#undef ECase
|
||||
}
|
||||
|
||||
void ScalarEnumerationTraits<ELFYAML::ELF_REL>::enumeration(
|
||||
IO &IO, ELFYAML::ELF_REL &Value) {
|
||||
const auto *Object = static_cast<ELFYAML::Object *>(IO.getContext());
|
||||
@ -649,6 +659,7 @@ void MappingTraits<ELFYAML::Symbol>::mapping(IO &IO, ELFYAML::Symbol &Symbol) {
|
||||
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));
|
||||
}
|
||||
|
||||
void MappingTraits<ELFYAML::LocalGlobalWeakSymbols>::mapping(
|
||||
|
126
test/Object/yaml2obj-elf-symbol-visibility.yaml
Normal file
126
test/Object/yaml2obj-elf-symbol-visibility.yaml
Normal file
@ -0,0 +1,126 @@
|
||||
# RUN: yaml2obj -format=elf %s | llvm-readobj -symbols - | \
|
||||
# RUN: FileCheck --check-prefix OBJ %s
|
||||
# RUN: yaml2obj -format=elf %s | obj2yaml - | FileCheck --check-prefix YAML %s
|
||||
|
||||
# OBJ: Symbol {
|
||||
# OBJ: Name: default1 (36)
|
||||
# OBJ-NEXT: Value: 0x0
|
||||
# OBJ-NEXT: Size: 4
|
||||
# OBJ-NEXT: Binding: Global (0x1)
|
||||
# OBJ-NEXT: Type: Object (0x1)
|
||||
# OBJ-NEXT: Other: 0
|
||||
# OBJ-NEXT: Section: .data (0x1)
|
||||
# OBJ-NEXT: }
|
||||
# OBJ-NEXT: Symbol {
|
||||
# OBJ-NEXT: Name: default2 (27)
|
||||
# OBJ-NEXT: Value: 0x4
|
||||
# OBJ-NEXT: Size: 4
|
||||
# OBJ-NEXT: Binding: Global (0x1)
|
||||
# OBJ-NEXT: Type: Object (0x1)
|
||||
# OBJ-NEXT: Other: 0
|
||||
# OBJ-NEXT: Section: .data (0x1)
|
||||
# OBJ-NEXT: }
|
||||
# OBJ-NEXT: Symbol {
|
||||
# OBJ-NEXT: Name: internal (8)
|
||||
# OBJ-NEXT: Value: 0x8
|
||||
# OBJ-NEXT: Size: 4
|
||||
# OBJ-NEXT: Binding: Global (0x1)
|
||||
# OBJ-NEXT: Type: Object (0x1)
|
||||
# OBJ-NEXT: Other: 1
|
||||
# OBJ-NEXT: Section: .data (0x1)
|
||||
# OBJ-NEXT: }
|
||||
# OBJ-NEXT: Symbol {
|
||||
# OBJ-NEXT: Name: hidden (1)
|
||||
# OBJ-NEXT: Value: 0xC
|
||||
# OBJ-NEXT: Size: 4
|
||||
# OBJ-NEXT: Binding: Global (0x1)
|
||||
# OBJ-NEXT: Type: Object (0x1)
|
||||
# OBJ-NEXT: Other: 2
|
||||
# OBJ-NEXT: Section: .data (0x1)
|
||||
# OBJ-NEXT: }
|
||||
# OBJ-NEXT: Symbol {
|
||||
# OBJ-NEXT: Name: protected (17)
|
||||
# OBJ-NEXT: Value: 0x10
|
||||
# OBJ-NEXT: Size: 4
|
||||
# OBJ-NEXT: Binding: Global (0x1)
|
||||
# OBJ-NEXT: Type: Object (0x1)
|
||||
# OBJ-NEXT: Other: 3
|
||||
# OBJ-NEXT: Section: .data (0x1)
|
||||
# OBJ-NEXT: }
|
||||
|
||||
# YAML: Symbols:
|
||||
# YAML-NEXT: Global:
|
||||
# YAML-NEXT: - Name: default1
|
||||
# YAML-NEXT: Type: STT_OBJECT
|
||||
# YAML-NEXT: Section: .data
|
||||
# YAML-NEXT: Size: 0x0000000000000004
|
||||
# YAML-NEXT: - Name: default2
|
||||
# YAML-NEXT: Type: STT_OBJECT
|
||||
# YAML-NEXT: Section: .data
|
||||
# YAML-NEXT: Value: 0x0000000000000004
|
||||
# YAML-NEXT: Size: 0x0000000000000004
|
||||
# YAML-NEXT: - Name: internal
|
||||
# YAML-NEXT: Type: STT_OBJECT
|
||||
# YAML-NEXT: Section: .data
|
||||
# YAML-NEXT: Value: 0x0000000000000008
|
||||
# YAML-NEXT: Size: 0x0000000000000004
|
||||
# YAML-NEXT: Visibility: STV_INTERNAL
|
||||
# YAML-NEXT: - Name: hidden
|
||||
# YAML-NEXT: Type: STT_OBJECT
|
||||
# YAML-NEXT: Section: .data
|
||||
# YAML-NEXT: Value: 0x000000000000000C
|
||||
# YAML-NEXT: Size: 0x0000000000000004
|
||||
# YAML-NEXT: Visibility: STV_HIDDEN
|
||||
# YAML-NEXT: - Name: protected
|
||||
# YAML-NEXT: Type: STT_OBJECT
|
||||
# YAML-NEXT: Section: .data
|
||||
# YAML-NEXT: Value: 0x0000000000000010
|
||||
# YAML-NEXT: Size: 0x0000000000000004
|
||||
# YAML-NEXT: Visibility: STV_PROTECTED
|
||||
|
||||
---
|
||||
FileHeader:
|
||||
Class: ELFCLASS32
|
||||
Data: ELFDATA2LSB
|
||||
Type: ET_REL
|
||||
Machine: EM_MIPS
|
||||
Flags: [ EF_MIPS_ABI_O32, EF_MIPS_ARCH_32 ]
|
||||
|
||||
Sections:
|
||||
- Name: .data
|
||||
Type: SHT_PROGBITS
|
||||
Flags: [ SHF_ALLOC, SHF_WRITE ]
|
||||
AddressAlign: 0x04
|
||||
Size: 0x14
|
||||
|
||||
Symbols:
|
||||
Global:
|
||||
- Name: default1
|
||||
Type: STT_OBJECT
|
||||
Visibility: STV_DEFAULT
|
||||
Section: .data
|
||||
Value: 0x00
|
||||
Size: 0x04
|
||||
- Name: default2
|
||||
Type: STT_OBJECT
|
||||
Section: .data
|
||||
Value: 0x04
|
||||
Size: 0x04
|
||||
- Name: internal
|
||||
Type: STT_OBJECT
|
||||
Visibility: STV_INTERNAL
|
||||
Section: .data
|
||||
Value: 0x08
|
||||
Size: 0x04
|
||||
- Name: hidden
|
||||
Type: STT_OBJECT
|
||||
Visibility: STV_HIDDEN
|
||||
Section: .data
|
||||
Value: 0x0C
|
||||
Size: 0x04
|
||||
- Name: protected
|
||||
Type: STT_OBJECT
|
||||
Visibility: STV_PROTECTED
|
||||
Section: .data
|
||||
Value: 0x10
|
||||
Size: 0x04
|
@ -132,6 +132,7 @@ error_code ELFDumper<ELFT>::dumpSymbol(Elf_Sym_Iter Sym, ELFYAML::Symbol &S) {
|
||||
S.Type = Sym->getType();
|
||||
S.Value = Sym->st_value;
|
||||
S.Size = Sym->st_size;
|
||||
S.Visibility = Sym->st_other & 0x3;
|
||||
|
||||
ErrorOr<StringRef> NameOrErr = Obj.getSymbolName(Sym);
|
||||
if (error_code EC = NameOrErr.getError())
|
||||
|
@ -304,6 +304,7 @@ void ELFState<ELFT>::addSymbols(const std::vector<ELFYAML::Symbol> &Symbols,
|
||||
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_size = Sym.Size;
|
||||
Syms.push_back(Symbol);
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user