[llvm] 422b078 - [llvm-readobj] - Fix letters used for dumping section types in GNU style.

Georgii Rymar via llvm-commits llvm-commits at lists.llvm.org
Fri Dec 13 00:42:28 PST 2019


Author: Georgii Rymar
Date: 2019-12-13T11:31:24+03:00
New Revision: 422b078c69ee7ae5c2529992eed4fd8a21aedda4

URL: https://github.com/llvm/llvm-project/commit/422b078c69ee7ae5c2529992eed4fd8a21aedda4
DIFF: https://github.com/llvm/llvm-project/commit/422b078c69ee7ae5c2529992eed4fd8a21aedda4.diff

LOG: [llvm-readobj] - Fix letters used for dumping section types in GNU style.

I've noticed that when we have all regular flags set, we print "WAEXMSILoGTx"
instead of "WAXMSILOGTCE" printed by GNU readelf.

It happens because:
1) We print SHF_EXCLUDE at the wrong place.
2) We do not recognize SHF_COMPRESSED, we print "x" instead of "C".
3) We print "o" instead of "O" for SHF_OS_NONCONFORMING.

This patch fixes differences and adds test cases.

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

Added: 
    

Modified: 
    llvm/test/MC/ELF/exclude-debug-dwo.s
    llvm/test/tools/llvm-readobj/ELF/section-flags.test
    llvm/tools/llvm-readobj/ELFDumper.cpp

Removed: 
    


################################################################################
diff  --git a/llvm/test/MC/ELF/exclude-debug-dwo.s b/llvm/test/MC/ELF/exclude-debug-dwo.s
index 058ae848e27e..5288b37f470b 100644
--- a/llvm/test/MC/ELF/exclude-debug-dwo.s
+++ b/llvm/test/MC/ELF/exclude-debug-dwo.s
@@ -5,7 +5,7 @@
 # CHECK: .debug_info.dwo        {{.*}} E
 # CHECK: .debug_types.dwo       {{.*}} E
 # CHECK: .debug_abbrev.dwo      {{.*}} E
-# CHECK: .debug_str.dwo         {{.*}} EMS
+# CHECK: .debug_str.dwo         {{.*}} MSE
 # CHECK: .debug_line.dwo        {{.*}} E
 # CHECK: .debug_loc.dwo         {{.*}} E
 # CHECK: .debug_str_offsets.dwo {{.*}} E

diff  --git a/llvm/test/tools/llvm-readobj/ELF/section-flags.test b/llvm/test/tools/llvm-readobj/ELF/section-flags.test
index ffc95aad6d52..9b27b5c065d3 100644
--- a/llvm/test/tools/llvm-readobj/ELF/section-flags.test
+++ b/llvm/test/tools/llvm-readobj/ELF/section-flags.test
@@ -26,9 +26,93 @@
 # LLVM-NEXT: Flags [ (0x0)
 # LLVM-NEXT: ]
 
-# GNU: [Nr] Name     Type     Address          Off    Size   ES Flg          Lk Inf Al
-# GNU: [ 1] allflags PROGBITS 0000000000000000 000040 000000 00 WAEXMSILoGTx 0   0  0
-# GNU: [ 2] noflags  PROGBITS 0000000000000000 000040 000000 00              0   0  0
+# LLVM:      Name: write
+# LLVM-NEXT: Type: SHT_PROGBITS
+# LLVM-NEXT: Flags [ (0x1)
+# LLVM-NEXT:   SHF_WRITE (0x1)
+# LLVM-NEXT: ]
+
+# LLVM:      Name: alloc
+# LLVM-NEXT: Type: SHT_PROGBITS
+# LLVM-NEXT: Flags [ (0x2)
+# LLVM-NEXT:   SHF_ALLOC (0x2)
+# LLVM-NEXT: ]
+
+# LLVM:      Name: exec
+# LLVM-NEXT: Type: SHT_PROGBITS
+# LLVM-NEXT: Flags [ (0x4)
+# LLVM-NEXT:   SHF_EXECINSTR (0x4)
+# LLVM-NEXT: ]
+
+# LLVM:      Name: merge
+# LLVM-NEXT: Type: SHT_PROGBITS
+# LLVM-NEXT: Flags [ (0x10)
+# LLVM-NEXT:   SHF_MERGE (0x10)
+# LLVM-NEXT: ]
+
+# LLVM:      Name: strings
+# LLVM-NEXT: Type: SHT_PROGBITS
+# LLVM-NEXT: Flags [ (0x20)
+# LLVM-NEXT:   SHF_STRINGS (0x20)
+# LLVM-NEXT: ]
+
+# LLVM:      Name: infolink
+# LLVM-NEXT: Type: SHT_PROGBITS
+# LLVM-NEXT: Flags [ (0x40)
+# LLVM-NEXT:   SHF_INFO_LINK (0x40)
+# LLVM-NEXT: ]
+
+# LLVM:      Name: linkorder
+# LLVM-NEXT: Type: SHT_PROGBITS
+# LLVM-NEXT: Flags [ (0x80)
+# LLVM-NEXT:   SHF_LINK_ORDER (0x80)
+# LLVM-NEXT: ]
+
+# LLVM:      Name: nonconforming
+# LLVM-NEXT: Type: SHT_PROGBITS
+# LLVM-NEXT: Flags [ (0x100)
+# LLVM-NEXT:   SHF_OS_NONCONFORMING (0x100)
+# LLVM-NEXT: ]
+
+# LLVM:      Name: group
+# LLVM-NEXT: Type: SHT_PROGBITS
+# LLVM-NEXT: Flags [ (0x200)
+# LLVM-NEXT:   SHF_GROUP (0x200)
+# LLVM-NEXT: ]
+
+# LLVM:      Name: tls
+# LLVM-NEXT: Type: SHT_PROGBITS
+# LLVM-NEXT: Flags [ (0x400)
+# LLVM-NEXT:   SHF_TLS (0x400)
+# LLVM-NEXT: ]
+
+# LLVM:      Name: compressed
+# LLVM-NEXT: Type: SHT_PROGBITS
+# LLVM-NEXT: Flags [ (0x800)
+# LLVM-NEXT:   SHF_COMPRESSED (0x800)
+# LLVM-NEXT: ]
+
+# LLVM:      Name: exclude
+# LLVM-NEXT: Type: SHT_PROGBITS
+# LLVM-NEXT: Flags [ (0x80000000)
+# LLVM-NEXT:   SHF_EXCLUDE (0x80000000)
+# LLVM-NEXT: ]
+
+# GNU: [Nr] Name          Type     Address          Off    Size   ES Flg          Lk Inf Al
+# GNU: [ 1] allflags      PROGBITS 0000000000000000 000040 000000 00 WAXMSILOGTCE 0   0  0
+# GNU: [ 2] noflags       PROGBITS 0000000000000000 000040 000000 00              0   0  0
+# GNU: [ 3] write         PROGBITS 0000000000000000 000040 000000 00 W            0   0  0
+# GNU: [ 4] alloc         PROGBITS 0000000000000000 000040 000000 00 A            0   0  0
+# GNU: [ 5] exec          PROGBITS 0000000000000000 000040 000000 00 X            0   0  0
+# GNU: [ 6] merge         PROGBITS 0000000000000000 000040 000000 00 M            0   0  0
+# GNU: [ 7] strings       PROGBITS 0000000000000000 000040 000000 00 S            0   0  0
+# GNU: [ 8] infolink      PROGBITS 0000000000000000 000040 000000 00 I            0   0  0
+# GNU: [ 9] linkorder     PROGBITS 0000000000000000 000040 000000 00 L            0   0  0
+# GNU: [10] nonconforming PROGBITS 0000000000000000 000040 000000 00 O            0   0  0
+# GNU: [11] group         PROGBITS 0000000000000000 000040 000000 00 G            0   0  0
+# GNU: [12] tls           PROGBITS 0000000000000000 000040 000000 00 T            0   0  0
+# GNU: [13] compressed    PROGBITS 0000000000000000 000040 000000 00 C            0   0  0
+# GNU: [14] exclude       PROGBITS 0000000000000000 000040 000000 00 E            0   0  0
 
 --- !ELF
 FileHeader:
@@ -46,3 +130,39 @@ Sections:
   - Name:  noflags
     Type:  SHT_PROGBITS
     Flags: [ ]
+  - Name:  write
+    Type:  SHT_PROGBITS
+    Flags: [ SHF_WRITE ]
+  - Name:  alloc
+    Type:  SHT_PROGBITS
+    Flags: [ SHF_ALLOC ]
+  - Name:  exec
+    Type:  SHT_PROGBITS
+    Flags: [ SHF_EXECINSTR ]
+  - Name:  merge
+    Type:  SHT_PROGBITS
+    Flags: [ SHF_MERGE ]
+  - Name:  strings
+    Type:  SHT_PROGBITS
+    Flags: [ SHF_STRINGS ]
+  - Name:  infolink
+    Type:  SHT_PROGBITS
+    Flags: [ SHF_INFO_LINK ]
+  - Name:  linkorder
+    Type:  SHT_PROGBITS
+    Flags: [ SHF_LINK_ORDER ]
+  - Name:  nonconforming
+    Type:  SHT_PROGBITS
+    Flags: [ SHF_OS_NONCONFORMING ]
+  - Name:  group
+    Type:  SHT_PROGBITS
+    Flags: [ SHF_GROUP ]
+  - Name:  tls
+    Type:  SHT_PROGBITS
+    Flags: [ SHF_TLS ]
+  - Name:  compressed
+    Type:  SHT_PROGBITS
+    Flags: [ SHF_COMPRESSED ]
+  - Name:  exclude
+    Type:  SHT_PROGBITS
+    Flags: [ SHF_EXCLUDE ]

diff  --git a/llvm/tools/llvm-readobj/ELFDumper.cpp b/llvm/tools/llvm-readobj/ELFDumper.cpp
index 733b36ef2a06..531ca351e212 100644
--- a/llvm/tools/llvm-readobj/ELFDumper.cpp
+++ b/llvm/tools/llvm-readobj/ELFDumper.cpp
@@ -1434,18 +1434,18 @@ static const char *getGroupType(uint32_t Flag) {
 static const EnumEntry<unsigned> ElfSectionFlags[] = {
   ENUM_ENT(SHF_WRITE,            "W"),
   ENUM_ENT(SHF_ALLOC,            "A"),
-  ENUM_ENT(SHF_EXCLUDE,          "E"),
   ENUM_ENT(SHF_EXECINSTR,        "X"),
   ENUM_ENT(SHF_MERGE,            "M"),
   ENUM_ENT(SHF_STRINGS,          "S"),
   ENUM_ENT(SHF_INFO_LINK,        "I"),
   ENUM_ENT(SHF_LINK_ORDER,       "L"),
-  ENUM_ENT(SHF_OS_NONCONFORMING, "o"),
+  ENUM_ENT(SHF_OS_NONCONFORMING, "O"),
   ENUM_ENT(SHF_GROUP,            "G"),
   ENUM_ENT(SHF_TLS,              "T"),
+  ENUM_ENT(SHF_COMPRESSED,       "C"),
+  ENUM_ENT(SHF_EXCLUDE,          "E"),
   ENUM_ENT(SHF_MASKOS,           "o"),
   ENUM_ENT(SHF_MASKPROC,         "p"),
-  ENUM_ENT_1(SHF_COMPRESSED),
 };
 
 static const EnumEntry<unsigned> ElfXCoreSectionFlags[] = {
@@ -1492,6 +1492,7 @@ static std::string getGNUFlags(uint64_t Flags) {
     case ELF::SHF_OS_NONCONFORMING:
     case ELF::SHF_GROUP:
     case ELF::SHF_TLS:
+    case ELF::SHF_COMPRESSED:
     case ELF::SHF_EXCLUDE:
       Str += Entry.AltName;
       break;


        


More information about the llvm-commits mailing list