Conversation
The linker can put additional data in a segment before a section, but that violates assumptions that our linker files are making. elf2tab requires that data exist within sections, and expects that segments start with sections. Most of the time this requirement is upheld by the linker. However, in the case of VERY small apps, the linker tries to optimize by packing in more in the first segment. This makes the segment start where a section does not. This patch adds logic to check for this discrepency and adjust the segment to remove this (essentially) padding at the beginning of the segment. The rest of elf2tab can then operate as expected.
|
With stack size set to 0, and therefore no .stack section, the output elf looks like: With stack size set to anything else, for example 1, the output elf looks like: The major issue (with the stack=0 version) is this line: The segment is at address When adding any stack, the linker does not put text/crt0 in that first 4k page, and everything is great. |
|
I know I created this PR, but I'm not really sure how to handle this. What if the linker adds some padding at the start of a segment for some reason, and the binary relies on the section starting at that offset? We're telling the linker something like this: and yet its giving us a segment which starts before flash. So, that's a problem, and not clear why it's our fault. This might be the signal that, despite all my effort, we cannot really make elf2tab too agnostic to whether the app is fixed address or not. Because if elf2tab knew that the linker was trying to put content before the start of flash, then it can just ignore that portion, which would fix this issue. We also maybe can't assume that the linker will respect the start of flash. So maybe the key is to also pass |
|
I'm leaning towards closing this in favor of #75 |
The linker can put additional data in a segment before a section, but that violates assumptions that our linker files are making. elf2tab requires that data exist within sections, and expects that segments start with sections.
Most of the time this requirement is upheld by the linker. However, in the case of apps with 0 stack, puts everything in the first page. This makes the segment start where a section does not.
This patch adds logic to check for this discrepancy and adjust the segment to remove this (essentially) padding at the beginning of the segment. The rest of elf2tab can then operate as expected.
Short term fix
The easy fix is to just not have apps with 0 stack. Without this PR or something else like it apps with 0 stack do not work with elf2tab and that is a known bug.