Skip to content

Commit 56a8150

Browse files
author
Georgii Rymar
committed
[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
1 parent 45ab677 commit 56a8150

File tree

3 files changed

+8
-10
lines changed

3 files changed

+8
-10
lines changed

llvm/test/Object/obj2yaml.test

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -672,7 +672,6 @@ Symbols:
672672
# ELF-AVR-NEXT: - Section: .data
673673
# ELF-AVR-NEXT: VAddr: 0x0000000000800060
674674
# ELF-AVR-NEXT: PAddr: 0x0000000000000004
675-
# ELF-AVR-NEXT: Align: 0x0000000000000001
676675
# ELF-AVR-NEXT: Sections:
677676
# ELF-AVR-NEXT: - Name: .text
678677
# ELF-AVR-NEXT: Type: SHT_PROGBITS

llvm/test/tools/obj2yaml/program-headers.yaml

Lines changed: 3 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -77,23 +77,19 @@
7777
# YAML-NEXT: Sections:
7878
# YAML-NEXT: - Section: .dynamic
7979
# YAML-NEXT: VAddr: 0x0000000000003EF0
80-
# YAML-NEXT: Align: 0x0000000000000001
8180
# YAML-NEXT: - Type: PT_LOAD
8281
# YAML-NEXT: Flags: [ PF_R ]
8382
# YAML-NEXT: VAddr: 0x0000000000004000
84-
# YAML-NEXT: Align: 0x0000000000000001
8583
# YAML-NEXT: - Type: PT_LOAD
8684
# YAML-NEXT: Flags: [ PF_R ]
8785
# YAML-NEXT: Sections:
8886
# YAML-NEXT: - Section: .gnu.hash
8987
# YAML-NEXT: VAddr: 0x00000000000001A0
90-
# YAML-NEXT: Align: 0x0000000000000001
9188
# YAML-NEXT: - Type: PT_LOAD
9289
# YAML-NEXT: Flags: [ PF_R ]
9390
# YAML-NEXT: Sections:
9491
# YAML-NEXT: - Section: .gnu.hash
9592
# YAML-NEXT: VAddr: 0x00000000000001A0
96-
# YAML-NEXT: Align: 0x0000000000000001
9793
# YAML-NEXT: Sections:
9894

9995
--- !ELF
@@ -150,6 +146,9 @@ ProgramHeaders:
150146
## Show we can create a relro segment and put a section into it.
151147
## We used .dynamic here and in tests above to demonstrate that
152148
## we can place a section in any number of segments.
149+
## Also, we explicitly set the "Align" property to 1 to demonstate
150+
## that we do not dump it, because it is the default alignment
151+
## value set by yaml2obj.
153152
- Type: PT_GNU_RELRO
154153
Flags: [ PF_R ]
155154
Sections:
@@ -257,19 +256,16 @@ DynamicSymbols: []
257256
# EMPTY-NEXT: Sections:
258257
# EMPTY-NEXT: - Section: .empty.tls.start
259258
# EMPTY-NEXT: VAddr: 0x0000000000001000
260-
# EMPTY-NEXT: Align: 0x0000000000000001
261259
# EMPTY-NEXT: - Type: PT_TLS
262260
# EMPTY-NEXT: Flags: [ PF_W, PF_R ]
263261
# EMPTY-NEXT: Sections:
264262
# EMPTY-NEXT: - Section: .empty.tls.middle
265263
# EMPTY-NEXT: VAddr: 0x0000000000001100
266-
# EMPTY-NEXT: Align: 0x0000000000000001
267264
# EMPTY-NEXT: - Type: PT_TLS
268265
# EMPTY-NEXT: Flags: [ PF_W, PF_R ]
269266
# EMPTY-NEXT: Sections:
270267
# EMPTY-NEXT: - Section: .empty.tls.end
271268
# EMPTY-NEXT: VAddr: 0x0000000000001200
272-
# EMPTY-NEXT: Align: 0x0000000000000001
273269
# EMPTY-NEXT: Sections:
274270

275271
--- !ELF
@@ -385,7 +381,6 @@ Sections:
385381
# NON-ALLOC-NEXT: - Section: .non-alloc.1
386382
# NON-ALLOC-NEXT: - Section: .alloc.2
387383
# NON-ALLOC-NEXT: VAddr: 0x0000000000001000
388-
# NON-ALLOC-NEXT: Align: 0x0000000000000001
389384
# NON-ALLOC-NEXT: Sections:
390385

391386
--- !ELF

llvm/tools/obj2yaml/elf2yaml.cpp

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -317,7 +317,11 @@ ELFDumper<ELFT>::dumpProgramHeaders(
317317
PH.Flags = Phdr.p_flags;
318318
PH.VAddr = Phdr.p_vaddr;
319319
PH.PAddr = Phdr.p_paddr;
320-
PH.Align = static_cast<llvm::yaml::Hex64>(Phdr.p_align);
320+
321+
// yaml2obj sets the alignment of a segment to 1 by default.
322+
// We do not print the default alignment to reduce noise in the output.
323+
if (Phdr.p_align != 1)
324+
PH.Align = static_cast<llvm::yaml::Hex64>(Phdr.p_align);
321325

322326
// Here we match sections with segments.
323327
// It is not possible to have a non-Section chunk, because

0 commit comments

Comments
 (0)