[yaml2obj] - Set a default value for `PAddr` property of a program header to a value...
authorGeorgii Rymar <grimar@accesssoftek.com>
Fri, 13 Mar 2020 13:31:16 +0000 (16:31 +0300)
committerGeorgii Rymar <grimar@accesssoftek.com>
Sat, 14 Mar 2020 14:44:57 +0000 (17:44 +0300)
`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

38 files changed:
llvm/lib/ObjectYAML/ELFYAML.cpp
llvm/test/tools/llvm-elfabi/binary-read-add-soname.test
llvm/test/tools/llvm-elfabi/binary-read-arch.test
llvm/test/tools/llvm-elfabi/binary-read-bad-soname.test
llvm/test/tools/llvm-elfabi/binary-read-bad-vaddr.test
llvm/test/tools/llvm-elfabi/binary-read-neededlibs-bad-offset.test
llvm/test/tools/llvm-elfabi/binary-read-neededlibs.test
llvm/test/tools/llvm-elfabi/binary-read-no-dt-strsz.test
llvm/test/tools/llvm-elfabi/binary-read-no-dt-strtab.test
llvm/test/tools/llvm-elfabi/binary-read-replace-soname.test
llvm/test/tools/llvm-elfabi/binary-read-soname-no-null.test
llvm/test/tools/llvm-elfabi/binary-read-soname.test
llvm/test/tools/llvm-gsymutil/X86/elf-dwarf.yaml
llvm/test/tools/llvm-objcopy/ELF/add-symbol.test
llvm/test/tools/llvm-objcopy/ELF/binary-first-seg-offset-zero.test
llvm/test/tools/llvm-objcopy/ELF/binary-paddr.test
llvm/test/tools/llvm-objcopy/ELF/binary-remove-all-but-one.test
llvm/test/tools/llvm-objcopy/ELF/binary-remove-end.test
llvm/test/tools/llvm-objcopy/ELF/binary-remove-middle.test
llvm/test/tools/llvm-objcopy/ELF/check-addr-offset-align-binary.test
llvm/test/tools/llvm-objcopy/ELF/check-addr-offset-align.test
llvm/test/tools/llvm-objcopy/ELF/empty-section.test
llvm/test/tools/llvm-objcopy/ELF/marker-segment.test
llvm/test/tools/llvm-objcopy/ELF/only-keep-debug.test
llvm/test/tools/llvm-objcopy/ELF/parent-loop-check.test
llvm/test/tools/llvm-objcopy/ELF/preserve-segment-contents.test
llvm/test/tools/llvm-objcopy/ELF/segment-shift-section-remove.test
llvm/test/tools/llvm-objcopy/ELF/segment-shift.test
llvm/test/tools/llvm-objcopy/ELF/two-seg-remove-end.test
llvm/test/tools/llvm-objcopy/ELF/two-seg-remove-first.test
llvm/test/tools/llvm-objcopy/ELF/two-seg-remove-third-sec.test
llvm/test/tools/llvm-objdump/X86/phdrs-lma2.test
llvm/test/tools/llvm-readobj/ELF/demangle.test
llvm/test/tools/llvm-readobj/ELF/hash-symbols.test
llvm/test/tools/llvm-readobj/ELF/loadname.test
llvm/test/tools/yaml2obj/ELF/custom-fill.yaml
llvm/test/tools/yaml2obj/ELF/dynamic-section-i386.yaml
llvm/test/tools/yaml2obj/ELF/program-header-address.yaml [new file with mode: 0644]

index 55589a9..d567153 100644 (file)
@@ -848,7 +848,7 @@ void MappingTraits<ELFYAML::ProgramHeader>::mapping(
   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);
index e5d0860..6539178 100644 (file)
@@ -33,7 +33,6 @@ ProgramHeaders:
   - Type: PT_LOAD
     Flags: [ PF_R ]
     VAddr: 0x0000
-    PAddr: 0x0000
     Align: 8
     Sections:
       - Section: .dynstr
@@ -41,7 +40,6 @@ ProgramHeaders:
   - Type: PT_DYNAMIC
     Flags: [ PF_X, PF_R ]
     VAddr: 0x0008
-    PAddr: 0x0008
     Sections:
       - Section: .dynamic
 
index 1fea6eb..84c331b 100644 (file)
@@ -33,7 +33,6 @@ ProgramHeaders:
   - Type: PT_LOAD
     Flags: [ PF_R ]
     VAddr: 0x0000
-    PAddr: 0x0000
     Align: 8
     Sections:
       - Section: .dynstr
@@ -41,7 +40,6 @@ ProgramHeaders:
   - Type: PT_DYNAMIC
     Flags: [ PF_X, PF_R ]
     VAddr: 0x0008
-    PAddr: 0x0008
     Sections:
       - Section: .dynamic
 
index 0a1f9d9..e555c6f 100644 (file)
@@ -35,7 +35,6 @@ ProgramHeaders:
   - Type: PT_LOAD
     Flags: [ PF_R ]
     VAddr: 0x0000
-    PAddr: 0x0000
     Align: 8
     Sections:
       - Section: .dynstr
@@ -43,7 +42,6 @@ ProgramHeaders:
   - Type: PT_DYNAMIC
     Flags: [ PF_X, PF_R ]
     VAddr: 0x0008
-    PAddr: 0x0008
     Sections:
       - Section: .dynamic
 
index dfdc0e6..fa71305 100644 (file)
@@ -35,7 +35,6 @@ ProgramHeaders:
   - Type: PT_LOAD
     Flags: [ PF_R ]
     VAddr: 0x1000
-    PAddr: 0x1000
     Align: 8
     Sections:
       - Section: .dynstr
@@ -43,7 +42,6 @@ ProgramHeaders:
   - Type: PT_DYNAMIC
     Flags: [ PF_X, PF_R ]
     VAddr: 0x1008
-    PAddr: 0x1008
     Sections:
       - Section: .dynamic
 
index bb83221..2acdf5b 100644 (file)
@@ -39,7 +39,6 @@ ProgramHeaders:
   - Type: PT_LOAD
     Flags: [ PF_R ]
     VAddr: 0x1000
-    PAddr: 0x1000
     Align: 8
     Sections:
       - Section: .dynstr
@@ -47,7 +46,6 @@ ProgramHeaders:
   - Type: PT_DYNAMIC
     Flags: [ PF_X, PF_R ]
     VAddr: 0x1024
-    PAddr: 0x1024
     Sections:
 
 # CHECK: DT_NEEDED string offset (0x000000000000ffff) outside of dynamic string table
index 09567e0..8914cae 100644 (file)
@@ -38,7 +38,6 @@ ProgramHeaders:
   - Type: PT_LOAD
     Flags: [ PF_R ]
     VAddr: 0x1000
-    PAddr: 0x1000
     Align: 8
     Sections:
       - Section: .dynstr
@@ -46,7 +45,6 @@ ProgramHeaders:
   - Type: PT_DYNAMIC
     Flags: [ PF_X, PF_R ]
     VAddr: 0x1024
-    PAddr: 0x1024
     Sections:
 
 # CHECK:      NeededLibs:
index cf4561e..643b814 100644 (file)
@@ -30,7 +30,6 @@ ProgramHeaders:
   - Type: PT_LOAD
     Flags: [ PF_R ]
     VAddr: 0x0000
-    PAddr: 0x0000
     Align: 8
     Sections:
       - Section: .dynstr
@@ -38,7 +37,6 @@ ProgramHeaders:
   - Type: PT_DYNAMIC
     Flags: [ PF_X, PF_R ]
     VAddr: 0x0008
-    PAddr: 0x0008
     Sections:
       - Section: .dynamic
 
index 315aae3..699c60c 100644 (file)
@@ -29,7 +29,6 @@ ProgramHeaders:
   - Type: PT_LOAD
     Flags: [ PF_R ]
     VAddr: 0x0000
-    PAddr: 0x0000
     Align: 8
     Sections:
       - Section: .dynstr
@@ -37,7 +36,6 @@ ProgramHeaders:
   - Type: PT_DYNAMIC
     Flags: [ PF_X, PF_R ]
     VAddr: 0x0008
-    PAddr: 0x0008
     Sections:
       - Section: .dynamic
 
index 4e6c1f7..c8e592f 100644 (file)
@@ -37,7 +37,6 @@ ProgramHeaders:
   - Type: PT_LOAD
     Flags: [ PF_R ]
     VAddr: 0x1000
-    PAddr: 0x1000
     Align: 8
     Sections:
       - Section: .dynstr
@@ -45,7 +44,6 @@ ProgramHeaders:
   - Type: PT_DYNAMIC
     Flags: [ PF_X, PF_R ]
     VAddr: 0x1018
-    PAddr: 0x1018
     Sections:
       - Section: .dynamic
 
index 099b574..8c499c9 100644 (file)
@@ -36,7 +36,6 @@ ProgramHeaders:
   - Type: PT_LOAD
     Flags: [ PF_R ]
     VAddr: 0x1000
-    PAddr: 0x1000
     Align: 8
     Sections:
       - Section: .dynstr
@@ -44,7 +43,6 @@ ProgramHeaders:
   - Type: PT_DYNAMIC
     Flags: [ PF_X, PF_R ]
     VAddr: 0x1018
-    PAddr: 0x1018
     Sections:
       - Section: .dynamic
 
index 960cc65..5b67ada 100644 (file)
@@ -36,7 +36,6 @@ ProgramHeaders:
   - Type: PT_LOAD
     Flags: [ PF_R ]
     VAddr: 0x1000
-    PAddr: 0x1000
     Align: 8
     Sections:
       - Section: .dynstr
@@ -44,7 +43,6 @@ ProgramHeaders:
   - Type: PT_DYNAMIC
     Flags: [ PF_X, PF_R ]
     VAddr: 0x1018
-    PAddr: 0x1018
     Sections:
       - Section: .dynamic
 
index fe696e4..0fb56a5 100644 (file)
@@ -388,7 +388,6 @@ ProgramHeaders:
   - Type: PT_LOAD
     Flags: [ PF_X, PF_R ]
     VAddr: 0x0000000000400000
-    PAddr: 0x0000000000400000
     Align: 1024
     Sections:
       - Section: .interp
index a9002d4..8950894 100644 (file)
@@ -47,14 +47,12 @@ ProgramHeaders:
   - 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
index 2f04d64..9af417f 100644 (file)
@@ -26,7 +26,6 @@ ProgramHeaders:
   - Type: PT_LOAD
     Flags: [ PF_R ]
     VAddr: 0x1000
-    PAddr: 0x1000
     Sections:
       - Section: .note
       - Section: .rodata
index 5ac692d..fd78d43 100644 (file)
@@ -127,6 +127,5 @@ ProgramHeaders:
   - Type: PT_LOAD
     Flags: [ PF_R, PF_W ]
     VAddr: 0x3000
-    PAddr: 0x3000
     Sections:
       - Section: .data
index 857b76d..1336b7d 100644 (file)
@@ -35,7 +35,6 @@ ProgramHeaders:
   - Type: PT_LOAD
     Flags: [ PF_R ]
     VAddr: 0x1000
-    PAddr: 0x1000
     Sections:
       - Section: .text
       - Section: .text2
index eddeaf1..d9f2752 100644 (file)
@@ -35,7 +35,6 @@ ProgramHeaders:
   - Type: PT_LOAD
     Flags: [ PF_R ]
     VAddr: 0x1000
-    PAddr: 0x1000
     Sections:
       - Section: .text
       - Section: .text2
index fbc2f6a..4ed3ca6 100644 (file)
@@ -35,7 +35,6 @@ ProgramHeaders:
   - Type: PT_LOAD
     Flags: [ PF_R ]
     VAddr: 0x1000
-    PAddr: 0x1000
     Sections:
       - Section: .text
       - Section: .text2
index 6d4cb1b..c36f812 100644 (file)
@@ -25,14 +25,12 @@ ProgramHeaders:
   - 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
index bc219ff..54c65ce 100644 (file)
@@ -25,14 +25,12 @@ ProgramHeaders:
   - 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
index 3ad1b7c..25c6c45 100644 (file)
@@ -81,13 +81,11 @@ Sections:
 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
index 548def4..f52f9fb 100644 (file)
@@ -32,26 +32,22 @@ ProgramHeaders:
   - 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
index 8f21bce..4d202ed 100644 (file)
@@ -21,9 +21,9 @@
 
 # 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.
 
@@ -136,9 +136,9 @@ ProgramHeaders:
 
 ## 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:
index b3b48c9..bdd82af 100644 (file)
@@ -36,14 +36,12 @@ ProgramHeaders:
   - 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
 
index f54e832..5555a42 100644 (file)
@@ -313,7 +313,6 @@ ProgramHeaders:
   # First segment has unlabelled space at start and end.
   - Type:  0x6ABCDEF0 # Non-specific segment type.
     VAddr: 0x2000
-    PAddr: 0x2000
     Align: 0x2000
     Sections:
       - Section: blob1
@@ -326,7 +325,6 @@ ProgramHeaders:
   # Second segment has sections at start and end.
   - Type:  0x6ABCDEF0
     VAddr: 0x2100
-    PAddr: 0x2100
     Align: 0x100
     Sections:
       - Section: section4
@@ -335,28 +333,24 @@ ProgramHeaders:
   # 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
@@ -379,24 +373,20 @@ ProgramHeaders:
   # 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
@@ -404,7 +394,6 @@ ProgramHeaders:
   # 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
@@ -414,7 +403,6 @@ ProgramHeaders:
   # 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:
@@ -422,7 +410,6 @@ ProgramHeaders:
   # Thirteenth segment contains overlaps sections at either end in parent segment.
   - Type:     0x6ABCDEF0
     VAddr:    0x303A
-    PAddr:    0x303A
     Offset:   0x303A
     FileSize: 0x8
     Sections:
@@ -434,13 +421,11 @@ ProgramHeaders:
   # 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
@@ -450,13 +435,11 @@ ProgramHeaders:
   # Segment17:    |--|----unlabelled---|
   - Type:  0x6ABCDEF0
     VAddr: 0x400C
-    PAddr: 0x400C
     FileSize: 6
     Sections:
       - Section: sectiony
   - Type:   0x6ABCDEF0
     VAddr:  0x400E
-    PAddr:  0x400E
     Offset: 0x400E
     Sections:
       - Section: blobx
@@ -465,13 +448,11 @@ ProgramHeaders:
   # 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
@@ -480,12 +461,10 @@ ProgramHeaders:
   # Segment21:    |--|-unlabelled-|-Sec-|
   - Type:  0x6ABCDEF0
     VAddr: 0x4020
-    PAddr: 0x4020
     Sections:
       - Section: sectionw
   - Type:   0x6ABCDEF0
     VAddr:  0x4022
-    PAddr:  0x4022
     Offset: 0x4022
     Sections:
       - Section: blobu
@@ -495,12 +474,10 @@ ProgramHeaders:
   # Segment23:    |--|-Sec-|
   - Type:  0x6ABCDEF0
     VAddr: 0x402C
-    PAddr: 0x402C
     Sections:
       - Section: sectionu
   - Type:   0x6ABCDEF0
     VAddr:  0x402E
-    PAddr:  0x402E
     Offset: 0x402E
     Sections:
       - Section: sectiont
@@ -509,13 +486,11 @@ ProgramHeaders:
   # Segment25:              |--Sec--|
   - Type:  0x6ABCDEF0
     VAddr: 0x4034
-    PAddr: 0x4034
     FileSize: 6
     Sections:
       - Section: blobt
   - Type:  0x6ABCDEF0
     VAddr: 0x4038
-    PAddr: 0x4038
     Sections:
       - Section: sections
 
@@ -527,7 +502,6 @@ ProgramHeaders:
   # Segment28:              |-Sec-|------------|
   - Type:  0x6ABCDEF0
     VAddr: 0x5000
-    PAddr: 0x5000
     Align: 0x1000
     Sections:
       - Section: bloba
@@ -535,13 +509,11 @@ ProgramHeaders:
       - Section: blobb
   - Type:  0x6ABCDEF0
     VAddr: 0x5000
-    PAddr: 0x5000
     FileSize: 6
     Sections:
       - Section: bloba
   - Type:  0x6ABCDEF0
     VAddr: 0x5004
-    PAddr: 0x5004
     Sections:
       - Section: sectiona
       - Section: blobb
@@ -551,20 +523,17 @@ ProgramHeaders:
   # 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
@@ -574,20 +543,17 @@ ProgramHeaders:
   # 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
@@ -597,20 +563,17 @@ ProgramHeaders:
   # 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
@@ -620,20 +583,17 @@ ProgramHeaders:
   # 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
index 9a50a10..7a9f4cd 100644 (file)
@@ -31,13 +31,11 @@ ProgramHeaders:
   - 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),
index b4caa19..303edaf 100644 (file)
@@ -31,13 +31,11 @@ ProgramHeaders:
   - 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
 
index 20c2689..2ad3a76 100644 (file)
@@ -42,14 +42,12 @@ ProgramHeaders:
   - 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
index a541fc6..6b58363 100644 (file)
@@ -42,14 +42,12 @@ ProgramHeaders:
   - 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
index 254273d..54eef26 100644 (file)
@@ -42,14 +42,12 @@ ProgramHeaders:
   - 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
index ead250e..a8f3e2c 100644 (file)
@@ -48,13 +48,11 @@ ProgramHeaders:
   - 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
index 230ba92..46ea48f 100644 (file)
@@ -212,7 +212,6 @@ ProgramHeaders:
   - Type:  PT_LOAD
     Flags: [ PF_R, PF_X ]
     VAddr: 0x0
-    PAddr: 0x0
     Sections:
       - Section: .dynsym
       - Section: .dynstr
@@ -222,6 +221,5 @@ ProgramHeaders:
   - Type:  PT_DYNAMIC
     Flags: [ PF_R ]
     VAddr: 0x1000
-    PAddr: 0x1000
     Sections:
       - Section: .dynamic
index e4515b6..0348444 100644 (file)
@@ -363,7 +363,6 @@ ProgramHeaders:
   - Type:  PT_LOAD
     Flags: [ PF_R, PF_X ]
     VAddr: 0x0
-    PAddr: 0x0
     Sections:
       - Section: .dynsym
       - Section: .dynstr
@@ -372,7 +371,6 @@ ProgramHeaders:
   - Type:  PT_DYNAMIC
     Flags: [ PF_R ]
     VAddr: 0x1000
-    PAddr: 0x1000
     Sections:
       - Section: .dynamic
 
index d12076f..c29ee33 100644 (file)
@@ -44,7 +44,6 @@ ProgramHeaders:
   - Type:  PT_LOAD
     Flags: [ PF_R ]
     VAddr: 0x0000
-    PAddr: 0x0000
     Sections:
       - Section: .dynstr
       - Section: .dynamic
index 8dfc2fd..4d7b91d 100644 (file)
@@ -124,14 +124,12 @@ Sections:
 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
 
index 89f7de6..4d9d5e4 100644 (file)
@@ -31,13 +31,11 @@ ProgramHeaders:
   - 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
diff --git a/llvm/test/tools/yaml2obj/ELF/program-header-address.yaml b/llvm/test/tools/yaml2obj/ELF/program-header-address.yaml
new file mode 100644 (file)
index 0000000..a1e5460
--- /dev/null
@@ -0,0 +1,55 @@
+## 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