Revert "Generate segment padding from ELF-internal offsets"#72
Revert "Generate segment padding from ELF-internal offsets"#72bradjc merged 3 commits intotock:masterfrom
Conversation
This reverts commit d89f703. Ultimately, the underlying issue motivating these changes seems to be a linker bug, as documented in libtock-rs PR tock/libtock-rs#477 [1]. Indeed, we should follow the physical addresses as specified in the ELF file to generate padding, meaning that the previous code was correct. However, there's two invariants which elf2tab should ensure still: - the libtock-rs bug seems to indicate that the section placement in ELF files does not necessarily have to correlate to their physical (load) address. It appears to be valid for ELF files to list sections in an arbitrary order, and thus elf2tab should presumably sort sections by their physical address (intended load address), and then walk them and insert padding as necessary. - the confusing behavior which lead to this incorrect bugfix was that elf2tab generated a very large (> 256MB) TBF. To ensure that this does not happen, we can introduce sanity checks. elf2tab acts as the Tock application loader, by placing apps into memory such that they can be executed in place. This means that the physical address of all LOADed segments must be within the board's FLASH address space. We can have elf2tab issue a warning if there is an excessive amount of space (>= 4kB) between the physical (load) end address of one segment, and the start address of the next. This prevents linker script bugs from creeping into elf2tab undetected, and cause it to blindly generate nonsensical binaries. [1]: tock/libtock-rs#477
|
In addition to reverting the incorrect change, I've inserted two assertions that generate warnings when certain invariants are violated:
Thus, running Running
|
94b4a26 to
7e33b20
Compare
This can happen when iterating over sections which are not placed in physical address order in the ELF file. When this occurs, elf2tab has a chance of producing an incorrect TBF file, which we should warn users about. It can be an indication of an incorrect / broken ELF file, although placing sections in an arbitrary order within an ELF file may well be allowed. This change is deliberately conservative by issuing a warning instead of exiting with an error, to avoid breaking anyone's toolchain. It may be reasonable to sort sections by their physical address in the future, if this is confirmed to be correct behavior.
elf2tab generates TBFs which place ELF sections into flash according to their physical address, thus acting as a flash loader. To ensure that segments end up at their correct flash offset, it may need to insert some padding in between two sections. However, this padding insertion can also mask errors in the ELFs placement constraints. For instance, when the ELF file includes a non-zero sized segment which is specified to be loaded at a non-flash address (e.g. a RAM segment having its PhysAddr == VirtAddr), elf2tab may insert an excessive amount of padding to meet those placement constraints. This generates incorrect TBFs. We issue a warning when encountering such a situation. 4096 bytes is larger than the default ELF segment padding, and thus we assume that applications will likely not require more padding in between their sections. A warning will ensure that developers are made aware of potential issues, and can be directed to this comment, this commit, or the accompanying PR.
7e33b20 to
161bbb2
Compare
This reverts commit d89f703. Ultimately, the underlying issue motivating these changes seems to be a linker bug, as documented in libtock-rs PR tock/libtock-rs#477 1. Indeed, we should follow the physical addresses as specified in the ELF file to generate padding, meaning that the previous code was correct.
However, there's two invariants which elf2tab should ensure still:
the libtock-rs bug seems to indicate that the section placement in ELF files does not necessarily have to correlate to their physical (load) address. It appears to be valid for ELF files to list sections in an arbitrary order, and thus elf2tab should presumably sort sections by their physical address (intended load address), and then walk them and insert padding as necessary.
the confusing behavior which lead to this incorrect bugfix was that elf2tab generated a very large (> 256MB) TBF. To ensure that this does not happen, we can introduce sanity checks.
elf2tab acts as the Tock application loader, by placing apps into memory such that they can be executed in place. This means that the physical address of all LOADed segments must be within the board's FLASH address space. We can have elf2tab issue a warning if there is an excessive amount of space (>= 4kB) between the physical (load) end address of one segment, and the start address of the next. This prevents linker script bugs from creeping into elf2tab undetected, and cause it to blindly generate nonsensical binaries.