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: 0x1000
Offset: 0x0
Sections:
- Name: .foo1
Type: SHT_NOBITS
Flags: [ SHF_WRITE, SHF_ALLOC ]
Size: 0x100
Address: 0x1000
- Name: .foo2
Type: SHT_NOBITS
Flags: [ SHF_WRITE, SHF_ALLOC ]
Size: 0x88In 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 refines the test case.
I'm concerned that if there are multiple sections with the same offset but different sizes, this doesn't enforce a particular ordering. I'm thinking multiple trailing SHT_NOBITS sections here again. There needs to be one or more fallbacks, probably the section address at least.