[yaml2obj][obj2yaml] - Change how symbol's binding is descibed when parsing/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
diff --git a/llvm/test/tools/llvm-readobj/Inputs/dwarf-exprs.exe-x86-64.yaml b/llvm/test/tools/llvm-readobj/Inputs/dwarf-exprs.exe-x86-64.yaml
index 5b8f367..37b790d 100644
--- a/llvm/test/tools/llvm-readobj/Inputs/dwarf-exprs.exe-x86-64.yaml
+++ b/llvm/test/tools/llvm-readobj/Inputs/dwarf-exprs.exe-x86-64.yaml
@@ -25,11 +25,11 @@
     AddressAlign:    8
     Content:         1400000000000000017A5200017810011B0C070890010710140000001C000000B0F0FFFF2A00000000000000000000001400000000000000017A5200017810011B0C070890010000240000001C00000050F0FFFF20000000000E10460E184A0F0B770880003F1A3B2A332422000000001C000000440000003EF1FFFF1000000000410E108602430D064B0C07080000002C0000006400000038F1FFFF7F0C000000450C0A00491006027600450F0376780603660C0C0A00450C070800000000002C0000009400000088FDFFFF6600000000410E108602430D06428F03458E04478D058C06488307024B0C07080000000014000000C4000000C8FDFFFF01000000000000000000000000000000
 Symbols:
-  Global:
-    - Name:            myfunc
-      Type:            STT_FUNC
-      Section:         .text
-      Value:           0x0000000000400000
+  - Name:            myfunc
+    Type:            STT_FUNC
+    Section:         .text
+    Value:           0x0000000000400000
+    Binding:         STB_GLOBAL
 ProgramHeaders:
   - Type: PT_LOAD
     Flags: [ PF_X, PF_R ]
diff --git a/llvm/test/tools/llvm-readobj/broken-group.test b/llvm/test/tools/llvm-readobj/broken-group.test
index c50a9dd..8b8989a 100644
--- a/llvm/test/tools/llvm-readobj/broken-group.test
+++ b/llvm/test/tools/llvm-readobj/broken-group.test
@@ -73,9 +73,8 @@
     Members:         
       - SectionOrType:   GRP_COMDAT
       - SectionOrType:   .foo
-Symbols:         
-  Local:           
-    - Name:            bar
-      Section:         .group
-    - Name:            zed
-      Section:         .group1
+Symbols:
+  - Name:            bar
+    Section:         .group
+  - Name:            zed
+    Section:         .group1
diff --git a/llvm/test/tools/llvm-readobj/demangle.test b/llvm/test/tools/llvm-readobj/demangle.test
index 809a724..fb6c64b 100644
--- a/llvm/test/tools/llvm-readobj/demangle.test
+++ b/llvm/test/tools/llvm-readobj/demangle.test
@@ -210,13 +210,14 @@
     Link: .symtab
     Content: "0102"
 Symbols:
-  Global:
-    - Name:    _Z3fooc
-      Type:    STT_FUNC
-      Section: .text.foo
-    - Name:    _Z4blahf
-      Type:    STT_FUNC
-      Section: .text.foo
+  - Name:    _Z3fooc
+    Type:    STT_FUNC
+    Section: .text.foo
+    Binding: STB_GLOBAL
+  - Name:    _Z4blahf
+    Type:    STT_FUNC
+    Section: .text.foo
+    Binding: STB_GLOBAL
 ProgramHeaders:
   - Type:  PT_LOAD
     Flags: [ PF_R, PF_X ]
diff --git a/llvm/test/tools/llvm-readobj/elf-no-shdrs.test b/llvm/test/tools/llvm-readobj/elf-no-shdrs.test
index 38111bc..4e21ae7 100644
--- a/llvm/test/tools/llvm-readobj/elf-no-shdrs.test
+++ b/llvm/test/tools/llvm-readobj/elf-no-shdrs.test
@@ -28,6 +28,6 @@
   - Name: .text
     Type: SHT_PROGBITS
 Symbols:
-  Global:
-    - Name: foobar
-      Section: .text
+  - Name:    foobar
+    Section: .text
+    Binding: STB_GLOBAL
diff --git a/llvm/test/tools/llvm-readobj/elf-packed-relocs.test b/llvm/test/tools/llvm-readobj/elf-packed-relocs.test
index 84acd06..8fa73c3 100644
--- a/llvm/test/tools/llvm-readobj/elf-packed-relocs.test
+++ b/llvm/test/tools/llvm-readobj/elf-packed-relocs.test
@@ -41,9 +41,10 @@
     AddressAlign:    0x0000000000000001
     Content:         41505332088020020108800280010202088180808010818080802002080181808080100802818080802004020C7E048180808010088180808020
 Symbols:
-  Global:
-    - Name:            sym1
-    - Name:            sym2
+  - Name:            sym1
+    Binding:         STB_GLOBAL
+  - Name:            sym2
+    Binding:         STB_GLOBAL
 ...
 
 # RUN: yaml2obj -docnum 2 %s | llvm-readobj -elf-output-style=LLVM -relocations - | FileCheck --check-prefix=LLVM2 %s
@@ -90,9 +91,10 @@
     AddressAlign:    0x0000000000000001
     Content:         415053320A80200202088102830408037C08
 Symbols:
-  Global:
-    - Name:            sym1
-    - Name:            sym2
+  - Name:            sym1
+    Binding:         STB_GLOBAL
+  - Name:            sym2
+    Binding:         STB_GLOBAL
 ...
 
 # RUN: yaml2obj -docnum 3 %s | llvm-readobj -elf-output-style=LLVM -relocations - | FileCheck --check-prefix=LLVM3 %s
@@ -132,7 +134,8 @@
     AddressAlign:    0x0000000000000001
     Content:         415053320680200208800208008001080802008001818080801008818080802002080881808080100008818080802008
 Symbols:
-  Global:
-    - Name:            sym1
-    - Name:            sym2
+  - Name:            sym1
+    Binding:         STB_GLOBAL
+  - Name:            sym2
+    Binding:         STB_GLOBAL
 ...
diff --git a/llvm/test/tools/llvm-readobj/elf-reloc-negative-addend-no-sym.test b/llvm/test/tools/llvm-readobj/elf-reloc-negative-addend-no-sym.test
index 13e6a96..86ec658 100644
--- a/llvm/test/tools/llvm-readobj/elf-reloc-negative-addend-no-sym.test
+++ b/llvm/test/tools/llvm-readobj/elf-reloc-negative-addend-no-sym.test
@@ -60,8 +60,8 @@
         Type: R_X86_64_NONE
         Addend: -1
 DynamicSymbols:
-  Global:
-    - Name: force_dynsym
+  - Name:    force_dynsym
+    Binding: STB_GLOBAL
 ProgramHeaders:
   - Type: PT_LOAD
     VAddr: 0x1000
diff --git a/llvm/test/tools/llvm-readobj/elf-reloc-symbol-with-versioning.test b/llvm/test/tools/llvm-readobj/elf-reloc-symbol-with-versioning.test
index c542b80..3d078d3 100644
--- a/llvm/test/tools/llvm-readobj/elf-reloc-symbol-with-versioning.test
+++ b/llvm/test/tools/llvm-readobj/elf-reloc-symbol-with-versioning.test
@@ -84,17 +84,25 @@
         Symbol:          f3
         Type:            R_X86_64_JUMP_SLOT
 Symbols:
-  Global:
-    - Name:            f1
-    - Name:            f2
-    - Name:            g1
-    - Name:            _Z2f1v
-    - Name:            f3
+  - Name:            f1
+    Binding:         STB_GLOBAL
+  - Name:            f2
+    Binding:         STB_GLOBAL
+  - Name:            g1
+    Binding:         STB_GLOBAL
+  - Name:            _Z2f1v
+    Binding:         STB_GLOBAL
+  - Name:            f3
+    Binding:         STB_GLOBAL
 DynamicSymbols:  
-  Global:          
-    - Name:            f1
-    - Name:            f2
-    - Name:            g1
-    - Name:            _Z2f1v
-    - Name:            f3
+  - Name:            f1
+    Binding:         STB_GLOBAL
+  - Name:            f2
+    Binding:         STB_GLOBAL
+  - Name:            g1
+    Binding:         STB_GLOBAL
+  - Name:            _Z2f1v
+    Binding:         STB_GLOBAL
+  - Name:            f3
+    Binding:         STB_GLOBAL
 ...
diff --git a/llvm/test/tools/llvm-readobj/elf-reloc-zero-name-or-value.test b/llvm/test/tools/llvm-readobj/elf-reloc-zero-name-or-value.test
index 7adc1ea..6b1a416 100644
--- a/llvm/test/tools/llvm-readobj/elf-reloc-zero-name-or-value.test
+++ b/llvm/test/tools/llvm-readobj/elf-reloc-zero-name-or-value.test
@@ -74,15 +74,15 @@
         Addend: 1
         Symbol: sym
 Symbols:
-  Global:
-    - Name:    sym
-      Value:   0
-      Section: .text
+  - Name:    sym
+    Value:   0
+    Section: .text
+    Binding: STB_GLOBAL
 DynamicSymbols:
-  Global:
-    - Name:    sym
-      Value:   0
-      Section: .text
+  - Name:    sym
+    Value:   0
+    Section: .text
+    Binding: STB_GLOBAL
 ProgramHeaders:
   - Type: PT_LOAD
     VAddr: 0x1000
diff --git a/llvm/test/tools/llvm-readobj/elf-section-types.test b/llvm/test/tools/llvm-readobj/elf-section-types.test
index 66bfa8a..f65655a 100644
--- a/llvm/test/tools/llvm-readobj/elf-section-types.test
+++ b/llvm/test/tools/llvm-readobj/elf-section-types.test
@@ -218,5 +218,5 @@
   - Name: hiuser
     Type: 0xffffffff
 Symbols:
-  Global:
-    - Name: foo
+  - Name:    foo
+    Binding: STB_GLOBAL
diff --git a/llvm/test/tools/llvm-readobj/elf-symbol-64bit.test b/llvm/test/tools/llvm-readobj/elf-symbol-64bit.test
index 6c45374..dbd8f0e 100644
--- a/llvm/test/tools/llvm-readobj/elf-symbol-64bit.test
+++ b/llvm/test/tools/llvm-readobj/elf-symbol-64bit.test
@@ -18,7 +18,6 @@
   Type:    ET_REL
   Machine: EM_X86_64
 Symbols:
-  Local:
-    - Name:  a_sym
-      Value: 0xfedcba9876543210
-      Size:  0x0123456789abcdef
+  - Name:  a_sym
+    Value: 0xfedcba9876543210
+    Size:  0x0123456789abcdef
diff --git a/llvm/test/tools/llvm-readobj/elf-symbol-binding.test b/llvm/test/tools/llvm-readobj/elf-symbol-binding.test
index 4813d75b..9ca5142 100644
--- a/llvm/test/tools/llvm-readobj/elf-symbol-binding.test
+++ b/llvm/test/tools/llvm-readobj/elf-symbol-binding.test
@@ -52,9 +52,8 @@
     # Symbol with st_name = 19, binding = 0xf
     Content: "0000000000000000000000000000000001000000000000000000000030000000090000000000000000000000a0000000100000000000000000000000b0000000130000000000000000000000f0000000"
 Symbols:
-  Local:
-    - Name: local
-  Global:
-    - Name: global
-  Weak:
-    - Name: weak
+  - Name:    local
+  - Name:    global
+    Binding: STB_GLOBAL
+  - Name:    weak
+    Binding: STB_WEAK
diff --git a/llvm/test/tools/llvm-readobj/elf-symbol-shndx.test b/llvm/test/tools/llvm-readobj/elf-symbol-shndx.test
index 7f4a6c9..ad04be5 100644
--- a/llvm/test/tools/llvm-readobj/elf-symbol-shndx.test
+++ b/llvm/test/tools/llvm-readobj/elf-symbol-shndx.test
@@ -75,20 +75,26 @@
     EntSize: 4
     Content: "0000000001000000"
 Symbols:
-  Global:
-    - Name:    undef
-    - Name:    normal
-      Section: .text
-    - Name:    common
-      Index:   SHN_COMMON
-    - Name:    absolute
-      Index:   SHN_ABS
-    - Name:    proc
-      Index:   0xff01
-    - Name:    os
-      Index:   0xff21
-    - Name:    reserved
-      Index:   0xfffe
+  - Name:    undef
+    Binding: STB_GLOBAL
+  - Name:    normal
+    Section: .text
+    Binding: STB_GLOBAL
+  - Name:    common
+    Index:   SHN_COMMON
+    Binding: STB_GLOBAL
+  - Name:    absolute
+    Index:   SHN_ABS
+    Binding: STB_GLOBAL
+  - Name:    proc
+    Index:   0xff01
+    Binding: STB_GLOBAL
+  - Name:    os
+    Index:   0xff21
+    Binding: STB_GLOBAL
+  - Name:    reserved
+    Index:   0xfffe
+    Binding: STB_GLOBAL
 
 --- !ELF
 FileHeader:
@@ -97,6 +103,6 @@
   Type:    ET_REL
   Machine: EM_386
 Symbols:
-  Global:
-    - Name:    bad
-      Index:   0x42
+  - Name:    bad
+    Index:   0x42
+    Binding: STB_GLOBAL
diff --git a/llvm/test/tools/llvm-readobj/elf-symbol-types.test b/llvm/test/tools/llvm-readobj/elf-symbol-types.test
index cf09a96..8d46b16 100644
--- a/llvm/test/tools/llvm-readobj/elf-symbol-types.test
+++ b/llvm/test/tools/llvm-readobj/elf-symbol-types.test
@@ -51,27 +51,37 @@
   - Name: .text
     Type: SHT_PROGBITS
 Symbols:
-  Global:
-    - Name: notype
-      Type: STT_NOTYPE
-    - Name: object
-      Type: STT_OBJECT
-    - Name: func
-      Type: STT_FUNC
-    - Name: .text
-      Type: STT_SECTION
-      Section: .text
-    - Name: file
-      Type: STT_FILE
-    - Name: common
-      Type: STT_COMMON
-    - Name: tls
-      Type: STT_TLS
-    - Name: gnu_ifunc
-      Type: STT_GNU_IFUNC
-    - Name: os_specific
-      Type: 11
-    - Name: proc_specific
-      Type: 13
-    - Name: unknown
-      Type: 7
+  - Name:    notype
+    Type:    STT_NOTYPE
+    Binding: STB_GLOBAL
+  - Name:    object
+    Type:    STT_OBJECT
+    Binding: STB_GLOBAL
+  - Name:    func
+    Type:    STT_FUNC
+    Binding: STB_GLOBAL
+  - Name:    .text
+    Type:    STT_SECTION
+    Section: .text
+    Binding: STB_GLOBAL
+  - Name:    file
+    Type:    STT_FILE
+    Binding: STB_GLOBAL
+  - Name:    common
+    Type:    STT_COMMON
+    Binding: STB_GLOBAL 
+  - Name:    tls
+    Type:    STT_TLS
+    Binding: STB_GLOBAL
+  - Name:    gnu_ifunc
+    Type:    STT_GNU_IFUNC
+    Binding: STB_GLOBAL
+  - Name:    os_specific
+    Type:    11
+    Binding: STB_GLOBAL
+  - Name:    proc_specific
+    Type:    13
+    Binding: STB_GLOBAL
+  - Name:    unknown
+    Type:    7
+    Binding: STB_GLOBAL
diff --git a/llvm/test/tools/llvm-readobj/elf-symbol-visibility.test b/llvm/test/tools/llvm-readobj/elf-symbol-visibility.test
index 7a25f87..f2e4020 100644
--- a/llvm/test/tools/llvm-readobj/elf-symbol-visibility.test
+++ b/llvm/test/tools/llvm-readobj/elf-symbol-visibility.test
@@ -52,12 +52,15 @@
     # Symbol with st_name = 1, st_other = 0x4
     Content: "0000000000000000000000000000000001000000000000000000000000040000"
 Symbols:
-  Global:
-    - Name: default
-      Visibility: STV_DEFAULT
-    - Name: internal
-      Visibility: STV_INTERNAL
-    - Name: hidden
-      Visibility: STV_HIDDEN
-    - Name: protected
-      Visibility: STV_PROTECTED
+  - Name: default
+    Visibility: STV_DEFAULT
+    Binding: STB_GLOBAL
+  - Name: internal
+    Visibility: STV_INTERNAL
+    Binding: STB_GLOBAL
+  - Name: hidden
+    Visibility: STV_HIDDEN
+    Binding: STB_GLOBAL
+  - Name: protected
+    Visibility: STV_PROTECTED
+    Binding: STB_GLOBAL
diff --git a/llvm/test/tools/llvm-readobj/gnu-notes.test b/llvm/test/tools/llvm-readobj/gnu-notes.test
index 2107823..ab7dcde 100644
--- a/llvm/test/tools/llvm-readobj/gnu-notes.test
+++ b/llvm/test/tools/llvm-readobj/gnu-notes.test
@@ -101,20 +101,22 @@
     AddressAlign:    0x0000000000000004
     Content:         040000000900000004000000474E5500676F6C6420312E3131000000
 Symbols:
-  Local:
-    - Name:            reduced.c
-      Type:            STT_FILE
-    - Type:            STT_FILE
-  Global:
-    - Name:            main
-      Type:            STT_FUNC
-      Section:         .text
-      Value:           0x0000000000400140
-      Size:            0x0000000000000003
-    - Name:            _edata
-      Value:           0x0000000000401000
-    - Name:            __bss_start
-      Value:           0x0000000000401000
-    - Name:            _end
-      Value:           0x0000000000401000
+  - Name:            reduced.c
+    Type:            STT_FILE
+  - Type:            STT_FILE
+  - Name:            main
+    Type:            STT_FUNC
+    Section:         .text
+    Value:           0x0000000000400140
+    Size:            0x0000000000000003
+    Binding: STB_GLOBAL
+  - Name:            _edata
+    Value:           0x0000000000401000
+    Binding: STB_GLOBAL
+  - Name:            __bss_start
+    Value:           0x0000000000401000
+    Binding: STB_GLOBAL
+  - Name:            _end
+    Value:           0x0000000000401000
+    Binding: STB_GLOBAL
 ...