Skip to content

Commit

Permalink
[yaml2obj][obj2yaml] - Change how symbol's binding is descibed when p…
Browse files Browse the repository at this point in the history
…arsing/dumping.

Currently, YAML has the following syntax for describing the symbols:

Symbols:
  Local:
    LocalSymbol1:
    ...
    LocalSymbol2:
    ...
  ...
  Global:
    GlobalSymbol1:
  ...
  Weak:
  ...
  GNUUnique:

I.e. symbols are grouped by their bindings. That is not very convenient,
because:

It does not allow to set a custom binding, what can be useful for producing
broken/special outputs for test cases. Adding a new binding would require to
change a syntax (what we observed when added GNUUnique recently).

It does not allow to change the order of the symbols in .symtab/.dynsym,
i.e. currently all Local symbols are placed first, then Global, Weak and GNUUnique
are following, but we are not able to change the order.

It is not consistent. Binding is just one of the properties of the symbol,
we do not group them by other properties.

It makes the code more complex that it can be. This patch shows it can be simplified
with the change performed.

The patch changes the syntax to just:

Symbols:
  Symbol1:
  ...
  Symbol2:
  ...
...

With that, we are able to work with the binding field just like with any other symbol property.

Differential revision: https://reviews.llvm.org/D60122

llvm-svn: 357595
  • Loading branch information
George Rimar committed Apr 3, 2019
1 parent f5b181e commit 6da44ad
Show file tree
Hide file tree
Showing 119 changed files with 1,409 additions and 1,342 deletions.
21 changes: 8 additions & 13 deletions llvm/include/llvm/ObjectYAML/ELFYAML.h
Expand Up @@ -52,6 +52,7 @@ LLVM_YAML_STRONG_TYPEDEF(uint8_t, ELF_RSS)
// Just use 64, since it can hold 32-bit values too.
LLVM_YAML_STRONG_TYPEDEF(uint64_t, ELF_SHF)
LLVM_YAML_STRONG_TYPEDEF(uint16_t, ELF_SHN)
LLVM_YAML_STRONG_TYPEDEF(uint8_t, ELF_STB)
LLVM_YAML_STRONG_TYPEDEF(uint8_t, ELF_STT)
LLVM_YAML_STRONG_TYPEDEF(uint8_t, ELF_STV)
LLVM_YAML_STRONG_TYPEDEF(uint8_t, ELF_STO)
Expand Down Expand Up @@ -97,18 +98,12 @@ struct Symbol {
ELF_STT Type;
StringRef Section;
Optional<ELF_SHN> Index;
ELF_STB Binding;
llvm::yaml::Hex64 Value;
llvm::yaml::Hex64 Size;
uint8_t Other;
};

struct SymbolsDef {
std::vector<Symbol> Local;
std::vector<Symbol> Global;
std::vector<Symbol> Weak;
std::vector<Symbol> GNUUnique;
};

struct SectionOrType {
StringRef sectionNameOrType;
};
Expand Down Expand Up @@ -289,8 +284,8 @@ struct Object {
// cleaner and nicer if we read them from the YAML as a separate
// top-level key, which automatically ensures that invariants like there
// being a single SHT_SYMTAB section are upheld.
SymbolsDef Symbols;
SymbolsDef DynamicSymbols;
std::vector<Symbol> Symbols;
std::vector<Symbol> DynamicSymbols;
};

} // end namespace ELFYAML
Expand Down Expand Up @@ -362,6 +357,10 @@ template <> struct ScalarEnumerationTraits<ELFYAML::ELF_SHN> {
static void enumeration(IO &IO, ELFYAML::ELF_SHN &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);
Expand Down Expand Up @@ -437,10 +436,6 @@ struct MappingTraits<ELFYAML::Symbol> {
static StringRef validate(IO &IO, ELFYAML::Symbol &Symbol);
};

template <> struct MappingTraits<ELFYAML::SymbolsDef> {
static void mapping(IO &IO, ELFYAML::SymbolsDef &Symbols);
};

template <> struct MappingTraits<ELFYAML::DynamicEntry> {
static void mapping(IO &IO, ELFYAML::DynamicEntry &Rel);
};
Expand Down
21 changes: 12 additions & 9 deletions llvm/lib/ObjectYAML/ELFYAML.cpp
Expand Up @@ -560,6 +560,17 @@ void ScalarEnumerationTraits<ELFYAML::ELF_SHN>::enumeration(
IO.enumFallback<Hex32>(Value);
}

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);
ECase(STB_GNU_UNIQUE);
#undef ECase
IO.enumFallback<Hex8>(Value);
}

void ScalarEnumerationTraits<ELFYAML::ELF_STT>::enumeration(
IO &IO, ELFYAML::ELF_STT &Value) {
#define ECase(X) IO.enumCase(Value, #X, ELF::X)
Expand Down Expand Up @@ -845,9 +856,9 @@ void MappingTraits<ELFYAML::Symbol>::mapping(IO &IO, ELFYAML::Symbol &Symbol) {
IO.mapOptional("Type", Symbol.Type, ELFYAML::ELF_STT(0));
IO.mapOptional("Section", Symbol.Section, StringRef());
IO.mapOptional("Index", Symbol.Index);
IO.mapOptional("Binding", Symbol.Binding, ELFYAML::ELF_STB(0));
IO.mapOptional("Value", Symbol.Value, Hex64(0));
IO.mapOptional("Size", Symbol.Size, Hex64(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));
Expand All @@ -864,14 +875,6 @@ StringRef MappingTraits<ELFYAML::Symbol>::validate(IO &IO,
return StringRef();
}

void MappingTraits<ELFYAML::SymbolsDef>::mapping(IO &IO,
ELFYAML::SymbolsDef &Symbols) {
IO.mapOptional("Local", Symbols.Local);
IO.mapOptional("Global", Symbols.Global);
IO.mapOptional("Weak", Symbols.Weak);
IO.mapOptional("GNUUnique", Symbols.GNUUnique);
}

static void commonSectionMapping(IO &IO, ELFYAML::Section &Section) {
IO.mapOptional("Name", Section.Name, StringRef());
IO.mapRequired("Type", Section.Type);
Expand Down
10 changes: 5 additions & 5 deletions llvm/test/DebugInfo/invalid-relocations.test
Expand Up @@ -28,8 +28,8 @@ Sections:
Symbol: _start
Type: 0xFF
Symbols:
Global:
- Name: _start
Type: STT_FUNC
Section: .text
Value: 0x0
- Name: _start
Type: STT_FUNC
Section: .text
Value: 0x0
Binding: STB_GLOBAL
18 changes: 8 additions & 10 deletions llvm/test/Object/AArch64/yaml2obj-elf-aarch64-rel.yaml
Expand Up @@ -43,13 +43,11 @@ Sections:
Addend: 0

Symbols:
Local:
- Name: .text
Type: STT_SECTION
Section: .text

Global:
- Name: main
Type: STT_FUNC
Section: .text
Size: 0x08
- Name: .text
Type: STT_SECTION
Section: .text
- Name: main
Type: STT_FUNC
Section: .text
Size: 0x08
Binding: STB_GLOBAL
18 changes: 8 additions & 10 deletions llvm/test/Object/AMDGPU/elf64-relocs.yaml
Expand Up @@ -65,13 +65,11 @@ Sections:
Type: R_AMDGPU_RELATIVE64

Symbols:
Local:
- Name: .text
Type: STT_SECTION
Section: .text

Global:
- Name: main
Type: STT_FUNC
Section: .text
Size: 0x08
- Name: .text
Type: STT_SECTION
Section: .text
- Name: main
Type: STT_FUNC
Section: .text
Size: 0x08
Binding: STB_GLOBAL
18 changes: 8 additions & 10 deletions llvm/test/Object/Lanai/yaml2obj-elf-lanai-rel.yaml
Expand Up @@ -49,13 +49,11 @@ Sections:


Symbols:
Local:
- Name: .text
Type: STT_SECTION
Section: .text

Global:
- Name: main
Type: STT_FUNC
Section: .text
Size: 0x08
- Name: .text
Type: STT_SECTION
Section: .text
- Name: main
Type: STT_FUNC
Section: .text
Size: 0x08
Binding: STB_GLOBAL
7 changes: 3 additions & 4 deletions llvm/test/Object/Mips/abi-flags.yaml
Expand Up @@ -59,7 +59,6 @@ Sections:
Flags2: 0x0

Symbols:
Local:
- Name: .MIPS.abiflags
Type: STT_SECTION
Section: .MIPS.abiflags
- Name: .MIPS.abiflags
Type: STT_SECTION
Section: .MIPS.abiflags
40 changes: 20 additions & 20 deletions llvm/test/Object/Mips/elf-abi.yaml
Expand Up @@ -62,11 +62,11 @@ Sections:
Size: 4

Symbols:
Global:
- Name: T1
Section: .text
Value: 0
Size: 4
- Name: T1
Section: .text
Value: 0
Size: 4
Binding: STB_GLOBAL

# o64
--- !ELF
Expand All @@ -84,11 +84,11 @@ Sections:
Size: 4

Symbols:
Global:
- Name: T1
Section: .text
Value: 0
Size: 4
- Name: T1
Section: .text
Value: 0
Size: 4
Binding: STB_GLOBAL

# eabio32
--- !ELF
Expand All @@ -106,11 +106,11 @@ Sections:
Size: 4

Symbols:
Global:
- Name: T1
Section: .text
Value: 0
Size: 4
- Name: T1
Section: .text
Value: 0
Size: 4
Binding: STB_GLOBAL

# eabi64
--- !ELF
Expand All @@ -128,9 +128,9 @@ Sections:
Size: 4

Symbols:
Global:
- Name: T1
Section: .text
Value: 0
Size: 4
- Name: T1
Section: .text
Value: 0
Size: 4
Binding: STB_GLOBAL
...
10 changes: 5 additions & 5 deletions llvm/test/Object/Mips/elf-flags.yaml
Expand Up @@ -44,9 +44,9 @@ Sections:
Size: 4

Symbols:
Global:
- Name: T1
Section: .text
Value: 0
Size: 4
- Name: T1
Section: .text
Value: 0
Size: 4
Binding: STB_GLOBAL
...
26 changes: 13 additions & 13 deletions llvm/test/Object/Mips/elf-mips64-rel.yaml
Expand Up @@ -98,17 +98,17 @@ Sections:
Size: 0x0F

Symbols:
Local:
- Name: .text
Type: STT_SECTION
Section: .text
- Name: .rodata
Type: STT_SECTION
Section: .rodata
Global:
- Name: main
Type: STT_FUNC
Section: .text
Size: 0x58
- Name: printf
- Name: .text
Type: STT_SECTION
Section: .text
- Name: .rodata
Type: STT_SECTION
Section: .rodata
- Name: main
Type: STT_FUNC
Section: .text
Size: 0x58
Binding: STB_GLOBAL
- Name: printf
Binding: STB_GLOBAL
...
4 changes: 2 additions & 2 deletions llvm/test/Object/X86/yaml-elf-x86-rel-broken.yaml
Expand Up @@ -28,5 +28,5 @@ Sections:
Symbol: main
Type: 0xFF
Symbols:
Global:
- Name: main
- Name: main
Binding: STB_GLOBAL
18 changes: 8 additions & 10 deletions llvm/test/Object/X86/yaml2obj-elf-x86-rel.yaml
Expand Up @@ -30,13 +30,11 @@ Sections:
Type: R_386_32

Symbols:
Local:
- Name: .text
Type: STT_SECTION
Section: .text

Global:
- Name: main
Type: STT_FUNC
Section: .text
Size: 0x08
- Name: .text
Type: STT_SECTION
Section: .text
- Name: main
Type: STT_FUNC
Section: .text
Size: 0x08
Binding: STB_GLOBAL
4 changes: 2 additions & 2 deletions llvm/test/Object/obj2yaml-invalid-reloc.test
Expand Up @@ -24,16 +24,16 @@ CHECK-NEXT: - Offset: 0x0000000000000000
CHECK-NEXT: Symbol: ''
CHECK-NEXT: Type: R_X86_64_NONE
CHECK-NEXT: Symbols:
CHECK-NEXT: Local:
CHECK-NEXT: - Name: rb_ary_new_capa
CHECK-NEXT: Type: STT_FUNC
CHECK-NEXT: Section: .text
CHECK-NEXT: Size: 0x0000000000000005
CHECK-NEXT: Global:
CHECK-NEXT: - Name: __dtraceenabled_ruby___array-create
CHECK-NEXT: Index: SHN_ABS
CHECK-NEXT: Binding: STB_GLOBAL
CHECK-NEXT: - Name: '$dtrace1316529.rb_ary_new_capa'
CHECK-NEXT: Type: STT_FUNC
CHECK-NEXT: Section: .text
CHECK-NEXT: Binding: STB_GLOBAL
CHECK-NEXT: Size: 0x0000000000000005
CHECK-NEXT: Visibility: STV_HIDDEN

0 comments on commit 6da44ad

Please sign in to comment.