`PAddr` corresponds to `p_paddr` of a program header, which is the segment's physical
address for systems in which physical addressing is relevant. `p_paddr` is often equal
to `p_vaddr`, which is the virtual address of a segment.
This patch changes the default for `PAddr` from 0 to a value of `VAddr`.
Differential revision: https://reviews.llvm.org/D76131
IO.mapOptional("Flags", Phdr.Flags, ELFYAML::ELF_PF(0));
IO.mapOptional("Sections", Phdr.Sections);
IO.mapOptional("VAddr", Phdr.VAddr, Hex64(0));
- IO.mapOptional("PAddr", Phdr.PAddr, Hex64(0));
+ IO.mapOptional("PAddr", Phdr.PAddr, Phdr.VAddr);
IO.mapOptional("Align", Phdr.Align);
IO.mapOptional("FileSize", Phdr.FileSize);
IO.mapOptional("MemSize", Phdr.MemSize);
- Type: PT_LOAD
Flags: [ PF_R ]
VAddr: 0x0000
- PAddr: 0x0000
Align: 8
Sections:
- Section: .dynstr
- Type: PT_DYNAMIC
Flags: [ PF_X, PF_R ]
VAddr: 0x0008
- PAddr: 0x0008
Sections:
- Section: .dynamic
- Type: PT_LOAD
Flags: [ PF_R ]
VAddr: 0x0000
- PAddr: 0x0000
Align: 8
Sections:
- Section: .dynstr
- Type: PT_DYNAMIC
Flags: [ PF_X, PF_R ]
VAddr: 0x0008
- PAddr: 0x0008
Sections:
- Section: .dynamic
- Type: PT_LOAD
Flags: [ PF_R ]
VAddr: 0x0000
- PAddr: 0x0000
Align: 8
Sections:
- Section: .dynstr
- Type: PT_DYNAMIC
Flags: [ PF_X, PF_R ]
VAddr: 0x0008
- PAddr: 0x0008
Sections:
- Section: .dynamic
- Type: PT_LOAD
Flags: [ PF_R ]
VAddr: 0x1000
- PAddr: 0x1000
Align: 8
Sections:
- Section: .dynstr
- Type: PT_DYNAMIC
Flags: [ PF_X, PF_R ]
VAddr: 0x1008
- PAddr: 0x1008
Sections:
- Section: .dynamic
- Type: PT_LOAD
Flags: [ PF_R ]
VAddr: 0x1000
- PAddr: 0x1000
Align: 8
Sections:
- Section: .dynstr
- Type: PT_DYNAMIC
Flags: [ PF_X, PF_R ]
VAddr: 0x1024
- PAddr: 0x1024
Sections:
# CHECK: DT_NEEDED string offset (0x000000000000ffff) outside of dynamic string table
- Type: PT_LOAD
Flags: [ PF_R ]
VAddr: 0x1000
- PAddr: 0x1000
Align: 8
Sections:
- Section: .dynstr
- Type: PT_DYNAMIC
Flags: [ PF_X, PF_R ]
VAddr: 0x1024
- PAddr: 0x1024
Sections:
# CHECK: NeededLibs:
- Type: PT_LOAD
Flags: [ PF_R ]
VAddr: 0x0000
- PAddr: 0x0000
Align: 8
Sections:
- Section: .dynstr
- Type: PT_DYNAMIC
Flags: [ PF_X, PF_R ]
VAddr: 0x0008
- PAddr: 0x0008
Sections:
- Section: .dynamic
- Type: PT_LOAD
Flags: [ PF_R ]
VAddr: 0x0000
- PAddr: 0x0000
Align: 8
Sections:
- Section: .dynstr
- Type: PT_DYNAMIC
Flags: [ PF_X, PF_R ]
VAddr: 0x0008
- PAddr: 0x0008
Sections:
- Section: .dynamic
- Type: PT_LOAD
Flags: [ PF_R ]
VAddr: 0x1000
- PAddr: 0x1000
Align: 8
Sections:
- Section: .dynstr
- Type: PT_DYNAMIC
Flags: [ PF_X, PF_R ]
VAddr: 0x1018
- PAddr: 0x1018
Sections:
- Section: .dynamic
- Type: PT_LOAD
Flags: [ PF_R ]
VAddr: 0x1000
- PAddr: 0x1000
Align: 8
Sections:
- Section: .dynstr
- Type: PT_DYNAMIC
Flags: [ PF_X, PF_R ]
VAddr: 0x1018
- PAddr: 0x1018
Sections:
- Section: .dynamic
- Type: PT_LOAD
Flags: [ PF_R ]
VAddr: 0x1000
- PAddr: 0x1000
Align: 8
Sections:
- Section: .dynstr
- Type: PT_DYNAMIC
Flags: [ PF_X, PF_R ]
VAddr: 0x1018
- PAddr: 0x1018
Sections:
- Section: .dynamic
- Type: PT_LOAD
Flags: [ PF_X, PF_R ]
VAddr: 0x0000000000400000
- PAddr: 0x0000000000400000
Align: 1024
Sections:
- Section: .interp
- Type: PT_LOAD
Flags: [ PF_X, PF_R ]
VAddr: 0x1000
- PAddr: 0x1000
Align: 0x1000
Sections:
- Section: .text
- Type: PT_LOAD
Flags: [ PF_R, PF_W ]
VAddr: 0x2000
- PAddr: 0x2000
Align: 0x1000
Sections:
- Section: .data
- Type: PT_LOAD
Flags: [ PF_R ]
VAddr: 0x1000
- PAddr: 0x1000
Sections:
- Section: .note
- Section: .rodata
- Type: PT_LOAD
Flags: [ PF_R, PF_W ]
VAddr: 0x3000
- PAddr: 0x3000
Sections:
- Section: .data
- Type: PT_LOAD
Flags: [ PF_R ]
VAddr: 0x1000
- PAddr: 0x1000
Sections:
- Section: .text
- Section: .text2
- Type: PT_LOAD
Flags: [ PF_R ]
VAddr: 0x1000
- PAddr: 0x1000
Sections:
- Section: .text
- Section: .text2
- Type: PT_LOAD
Flags: [ PF_R ]
VAddr: 0x1000
- PAddr: 0x1000
Sections:
- Section: .text
- Section: .text2
- Type: PT_LOAD
Flags: [ PF_X, PF_R ]
VAddr: 0x1000
- PAddr: 0x1000
Align: 0x1000
Sections:
- Section: .text
- Type: PT_LOAD
Flags: [ PF_R, PF_W ]
VAddr: 0x1008
- PAddr: 0x1008
Align: 0x1000
Sections:
- Section: .data
- Type: PT_LOAD
Flags: [ PF_X, PF_R ]
VAddr: 0x1000
- PAddr: 0x1000
Align: 0x1000
Sections:
- Section: .text
- Type: PT_LOAD
Flags: [ PF_R, PF_W ]
VAddr: 0x1008
- PAddr: 0x1008
Align: 0x1000
Sections:
- Section: .data
ProgramHeaders:
- Type: PT_LOAD
VAddr: 0
- PAddr: 0
Align: 0x100
Sections:
- Section: .foo
- Type: PT_LOAD
VAddr: 0x1000
- PAddr: 0x1000
Align: 0x1000
Sections:
- Section: .empty
- Type: PT_LOAD
Flags: [ PF_X, PF_R ]
VAddr: 0x1000
- PAddr: 0x1000
Align: 0x1000
Sections:
- Section: .text
- Type: PT_LOAD
Flags: [ PF_R, PF_W ]
VAddr: 0x2000
- PAddr: 0x2000
Align: 0x1000
Sections:
- Section: .data
- Type: PT_GNU_STACK
Flags: [ PF_R, PF_W ]
VAddr: 0x0000
- PAddr: 0x0000
Align: 0x0000
- Type: PT_LOAD
Flags: [ PF_R ]
VAddr: 0x2010
- PAddr: 0x2010
Sections:
- Section: .xdata
- Section: .after
# CHECK: Type Offset VirtAddr PhysAddr FileSiz MemSiz Flg Align
# CHECK-NEXT: LOAD 0x000000 0x0000000000000000 0x0000000000000000 0x000402 0x000403 R E 0x1000
-# CHECK-NEXT: LOAD 0x000480 0x0000000000001480 0x0000000000000000 0x000000 0x00005f RW 0x1000
-# CHECK-NEXT: TLS 0x000480 0x0000000000001480 0x0000000000000000 0x000000 0x00000c RW 0x80
-# CHECK-NEXT: NOTE 0x000400 0x0000000000000400 0x0000000000000000 0x000002 0x000002 0x400
+# CHECK-NEXT: LOAD 0x000480 0x0000000000001480 0x0000000000001480 0x000000 0x00005f RW 0x1000
+# CHECK-NEXT: TLS 0x000480 0x0000000000001480 0x0000000000001480 0x000000 0x00000c RW 0x80
+# CHECK-NEXT: NOTE 0x000400 0x0000000000000400 0x0000000000000400 0x000002 0x000002 0x400
## Contents of SHT_NOTE and .debug* are kept.
## Check that p_offset or p_filesz of empty segments or PT_PHDR are not modified.
# CHECK2: Type Offset VirtAddr PhysAddr FileSiz MemSiz Flg Align
-# CHECK2-NEXT: PHDR 0x000040 0x0000000000000040 0x0000000000000000 0x0000a8 0x0000a8 R 0x8
+# CHECK2-NEXT: PHDR 0x000040 0x0000000000000040 0x0000000000000040 0x0000a8 0x0000a8 R 0x8
# CHECK2-NEXT: LOAD 0x000000 0x0000000000000000 0x0000000000000000 0x000202 0x000202 R E 0x1000
-# CHECK2-NEXT: LOAD 0x000202 0x0000000000000202 0x0000000000000000 0x00000e 0x00000e RW 0x1
+# CHECK2-NEXT: LOAD 0x000202 0x0000000000000202 0x0000000000000202 0x00000e 0x00000e RW 0x1
--- !ELF
FileHeader:
- Type: PT_LOAD
Flags: [ PF_R ]
VAddr: 0x1000
- PAddr: 0x1000
Sections:
- Section: .note
- Section: .rodata
- Type: PT_NOTE
Flags: [ PF_R ]
VAddr: 0x1000
- PAddr: 0x1000
Sections:
- Section: .note
# First segment has unlabelled space at start and end.
- Type: 0x6ABCDEF0 # Non-specific segment type.
VAddr: 0x2000
- PAddr: 0x2000
Align: 0x2000
Sections:
- Section: blob1
# Second segment has sections at start and end.
- Type: 0x6ABCDEF0
VAddr: 0x2100
- PAddr: 0x2100
Align: 0x100
Sections:
- Section: section4
# Third segment is all covered by a section.
- Type: 0x6ABCDEF0
VAddr: 0x2200
- PAddr: 0x2200
Align: 0x100
Sections:
- Section: section6
# Fourth segment has no sections (after removing blob headers).
- Type: 0x6ABCDEF0
VAddr: 0x2300
- PAddr: 0x2300
Align: 0x100
Sections:
- Section: blob6
# Fifth segment is empty.
- Type: 0x6ABCDEF0
VAddr: 0x2308
- PAddr: 0x2308
Offset: 0x2308
# The next few segments test behaviour of fully nested segments.
# Sixth segment is the "parent" segment.
- Type: 0x6ABCDEF0
VAddr: 0x3000
- PAddr: 0x3000
Align: 0x1000
Sections:
- Section: sectionA
# Seventh segment is empty and nested.
- Type: 0x6ABCDEF0
VAddr: 0x3002
- PAddr: 0x3002
Offset: 0x3002
# Eighth segment contains only a section and is nested.
- Type: 0x6ABCDEF0
VAddr: 0x3004
- PAddr: 0x3004
Sections:
- Section: sectionB
# Ninth segment contains only unlabelled space and is nested.
- Type: 0x6ABCDEF0
VAddr: 0x3008
- PAddr: 0x3008
Sections:
- Section: blobA
# Tenth segment contains two sections with space between and is nested.
- Type: 0x6ABCDEF0
VAddr: 0x300C
- PAddr: 0x300C
Sections:
- Section: sectionC
- Section: blobB
# Eleventh segment contains two sections with space between and at ends and is nested.
- Type: 0x6ABCDEF0
VAddr: 0x3018
- PAddr: 0x3018
Sections:
- Section: blobC
- Section: sectionE
# Twelfth segment contains one section with space at ends adjacent to space in parent segment.
- Type: 0x6ABCDEF0
VAddr: 0x302E
- PAddr: 0x302E
Offset: 0x302E
FileSize: 8
Sections:
# Thirteenth segment contains overlaps sections at either end in parent segment.
- Type: 0x6ABCDEF0
VAddr: 0x303A
- PAddr: 0x303A
Offset: 0x303A
FileSize: 0x8
Sections:
# Segment15: |--|-Sec-|-unlabelled-|
- Type: 0x6ABCDEF0
VAddr: 0x4000
- PAddr: 0x4000
Sections:
- Section: blobz
- Section: sectionz
- Type: 0x6ABCDEF0
VAddr: 0x4002
- PAddr: 0x4002
Offset: 0x4002
Sections:
- Section: sectionz
# Segment17: |--|----unlabelled---|
- Type: 0x6ABCDEF0
VAddr: 0x400C
- PAddr: 0x400C
FileSize: 6
Sections:
- Section: sectiony
- Type: 0x6ABCDEF0
VAddr: 0x400E
- PAddr: 0x400E
Offset: 0x400E
Sections:
- Section: blobx
# Segment19: |-Sec-|-unlabelled-|
- Type: 0x6ABCDEF0
VAddr: 0x4014
- PAddr: 0x4014
Sections:
- Section: blobw
- Section: sectionx
- Type: 0x6ABCDEF0
VAddr: 0x4018
- PAddr: 0x4018
Sections:
- Section: sectionx
- Section: blobv
# Segment21: |--|-unlabelled-|-Sec-|
- Type: 0x6ABCDEF0
VAddr: 0x4020
- PAddr: 0x4020
Sections:
- Section: sectionw
- Type: 0x6ABCDEF0
VAddr: 0x4022
- PAddr: 0x4022
Offset: 0x4022
Sections:
- Section: blobu
# Segment23: |--|-Sec-|
- Type: 0x6ABCDEF0
VAddr: 0x402C
- PAddr: 0x402C
Sections:
- Section: sectionu
- Type: 0x6ABCDEF0
VAddr: 0x402E
- PAddr: 0x402E
Offset: 0x402E
Sections:
- Section: sectiont
# Segment25: |--Sec--|
- Type: 0x6ABCDEF0
VAddr: 0x4034
- PAddr: 0x4034
FileSize: 6
Sections:
- Section: blobt
- Type: 0x6ABCDEF0
VAddr: 0x4038
- PAddr: 0x4038
Sections:
- Section: sections
# Segment28: |-Sec-|------------|
- Type: 0x6ABCDEF0
VAddr: 0x5000
- PAddr: 0x5000
Align: 0x1000
Sections:
- Section: bloba
- Section: blobb
- Type: 0x6ABCDEF0
VAddr: 0x5000
- PAddr: 0x5000
FileSize: 6
Sections:
- Section: bloba
- Type: 0x6ABCDEF0
VAddr: 0x5004
- PAddr: 0x5004
Sections:
- Section: sectiona
- Section: blobb
# Segment31: |---------|-Sec-|
- Type: 0x6ABCDEF0
VAddr: 0x500C
- PAddr: 0x500C
Sections:
- Section: sectionb
- Section: blobc
- Section: sectionc
- Type: 0x6ABCDEF0
VAddr: 0x500C
- PAddr: 0x500C
FileSize: 7
Sections:
- Section: sectionb
- Type: 0x6ABCDEF0
VAddr: 0x5011
- PAddr: 0x5011
Offset: 0x5011
Sections:
- Section: sectionc
# Segment34: |------------|-Sec-|
- Type: 0x6ABCDEF0
VAddr: 0x5018
- PAddr: 0x5018
Sections:
- Section: sectiond
- Section: blobd
- Section: sectione
- Type: 0x6ABCDEF0
VAddr: 0x5018
- PAddr: 0x5018
Sections:
- Section: sectiond
- Section: blobd
- Type: 0x6ABCDEF0
VAddr: 0x501C
- PAddr: 0x501C
Sections:
- Section: blobd
- Section: sectione
# Segment37: |-Sec-|------------|
- Type: 0x6ABCDEF0
VAddr: 0x5024
- PAddr: 0x5024
Sections:
- Section: blobe
- Section: sectionf
- Section: blobf
- Type: 0x6ABCDEF0
VAddr: 0x5024
- PAddr: 0x5024
Sections:
- Section: blobe
- Section: sectionf
- Type: 0x6ABCDEF0
VAddr: 0x5028
- PAddr: 0x5028
Sections:
- Section: sectionf
- Section: blobf
# Segment40: |---|------------|
- Type: 0x6ABCDEF0
VAddr: 0x5030
- PAddr: 0x5030
Sections:
- Section: blobg
- Section: sectiong
- Section: blobh
- Type: 0x6ABCDEF0
VAddr: 0x5030
- PAddr: 0x5030
FileSize: 7
Sections:
- Section: blobg
- Type: 0x6ABCDEF0
VAddr: 0x5035
- PAddr: 0x5035
Offset: 0x5035
Sections:
- Section: blobh
- Type: PT_LOAD
Flags: [ PF_R ]
VAddr: 0x1000
- PAddr: 0x1000
Sections:
- Section: .text
- Type: PT_LOAD
Flags: [ PF_X, PF_R ]
VAddr: 0x3000
- PAddr: 0x3000
Sections:
- Section: .text3
## TODO (grimar): without the following line (i.e. without an empty symbol table),
- Type: PT_LOAD
Flags: [ PF_R ]
VAddr: 0x1000
- PAddr: 0x1000
Sections:
- Section: .text
- Type: PT_LOAD
Flags: [ PF_X, PF_R ]
VAddr: 0x3000
- PAddr: 0x3000
Sections:
- Section: .text3
- Type: PT_LOAD
Flags: [ PF_R ]
VAddr: 0x1000
- PAddr: 0x1000
Sections:
- Section: .text
- Section: .text2
- Type: PT_LOAD
Flags: [ PF_R ]
VAddr: 0x3000
- PAddr: 0x3000
Sections:
- Section: .text3
- Section: .text4
- Type: PT_LOAD
Flags: [ PF_R ]
VAddr: 0x1000
- PAddr: 0x1000
Sections:
- Section: .text
- Section: .text2
- Type: PT_LOAD
Flags: [ PF_R ]
VAddr: 0x3000
- PAddr: 0x3000
Sections:
- Section: .text3
- Section: .text4
- Type: PT_LOAD
Flags: [ PF_R ]
VAddr: 0x1000
- PAddr: 0x1000
Sections:
- Section: .text
- Section: .text2
- Type: PT_LOAD
Flags: [ PF_R ]
VAddr: 0x3000
- PAddr: 0x3000
Sections:
- Section: .text3
- Section: .text4
- Type: PT_LOAD
Flags: [ PF_X, PF_R ]
VAddr: 0x00001000
- PAddr: 0x00001000
Sections:
- Section: .text
- Section: .init
- Type: PT_LOAD
Flags: [ PF_R ]
VAddr: 0x00002000
- PAddr: 0x00002000
Sections:
- Section: .data
- Type: PT_LOAD
Flags: [ PF_R, PF_X ]
VAddr: 0x0
- PAddr: 0x0
Sections:
- Section: .dynsym
- Section: .dynstr
- Type: PT_DYNAMIC
Flags: [ PF_R ]
VAddr: 0x1000
- PAddr: 0x1000
Sections:
- Section: .dynamic
- Type: PT_LOAD
Flags: [ PF_R, PF_X ]
VAddr: 0x0
- PAddr: 0x0
Sections:
- Section: .dynsym
- Section: .dynstr
- Type: PT_DYNAMIC
Flags: [ PF_R ]
VAddr: 0x1000
- PAddr: 0x1000
Sections:
- Section: .dynamic
- Type: PT_LOAD
Flags: [ PF_R ]
VAddr: 0x0000
- PAddr: 0x0000
Sections:
- Section: .dynstr
- Section: .dynamic
ProgramHeaders:
- Type: PT_LOAD
VAddr: 0x100
- PAddr: 0x100
Sections:
- Section: fill1
- Section: .bar
- Section: fill2
- Type: PT_GNU_RELRO
VAddr: 0x105
- PAddr: 0x105
Sections:
- Section: fill2
- Type: PT_LOAD
Flags: [ PF_R ]
VAddr: 0x0000
- PAddr: 0x0000
Align: 8
Sections:
- Section: .dynamic
- Type: PT_DYNAMIC
Flags: [ PF_X, PF_R ]
VAddr: 0x0008
- PAddr: 0x0008
Sections:
- Section: .dynamic
--- /dev/null
+## Show how yaml2obj sets physical and virtual addresses of program headers.
+
+# RUN: yaml2obj %s -o %t
+# RUN: llvm-readelf --sections --segments %t | FileCheck %s
+
+# CHECK: Section Headers:
+# CHECK: [Nr] Name Type Address Off Size ES Flg
+# CHECK: [ 1] .foo PROGBITS 0000000000001234 000120 000001 00 A
+
+# CHECK: Program Headers:
+# CHECK-NEXT: Type Offset VirtAddr PhysAddr FileSiz MemSiz Flg Align
+# CHECK-NEXT: LOAD 0x000000 0x0000000000000000 0x0000000000000000 0x000000 0x000000 R E 0x1
+# CHECK-NEXT: LOAD 0x000120 0x0000000000000000 0x0000000000000000 0x000001 0x000001 R E 0x1
+# CHECK-NEXT: LOAD 0x000120 0x00000000aaaa1000 0x00000000aaaa1000 0x000001 0x000001 R E 0x1
+# CHECK-NEXT: LOAD 0x000120 0x00000000aaaa1000 0x00000000bbbb2000 0x000001 0x000001 R E 0x1
+
+--- !ELF
+FileHeader:
+ Class: ELFCLASS64
+ Data: ELFDATA2LSB
+ Type: ET_EXEC
+ Machine: EM_X86_64
+Sections:
+ - Name: .foo
+ Type: SHT_PROGBITS
+ Flags: [ SHF_ALLOC ]
+ Size: 0x1
+ Address: 0x1234
+ProgramHeaders:
+## Show addresses we emit by default for a case when a program header
+## has no sections included.
+ - Type: PT_LOAD
+ Flags: [ PF_X, PF_R ]
+ Sections: []
+## Show addresses we emit by default for a case when a program header
+## includes a section with a virtual address that is explicitly set.
+ - Type: PT_LOAD
+ Flags: [ PF_X, PF_R ]
+ Sections:
+ - Section: .foo
+## Now we have a program header that has a virtual address different from
+## a address of the section included. Show that the default physical address
+## is equal to virtual address.
+ - Type: PT_LOAD
+ Flags: [ PF_X, PF_R ]
+ VAddr: 0xAAAA1000
+ Sections:
+ - Section: .foo
+## Show that we are able to set different virtual and physical addresses.
+ - Type: PT_LOAD
+ Flags: [ PF_X, PF_R ]
+ VAddr: 0xAAAA1000
+ PAddr: 0xBBBB2000
+ Sections:
+ - Section: .foo