[llvm] 56a8150 - [obj2yaml] - Do not dump the segment's "Align" field when it is equal to 1.

Georgii Rymar via llvm-commits llvm-commits at lists.llvm.org
Thu Apr 9 04:21:13 PDT 2020


Author: Georgii Rymar
Date: 2020-04-09T14:20:36+03:00
New Revision: 56a8150428d45e6831d60e8d547626780634f511

URL: https://github.com/llvm/llvm-project/commit/56a8150428d45e6831d60e8d547626780634f511
DIFF: https://github.com/llvm/llvm-project/commit/56a8150428d45e6831d60e8d547626780634f511.diff

LOG: [obj2yaml] - Do not dump the segment's "Align" field when it is equal to 1.

yaml2obj sets the `Align` to 1 by default, hence we can stop
dumping it to reduce the output.

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

Added: 
    

Modified: 
    llvm/test/Object/obj2yaml.test
    llvm/test/tools/obj2yaml/program-headers.yaml
    llvm/tools/obj2yaml/elf2yaml.cpp

Removed: 
    


################################################################################
diff  --git a/llvm/test/Object/obj2yaml.test b/llvm/test/Object/obj2yaml.test
index 808e9fa0a34c..a4398fb1e313 100644
--- a/llvm/test/Object/obj2yaml.test
+++ b/llvm/test/Object/obj2yaml.test
@@ -672,7 +672,6 @@ Symbols:
 # ELF-AVR-NEXT:     - Section: .data
 # ELF-AVR-NEXT:    VAddr: 0x0000000000800060
 # ELF-AVR-NEXT:    PAddr: 0x0000000000000004
-# ELF-AVR-NEXT:    Align: 0x0000000000000001
 # ELF-AVR-NEXT: Sections:
 # ELF-AVR-NEXT:   - Name:            .text
 # ELF-AVR-NEXT:     Type:            SHT_PROGBITS

diff  --git a/llvm/test/tools/obj2yaml/program-headers.yaml b/llvm/test/tools/obj2yaml/program-headers.yaml
index 1c784f17b6e5..7f31494bd20e 100644
--- a/llvm/test/tools/obj2yaml/program-headers.yaml
+++ b/llvm/test/tools/obj2yaml/program-headers.yaml
@@ -77,23 +77,19 @@
 # YAML-NEXT:    Sections:
 # YAML-NEXT:      - Section: .dynamic
 # YAML-NEXT:    VAddr: 0x0000000000003EF0
-# YAML-NEXT:    Align: 0x0000000000000001
 # YAML-NEXT:  - Type:  PT_LOAD
 # YAML-NEXT:    Flags: [ PF_R ]
 # YAML-NEXT:    VAddr: 0x0000000000004000
-# YAML-NEXT:    Align: 0x0000000000000001
 # YAML-NEXT:  - Type:  PT_LOAD
 # YAML-NEXT:    Flags: [ PF_R ]
 # YAML-NEXT:    Sections:
 # YAML-NEXT:      - Section: .gnu.hash
 # YAML-NEXT:    VAddr: 0x00000000000001A0
-# YAML-NEXT:    Align: 0x0000000000000001
 # YAML-NEXT:  - Type:  PT_LOAD
 # YAML-NEXT:    Flags: [ PF_R ]
 # YAML-NEXT:    Sections:
 # YAML-NEXT:      - Section: .gnu.hash
 # YAML-NEXT:    VAddr: 0x00000000000001A0
-# YAML-NEXT:    Align: 0x0000000000000001
 # YAML-NEXT: Sections:
 
 --- !ELF
@@ -150,6 +146,9 @@ ProgramHeaders:
 ## Show we can create a relro segment and put a section into it.
 ## We used .dynamic here and in tests above to demonstrate that
 ## we can place a section in any number of segments.
+## Also, we explicitly set the "Align" property to 1 to demonstate
+## that we do not dump it, because it is the default alignment
+## value set by yaml2obj.
   - Type:  PT_GNU_RELRO
     Flags: [ PF_R ]
     Sections:
@@ -257,19 +256,16 @@ DynamicSymbols: []
 # EMPTY-NEXT:   Sections:
 # EMPTY-NEXT:     - Section:         .empty.tls.start
 # EMPTY-NEXT:   VAddr:           0x0000000000001000
-# EMPTY-NEXT:   Align:           0x0000000000000001
 # EMPTY-NEXT: - Type:            PT_TLS
 # EMPTY-NEXT:   Flags:           [ PF_W, PF_R ]
 # EMPTY-NEXT:   Sections:
 # EMPTY-NEXT:     - Section:         .empty.tls.middle
 # EMPTY-NEXT:   VAddr:           0x0000000000001100
-# EMPTY-NEXT:   Align:           0x0000000000000001
 # EMPTY-NEXT: - Type:            PT_TLS
 # EMPTY-NEXT:   Flags:           [ PF_W, PF_R ]
 # EMPTY-NEXT:   Sections:
 # EMPTY-NEXT:     - Section:         .empty.tls.end
 # EMPTY-NEXT:   VAddr:           0x0000000000001200
-# EMPTY-NEXT:   Align:           0x0000000000000001
 # EMPTY-NEXT: Sections:
 
 --- !ELF
@@ -385,7 +381,6 @@ Sections:
 # NON-ALLOC-NEXT:      - Section: .non-alloc.1
 # NON-ALLOC-NEXT:      - Section: .alloc.2
 # NON-ALLOC-NEXT:     VAddr: 0x0000000000001000
-# NON-ALLOC-NEXT:     Align: 0x0000000000000001
 # NON-ALLOC-NEXT: Sections:
 
 --- !ELF

diff  --git a/llvm/tools/obj2yaml/elf2yaml.cpp b/llvm/tools/obj2yaml/elf2yaml.cpp
index 464f899352f4..ac0d1e9e1ba7 100644
--- a/llvm/tools/obj2yaml/elf2yaml.cpp
+++ b/llvm/tools/obj2yaml/elf2yaml.cpp
@@ -317,7 +317,11 @@ ELFDumper<ELFT>::dumpProgramHeaders(
     PH.Flags = Phdr.p_flags;
     PH.VAddr = Phdr.p_vaddr;
     PH.PAddr = Phdr.p_paddr;
-    PH.Align = static_cast<llvm::yaml::Hex64>(Phdr.p_align);
+
+    // yaml2obj sets the alignment of a segment to 1 by default.
+    // We do not print the default alignment to reduce noise in the output.
+    if (Phdr.p_align != 1)
+      PH.Align = static_cast<llvm::yaml::Hex64>(Phdr.p_align);
 
     // Here we match sections with segments.
     // It is not possible to have a non-Section chunk, because


        


More information about the llvm-commits mailing list