[PATCH] D78005: [yaml2obj] - Reimplement how tool calculates file and memory sizes of segments.

George Rimar via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Mon Apr 13 00:29:50 PDT 2020


grimar created this revision.
grimar added reviewers: jhenderson, MaskRay.
Herald added subscribers: rupprecht, hiraditya, emaste.
Herald added a reviewer: espindola.

We do not calculate the memory size properly, e.g when we have 2 or more
SHT_NOBITS sections at the end of a segment or when we mix SHT_NOBITS
and regular sections.

The simple example is:

  ProgramHeaders:
    - Type:  PT_LOAD
      Flags: [ PF_W, PF_R ]
      Sections:
        - Section: .foo1
        - Section: .foo2
      VAddr: 0x200000000
      Offset: 0x0
  Sections:
    - Name:    .foo1
      Type:    SHT_NOBITS
      Flags:   [ SHF_WRITE, SHF_ALLOC ]
      Size:    0x100
      Address: 0x200000000
    - Name:    .foo2
      Type:    SHT_NOBITS
      Flags:   [ SHF_WRITE, SHF_ALLOC ]
      Size:    0x88

In this case the memory size of the segment should be
0x100 + 0x88 + file offset of the segment (0x78) = 0x200.
But without this patch yaml2obj sets the memory size to 0x178,
because it calculates the memory size as 0x78 + max(0x100, 0x88).

This patch changes the implementation and adds and refines test cases.

I've also introduced a limitation: sections listed for a segment
in the YAML declaration now must be ordered by file offsets.
I think that makes much more sense.


https://reviews.llvm.org/D78005

Files:
  llvm/lib/ObjectYAML/ELFEmitter.cpp
  llvm/test/Object/invalid.test
  llvm/test/tools/llvm-gsymutil/X86/elf-dwarf.yaml
  llvm/test/tools/llvm-readobj/ELF/demangle.test
  llvm/test/tools/llvm-readobj/ELF/gnu-notes.test
  llvm/test/tools/llvm-readobj/ELF/hash-symbols.test
  llvm/test/tools/llvm-readobj/ELF/reloc-negative-addend-no-sym.test
  llvm/test/tools/llvm-readobj/ELF/reloc-zero-name-or-value.test
  llvm/test/tools/obj2yaml/program-headers.yaml
  llvm/test/tools/yaml2obj/ELF/program-header-nobits.yaml
  llvm/test/tools/yaml2obj/ELF/program-header-size-offset.yaml

-------------- next part --------------
A non-text attachment was scrubbed...
Name: D78005.256933.patch
Type: text/x-patch
Size: 17139 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20200413/854b1e86/attachment-0001.bin>


More information about the llvm-commits mailing list