[llvm] 89e6601 - [llvm-readelf][llvm-readobj] - Fix the indentation when printing dynamic tags.

Georgii Rymar via llvm-commits llvm-commits at lists.llvm.org
Tue Jan 21 03:25:13 PST 2020


Author: Georgii Rymar
Date: 2020-01-21T14:24:50+03:00
New Revision: 89e6601fb152b39700977d70e5604309f05475e5

URL: https://github.com/llvm/llvm-project/commit/89e6601fb152b39700977d70e5604309f05475e5
DIFF: https://github.com/llvm/llvm-project/commit/89e6601fb152b39700977d70e5604309f05475e5.diff

LOG: [llvm-readelf][llvm-readobj] - Fix the indentation when printing dynamic tags.

This change is similar to one made for llvm-objdump in D72838.

llvm-readelf/llvm-readobj tools do not align the "Name/Value" column properly.
This patch adds a logic to calculate the size of indentation on fly
to fix such issues.

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

Added: 
    

Modified: 
    llvm/test/tools/llvm-readobj/ELF/dynamic-tags-machine-specific.test
    llvm/test/tools/llvm-readobj/ELF/dynamic-tags.test
    llvm/tools/llvm-readobj/ELFDumper.cpp

Removed: 
    


################################################################################
diff  --git a/llvm/test/tools/llvm-readobj/ELF/dynamic-tags-machine-specific.test b/llvm/test/tools/llvm-readobj/ELF/dynamic-tags-machine-specific.test
index 1f2e4e781ff8..4a7780815764 100644
--- a/llvm/test/tools/llvm-readobj/ELF/dynamic-tags-machine-specific.test
+++ b/llvm/test/tools/llvm-readobj/ELF/dynamic-tags-machine-specific.test
@@ -54,107 +54,105 @@ ProgramHeaders:
 # RUN:  | FileCheck %s --strict-whitespace --match-full-lines --check-prefix=GNU-MIPS
 
 #      LLVM-MIPS:DynamicSection [ (47 entries)
-# LLVM-MIPS-NEXT:  Tag                Type                 Name/Value
-# LLVM-MIPS-NEXT:  0x0000000000000004 HASH                 0x1000
-# LLVM-MIPS-NEXT:  0x0000000070000001 MIPS_RLD_VERSION     305419896
-# LLVM-MIPS-NEXT:  0x0000000070000002 MIPS_TIME_STAMP      0x11223344
-# LLVM-MIPS-NEXT:  0x0000000070000003 MIPS_ICHECKSUM       0x11112222
-# LLVM-MIPS-NEXT:  0x0000000070000004 MIPS_IVERSION        0x1
-# LLVM-MIPS-NEXT:  0x0000000070000005 MIPS_FLAGS           QUICKSTART SGI_ONLY PIXIE CORD 
-# LLVM-MIPS-NEXT:  0x0000000070000006 MIPS_BASE_ADDRESS    0x87654321
-# LLVM-MIPS-NEXT:  0x0000000070000007 MIPS_MSYM            0x1000
-# LLVM-MIPS-NEXT:  0x0000000070000008 MIPS_CONFLICT        0x1000
-# LLVM-MIPS-NEXT:  0x0000000070000009 MIPS_LIBLIST         0x1000
-# LLVM-MIPS-NEXT:  0x000000007000000A MIPS_LOCAL_GOTNO     1
-# LLVM-MIPS-NEXT:  0x000000007000000B MIPS_CONFLICTNO      0x1
-# LLVM-MIPS-NEXT:  0x0000000070000010 MIPS_LIBLISTNO       0x1
-# LLVM-MIPS-NEXT:  0x0000000070000011 MIPS_SYMTABNO        1
-# LLVM-MIPS-NEXT:  0x0000000070000012 MIPS_UNREFEXTNO      0
-# LLVM-MIPS-NEXT:  0x0000000070000013 MIPS_GOTSYM          0x0
-# LLVM-MIPS-NEXT:  0x0000000070000014 MIPS_HIPAGENO        0x88776655
-# LLVM-MIPS-NEXT:  0x0000000070000016 MIPS_RLD_MAP         0x1000
-# LLVM-MIPS-NEXT:  0x0000000070000017 MIPS_DELTA_CLASS     0x1000
-# LLVM-MIPS-NEXT:  0x0000000070000018 MIPS_DELTA_CLASS_NO  0x1
-# LLVM-MIPS-NEXT:  0x0000000070000019 MIPS_DELTA_INSTANCE  0x1000
-## FIXME: llvm-readobj does not print spaces after MIPS_DELTA_INSTANCE_NO, MIPS_PROTECTED_GOTIDX
-##        and other long tags. The output looks broken because of that.
-# LLVM-MIPS-NEXT:  0x000000007000001A MIPS_DELTA_INSTANCE_NO0x1
-# LLVM-MIPS-NEXT:  0x000000007000001B MIPS_DELTA_RELOC     0x1000
-# LLVM-MIPS-NEXT:  0x000000007000001C MIPS_DELTA_RELOC_NO  0x1
-# LLVM-MIPS-NEXT:  0x000000007000001D MIPS_DELTA_SYM       0x1000
-# LLVM-MIPS-NEXT:  0x000000007000001E MIPS_DELTA_SYM_NO    0x1
-# LLVM-MIPS-NEXT:  0x0000000070000020 MIPS_DELTA_CLASSSYM  0x1000
-# LLVM-MIPS-NEXT:  0x0000000070000021 MIPS_DELTA_CLASSSYM_NO0x1
-# LLVM-MIPS-NEXT:  0x0000000070000022 MIPS_CXX_FLAGS       0x88887777
-# LLVM-MIPS-NEXT:  0x0000000070000023 MIPS_PIXIE_INIT      0x1000
-# LLVM-MIPS-NEXT:  0x0000000070000025 MIPS_LOCALPAGE_GOTIDX0x1
-# LLVM-MIPS-NEXT:  0x0000000070000026 MIPS_LOCAL_GOTIDX    0x1
-# LLVM-MIPS-NEXT:  0x0000000070000027 MIPS_HIDDEN_GOTIDX   0x1
-# LLVM-MIPS-NEXT:  0x0000000070000028 MIPS_PROTECTED_GOTIDX0x1
-# LLVM-MIPS-NEXT:  0x0000000070000029 MIPS_OPTIONS         0x1000
-# LLVM-MIPS-NEXT:  0x000000007000002A MIPS_INTERFACE       0x1000
-# LLVM-MIPS-NEXT:  0x000000007000002B MIPS_DYNSTR_ALIGN    0x88888888
-# LLVM-MIPS-NEXT:  0x000000007000002C MIPS_INTERFACE_SIZE  0x10
-# LLVM-MIPS-NEXT:  0x000000007000002D MIPS_RLD_TEXT_RESOLVE_ADDR0x8
-# LLVM-MIPS-NEXT:  0x000000007000002E MIPS_PERF_SUFFIX     0x0
-# LLVM-MIPS-NEXT:  0x000000007000002F MIPS_COMPACT_SIZE    0x10
-# LLVM-MIPS-NEXT:  0x0000000070000030 MIPS_GP_VALUE        0x1
-# LLVM-MIPS-NEXT:  0x0000000070000031 MIPS_AUX_DYNAMIC     0x1000
-# LLVM-MIPS-NEXT:  0x0000000070000032 MIPS_PLTGOT          0x1000
-# LLVM-MIPS-NEXT:  0x0000000070000034 MIPS_RWPLT           0x1000
-# LLVM-MIPS-NEXT:  0x0000000070000035 MIPS_RLD_MAP_REL     0x1000
-# LLVM-MIPS-NEXT:  0x0000000000000000 NULL                 0x0
+# LLVM-MIPS-NEXT:  Tag                Type                       Name/Value
+# LLVM-MIPS-NEXT:  0x0000000000000004 HASH                       0x1000
+# LLVM-MIPS-NEXT:  0x0000000070000001 MIPS_RLD_VERSION           305419896
+# LLVM-MIPS-NEXT:  0x0000000070000002 MIPS_TIME_STAMP            0x11223344
+# LLVM-MIPS-NEXT:  0x0000000070000003 MIPS_ICHECKSUM             0x11112222
+# LLVM-MIPS-NEXT:  0x0000000070000004 MIPS_IVERSION              0x1
+# LLVM-MIPS-NEXT:  0x0000000070000005 MIPS_FLAGS                 QUICKSTART SGI_ONLY PIXIE CORD 
+# LLVM-MIPS-NEXT:  0x0000000070000006 MIPS_BASE_ADDRESS          0x87654321
+# LLVM-MIPS-NEXT:  0x0000000070000007 MIPS_MSYM                  0x1000
+# LLVM-MIPS-NEXT:  0x0000000070000008 MIPS_CONFLICT              0x1000
+# LLVM-MIPS-NEXT:  0x0000000070000009 MIPS_LIBLIST               0x1000
+# LLVM-MIPS-NEXT:  0x000000007000000A MIPS_LOCAL_GOTNO           1
+# LLVM-MIPS-NEXT:  0x000000007000000B MIPS_CONFLICTNO            0x1
+# LLVM-MIPS-NEXT:  0x0000000070000010 MIPS_LIBLISTNO             0x1
+# LLVM-MIPS-NEXT:  0x0000000070000011 MIPS_SYMTABNO              1
+# LLVM-MIPS-NEXT:  0x0000000070000012 MIPS_UNREFEXTNO            0
+# LLVM-MIPS-NEXT:  0x0000000070000013 MIPS_GOTSYM                0x0
+# LLVM-MIPS-NEXT:  0x0000000070000014 MIPS_HIPAGENO              0x88776655
+# LLVM-MIPS-NEXT:  0x0000000070000016 MIPS_RLD_MAP               0x1000
+# LLVM-MIPS-NEXT:  0x0000000070000017 MIPS_DELTA_CLASS           0x1000
+# LLVM-MIPS-NEXT:  0x0000000070000018 MIPS_DELTA_CLASS_NO        0x1
+# LLVM-MIPS-NEXT:  0x0000000070000019 MIPS_DELTA_INSTANCE        0x1000
+# LLVM-MIPS-NEXT:  0x000000007000001A MIPS_DELTA_INSTANCE_NO     0x1
+# LLVM-MIPS-NEXT:  0x000000007000001B MIPS_DELTA_RELOC           0x1000
+# LLVM-MIPS-NEXT:  0x000000007000001C MIPS_DELTA_RELOC_NO        0x1
+# LLVM-MIPS-NEXT:  0x000000007000001D MIPS_DELTA_SYM             0x1000
+# LLVM-MIPS-NEXT:  0x000000007000001E MIPS_DELTA_SYM_NO          0x1
+# LLVM-MIPS-NEXT:  0x0000000070000020 MIPS_DELTA_CLASSSYM        0x1000
+# LLVM-MIPS-NEXT:  0x0000000070000021 MIPS_DELTA_CLASSSYM_NO     0x1
+# LLVM-MIPS-NEXT:  0x0000000070000022 MIPS_CXX_FLAGS             0x88887777
+# LLVM-MIPS-NEXT:  0x0000000070000023 MIPS_PIXIE_INIT            0x1000
+# LLVM-MIPS-NEXT:  0x0000000070000025 MIPS_LOCALPAGE_GOTIDX      0x1
+# LLVM-MIPS-NEXT:  0x0000000070000026 MIPS_LOCAL_GOTIDX          0x1
+# LLVM-MIPS-NEXT:  0x0000000070000027 MIPS_HIDDEN_GOTIDX         0x1
+# LLVM-MIPS-NEXT:  0x0000000070000028 MIPS_PROTECTED_GOTIDX      0x1
+# LLVM-MIPS-NEXT:  0x0000000070000029 MIPS_OPTIONS               0x1000
+# LLVM-MIPS-NEXT:  0x000000007000002A MIPS_INTERFACE             0x1000
+# LLVM-MIPS-NEXT:  0x000000007000002B MIPS_DYNSTR_ALIGN          0x88888888
+# LLVM-MIPS-NEXT:  0x000000007000002C MIPS_INTERFACE_SIZE        0x10
+# LLVM-MIPS-NEXT:  0x000000007000002D MIPS_RLD_TEXT_RESOLVE_ADDR 0x8
+# LLVM-MIPS-NEXT:  0x000000007000002E MIPS_PERF_SUFFIX           0x0
+# LLVM-MIPS-NEXT:  0x000000007000002F MIPS_COMPACT_SIZE          0x10
+# LLVM-MIPS-NEXT:  0x0000000070000030 MIPS_GP_VALUE              0x1
+# LLVM-MIPS-NEXT:  0x0000000070000031 MIPS_AUX_DYNAMIC           0x1000
+# LLVM-MIPS-NEXT:  0x0000000070000032 MIPS_PLTGOT                0x1000
+# LLVM-MIPS-NEXT:  0x0000000070000034 MIPS_RWPLT                 0x1000
+# LLVM-MIPS-NEXT:  0x0000000070000035 MIPS_RLD_MAP_REL           0x1000
+# LLVM-MIPS-NEXT:  0x0000000000000000 NULL                       0x0
 # LLVM-MIPS-NEXT:]
 
 #      GNU-MIPS:Dynamic section at offset {{.*}} contains 47 entries:
-# GNU-MIPS-NEXT:  Tag                Type                 Name/Value
-# GNU-MIPS-NEXT:  0x0000000000000004 (HASH)               0x1000
-# GNU-MIPS-NEXT:  0x0000000070000001 (MIPS_RLD_VERSION)   305419896
-# GNU-MIPS-NEXT:  0x0000000070000002 (MIPS_TIME_STAMP)    0x11223344
-# GNU-MIPS-NEXT:  0x0000000070000003 (MIPS_ICHECKSUM)     0x11112222
-# GNU-MIPS-NEXT:  0x0000000070000004 (MIPS_IVERSION)      0x1
-# GNU-MIPS-NEXT:  0x0000000070000005 (MIPS_FLAGS)         QUICKSTART SGI_ONLY PIXIE CORD 
-# GNU-MIPS-NEXT:  0x0000000070000006 (MIPS_BASE_ADDRESS)  0x87654321
-# GNU-MIPS-NEXT:  0x0000000070000007 (MIPS_MSYM)          0x1000
-# GNU-MIPS-NEXT:  0x0000000070000008 (MIPS_CONFLICT)      0x1000
-# GNU-MIPS-NEXT:  0x0000000070000009 (MIPS_LIBLIST)       0x1000
-# GNU-MIPS-NEXT:  0x000000007000000a (MIPS_LOCAL_GOTNO)   1
-# GNU-MIPS-NEXT:  0x000000007000000b (MIPS_CONFLICTNO)    0x1
-# GNU-MIPS-NEXT:  0x0000000070000010 (MIPS_LIBLISTNO)     0x1
-# GNU-MIPS-NEXT:  0x0000000070000011 (MIPS_SYMTABNO)      1
-# GNU-MIPS-NEXT:  0x0000000070000012 (MIPS_UNREFEXTNO)    0
-# GNU-MIPS-NEXT:  0x0000000070000013 (MIPS_GOTSYM)        0x0
-# GNU-MIPS-NEXT:  0x0000000070000014 (MIPS_HIPAGENO)      0x88776655
-# GNU-MIPS-NEXT:  0x0000000070000016 (MIPS_RLD_MAP)       0x1000
-# GNU-MIPS-NEXT:  0x0000000070000017 (MIPS_DELTA_CLASS)   0x1000
-# GNU-MIPS-NEXT:  0x0000000070000018 (MIPS_DELTA_CLASS_NO) 0x1
-# GNU-MIPS-NEXT:  0x0000000070000019 (MIPS_DELTA_INSTANCE) 0x1000
-# GNU-MIPS-NEXT:  0x000000007000001a (MIPS_DELTA_INSTANCE_NO) 0x1
-# GNU-MIPS-NEXT:  0x000000007000001b (MIPS_DELTA_RELOC)   0x1000
-# GNU-MIPS-NEXT:  0x000000007000001c (MIPS_DELTA_RELOC_NO) 0x1
-# GNU-MIPS-NEXT:  0x000000007000001d (MIPS_DELTA_SYM)     0x1000
-# GNU-MIPS-NEXT:  0x000000007000001e (MIPS_DELTA_SYM_NO)  0x1
-# GNU-MIPS-NEXT:  0x0000000070000020 (MIPS_DELTA_CLASSSYM) 0x1000
-# GNU-MIPS-NEXT:  0x0000000070000021 (MIPS_DELTA_CLASSSYM_NO) 0x1
-# GNU-MIPS-NEXT:  0x0000000070000022 (MIPS_CXX_FLAGS)     0x88887777
-# GNU-MIPS-NEXT:  0x0000000070000023 (MIPS_PIXIE_INIT)    0x1000
-# GNU-MIPS-NEXT:  0x0000000070000025 (MIPS_LOCALPAGE_GOTIDX) 0x1
-# GNU-MIPS-NEXT:  0x0000000070000026 (MIPS_LOCAL_GOTIDX)  0x1
-# GNU-MIPS-NEXT:  0x0000000070000027 (MIPS_HIDDEN_GOTIDX) 0x1
-# GNU-MIPS-NEXT:  0x0000000070000028 (MIPS_PROTECTED_GOTIDX) 0x1
-# GNU-MIPS-NEXT:  0x0000000070000029 (MIPS_OPTIONS)       0x1000
-# GNU-MIPS-NEXT:  0x000000007000002a (MIPS_INTERFACE)     0x1000
-# GNU-MIPS-NEXT:  0x000000007000002b (MIPS_DYNSTR_ALIGN)  0x88888888
-# GNU-MIPS-NEXT:  0x000000007000002c (MIPS_INTERFACE_SIZE) 0x10
+# GNU-MIPS-NEXT:  Tag                Type                         Name/Value
+# GNU-MIPS-NEXT:  0x0000000000000004 (HASH)                       0x1000
+# GNU-MIPS-NEXT:  0x0000000070000001 (MIPS_RLD_VERSION)           305419896
+# GNU-MIPS-NEXT:  0x0000000070000002 (MIPS_TIME_STAMP)            0x11223344
+# GNU-MIPS-NEXT:  0x0000000070000003 (MIPS_ICHECKSUM)             0x11112222
+# GNU-MIPS-NEXT:  0x0000000070000004 (MIPS_IVERSION)              0x1
+# GNU-MIPS-NEXT:  0x0000000070000005 (MIPS_FLAGS)                 QUICKSTART SGI_ONLY PIXIE CORD 
+# GNU-MIPS-NEXT:  0x0000000070000006 (MIPS_BASE_ADDRESS)          0x87654321
+# GNU-MIPS-NEXT:  0x0000000070000007 (MIPS_MSYM)                  0x1000
+# GNU-MIPS-NEXT:  0x0000000070000008 (MIPS_CONFLICT)              0x1000
+# GNU-MIPS-NEXT:  0x0000000070000009 (MIPS_LIBLIST)               0x1000
+# GNU-MIPS-NEXT:  0x000000007000000a (MIPS_LOCAL_GOTNO)           1
+# GNU-MIPS-NEXT:  0x000000007000000b (MIPS_CONFLICTNO)            0x1
+# GNU-MIPS-NEXT:  0x0000000070000010 (MIPS_LIBLISTNO)             0x1
+# GNU-MIPS-NEXT:  0x0000000070000011 (MIPS_SYMTABNO)              1
+# GNU-MIPS-NEXT:  0x0000000070000012 (MIPS_UNREFEXTNO)            0
+# GNU-MIPS-NEXT:  0x0000000070000013 (MIPS_GOTSYM)                0x0
+# GNU-MIPS-NEXT:  0x0000000070000014 (MIPS_HIPAGENO)              0x88776655
+# GNU-MIPS-NEXT:  0x0000000070000016 (MIPS_RLD_MAP)               0x1000
+# GNU-MIPS-NEXT:  0x0000000070000017 (MIPS_DELTA_CLASS)           0x1000
+# GNU-MIPS-NEXT:  0x0000000070000018 (MIPS_DELTA_CLASS_NO)        0x1
+# GNU-MIPS-NEXT:  0x0000000070000019 (MIPS_DELTA_INSTANCE)        0x1000
+# GNU-MIPS-NEXT:  0x000000007000001a (MIPS_DELTA_INSTANCE_NO)     0x1
+# GNU-MIPS-NEXT:  0x000000007000001b (MIPS_DELTA_RELOC)           0x1000
+# GNU-MIPS-NEXT:  0x000000007000001c (MIPS_DELTA_RELOC_NO)        0x1
+# GNU-MIPS-NEXT:  0x000000007000001d (MIPS_DELTA_SYM)             0x1000
+# GNU-MIPS-NEXT:  0x000000007000001e (MIPS_DELTA_SYM_NO)          0x1
+# GNU-MIPS-NEXT:  0x0000000070000020 (MIPS_DELTA_CLASSSYM)        0x1000
+# GNU-MIPS-NEXT:  0x0000000070000021 (MIPS_DELTA_CLASSSYM_NO)     0x1
+# GNU-MIPS-NEXT:  0x0000000070000022 (MIPS_CXX_FLAGS)             0x88887777
+# GNU-MIPS-NEXT:  0x0000000070000023 (MIPS_PIXIE_INIT)            0x1000
+# GNU-MIPS-NEXT:  0x0000000070000025 (MIPS_LOCALPAGE_GOTIDX)      0x1
+# GNU-MIPS-NEXT:  0x0000000070000026 (MIPS_LOCAL_GOTIDX)          0x1
+# GNU-MIPS-NEXT:  0x0000000070000027 (MIPS_HIDDEN_GOTIDX)         0x1
+# GNU-MIPS-NEXT:  0x0000000070000028 (MIPS_PROTECTED_GOTIDX)      0x1
+# GNU-MIPS-NEXT:  0x0000000070000029 (MIPS_OPTIONS)               0x1000
+# GNU-MIPS-NEXT:  0x000000007000002a (MIPS_INTERFACE)             0x1000
+# GNU-MIPS-NEXT:  0x000000007000002b (MIPS_DYNSTR_ALIGN)          0x88888888
+# GNU-MIPS-NEXT:  0x000000007000002c (MIPS_INTERFACE_SIZE)        0x10
 # GNU-MIPS-NEXT:  0x000000007000002d (MIPS_RLD_TEXT_RESOLVE_ADDR) 0x8
-# GNU-MIPS-NEXT:  0x000000007000002e (MIPS_PERF_SUFFIX)   0x0
-# GNU-MIPS-NEXT:  0x000000007000002f (MIPS_COMPACT_SIZE)  0x10
-# GNU-MIPS-NEXT:  0x0000000070000030 (MIPS_GP_VALUE)      0x1
-# GNU-MIPS-NEXT:  0x0000000070000031 (MIPS_AUX_DYNAMIC)   0x1000
-# GNU-MIPS-NEXT:  0x0000000070000032 (MIPS_PLTGOT)        0x1000
-# GNU-MIPS-NEXT:  0x0000000070000034 (MIPS_RWPLT)         0x1000
-# GNU-MIPS-NEXT:  0x0000000070000035 (MIPS_RLD_MAP_REL)   0x1000
-# GNU-MIPS-NEXT:  0x0000000000000000 (NULL)               0x0
+# GNU-MIPS-NEXT:  0x000000007000002e (MIPS_PERF_SUFFIX)           0x0
+# GNU-MIPS-NEXT:  0x000000007000002f (MIPS_COMPACT_SIZE)          0x10
+# GNU-MIPS-NEXT:  0x0000000070000030 (MIPS_GP_VALUE)              0x1
+# GNU-MIPS-NEXT:  0x0000000070000031 (MIPS_AUX_DYNAMIC)           0x1000
+# GNU-MIPS-NEXT:  0x0000000070000032 (MIPS_PLTGOT)                0x1000
+# GNU-MIPS-NEXT:  0x0000000070000034 (MIPS_RWPLT)                 0x1000
+# GNU-MIPS-NEXT:  0x0000000070000035 (MIPS_RLD_MAP_REL)           0x1000
+# GNU-MIPS-NEXT:  0x0000000000000000 (NULL)                       0x0
 
 --- !ELF
 FileHeader:

diff  --git a/llvm/test/tools/llvm-readobj/ELF/dynamic-tags.test b/llvm/test/tools/llvm-readobj/ELF/dynamic-tags.test
index c033a2ac60c7..0f3fe44b3543 100644
--- a/llvm/test/tools/llvm-readobj/ELF/dynamic-tags.test
+++ b/llvm/test/tools/llvm-readobj/ELF/dynamic-tags.test
@@ -75,68 +75,68 @@
 # LLVM64-NEXT:]
 
 #      GNU64:Dynamic section at offset {{.*}} contains 61 entries:
-# GNU64-NEXT:  Tag                Type                 Name/Value
-# GNU64-NEXT:  0x0000000000000001 (NEEDED)             Shared library: [D]
-# GNU64-NEXT:  0x0000000000000002 (PLTRELSZ)           16 (bytes)
-# GNU64-NEXT:  0x0000000000000003 (PLTGOT)             0x1000
-# GNU64-NEXT:  0x0000000000000004 (HASH)               0x1000
-# GNU64-NEXT:  0x0000000000000005 (STRTAB)             0x1000
-# GNU64-NEXT:  0x0000000000000006 (SYMTAB)             0x1000
-# GNU64-NEXT:  0x0000000000000007 (RELA)               0x1000
-# GNU64-NEXT:  0x0000000000000008 (RELASZ)             16 (bytes)
-# GNU64-NEXT:  0x0000000000000009 (RELAENT)            1929 (bytes)
-# GNU64-NEXT:  0x000000000000000a (STRSZ)              16 (bytes)
-# GNU64-NEXT:  0x000000000000000b (SYMENT)             2439 (bytes)
-# GNU64-NEXT:  0x000000000000000c (INIT)               0x1000
-# GNU64-NEXT:  0x000000000000000d (FINI)               0x1000
-# GNU64-NEXT:  0x000000000000000e (SONAME)             Library soname: [U]
-# GNU64-NEXT:  0x000000000000000f (RPATH)              Library rpath: [f]
-# GNU64-NEXT:  0x0000000000000010 (SYMBOLIC)           0x1234567890abcdef
-# GNU64-NEXT:  0x0000000000000011 (REL)                0x1000
-# GNU64-NEXT:  0x0000000000000012 (RELSZ)              16 (bytes)
-# GNU64-NEXT:  0x0000000000000013 (RELENT)             291 (bytes)
-# GNU64-NEXT:  0x0000000000000014 (PLTREL)             RELA
-# GNU64-NEXT:  0x0000000000000015 (DEBUG)              0xfedcba0987654321
-# GNU64-NEXT:  0x0000000000000016 (TEXTREL)            0x1122334455667788
-# GNU64-NEXT:  0x0000000000000017 (JMPREL)             0x1000
-# GNU64-NEXT:  0x0000000000000018 (BIND_NOW)           0x8877665544332211
-# GNU64-NEXT:  0x0000000000000019 (INIT_ARRAY)         0x1000
-# GNU64-NEXT:  0x000000000000001a (FINI_ARRAY)         0x1000
-# GNU64-NEXT:  0x000000000000001b (INIT_ARRAYSZ)       16 (bytes)
-# GNU64-NEXT:  0x000000000000001c (FINI_ARRAYSZ)       16 (bytes)
-# GNU64-NEXT:  0x000000000000001d (RUNPATH)            Library runpath: [w]
-# GNU64-NEXT:  0x000000000000001e (FLAGS)              ORIGIN SYMBOLIC TEXTREL BIND_NOW STATIC_TLS {{$}}
-# GNU64-NEXT:  0x0000000000000020 (PREINIT_ARRAY)      0x1000
-# GNU64-NEXT:  0x0000000000000021 (PREINIT_ARRAYSZ)    16 (bytes)
-# GNU64-NEXT:  0x0000000000000022 (SYMTAB_SHNDX)       0x1000
-# GNU64-NEXT:  0x0000000000000023 (RELRSZ)             0x10
-# GNU64-NEXT:  0x0000000000000024 (RELR)               0x1000
-# GNU64-NEXT:  0x0000000000000025 (RELRENT)            0x4321
-# GNU64-NEXT:  0x000000006000000f (ANDROID_REL)        0x1000
-# GNU64-NEXT:  0x0000000060000010 (ANDROID_RELSZ)      16 (bytes)
-# GNU64-NEXT:  0x0000000060000011 (ANDROID_RELA)       0x1000
-# GNU64-NEXT:  0x0000000060000012 (ANDROID_RELASZ)     16 (bytes)
-# GNU64-NEXT:  0x000000006fffe000 (ANDROID_RELR)       0x1000
-# GNU64-NEXT:  0x000000006fffe001 (ANDROID_RELRSZ)     0x10
-# GNU64-NEXT:  0x000000006fffe003 (ANDROID_RELRENT)    0x1234
-# GNU64-NEXT:  0x000000006ffffef5 (GNU_HASH)           0x1000
-# GNU64-NEXT:  0x000000006ffffef6 (TLSDESC_PLT)        0x1000
-# GNU64-NEXT:  0x000000006ffffef7 (TLSDESC_GOT)        0x1000
-# GNU64-NEXT:  0x000000006ffffff9 (RELACOUNT)          0
-# GNU64-NEXT:  0x000000006ffffffa (RELCOUNT)           0
-# GNU64-NEXT:  0x000000006ffffffb (FLAGS_1)            NOW GLOBAL GROUP NODELETE LOADFLTR INITFIRST NOOPEN ORIGIN DIRECT TRANS INTERPOSE NODEFLIB NODUMP CONFALT ENDFILTEE DISPRELDNE DISPRELPND NODIRECT IGNMULDEF NOKSYMS NOHDR EDITED NORELOC SYMINTPOSE GLOBAUDIT SINGLETON {{$}}
-# GNU64-NEXT:  0x000000006ffffff0 (VERSYM)             0x1000
-# GNU64-NEXT:  0x000000006ffffffc (VERDEF)             0x1000
-# GNU64-NEXT:  0x000000006ffffffd (VERDEFNUM)          0
-# GNU64-NEXT:  0x000000006ffffffe (VERNEED)            0x1000
-# GNU64-NEXT:  0x000000006fffffff (VERNEEDNUM)         0
-# GNU64-NEXT:  0x000000007ffffffd (AUXILIARY)          Auxiliary library: [D]
-# GNU64-NEXT:  0x000000007ffffffe (USED)               Not needed object: [U]
-# GNU64-NEXT:  0x000000007fffffff (FILTER)             Filter library: [U]
+# GNU64-NEXT:  Tag                Type                   Name/Value
+# GNU64-NEXT:  0x0000000000000001 (NEEDED)               Shared library: [D]
+# GNU64-NEXT:  0x0000000000000002 (PLTRELSZ)             16 (bytes)
+# GNU64-NEXT:  0x0000000000000003 (PLTGOT)               0x1000
+# GNU64-NEXT:  0x0000000000000004 (HASH)                 0x1000
+# GNU64-NEXT:  0x0000000000000005 (STRTAB)               0x1000
+# GNU64-NEXT:  0x0000000000000006 (SYMTAB)               0x1000
+# GNU64-NEXT:  0x0000000000000007 (RELA)                 0x1000
+# GNU64-NEXT:  0x0000000000000008 (RELASZ)               16 (bytes)
+# GNU64-NEXT:  0x0000000000000009 (RELAENT)              1929 (bytes)
+# GNU64-NEXT:  0x000000000000000a (STRSZ)                16 (bytes)
+# GNU64-NEXT:  0x000000000000000b (SYMENT)               2439 (bytes)
+# GNU64-NEXT:  0x000000000000000c (INIT)                 0x1000
+# GNU64-NEXT:  0x000000000000000d (FINI)                 0x1000
+# GNU64-NEXT:  0x000000000000000e (SONAME)               Library soname: [U]
+# GNU64-NEXT:  0x000000000000000f (RPATH)                Library rpath: [f]
+# GNU64-NEXT:  0x0000000000000010 (SYMBOLIC)             0x1234567890abcdef
+# GNU64-NEXT:  0x0000000000000011 (REL)                  0x1000
+# GNU64-NEXT:  0x0000000000000012 (RELSZ)                16 (bytes)
+# GNU64-NEXT:  0x0000000000000013 (RELENT)               291 (bytes)
+# GNU64-NEXT:  0x0000000000000014 (PLTREL)               RELA
+# GNU64-NEXT:  0x0000000000000015 (DEBUG)                0xfedcba0987654321
+# GNU64-NEXT:  0x0000000000000016 (TEXTREL)              0x1122334455667788
+# GNU64-NEXT:  0x0000000000000017 (JMPREL)               0x1000
+# GNU64-NEXT:  0x0000000000000018 (BIND_NOW)             0x8877665544332211
+# GNU64-NEXT:  0x0000000000000019 (INIT_ARRAY)           0x1000
+# GNU64-NEXT:  0x000000000000001a (FINI_ARRAY)           0x1000
+# GNU64-NEXT:  0x000000000000001b (INIT_ARRAYSZ)         16 (bytes)
+# GNU64-NEXT:  0x000000000000001c (FINI_ARRAYSZ)         16 (bytes)
+# GNU64-NEXT:  0x000000000000001d (RUNPATH)              Library runpath: [w]
+# GNU64-NEXT:  0x000000000000001e (FLAGS)                ORIGIN SYMBOLIC TEXTREL BIND_NOW STATIC_TLS {{$}}
+# GNU64-NEXT:  0x0000000000000020 (PREINIT_ARRAY)        0x1000
+# GNU64-NEXT:  0x0000000000000021 (PREINIT_ARRAYSZ)      16 (bytes)
+# GNU64-NEXT:  0x0000000000000022 (SYMTAB_SHNDX)         0x1000
+# GNU64-NEXT:  0x0000000000000023 (RELRSZ)               0x10
+# GNU64-NEXT:  0x0000000000000024 (RELR)                 0x1000
+# GNU64-NEXT:  0x0000000000000025 (RELRENT)              0x4321
+# GNU64-NEXT:  0x000000006000000f (ANDROID_REL)          0x1000
+# GNU64-NEXT:  0x0000000060000010 (ANDROID_RELSZ)        16 (bytes)
+# GNU64-NEXT:  0x0000000060000011 (ANDROID_RELA)         0x1000
+# GNU64-NEXT:  0x0000000060000012 (ANDROID_RELASZ)       16 (bytes)
+# GNU64-NEXT:  0x000000006fffe000 (ANDROID_RELR)         0x1000
+# GNU64-NEXT:  0x000000006fffe001 (ANDROID_RELRSZ)       0x10
+# GNU64-NEXT:  0x000000006fffe003 (ANDROID_RELRENT)      0x1234
+# GNU64-NEXT:  0x000000006ffffef5 (GNU_HASH)             0x1000
+# GNU64-NEXT:  0x000000006ffffef6 (TLSDESC_PLT)          0x1000
+# GNU64-NEXT:  0x000000006ffffef7 (TLSDESC_GOT)          0x1000
+# GNU64-NEXT:  0x000000006ffffff9 (RELACOUNT)            0
+# GNU64-NEXT:  0x000000006ffffffa (RELCOUNT)             0
+# GNU64-NEXT:  0x000000006ffffffb (FLAGS_1)              NOW GLOBAL GROUP NODELETE LOADFLTR INITFIRST NOOPEN ORIGIN DIRECT TRANS INTERPOSE NODEFLIB NODUMP CONFALT ENDFILTEE DISPRELDNE DISPRELPND NODIRECT IGNMULDEF NOKSYMS NOHDR EDITED NORELOC SYMINTPOSE GLOBAUDIT SINGLETON {{$}}
+# GNU64-NEXT:  0x000000006ffffff0 (VERSYM)               0x1000
+# GNU64-NEXT:  0x000000006ffffffc (VERDEF)               0x1000
+# GNU64-NEXT:  0x000000006ffffffd (VERDEFNUM)            0
+# GNU64-NEXT:  0x000000006ffffffe (VERNEED)              0x1000
+# GNU64-NEXT:  0x000000006fffffff (VERNEEDNUM)           0
+# GNU64-NEXT:  0x000000007ffffffd (AUXILIARY)            Auxiliary library: [D]
+# GNU64-NEXT:  0x000000007ffffffe (USED)                 Not needed object: [U]
+# GNU64-NEXT:  0x000000007fffffff (FILTER)               Filter library: [U]
 # GNU64-NEXT:  0x0000000012345678 (<unknown:>0x12345678) 0x8765432187654321
 # GNU64-NEXT:  0x000000006abcdef0 (<unknown:>0x6abcdef0) 0x9988776655443322
 # GNU64-NEXT:  0x0000000076543210 (<unknown:>0x76543210) 0x5555666677778888
-# GNU64-NEXT:  0x0000000000000000 (NULL)               0x0
+# GNU64-NEXT:  0x0000000000000000 (NULL)                 0x0
 
 --- !ELF
 FileHeader:
@@ -365,68 +365,68 @@ ProgramHeaders:
 # LLVM32-NEXT:]
 
 #      GNU32:Dynamic section at offset 0x84 contains 61 entries:
-# GNU32-NEXT:  Tag        Type                 Name/Value
-# GNU32-NEXT:  0x00000001 (NEEDED)             Shared library: [D]
-# GNU32-NEXT:  0x00000002 (PLTRELSZ)           16 (bytes)
-# GNU32-NEXT:  0x00000003 (PLTGOT)             0x1000
-# GNU32-NEXT:  0x00000004 (HASH)               0x1000
-# GNU32-NEXT:  0x00000005 (STRTAB)             0x1000
-# GNU32-NEXT:  0x00000006 (SYMTAB)             0x1000
-# GNU32-NEXT:  0x00000007 (RELA)               0x1000
-# GNU32-NEXT:  0x00000008 (RELASZ)             16 (bytes)
-# GNU32-NEXT:  0x00000009 (RELAENT)            1929 (bytes)
-# GNU32-NEXT:  0x0000000a (STRSZ)              16 (bytes)
-# GNU32-NEXT:  0x0000000b (SYMENT)             2439 (bytes)
-# GNU32-NEXT:  0x0000000c (INIT)               0x1000
-# GNU32-NEXT:  0x0000000d (FINI)               0x1000
-# GNU32-NEXT:  0x0000000e (SONAME)             Library soname: [U]
-# GNU32-NEXT:  0x0000000f (RPATH)              Library rpath: [f]
-# GNU32-NEXT:  0x00000010 (SYMBOLIC)           0x12345678
-# GNU32-NEXT:  0x00000011 (REL)                0x1000
-# GNU32-NEXT:  0x00000012 (RELSZ)              16 (bytes)
-# GNU32-NEXT:  0x00000013 (RELENT)             291 (bytes)
-# GNU32-NEXT:  0x00000014 (PLTREL)             RELA
-# GNU32-NEXT:  0x00000015 (DEBUG)              0xfedcba09
-# GNU32-NEXT:  0x00000016 (TEXTREL)            0x11223344
-# GNU32-NEXT:  0x00000017 (JMPREL)             0x1000
-# GNU32-NEXT:  0x00000018 (BIND_NOW)           0x88776655
-# GNU32-NEXT:  0x00000019 (INIT_ARRAY)         0x1000
-# GNU32-NEXT:  0x0000001a (FINI_ARRAY)         0x1000
-# GNU32-NEXT:  0x0000001b (INIT_ARRAYSZ)       16 (bytes)
-# GNU32-NEXT:  0x0000001c (FINI_ARRAYSZ)       16 (bytes)
-# GNU32-NEXT:  0x0000001d (RUNPATH)            Library runpath: [w]
-# GNU32-NEXT:  0x0000001e (FLAGS)              ORIGIN SYMBOLIC TEXTREL BIND_NOW STATIC_TLS {{$}}
-# GNU32-NEXT:  0x00000020 (PREINIT_ARRAY)      0x1000
-# GNU32-NEXT:  0x00000021 (PREINIT_ARRAYSZ)    16 (bytes)
-# GNU32-NEXT:  0x00000022 (SYMTAB_SHNDX)       0x1000
-# GNU32-NEXT:  0x00000023 (RELRSZ)             0x10
-# GNU32-NEXT:  0x00000024 (RELR)               0x1000
-# GNU32-NEXT:  0x00000025 (RELRENT)            0x4321
-# GNU32-NEXT:  0x6000000f (ANDROID_REL)        0x1000
-# GNU32-NEXT:  0x60000010 (ANDROID_RELSZ)      16 (bytes)
-# GNU32-NEXT:  0x60000011 (ANDROID_RELA)       0x1000
-# GNU32-NEXT:  0x60000012 (ANDROID_RELASZ)     16 (bytes)
-# GNU32-NEXT:  0x6fffe000 (ANDROID_RELR)       0x1000
-# GNU32-NEXT:  0x6fffe001 (ANDROID_RELRSZ)     0x10
-# GNU32-NEXT:  0x6fffe003 (ANDROID_RELRENT)    0x1234
-# GNU32-NEXT:  0x6ffffef5 (GNU_HASH)           0x1000
-# GNU32-NEXT:  0x6ffffef6 (TLSDESC_PLT)        0x1000
-# GNU32-NEXT:  0x6ffffef7 (TLSDESC_GOT)        0x1000
-# GNU32-NEXT:  0x6ffffff9 (RELACOUNT)          0
-# GNU32-NEXT:  0x6ffffffa (RELCOUNT)           0
-# GNU32-NEXT:  0x6ffffffb (FLAGS_1)            NOW GLOBAL GROUP NODELETE LOADFLTR INITFIRST NOOPEN ORIGIN DIRECT TRANS INTERPOSE NODEFLIB NODUMP CONFALT ENDFILTEE DISPRELDNE DISPRELPND NODIRECT IGNMULDEF NOKSYMS NOHDR EDITED NORELOC SYMINTPOSE GLOBAUDIT SINGLETON {{$}}
-# GNU32-NEXT:  0x6ffffff0 (VERSYM)             0x1000
-# GNU32-NEXT:  0x6ffffffc (VERDEF)             0x1000
-# GNU32-NEXT:  0x6ffffffd (VERDEFNUM)          0
-# GNU32-NEXT:  0x6ffffffe (VERNEED)            0x1000
-# GNU32-NEXT:  0x6fffffff (VERNEEDNUM)         0
-# GNU32-NEXT:  0x7ffffffd (AUXILIARY)          Auxiliary library: [D]
-# GNU32-NEXT:  0x7ffffffe (USED)               Not needed object: [U]
-# GNU32-NEXT:  0x7fffffff (FILTER)             Filter library: [U]
+# GNU32-NEXT:  Tag        Type                   Name/Value
+# GNU32-NEXT:  0x00000001 (NEEDED)               Shared library: [D]
+# GNU32-NEXT:  0x00000002 (PLTRELSZ)             16 (bytes)
+# GNU32-NEXT:  0x00000003 (PLTGOT)               0x1000
+# GNU32-NEXT:  0x00000004 (HASH)                 0x1000
+# GNU32-NEXT:  0x00000005 (STRTAB)               0x1000
+# GNU32-NEXT:  0x00000006 (SYMTAB)               0x1000
+# GNU32-NEXT:  0x00000007 (RELA)                 0x1000
+# GNU32-NEXT:  0x00000008 (RELASZ)               16 (bytes)
+# GNU32-NEXT:  0x00000009 (RELAENT)              1929 (bytes)
+# GNU32-NEXT:  0x0000000a (STRSZ)                16 (bytes)
+# GNU32-NEXT:  0x0000000b (SYMENT)               2439 (bytes)
+# GNU32-NEXT:  0x0000000c (INIT)                 0x1000
+# GNU32-NEXT:  0x0000000d (FINI)                 0x1000
+# GNU32-NEXT:  0x0000000e (SONAME)               Library soname: [U]
+# GNU32-NEXT:  0x0000000f (RPATH)                Library rpath: [f]
+# GNU32-NEXT:  0x00000010 (SYMBOLIC)             0x12345678
+# GNU32-NEXT:  0x00000011 (REL)                  0x1000
+# GNU32-NEXT:  0x00000012 (RELSZ)                16 (bytes)
+# GNU32-NEXT:  0x00000013 (RELENT)               291 (bytes)
+# GNU32-NEXT:  0x00000014 (PLTREL)               RELA
+# GNU32-NEXT:  0x00000015 (DEBUG)                0xfedcba09
+# GNU32-NEXT:  0x00000016 (TEXTREL)              0x11223344
+# GNU32-NEXT:  0x00000017 (JMPREL)               0x1000
+# GNU32-NEXT:  0x00000018 (BIND_NOW)             0x88776655
+# GNU32-NEXT:  0x00000019 (INIT_ARRAY)           0x1000
+# GNU32-NEXT:  0x0000001a (FINI_ARRAY)           0x1000
+# GNU32-NEXT:  0x0000001b (INIT_ARRAYSZ)         16 (bytes)
+# GNU32-NEXT:  0x0000001c (FINI_ARRAYSZ)         16 (bytes)
+# GNU32-NEXT:  0x0000001d (RUNPATH)              Library runpath: [w]
+# GNU32-NEXT:  0x0000001e (FLAGS)                ORIGIN SYMBOLIC TEXTREL BIND_NOW STATIC_TLS {{$}}
+# GNU32-NEXT:  0x00000020 (PREINIT_ARRAY)        0x1000
+# GNU32-NEXT:  0x00000021 (PREINIT_ARRAYSZ)      16 (bytes)
+# GNU32-NEXT:  0x00000022 (SYMTAB_SHNDX)         0x1000
+# GNU32-NEXT:  0x00000023 (RELRSZ)               0x10
+# GNU32-NEXT:  0x00000024 (RELR)                 0x1000
+# GNU32-NEXT:  0x00000025 (RELRENT)              0x4321
+# GNU32-NEXT:  0x6000000f (ANDROID_REL)          0x1000
+# GNU32-NEXT:  0x60000010 (ANDROID_RELSZ)        16 (bytes)
+# GNU32-NEXT:  0x60000011 (ANDROID_RELA)         0x1000
+# GNU32-NEXT:  0x60000012 (ANDROID_RELASZ)       16 (bytes)
+# GNU32-NEXT:  0x6fffe000 (ANDROID_RELR)         0x1000
+# GNU32-NEXT:  0x6fffe001 (ANDROID_RELRSZ)       0x10
+# GNU32-NEXT:  0x6fffe003 (ANDROID_RELRENT)      0x1234
+# GNU32-NEXT:  0x6ffffef5 (GNU_HASH)             0x1000
+# GNU32-NEXT:  0x6ffffef6 (TLSDESC_PLT)          0x1000
+# GNU32-NEXT:  0x6ffffef7 (TLSDESC_GOT)          0x1000
+# GNU32-NEXT:  0x6ffffff9 (RELACOUNT)            0
+# GNU32-NEXT:  0x6ffffffa (RELCOUNT)             0
+# GNU32-NEXT:  0x6ffffffb (FLAGS_1)              NOW GLOBAL GROUP NODELETE LOADFLTR INITFIRST NOOPEN ORIGIN DIRECT TRANS INTERPOSE NODEFLIB NODUMP CONFALT ENDFILTEE DISPRELDNE DISPRELPND NODIRECT IGNMULDEF NOKSYMS NOHDR EDITED NORELOC SYMINTPOSE GLOBAUDIT SINGLETON {{$}}
+# GNU32-NEXT:  0x6ffffff0 (VERSYM)               0x1000
+# GNU32-NEXT:  0x6ffffffc (VERDEF)               0x1000
+# GNU32-NEXT:  0x6ffffffd (VERDEFNUM)            0
+# GNU32-NEXT:  0x6ffffffe (VERNEED)              0x1000
+# GNU32-NEXT:  0x6fffffff (VERNEEDNUM)           0
+# GNU32-NEXT:  0x7ffffffd (AUXILIARY)            Auxiliary library: [D]
+# GNU32-NEXT:  0x7ffffffe (USED)                 Not needed object: [U]
+# GNU32-NEXT:  0x7fffffff (FILTER)               Filter library: [U]
 # GNU32-NEXT:  0x12345678 (<unknown:>0x12345678) 0x87654321
 # GNU32-NEXT:  0x6abcdef0 (<unknown:>0x6abcdef0) 0x99887766
 # GNU32-NEXT:  0x76543210 (<unknown:>0x76543210) 0x55556666
-# GNU32-NEXT:  0x00000000 (NULL)               0x0
+# GNU32-NEXT:  0x00000000 (NULL)                 0x0
 
 --- !ELF
 FileHeader:
@@ -580,3 +580,60 @@ ProgramHeaders:
     VAddr: 0x1010
     Sections:
       - Section: .dynamic
+
+## When printing the "Name/Value" column we want to have the minimal possible indentation.
+## Use an arbitrary dynamic tag to demonstrate this.
+
+# RUN: yaml2obj %s --docnum=3 -o %t3
+# RUN: llvm-readobj --dynamic-table %t3 \
+# RUN:   | FileCheck %s --check-prefix=INDENT-LLVM-64 --strict-whitespace
+# RUN: llvm-readelf --dynamic-table %t3 \
+# RUN:   | FileCheck %s --check-prefix=INDENT-GNU-64 --strict-whitespace
+
+# RUN: yaml2obj %s --docnum=4 -o %t4
+# RUN: llvm-readobj --dynamic-table %t4 \
+# RUN:   | FileCheck %s --check-prefix=INDENT-LLVM-32 --strict-whitespace
+# RUN: llvm-readelf --dynamic-table %t4 \
+# RUN:   | FileCheck %s --check-prefix=INDENT-GNU-32 --strict-whitespace
+
+# INDENT-LLVM-64:Tag                Type   Name/Value
+# INDENT-LLVM-64:0x0000000000000001 NEEDED Shared
+
+# INDENT-GNU-64:Tag                Type     Name/Value
+# INDENT-GNU-64:0x0000000000000001 (NEEDED) Shared
+
+# INDENT-LLVM-32:Tag        Type   Name/Value
+# INDENT-LLVM-32:0x00000001 NEEDED Shared
+
+# INDENT-GNU-32:Tag        Type     Name/Value
+# INDENT-GNU-32:0x00000001 (NEEDED) Shared
+
+--- !ELF
+FileHeader:
+  Class:   ELFCLASS64
+  Data:    ELFDATA2LSB
+  Type:    ET_EXEC
+  Machine: EM_X86_64
+Sections:
+  - Name: .dynamic
+    Type: SHT_DYNAMIC
+    Entries:
+     - Tag:   DT_NEEDED
+       Value: 0x1
+     - Tag:   DT_NULL
+       Value: 0x0
+
+--- !ELF
+FileHeader:
+  Class:   ELFCLASS32
+  Data:    ELFDATA2LSB
+  Type:    ET_EXEC
+  Machine: EM_386
+Sections:
+  - Name: .dynamic
+    Type: SHT_DYNAMIC
+    Entries:
+     - Tag:   DT_NEEDED
+       Value: 0x1
+     - Tag:   DT_NULL
+       Value: 0x0

diff  --git a/llvm/tools/llvm-readobj/ELFDumper.cpp b/llvm/tools/llvm-readobj/ELFDumper.cpp
index 8ffb68283405..e08edb0a02f8 100644
--- a/llvm/tools/llvm-readobj/ELFDumper.cpp
+++ b/llvm/tools/llvm-readobj/ELFDumper.cpp
@@ -3971,6 +3971,15 @@ void GNUStyle<ELFT>::printDynamicRelocation(const ELFO *Obj, Elf_Rela R,
   printRelocation(Obj, S.Sym, S.Name, R, IsRela);
 }
 
+template <class ELFT>
+static size_t getMaxDynamicTagSize(const ELFFile<ELFT> *Obj,
+                                   typename ELFT::DynRange Tags) {
+  size_t Max = 0;
+  for (const typename ELFT::Dyn &Dyn : Tags)
+    Max = std::max(Max, Obj->getDynamicTagAsString(Dyn.d_tag).size());
+  return Max;
+}
+
 template <class ELFT> void GNUStyle<ELFT>::printDynamic(const ELFO *Obj) {
   Elf_Dyn_Range Table = this->dumper()->dynamic_table();
   if (Table.empty())
@@ -3985,17 +3994,21 @@ template <class ELFT> void GNUStyle<ELFT>::printDynamic(const ELFO *Obj) {
                    1)
      << " contains " << Table.size() << " entries:\n";
 
-  bool Is64 = ELFT::Is64Bits;
-  if (Is64)
-    OS << "  Tag                Type                 Name/Value\n";
-  else
-    OS << "  Tag        Type                 Name/Value\n";
+  // The type name is surrounded with round brackets, hence add 2.
+  size_t MaxTagSize = getMaxDynamicTagSize(Obj, Table) + 2;
+  // The "Name/Value" column should be indented from the "Type" column by N
+  // spaces, where N = MaxTagSize - length of "Type" (4) + trailing
+  // space (1) = 3.
+  OS << "  Tag" + std::string(ELFT::Is64Bits ? 16 : 8, ' ') + "Type"
+     << std::string(MaxTagSize - 3, ' ') << "Name/Value\n";
+
+  std::string ValueFmt = " %-" + std::to_string(MaxTagSize) + "s ";
   for (auto Entry : Table) {
     uintX_t Tag = Entry.getTag();
     std::string TypeString =
         std::string("(") + Obj->getDynamicTagAsString(Tag).c_str() + ")";
-    OS << "  " << format_hex(Tag, Is64 ? 18 : 10)
-       << format(" %-20s ", TypeString.c_str());
+    OS << "  " << format_hex(Tag, ELFT::Is64Bits ? 18 : 10)
+       << format(ValueFmt.c_str(), TypeString.c_str());
     this->dumper()->printDynamicEntry(OS, Tag, Entry.getVal());
     OS << "\n";
   }
@@ -5788,15 +5801,20 @@ template <class ELFT> void LLVMStyle<ELFT>::printDynamic(const ELFFile<ELFT> *Ob
   raw_ostream &OS = W.getOStream();
   W.startLine() << "DynamicSection [ (" << Table.size() << " entries)\n";
 
-  bool Is64 = ELFT::Is64Bits;
-  if (Is64)
-    W.startLine() << "  Tag                Type                 Name/Value\n";
-  else
-    W.startLine() << "  Tag        Type                 Name/Value\n";
+  size_t MaxTagSize = getMaxDynamicTagSize(Obj, Table);
+  // The "Name/Value" column should be indented from the "Type" column by N
+  // spaces, where N = MaxTagSize - length of "Type" (4) + trailing
+  // space (1) = -3.
+  W.startLine() << "  Tag" << std::string(ELFT::Is64Bits ? 16 : 8, ' ')
+                << "Type" << std::string(MaxTagSize - 3, ' ') << "Name/Value\n";
+
+  std::string ValueFmt = "%-" + std::to_string(MaxTagSize) + "s ";
   for (auto Entry : Table) {
     uintX_t Tag = Entry.getTag();
-    W.startLine() << "  " << format_hex(Tag, Is64 ? 18 : 10, true) << " "
-                  << format("%-21s", Obj->getDynamicTagAsString(Tag).c_str());
+    W.startLine() << "  " << format_hex(Tag, ELFT::Is64Bits ? 18 : 10, true)
+                  << " "
+                  << format(ValueFmt.c_str(),
+                            Obj->getDynamicTagAsString(Tag).c_str());
     this->dumper()->printDynamicEntry(OS, Tag, Entry.getVal());
     OS << "\n";
   }


        


More information about the llvm-commits mailing list